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