• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 #ifndef ANDROID_IMEDIAPLAYER_H
18 #define ANDROID_IMEDIAPLAYER_H
19 
20 #include <utils/RefBase.h>
21 #include <binder/IInterface.h>
22 #include <binder/Parcel.h>
23 #include <utils/KeyedVector.h>
24 #include <system/audio.h>
25 
26 #include <media/AudioContainers.h>
27 #include <media/AudioResamplerPublic.h>
28 #include <media/stagefright/MediaSource.h>
29 #include <media/VolumeShaper.h>
30 
31 // Fwd decl to make sure everyone agrees that the scope of struct sockaddr_in is
32 // global, and not in android::
33 struct sockaddr_in;
34 
35 namespace android {
36 
37 class Parcel;
38 class Surface;
39 class IDataSource;
40 struct IStreamSource;
41 class IGraphicBufferProducer;
42 struct IMediaHTTPService;
43 struct AVSyncSettings;
44 struct BufferingSettings;
45 
46 typedef MediaSource::ReadOptions::SeekMode MediaPlayerSeekMode;
47 
48 class IMediaPlayer: public IInterface
49 {
50 public:
51     DECLARE_META_INTERFACE(MediaPlayer);
52 
53     virtual void            disconnect() = 0;
54 
55     virtual status_t        setDataSource(
56             const sp<IMediaHTTPService> &httpService,
57             const char *url,
58             const KeyedVector<String8, String8>* headers) = 0;
59 
60     virtual status_t        setDataSource(int fd, int64_t offset, int64_t length) = 0;
61     virtual status_t        setDataSource(const sp<IStreamSource>& source) = 0;
62     virtual status_t        setDataSource(const sp<IDataSource>& source) = 0;
63     virtual status_t        setDataSource(const String8& rtpParams) = 0;
64     virtual status_t        setVideoSurfaceTexture(
65                                     const sp<IGraphicBufferProducer>& bufferProducer) = 0;
66     virtual status_t        getBufferingSettings(
67                                     BufferingSettings* buffering /* nonnull */) = 0;
68     virtual status_t        setBufferingSettings(const BufferingSettings& buffering) = 0;
69     virtual status_t        prepareAsync() = 0;
70     virtual status_t        start() = 0;
71     virtual status_t        stop() = 0;
72     virtual status_t        pause() = 0;
73     virtual status_t        isPlaying(bool* state) = 0;
74     virtual status_t        setPlaybackSettings(const AudioPlaybackRate& rate) = 0;
75     virtual status_t        getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */) = 0;
76     virtual status_t        setSyncSettings(const AVSyncSettings& sync, float videoFpsHint) = 0;
77     virtual status_t        getSyncSettings(AVSyncSettings* sync /* nonnull */,
78                                             float* videoFps /* nonnull */) = 0;
79     virtual status_t        seekTo(
80             int msec,
81             MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) = 0;
82     virtual status_t        getCurrentPosition(int* msec) = 0;
83     virtual status_t        getDuration(int* msec) = 0;
84     virtual status_t        notifyAt(int64_t mediaTimeUs) = 0;
85     virtual status_t        reset() = 0;
86     virtual status_t        setAudioStreamType(audio_stream_type_t type) = 0;
87     virtual status_t        setLooping(int loop) = 0;
88     virtual status_t        setVolume(float leftVolume, float rightVolume) = 0;
89     virtual status_t        setAuxEffectSendLevel(float level) = 0;
90     virtual status_t        attachAuxEffect(int effectId) = 0;
91     virtual status_t        setParameter(int key, const Parcel& request) = 0;
92     virtual status_t        getParameter(int key, Parcel* reply) = 0;
93     virtual status_t        setRetransmitEndpoint(const struct sockaddr_in* endpoint) = 0;
94     virtual status_t        getRetransmitEndpoint(struct sockaddr_in* endpoint) = 0;
95     virtual status_t        setNextPlayer(const sp<IMediaPlayer>& next) = 0;
96 
97     virtual media::VolumeShaper::Status applyVolumeShaper(
98                                     const sp<media::VolumeShaper::Configuration>& configuration,
99                                     const sp<media::VolumeShaper::Operation>& operation) = 0;
100     virtual sp<media::VolumeShaper::State> getVolumeShaperState(int id) = 0;
101 
102     // Modular DRM
103     virtual status_t        prepareDrm(const uint8_t uuid[16],
104                                     const Vector<uint8_t>& drmSessionId) = 0;
105     virtual status_t        releaseDrm() = 0;
106 
107     // Invoke a generic method on the player by using opaque parcels
108     // for the request and reply.
109     // @param request Parcel that must start with the media player
110     // interface token.
111     // @param[out] reply Parcel to hold the reply data. Cannot be null.
112     // @return OK if the invocation was made successfully.
113     virtual status_t        invoke(const Parcel& request, Parcel *reply) = 0;
114 
115     // Set a new metadata filter.
116     // @param filter A set of allow and drop rules serialized in a Parcel.
117     // @return OK if the invocation was made successfully.
118     virtual status_t        setMetadataFilter(const Parcel& filter) = 0;
119 
120     // Retrieve a set of metadata.
121     // @param update_only Include only the metadata that have changed
122     //                    since the last invocation of getMetadata.
123     //                    The set is built using the unfiltered
124     //                    notifications the native player sent to the
125     //                    MediaPlayerService during that period of
126     //                    time. If false, all the metadatas are considered.
127     // @param apply_filter If true, once the metadata set has been built based
128     //                     on the value update_only, the current filter is
129     //                     applied.
130     // @param[out] metadata On exit contains a set (possibly empty) of metadata.
131     //                      Valid only if the call returned OK.
132     // @return OK if the invocation was made successfully.
133     virtual status_t        getMetadata(bool update_only,
134                                         bool apply_filter,
135                                         Parcel *metadata) = 0;
136 
137     // AudioRouting
138     virtual status_t        setOutputDevice(audio_port_handle_t deviceId) = 0;
139     virtual status_t        getRoutedDeviceIds(DeviceIdVector& deviceIds) = 0;
140     virtual status_t        enableAudioDeviceCallback(bool enabled) = 0;
141 protected:
142 
143     friend class IMediaPlayerTest;
144     enum {
145         DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
146         SET_DATA_SOURCE_URL,
147         SET_DATA_SOURCE_FD,
148         SET_DATA_SOURCE_STREAM,
149         SET_DATA_SOURCE_CALLBACK,
150         SET_DATA_SOURCE_RTP,
151         SET_BUFFERING_SETTINGS,
152         GET_BUFFERING_SETTINGS,
153         PREPARE_ASYNC,
154         START,
155         STOP,
156         IS_PLAYING,
157         SET_PLAYBACK_SETTINGS,
158         GET_PLAYBACK_SETTINGS,
159         SET_SYNC_SETTINGS,
160         GET_SYNC_SETTINGS,
161         PAUSE,
162         SEEK_TO,
163         GET_CURRENT_POSITION,
164         GET_DURATION,
165         RESET,
166         NOTIFY_AT,
167         SET_AUDIO_STREAM_TYPE,
168         SET_LOOPING,
169         SET_VOLUME,
170         INVOKE,
171         SET_METADATA_FILTER,
172         GET_METADATA,
173         SET_AUX_EFFECT_SEND_LEVEL,
174         ATTACH_AUX_EFFECT,
175         SET_VIDEO_SURFACETEXTURE,
176         SET_PARAMETER,
177         GET_PARAMETER,
178         SET_RETRANSMIT_ENDPOINT,
179         GET_RETRANSMIT_ENDPOINT,
180         SET_NEXT_PLAYER,
181         APPLY_VOLUME_SHAPER,
182         GET_VOLUME_SHAPER_STATE,
183         // Modular DRM
184         PREPARE_DRM,
185         RELEASE_DRM,
186         // AudioRouting
187         SET_OUTPUT_DEVICE,
188         GET_ROUTED_DEVICE_IDS,
189         ENABLE_AUDIO_DEVICE_CALLBACK,
190     };
191 };
192 
193 // ----------------------------------------------------------------------------
194 
195 class BnMediaPlayer: public BnInterface<IMediaPlayer>
196 {
197 public:
198     virtual status_t    onTransact( uint32_t code,
199                                     const Parcel& data,
200                                     Parcel* reply,
201                                     uint32_t flags = 0);
202 };
203 
204 }; // namespace android
205 
206 #endif // ANDROID_IMEDIAPLAYER_H
207