The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* mediaplayer.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, 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_NDEBUG 0 |
| 19 | #define LOG_TAG "MediaPlayer" |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include <sys/types.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <unistd.h> |
| 25 | #include <fcntl.h> |
| 26 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 27 | #include <binder/IServiceManager.h> |
| 28 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 30 | #include <gui/SurfaceTextureClient.h> |
| 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include <media/mediaplayer.h> |
| 33 | #include <media/AudioTrack.h> |
| 34 | |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 | #include <surfaceflinger/Surface.h> |
| 36 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 37 | #include <binder/MemoryBase.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 39 | #include <utils/KeyedVector.h> |
| 40 | #include <utils/String8.h> |
| 41 | |
Dima Zavin | 34bb419 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 42 | #include <system/audio.h> |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 43 | #include <system/window.h> |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 44 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | namespace android { |
| 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | MediaPlayer::MediaPlayer() |
| 48 | { |
| 49 | LOGV("constructor"); |
| 50 | mListener = NULL; |
| 51 | mCookie = NULL; |
| 52 | mDuration = -1; |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 53 | mStreamType = AUDIO_STREAM_MUSIC; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | mCurrentPosition = -1; |
| 55 | mSeekPosition = -1; |
| 56 | mCurrentState = MEDIA_PLAYER_IDLE; |
| 57 | mPrepareSync = false; |
| 58 | mPrepareStatus = NO_ERROR; |
| 59 | mLoop = false; |
| 60 | mLeftVolume = mRightVolume = 1.0; |
| 61 | mVideoWidth = mVideoHeight = 0; |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 62 | mLockThreadId = 0; |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 63 | mAudioSessionId = AudioSystem::newAudioSessionId(); |
Eric Laurent | b3bdf3f | 2010-10-07 18:23:03 -0700 | [diff] [blame] | 64 | mSendLevel = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | } |
| 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | MediaPlayer::~MediaPlayer() |
| 68 | { |
| 69 | LOGV("destructor"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | disconnect(); |
| 71 | IPCThreadState::self()->flushCommands(); |
| 72 | } |
| 73 | |
| 74 | void MediaPlayer::disconnect() |
| 75 | { |
| 76 | LOGV("disconnect"); |
| 77 | sp<IMediaPlayer> p; |
| 78 | { |
| 79 | Mutex::Autolock _l(mLock); |
| 80 | p = mPlayer; |
| 81 | mPlayer.clear(); |
| 82 | } |
| 83 | |
| 84 | if (p != 0) { |
| 85 | p->disconnect(); |
| 86 | } |
Jamie Gennis | 5129b68 | 2011-07-19 14:50:43 -0700 | [diff] [blame] | 87 | |
| 88 | disconnectNativeWindow(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // always call with lock held |
| 92 | void MediaPlayer::clear_l() |
| 93 | { |
| 94 | mDuration = -1; |
| 95 | mCurrentPosition = -1; |
| 96 | mSeekPosition = -1; |
| 97 | mVideoWidth = mVideoHeight = 0; |
| 98 | } |
| 99 | |
| 100 | status_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener) |
| 101 | { |
| 102 | LOGV("setListener"); |
| 103 | Mutex::Autolock _l(mLock); |
| 104 | mListener = listener; |
| 105 | return NO_ERROR; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | status_t MediaPlayer::setDataSource(const sp<IMediaPlayer>& player) |
| 110 | { |
| 111 | status_t err = UNKNOWN_ERROR; |
| 112 | sp<IMediaPlayer> p; |
| 113 | { // scope for the lock |
| 114 | Mutex::Autolock _l(mLock); |
| 115 | |
Marco Nelissen | e44b41b | 2010-03-10 10:53:16 -0800 | [diff] [blame] | 116 | if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) || |
| 117 | (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | LOGE("setDataSource called in state %d", mCurrentState); |
| 119 | return INVALID_OPERATION; |
| 120 | } |
| 121 | |
| 122 | clear_l(); |
| 123 | p = mPlayer; |
| 124 | mPlayer = player; |
| 125 | if (player != 0) { |
| 126 | mCurrentState = MEDIA_PLAYER_INITIALIZED; |
| 127 | err = NO_ERROR; |
| 128 | } else { |
| 129 | LOGE("Unable to to create media player"); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (p != 0) { |
| 134 | p->disconnect(); |
| 135 | } |
| 136 | |
| 137 | return err; |
| 138 | } |
| 139 | |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 140 | status_t MediaPlayer::setDataSource( |
| 141 | const char *url, const KeyedVector<String8, String8> *headers) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | { |
| 143 | LOGV("setDataSource(%s)", url); |
| 144 | status_t err = BAD_VALUE; |
| 145 | if (url != NULL) { |
| 146 | const sp<IMediaPlayerService>& service(getMediaPlayerService()); |
| 147 | if (service != 0) { |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 148 | sp<IMediaPlayer> player( |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 149 | service->create(getpid(), this, url, headers, mAudioSessionId)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | err = setDataSource(player); |
| 151 | } |
| 152 | } |
| 153 | return err; |
| 154 | } |
| 155 | |
| 156 | status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length) |
| 157 | { |
| 158 | LOGV("setDataSource(%d, %lld, %lld)", fd, offset, length); |
| 159 | status_t err = UNKNOWN_ERROR; |
| 160 | const sp<IMediaPlayerService>& service(getMediaPlayerService()); |
| 161 | if (service != 0) { |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 162 | sp<IMediaPlayer> player(service->create(getpid(), this, fd, offset, length, mAudioSessionId)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | err = setDataSource(player); |
| 164 | } |
| 165 | return err; |
| 166 | } |
| 167 | |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 168 | status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply) |
| 169 | { |
| 170 | Mutex::Autolock _l(mLock); |
Nicolas Catania | 7bd3d7d | 2010-03-10 10:41:04 -0800 | [diff] [blame] | 171 | const bool hasBeenInitialized = |
| 172 | (mCurrentState != MEDIA_PLAYER_STATE_ERROR) && |
| 173 | ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE); |
| 174 | if ((mPlayer != NULL) && hasBeenInitialized) { |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 175 | LOGV("invoke %d", request.dataSize()); |
| 176 | return mPlayer->invoke(request, reply); |
| 177 | } |
| 178 | LOGE("invoke failed: wrong state %X", mCurrentState); |
| 179 | return INVALID_OPERATION; |
| 180 | } |
| 181 | |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 182 | status_t MediaPlayer::setMetadataFilter(const Parcel& filter) |
| 183 | { |
| 184 | LOGD("setMetadataFilter"); |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 185 | Mutex::Autolock lock(mLock); |
| 186 | if (mPlayer == NULL) { |
Nicolas Catania | b2c6939 | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 187 | return NO_INIT; |
| 188 | } |
| 189 | return mPlayer->setMetadataFilter(filter); |
| 190 | } |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 191 | |
Nicolas Catania | 5d55c71 | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 192 | status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata) |
| 193 | { |
| 194 | LOGD("getMetadata"); |
| 195 | Mutex::Autolock lock(mLock); |
| 196 | if (mPlayer == NULL) { |
| 197 | return NO_INIT; |
| 198 | } |
| 199 | return mPlayer->getMetadata(update_only, apply_filter, metadata); |
| 200 | } |
| 201 | |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 202 | void MediaPlayer::disconnectNativeWindow() { |
| 203 | if (mConnectedWindow != NULL) { |
Mathias Agopian | 982d2da | 2011-07-29 17:55:48 -0700 | [diff] [blame^] | 204 | status_t err = native_window_api_disconnect(mConnectedWindow.get(), |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 205 | NATIVE_WINDOW_API_MEDIA); |
| 206 | |
| 207 | if (err != OK) { |
Mathias Agopian | 982d2da | 2011-07-29 17:55:48 -0700 | [diff] [blame^] | 208 | LOGW("native_window_api_disconnect returned an error: %s (%d)", |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 209 | strerror(-err), err); |
| 210 | } |
| 211 | } |
| 212 | mConnectedWindow.clear(); |
| 213 | } |
| 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | status_t MediaPlayer::setVideoSurface(const sp<Surface>& surface) |
| 216 | { |
| 217 | LOGV("setVideoSurface"); |
| 218 | Mutex::Autolock _l(mLock); |
| 219 | if (mPlayer == 0) return NO_INIT; |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 220 | |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 221 | sp<IBinder> binder(surface == NULL ? NULL : surface->asBinder()); |
| 222 | if (mConnectedWindowBinder == binder) { |
| 223 | return OK; |
| 224 | } |
| 225 | |
| 226 | if (surface != NULL) { |
Mathias Agopian | 982d2da | 2011-07-29 17:55:48 -0700 | [diff] [blame^] | 227 | status_t err = native_window_api_connect(surface.get(), |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 228 | NATIVE_WINDOW_API_MEDIA); |
| 229 | |
| 230 | if (err != OK) { |
James Dong | ce78dc5 | 2011-07-21 17:32:55 -0700 | [diff] [blame] | 231 | LOGE("setVideoSurface failed: %d", err); |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 232 | // Note that we must do the reset before disconnecting from the ANW. |
| 233 | // Otherwise queue/dequeue calls could be made on the disconnected |
| 234 | // ANW, which may result in errors. |
| 235 | reset_l(); |
| 236 | |
| 237 | disconnectNativeWindow(); |
| 238 | |
| 239 | return err; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // Note that we must set the player's new surface before disconnecting the |
| 244 | // old one. Otherwise queue/dequeue calls could be made on the disconnected |
| 245 | // ANW, which may result in errors. |
| 246 | status_t err = mPlayer->setVideoSurface(surface); |
| 247 | |
| 248 | disconnectNativeWindow(); |
| 249 | |
| 250 | mConnectedWindow = surface; |
| 251 | |
| 252 | if (err == OK) { |
| 253 | mConnectedWindowBinder = binder; |
| 254 | } else { |
| 255 | disconnectNativeWindow(); |
| 256 | } |
| 257 | |
| 258 | return err; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Glenn Kasten | cc562a3 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 261 | status_t MediaPlayer::setVideoSurfaceTexture( |
| 262 | const sp<ISurfaceTexture>& surfaceTexture) |
| 263 | { |
| 264 | LOGV("setVideoSurfaceTexture"); |
| 265 | Mutex::Autolock _l(mLock); |
| 266 | if (mPlayer == 0) return NO_INIT; |
| 267 | |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 268 | sp<IBinder> binder(surfaceTexture == NULL ? NULL : |
| 269 | surfaceTexture->asBinder()); |
| 270 | if (mConnectedWindowBinder == binder) { |
| 271 | return OK; |
| 272 | } |
| 273 | |
| 274 | sp<ANativeWindow> anw; |
| 275 | if (surfaceTexture != NULL) { |
| 276 | anw = new SurfaceTextureClient(surfaceTexture); |
Mathias Agopian | 982d2da | 2011-07-29 17:55:48 -0700 | [diff] [blame^] | 277 | status_t err = native_window_api_connect(anw.get(), |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 278 | NATIVE_WINDOW_API_MEDIA); |
| 279 | |
| 280 | if (err != OK) { |
James Dong | ce78dc5 | 2011-07-21 17:32:55 -0700 | [diff] [blame] | 281 | LOGE("setVideoSurfaceTexture failed: %d", err); |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 282 | // Note that we must do the reset before disconnecting from the ANW. |
| 283 | // Otherwise queue/dequeue calls could be made on the disconnected |
| 284 | // ANW, which may result in errors. |
| 285 | reset_l(); |
| 286 | |
| 287 | disconnectNativeWindow(); |
| 288 | |
| 289 | return err; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | // Note that we must set the player's new SurfaceTexture before |
| 294 | // disconnecting the old one. Otherwise queue/dequeue calls could be made |
| 295 | // on the disconnected ANW, which may result in errors. |
| 296 | status_t err = mPlayer->setVideoSurfaceTexture(surfaceTexture); |
| 297 | |
| 298 | disconnectNativeWindow(); |
| 299 | |
| 300 | mConnectedWindow = anw; |
| 301 | |
| 302 | if (err == OK) { |
| 303 | mConnectedWindowBinder = binder; |
| 304 | } else { |
| 305 | disconnectNativeWindow(); |
| 306 | } |
| 307 | |
| 308 | return err; |
Glenn Kasten | cc562a3 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 309 | } |
| 310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | // must call with lock held |
| 312 | status_t MediaPlayer::prepareAsync_l() |
| 313 | { |
| 314 | if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) { |
| 315 | mPlayer->setAudioStreamType(mStreamType); |
| 316 | mCurrentState = MEDIA_PLAYER_PREPARING; |
| 317 | return mPlayer->prepareAsync(); |
| 318 | } |
| 319 | LOGE("prepareAsync called in state %d", mCurrentState); |
| 320 | return INVALID_OPERATION; |
| 321 | } |
| 322 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 323 | // TODO: In case of error, prepareAsync provides the caller with 2 error codes, |
| 324 | // one defined in the Android framework and one provided by the implementation |
| 325 | // that generated the error. The sync version of prepare returns only 1 error |
| 326 | // code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | status_t MediaPlayer::prepare() |
| 328 | { |
| 329 | LOGV("prepare"); |
| 330 | Mutex::Autolock _l(mLock); |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 331 | mLockThreadId = getThreadId(); |
| 332 | if (mPrepareSync) { |
| 333 | mLockThreadId = 0; |
| 334 | return -EALREADY; |
| 335 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | mPrepareSync = true; |
| 337 | status_t ret = prepareAsync_l(); |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 338 | if (ret != NO_ERROR) { |
| 339 | mLockThreadId = 0; |
| 340 | return ret; |
| 341 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | |
| 343 | if (mPrepareSync) { |
| 344 | mSignal.wait(mLock); // wait for prepare done |
| 345 | mPrepareSync = false; |
| 346 | } |
| 347 | LOGV("prepare complete - status=%d", mPrepareStatus); |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 348 | mLockThreadId = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | return mPrepareStatus; |
| 350 | } |
| 351 | |
| 352 | status_t MediaPlayer::prepareAsync() |
| 353 | { |
| 354 | LOGV("prepareAsync"); |
| 355 | Mutex::Autolock _l(mLock); |
| 356 | return prepareAsync_l(); |
| 357 | } |
| 358 | |
| 359 | status_t MediaPlayer::start() |
| 360 | { |
| 361 | LOGV("start"); |
| 362 | Mutex::Autolock _l(mLock); |
| 363 | if (mCurrentState & MEDIA_PLAYER_STARTED) |
| 364 | return NO_ERROR; |
| 365 | if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED | |
| 366 | MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) { |
| 367 | mPlayer->setLooping(mLoop); |
| 368 | mPlayer->setVolume(mLeftVolume, mRightVolume); |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 369 | mPlayer->setAuxEffectSendLevel(mSendLevel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | mCurrentState = MEDIA_PLAYER_STARTED; |
| 371 | status_t ret = mPlayer->start(); |
| 372 | if (ret != NO_ERROR) { |
| 373 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 374 | } else { |
| 375 | if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) { |
| 376 | LOGV("playback completed immediately following start()"); |
| 377 | } |
| 378 | } |
| 379 | return ret; |
| 380 | } |
| 381 | LOGE("start called in state %d", mCurrentState); |
| 382 | return INVALID_OPERATION; |
| 383 | } |
| 384 | |
| 385 | status_t MediaPlayer::stop() |
| 386 | { |
| 387 | LOGV("stop"); |
| 388 | Mutex::Autolock _l(mLock); |
| 389 | if (mCurrentState & MEDIA_PLAYER_STOPPED) return NO_ERROR; |
| 390 | if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | |
| 391 | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) ) { |
| 392 | status_t ret = mPlayer->stop(); |
| 393 | if (ret != NO_ERROR) { |
| 394 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 395 | } else { |
| 396 | mCurrentState = MEDIA_PLAYER_STOPPED; |
| 397 | } |
| 398 | return ret; |
| 399 | } |
| 400 | LOGE("stop called in state %d", mCurrentState); |
| 401 | return INVALID_OPERATION; |
| 402 | } |
| 403 | |
| 404 | status_t MediaPlayer::pause() |
| 405 | { |
| 406 | LOGV("pause"); |
| 407 | Mutex::Autolock _l(mLock); |
Marco Nelissen | 465faa9 | 2010-02-26 13:16:23 -0800 | [diff] [blame] | 408 | if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE)) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | return NO_ERROR; |
| 410 | if ((mPlayer != 0) && (mCurrentState & MEDIA_PLAYER_STARTED)) { |
| 411 | status_t ret = mPlayer->pause(); |
| 412 | if (ret != NO_ERROR) { |
| 413 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 414 | } else { |
| 415 | mCurrentState = MEDIA_PLAYER_PAUSED; |
| 416 | } |
| 417 | return ret; |
| 418 | } |
| 419 | LOGE("pause called in state %d", mCurrentState); |
| 420 | return INVALID_OPERATION; |
| 421 | } |
| 422 | |
| 423 | bool MediaPlayer::isPlaying() |
| 424 | { |
| 425 | Mutex::Autolock _l(mLock); |
| 426 | if (mPlayer != 0) { |
| 427 | bool temp = false; |
| 428 | mPlayer->isPlaying(&temp); |
| 429 | LOGV("isPlaying: %d", temp); |
| 430 | if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) { |
| 431 | LOGE("internal/external state mismatch corrected"); |
| 432 | mCurrentState = MEDIA_PLAYER_PAUSED; |
| 433 | } |
| 434 | return temp; |
| 435 | } |
| 436 | LOGV("isPlaying: no active player"); |
| 437 | return false; |
| 438 | } |
| 439 | |
| 440 | status_t MediaPlayer::getVideoWidth(int *w) |
| 441 | { |
| 442 | LOGV("getVideoWidth"); |
| 443 | Mutex::Autolock _l(mLock); |
| 444 | if (mPlayer == 0) return INVALID_OPERATION; |
| 445 | *w = mVideoWidth; |
| 446 | return NO_ERROR; |
| 447 | } |
| 448 | |
| 449 | status_t MediaPlayer::getVideoHeight(int *h) |
| 450 | { |
| 451 | LOGV("getVideoHeight"); |
| 452 | Mutex::Autolock _l(mLock); |
| 453 | if (mPlayer == 0) return INVALID_OPERATION; |
| 454 | *h = mVideoHeight; |
| 455 | return NO_ERROR; |
| 456 | } |
| 457 | |
| 458 | status_t MediaPlayer::getCurrentPosition(int *msec) |
| 459 | { |
| 460 | LOGV("getCurrentPosition"); |
| 461 | Mutex::Autolock _l(mLock); |
| 462 | if (mPlayer != 0) { |
| 463 | if (mCurrentPosition >= 0) { |
| 464 | LOGV("Using cached seek position: %d", mCurrentPosition); |
| 465 | *msec = mCurrentPosition; |
| 466 | return NO_ERROR; |
| 467 | } |
| 468 | return mPlayer->getCurrentPosition(msec); |
| 469 | } |
| 470 | return INVALID_OPERATION; |
| 471 | } |
| 472 | |
| 473 | status_t MediaPlayer::getDuration_l(int *msec) |
| 474 | { |
| 475 | LOGV("getDuration"); |
| 476 | bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE)); |
| 477 | if (mPlayer != 0 && isValidState) { |
| 478 | status_t ret = NO_ERROR; |
| 479 | if (mDuration <= 0) |
| 480 | ret = mPlayer->getDuration(&mDuration); |
| 481 | if (msec) |
| 482 | *msec = mDuration; |
| 483 | return ret; |
| 484 | } |
| 485 | LOGE("Attempt to call getDuration without a valid mediaplayer"); |
| 486 | return INVALID_OPERATION; |
| 487 | } |
| 488 | |
| 489 | status_t MediaPlayer::getDuration(int *msec) |
| 490 | { |
| 491 | Mutex::Autolock _l(mLock); |
| 492 | return getDuration_l(msec); |
| 493 | } |
| 494 | |
| 495 | status_t MediaPlayer::seekTo_l(int msec) |
| 496 | { |
| 497 | LOGV("seekTo %d", msec); |
| 498 | if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) { |
| 499 | if ( msec < 0 ) { |
| 500 | LOGW("Attempt to seek to invalid position: %d", msec); |
| 501 | msec = 0; |
| 502 | } else if ((mDuration > 0) && (msec > mDuration)) { |
| 503 | LOGW("Attempt to seek to past end of file: request = %d, EOF = %d", msec, mDuration); |
| 504 | msec = mDuration; |
| 505 | } |
| 506 | // cache duration |
| 507 | mCurrentPosition = msec; |
| 508 | if (mSeekPosition < 0) { |
| 509 | getDuration_l(NULL); |
| 510 | mSeekPosition = msec; |
| 511 | return mPlayer->seekTo(msec); |
| 512 | } |
| 513 | else { |
| 514 | LOGV("Seek in progress - queue up seekTo[%d]", msec); |
| 515 | return NO_ERROR; |
| 516 | } |
| 517 | } |
| 518 | LOGE("Attempt to perform seekTo in wrong state: mPlayer=%p, mCurrentState=%u", mPlayer.get(), mCurrentState); |
| 519 | return INVALID_OPERATION; |
| 520 | } |
| 521 | |
| 522 | status_t MediaPlayer::seekTo(int msec) |
| 523 | { |
Andreas Huber | effd8d5 | 2009-03-24 20:48:51 -0700 | [diff] [blame] | 524 | mLockThreadId = getThreadId(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | Mutex::Autolock _l(mLock); |
Andreas Huber | effd8d5 | 2009-03-24 20:48:51 -0700 | [diff] [blame] | 526 | status_t result = seekTo_l(msec); |
| 527 | mLockThreadId = 0; |
| 528 | |
| 529 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | } |
| 531 | |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 532 | status_t MediaPlayer::reset_l() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | mLoop = false; |
| 535 | if (mCurrentState == MEDIA_PLAYER_IDLE) return NO_ERROR; |
| 536 | mPrepareSync = false; |
| 537 | if (mPlayer != 0) { |
| 538 | status_t ret = mPlayer->reset(); |
| 539 | if (ret != NO_ERROR) { |
| 540 | LOGE("reset() failed with return code (%d)", ret); |
| 541 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 542 | } else { |
| 543 | mCurrentState = MEDIA_PLAYER_IDLE; |
| 544 | } |
James Dong | c5bba6c | 2010-11-18 12:23:58 -0800 | [diff] [blame] | 545 | // setDataSource has to be called again to create a |
| 546 | // new mediaplayer. |
| 547 | mPlayer = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | return ret; |
| 549 | } |
| 550 | clear_l(); |
| 551 | return NO_ERROR; |
| 552 | } |
| 553 | |
Jamie Gennis | c85ca5d | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 554 | status_t MediaPlayer::reset() |
| 555 | { |
| 556 | LOGV("reset"); |
| 557 | Mutex::Autolock _l(mLock); |
| 558 | return reset_l(); |
| 559 | } |
| 560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | status_t MediaPlayer::setAudioStreamType(int type) |
| 562 | { |
| 563 | LOGV("MediaPlayer::setAudioStreamType"); |
| 564 | Mutex::Autolock _l(mLock); |
| 565 | if (mStreamType == type) return NO_ERROR; |
| 566 | if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | |
| 567 | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) { |
| 568 | // Can't change the stream type after prepare |
| 569 | LOGE("setAudioStream called in state %d", mCurrentState); |
| 570 | return INVALID_OPERATION; |
| 571 | } |
| 572 | // cache |
| 573 | mStreamType = type; |
| 574 | return OK; |
| 575 | } |
| 576 | |
| 577 | status_t MediaPlayer::setLooping(int loop) |
| 578 | { |
| 579 | LOGV("MediaPlayer::setLooping"); |
| 580 | Mutex::Autolock _l(mLock); |
| 581 | mLoop = (loop != 0); |
| 582 | if (mPlayer != 0) { |
| 583 | return mPlayer->setLooping(loop); |
| 584 | } |
| 585 | return OK; |
| 586 | } |
| 587 | |
| 588 | bool MediaPlayer::isLooping() { |
| 589 | LOGV("isLooping"); |
| 590 | Mutex::Autolock _l(mLock); |
| 591 | if (mPlayer != 0) { |
| 592 | return mLoop; |
| 593 | } |
| 594 | LOGV("isLooping: no active player"); |
| 595 | return false; |
| 596 | } |
| 597 | |
| 598 | status_t MediaPlayer::setVolume(float leftVolume, float rightVolume) |
| 599 | { |
| 600 | LOGV("MediaPlayer::setVolume(%f, %f)", leftVolume, rightVolume); |
| 601 | Mutex::Autolock _l(mLock); |
| 602 | mLeftVolume = leftVolume; |
| 603 | mRightVolume = rightVolume; |
| 604 | if (mPlayer != 0) { |
| 605 | return mPlayer->setVolume(leftVolume, rightVolume); |
| 606 | } |
| 607 | return OK; |
| 608 | } |
| 609 | |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 610 | status_t MediaPlayer::setAudioSessionId(int sessionId) |
| 611 | { |
| 612 | LOGV("MediaPlayer::setAudioSessionId(%d)", sessionId); |
| 613 | Mutex::Autolock _l(mLock); |
| 614 | if (!(mCurrentState & MEDIA_PLAYER_IDLE)) { |
| 615 | LOGE("setAudioSessionId called in state %d", mCurrentState); |
| 616 | return INVALID_OPERATION; |
| 617 | } |
| 618 | if (sessionId < 0) { |
| 619 | return BAD_VALUE; |
| 620 | } |
| 621 | mAudioSessionId = sessionId; |
| 622 | return NO_ERROR; |
| 623 | } |
| 624 | |
| 625 | int MediaPlayer::getAudioSessionId() |
| 626 | { |
| 627 | Mutex::Autolock _l(mLock); |
| 628 | return mAudioSessionId; |
| 629 | } |
| 630 | |
Eric Laurent | 7070b36 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 631 | status_t MediaPlayer::setAuxEffectSendLevel(float level) |
| 632 | { |
| 633 | LOGV("MediaPlayer::setAuxEffectSendLevel(%f)", level); |
| 634 | Mutex::Autolock _l(mLock); |
| 635 | mSendLevel = level; |
| 636 | if (mPlayer != 0) { |
| 637 | return mPlayer->setAuxEffectSendLevel(level); |
| 638 | } |
| 639 | return OK; |
| 640 | } |
| 641 | |
| 642 | status_t MediaPlayer::attachAuxEffect(int effectId) |
| 643 | { |
| 644 | LOGV("MediaPlayer::attachAuxEffect(%d)", effectId); |
| 645 | Mutex::Autolock _l(mLock); |
| 646 | if (mPlayer == 0 || |
| 647 | (mCurrentState & MEDIA_PLAYER_IDLE) || |
| 648 | (mCurrentState == MEDIA_PLAYER_STATE_ERROR )) { |
| 649 | LOGE("attachAuxEffect called in state %d", mCurrentState); |
| 650 | return INVALID_OPERATION; |
| 651 | } |
| 652 | |
| 653 | return mPlayer->attachAuxEffect(effectId); |
| 654 | } |
| 655 | |
Gloria Wang | d01ec6e | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 656 | status_t MediaPlayer::setParameter(int key, const Parcel& request) |
| 657 | { |
| 658 | LOGV("MediaPlayer::setParameter(%d)", key); |
| 659 | Mutex::Autolock _l(mLock); |
| 660 | if (mPlayer != NULL) { |
| 661 | return mPlayer->setParameter(key, request); |
| 662 | } |
| 663 | LOGV("setParameter: no active player"); |
| 664 | return INVALID_OPERATION; |
| 665 | } |
| 666 | |
| 667 | status_t MediaPlayer::getParameter(int key, Parcel *reply) |
| 668 | { |
| 669 | LOGV("MediaPlayer::getParameter(%d)", key); |
| 670 | Mutex::Autolock _l(mLock); |
| 671 | if (mPlayer != NULL) { |
| 672 | return mPlayer->getParameter(key, reply); |
| 673 | } |
| 674 | LOGV("getParameter: no active player"); |
| 675 | return INVALID_OPERATION; |
| 676 | } |
| 677 | |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 678 | void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | { |
| 680 | LOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2); |
| 681 | bool send = true; |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 682 | bool locked = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | |
| 684 | // TODO: In the future, we might be on the same thread if the app is |
| 685 | // running in the same process as the media server. In that case, |
| 686 | // this will deadlock. |
Nicolas Catania | 32f8277 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 687 | // |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 688 | // The threadId hack below works around this for the care of prepare |
Andreas Huber | effd8d5 | 2009-03-24 20:48:51 -0700 | [diff] [blame] | 689 | // and seekTo within the same process. |
| 690 | // FIXME: Remember, this is a hack, it's not even a hack that is applied |
| 691 | // consistently for all use-cases, this needs to be revisited. |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 692 | if (mLockThreadId != getThreadId()) { |
| 693 | mLock.lock(); |
| 694 | locked = true; |
Nicolas Catania | 32f8277 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 695 | } |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 696 | |
Eric Laurent | 1d53b2a | 2010-08-03 07:49:49 -0700 | [diff] [blame] | 697 | // Allows calls from JNI in idle state to notify errors |
| 698 | if (!(msg == MEDIA_ERROR && mCurrentState == MEDIA_PLAYER_IDLE) && mPlayer == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | LOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2); |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 700 | if (locked) mLock.unlock(); // release the lock when done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | return; |
| 702 | } |
| 703 | |
| 704 | switch (msg) { |
| 705 | case MEDIA_NOP: // interface test message |
| 706 | break; |
| 707 | case MEDIA_PREPARED: |
| 708 | LOGV("prepared"); |
| 709 | mCurrentState = MEDIA_PLAYER_PREPARED; |
| 710 | if (mPrepareSync) { |
| 711 | LOGV("signal application thread"); |
| 712 | mPrepareSync = false; |
| 713 | mPrepareStatus = NO_ERROR; |
| 714 | mSignal.signal(); |
| 715 | } |
| 716 | break; |
| 717 | case MEDIA_PLAYBACK_COMPLETE: |
| 718 | LOGV("playback complete"); |
Marco Nelissen | 3c473ea | 2010-09-17 15:04:01 -0700 | [diff] [blame] | 719 | if (mCurrentState == MEDIA_PLAYER_IDLE) { |
| 720 | LOGE("playback complete in idle state"); |
| 721 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | if (!mLoop) { |
| 723 | mCurrentState = MEDIA_PLAYER_PLAYBACK_COMPLETE; |
| 724 | } |
| 725 | break; |
| 726 | case MEDIA_ERROR: |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 727 | // Always log errors. |
| 728 | // ext1: Media framework error code. |
| 729 | // ext2: Implementation dependant error code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | LOGE("error (%d, %d)", ext1, ext2); |
| 731 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 732 | if (mPrepareSync) |
| 733 | { |
| 734 | LOGV("signal application thread"); |
| 735 | mPrepareSync = false; |
| 736 | mPrepareStatus = ext1; |
| 737 | mSignal.signal(); |
| 738 | send = false; |
| 739 | } |
| 740 | break; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 741 | case MEDIA_INFO: |
| 742 | // ext1: Media framework error code. |
| 743 | // ext2: Implementation dependant error code. |
Andreas Huber | 52c7832 | 2011-01-11 15:05:28 -0800 | [diff] [blame] | 744 | if (ext1 != MEDIA_INFO_VIDEO_TRACK_LAGGING) { |
| 745 | LOGW("info/warning (%d, %d)", ext1, ext2); |
| 746 | } |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 747 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | case MEDIA_SEEK_COMPLETE: |
| 749 | LOGV("Received seek complete"); |
| 750 | if (mSeekPosition != mCurrentPosition) { |
| 751 | LOGV("Executing queued seekTo(%d)", mSeekPosition); |
| 752 | mSeekPosition = -1; |
| 753 | seekTo_l(mCurrentPosition); |
| 754 | } |
| 755 | else { |
| 756 | LOGV("All seeks complete - return to regularly scheduled program"); |
| 757 | mCurrentPosition = mSeekPosition = -1; |
| 758 | } |
| 759 | break; |
| 760 | case MEDIA_BUFFERING_UPDATE: |
| 761 | LOGV("buffering %d", ext1); |
| 762 | break; |
| 763 | case MEDIA_SET_VIDEO_SIZE: |
| 764 | LOGV("New video size %d x %d", ext1, ext2); |
| 765 | mVideoWidth = ext1; |
| 766 | mVideoHeight = ext2; |
| 767 | break; |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 768 | case MEDIA_TIMED_TEXT: |
| 769 | LOGV("Received timed text message"); |
| 770 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | default: |
| 772 | LOGV("unrecognized message: (%d, %d, %d)", msg, ext1, ext2); |
| 773 | break; |
| 774 | } |
| 775 | |
| 776 | sp<MediaPlayerListener> listener = mListener; |
Jason Sams | ebb020a | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 777 | if (locked) mLock.unlock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | |
| 779 | // this prevents re-entrant calls into client code |
| 780 | if ((listener != 0) && send) { |
| 781 | Mutex::Autolock _l(mNotifyLock); |
| 782 | LOGV("callback application"); |
Gloria Wang | 162ee49 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 783 | listener->notify(msg, ext1, ext2, obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | LOGV("back from callback"); |
| 785 | } |
| 786 | } |
| 787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | /*static*/ sp<IMemory> MediaPlayer::decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) |
| 789 | { |
| 790 | LOGV("decode(%s)", url); |
| 791 | sp<IMemory> p; |
| 792 | const sp<IMediaPlayerService>& service = getMediaPlayerService(); |
| 793 | if (service != 0) { |
James Dong | 34bbc22 | 2010-01-15 18:13:58 -0800 | [diff] [blame] | 794 | p = service->decode(url, pSampleRate, pNumChannels, pFormat); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | } else { |
| 796 | LOGE("Unable to locate media service"); |
| 797 | } |
| 798 | return p; |
| 799 | |
| 800 | } |
| 801 | |
James Dong | 34bbc22 | 2010-01-15 18:13:58 -0800 | [diff] [blame] | 802 | void MediaPlayer::died() |
| 803 | { |
| 804 | LOGV("died"); |
| 805 | notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0); |
| 806 | } |
| 807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | /*static*/ sp<IMemory> MediaPlayer::decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) |
| 809 | { |
| 810 | LOGV("decode(%d, %lld, %lld)", fd, offset, length); |
| 811 | sp<IMemory> p; |
| 812 | const sp<IMediaPlayerService>& service = getMediaPlayerService(); |
| 813 | if (service != 0) { |
James Dong | 34bbc22 | 2010-01-15 18:13:58 -0800 | [diff] [blame] | 814 | p = service->decode(fd, offset, length, pSampleRate, pNumChannels, pFormat); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | } else { |
| 816 | LOGE("Unable to locate media service"); |
| 817 | } |
| 818 | return p; |
| 819 | |
| 820 | } |
| 821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | }; // namespace android |