blob: 3b0b4e99917d8b12ab303e0a55ab53ddb0d5505b [file] [log] [blame]
Jean-Michel Trivi63189322017-01-05 18:05:28 -08001/*
2**
3** Copyright 2017, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IPlayer"
19//#define LOG_NDEBUG 0
20#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
25#include <binder/Parcel.h>
26
27#include <audiomanager/IPlayer.h>
28
29namespace android {
30
31enum {
32 START = IBinder::FIRST_CALL_TRANSACTION,
33 PAUSE = IBinder::FIRST_CALL_TRANSACTION + 1,
34 STOP = IBinder::FIRST_CALL_TRANSACTION + 2,
35 SET_VOLUME = IBinder::FIRST_CALL_TRANSACTION + 3,
36};
37
38class BpPlayer : public BpInterface<IPlayer>
39{
40public:
41 explicit BpPlayer(const sp<IBinder>& impl)
42 : BpInterface<IPlayer>(impl)
43 {
44 }
45
46 virtual void start()
47 {
48 Parcel data, reply;
49 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
50 remote()->transact(START, data, &reply);
51 }
52
53 virtual void pause()
54 {
55 Parcel data, reply;
56 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
57 remote()->transact(PAUSE, data, &reply);
58 }
59
60 virtual void stop()
61 {
62 Parcel data, reply;
63 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
64 remote()->transact(STOP, data, &reply);
65 }
66
67 virtual void setVolume(float vol)
68 {
69 Parcel data, reply;
70 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
71 data.writeFloat(vol);
72 remote()->transact(SET_VOLUME, data, &reply);
73 }
74};
75
76IMPLEMENT_META_INTERFACE(Player, "android.media.IPlayer");
77
78// ----------------------------------------------------------------------
79
80status_t BnPlayer::onTransact(
81 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
82{
83 switch (code) {
84 case START: {
85 CHECK_INTERFACE(IPlayer, data, reply);
86 start();
87 return NO_ERROR;
88 } break;
89 case PAUSE: {
90 CHECK_INTERFACE(IPlayer, data, reply);
91 pause();
92 return NO_ERROR;
93 }
94 case STOP: {
95 CHECK_INTERFACE(IPlayer, data, reply);
96 stop();
97 return NO_ERROR;
98 } break;
99 case SET_VOLUME: {
100 CHECK_INTERFACE(IPlayer, data, reply);
101 setVolume(data.readFloat());
102 return NO_ERROR;
103 }
104 default:
105 return BBinder::onTransact(code, data, reply, flags);
106 }
107}
108
109} // namespace android