Glenn Kasten | 99e53b8 | 2012-01-19 08:59:58 -0800 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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" |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <fcntl.h> |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 22 | #include <inttypes.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <unistd.h> |
| 26 | |
| 27 | #include <utils/Log.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 29 | #include <binder/IServiceManager.h> |
| 30 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
Mathias Agopian | b1e7cd1 | 2013-02-14 17:11:27 -0800 | [diff] [blame] | 32 | #include <gui/Surface.h> |
Jamie Gennis | 61c7ef5 | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <media/mediaplayer.h> |
Glenn Kasten | a3f1fa3 | 2012-01-18 14:54:46 -0800 | [diff] [blame] | 35 | #include <media/AudioSystem.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 37 | #include <binder/MemoryBase.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 39 | #include <utils/KeyedVector.h> |
| 40 | #include <utils/String8.h> |
| 41 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 42 | #include <system/audio.h> |
Jamie Gennis | 61c7ef5 | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 43 | #include <system/window.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 44 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | namespace android { |
| 46 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | MediaPlayer::MediaPlayer() |
| 48 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 49 | ALOGV("constructor"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | mListener = NULL; |
| 51 | mCookie = NULL; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 52 | mStreamType = AUDIO_STREAM_MUSIC; |
Jean-Michel Trivi | 640adb3 | 2014-09-05 11:20:11 -0700 | [diff] [blame^] | 53 | mAudioAttributesParcel = NULL; |
The Android Open Source Project | 89fa4ad | 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 | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 62 | mLockThreadId = 0; |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 63 | mAudioSessionId = AudioSystem::newAudioUniqueId(); |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 64 | AudioSystem::acquireAudioSessionId(mAudioSessionId, -1); |
Eric Laurent | 8c563ed | 2010-10-07 18:23:03 -0700 | [diff] [blame] | 65 | mSendLevel = 0; |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 66 | mRetransmitEndpointValid = false; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | } |
| 68 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | MediaPlayer::~MediaPlayer() |
| 70 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 71 | ALOGV("destructor"); |
Jean-Michel Trivi | 640adb3 | 2014-09-05 11:20:11 -0700 | [diff] [blame^] | 72 | if (mAudioAttributesParcel != NULL) { |
| 73 | delete mAudioAttributesParcel; |
| 74 | mAudioAttributesParcel = NULL; |
| 75 | } |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 76 | AudioSystem::releaseAudioSessionId(mAudioSessionId, -1); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | disconnect(); |
| 78 | IPCThreadState::self()->flushCommands(); |
| 79 | } |
| 80 | |
| 81 | void MediaPlayer::disconnect() |
| 82 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 83 | ALOGV("disconnect"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | sp<IMediaPlayer> p; |
| 85 | { |
| 86 | Mutex::Autolock _l(mLock); |
| 87 | p = mPlayer; |
| 88 | mPlayer.clear(); |
| 89 | } |
| 90 | |
| 91 | if (p != 0) { |
| 92 | p->disconnect(); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // always call with lock held |
| 97 | void MediaPlayer::clear_l() |
| 98 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | mCurrentPosition = -1; |
| 100 | mSeekPosition = -1; |
| 101 | mVideoWidth = mVideoHeight = 0; |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 102 | mRetransmitEndpointValid = false; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | status_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener) |
| 106 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 107 | ALOGV("setListener"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | Mutex::Autolock _l(mLock); |
| 109 | mListener = listener; |
| 110 | return NO_ERROR; |
| 111 | } |
| 112 | |
| 113 | |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 114 | status_t MediaPlayer::attachNewPlayer(const sp<IMediaPlayer>& player) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | { |
| 116 | status_t err = UNKNOWN_ERROR; |
| 117 | sp<IMediaPlayer> p; |
| 118 | { // scope for the lock |
| 119 | Mutex::Autolock _l(mLock); |
| 120 | |
Marco Nelissen | 83ff143 | 2010-03-10 10:53:16 -0800 | [diff] [blame] | 121 | if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) || |
| 122 | (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 123 | ALOGE("attachNewPlayer called in state %d", mCurrentState); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | return INVALID_OPERATION; |
| 125 | } |
| 126 | |
| 127 | clear_l(); |
| 128 | p = mPlayer; |
| 129 | mPlayer = player; |
| 130 | if (player != 0) { |
| 131 | mCurrentState = MEDIA_PLAYER_INITIALIZED; |
| 132 | err = NO_ERROR; |
| 133 | } else { |
Masaki Muranaka | f65fa17 | 2013-06-06 09:36:34 +0000 | [diff] [blame] | 134 | ALOGE("Unable to create media player"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | if (p != 0) { |
| 139 | p->disconnect(); |
| 140 | } |
| 141 | |
| 142 | return err; |
| 143 | } |
| 144 | |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 145 | status_t MediaPlayer::setDataSource( |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 146 | const sp<IMediaHTTPService> &httpService, |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 147 | const char *url, const KeyedVector<String8, String8> *headers) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 149 | ALOGV("setDataSource(%s)", url); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | status_t err = BAD_VALUE; |
| 151 | if (url != NULL) { |
| 152 | const sp<IMediaPlayerService>& service(getMediaPlayerService()); |
| 153 | if (service != 0) { |
Glenn Kasten | f37971f | 2012-02-03 11:06:53 -0800 | [diff] [blame] | 154 | sp<IMediaPlayer> player(service->create(this, mAudioSessionId)); |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 155 | if ((NO_ERROR != doSetRetransmitEndpoint(player)) || |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 156 | (NO_ERROR != player->setDataSource(httpService, url, headers))) { |
Dave Burke | 0662067 | 2011-09-06 20:39:47 +0100 | [diff] [blame] | 157 | player.clear(); |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 158 | } |
Dave Burke | 0662067 | 2011-09-06 20:39:47 +0100 | [diff] [blame] | 159 | err = attachNewPlayer(player); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | return err; |
| 163 | } |
| 164 | |
| 165 | status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length) |
| 166 | { |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 167 | ALOGV("setDataSource(%d, %" PRId64 ", %" PRId64 ")", fd, offset, length); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | status_t err = UNKNOWN_ERROR; |
| 169 | const sp<IMediaPlayerService>& service(getMediaPlayerService()); |
| 170 | if (service != 0) { |
Glenn Kasten | f37971f | 2012-02-03 11:06:53 -0800 | [diff] [blame] | 171 | sp<IMediaPlayer> player(service->create(this, mAudioSessionId)); |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 172 | if ((NO_ERROR != doSetRetransmitEndpoint(player)) || |
| 173 | (NO_ERROR != player->setDataSource(fd, offset, length))) { |
Dave Burke | 0662067 | 2011-09-06 20:39:47 +0100 | [diff] [blame] | 174 | player.clear(); |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 175 | } |
Dave Burke | 0662067 | 2011-09-06 20:39:47 +0100 | [diff] [blame] | 176 | err = attachNewPlayer(player); |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 177 | } |
| 178 | return err; |
| 179 | } |
| 180 | |
| 181 | status_t MediaPlayer::setDataSource(const sp<IStreamSource> &source) |
| 182 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 183 | ALOGV("setDataSource"); |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 184 | status_t err = UNKNOWN_ERROR; |
| 185 | const sp<IMediaPlayerService>& service(getMediaPlayerService()); |
| 186 | if (service != 0) { |
Glenn Kasten | f37971f | 2012-02-03 11:06:53 -0800 | [diff] [blame] | 187 | sp<IMediaPlayer> player(service->create(this, mAudioSessionId)); |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 188 | if ((NO_ERROR != doSetRetransmitEndpoint(player)) || |
| 189 | (NO_ERROR != player->setDataSource(source))) { |
Dave Burke | 0662067 | 2011-09-06 20:39:47 +0100 | [diff] [blame] | 190 | player.clear(); |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 191 | } |
Dave Burke | 0662067 | 2011-09-06 20:39:47 +0100 | [diff] [blame] | 192 | err = attachNewPlayer(player); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
| 194 | return err; |
| 195 | } |
| 196 | |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 197 | status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply) |
| 198 | { |
| 199 | Mutex::Autolock _l(mLock); |
Nicolas Catania | 4023493 | 2010-03-10 10:41:04 -0800 | [diff] [blame] | 200 | const bool hasBeenInitialized = |
| 201 | (mCurrentState != MEDIA_PLAYER_STATE_ERROR) && |
| 202 | ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE); |
| 203 | if ((mPlayer != NULL) && hasBeenInitialized) { |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 204 | ALOGV("invoke %zu", request.dataSize()); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 205 | return mPlayer->invoke(request, reply); |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 206 | } |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 207 | ALOGE("invoke failed: wrong state %X", mCurrentState); |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 208 | return INVALID_OPERATION; |
| 209 | } |
| 210 | |
Nicolas Catania | a7e0e8b | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 211 | status_t MediaPlayer::setMetadataFilter(const Parcel& filter) |
| 212 | { |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 213 | ALOGD("setMetadataFilter"); |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 214 | Mutex::Autolock lock(mLock); |
| 215 | if (mPlayer == NULL) { |
Nicolas Catania | a7e0e8b | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 216 | return NO_INIT; |
| 217 | } |
| 218 | return mPlayer->setMetadataFilter(filter); |
| 219 | } |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 220 | |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 221 | status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata) |
| 222 | { |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 223 | ALOGD("getMetadata"); |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 224 | Mutex::Autolock lock(mLock); |
| 225 | if (mPlayer == NULL) { |
| 226 | return NO_INIT; |
| 227 | } |
| 228 | return mPlayer->getMetadata(update_only, apply_filter, metadata); |
| 229 | } |
| 230 | |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 231 | status_t MediaPlayer::setVideoSurfaceTexture( |
Andy McFadden | 484566c | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 232 | const sp<IGraphicBufferProducer>& bufferProducer) |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 233 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 234 | ALOGV("setVideoSurfaceTexture"); |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 235 | Mutex::Autolock _l(mLock); |
| 236 | if (mPlayer == 0) return NO_INIT; |
Andy McFadden | 484566c | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 237 | return mPlayer->setVideoSurfaceTexture(bufferProducer); |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 238 | } |
| 239 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | // must call with lock held |
| 241 | status_t MediaPlayer::prepareAsync_l() |
| 242 | { |
| 243 | if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) { |
| 244 | mPlayer->setAudioStreamType(mStreamType); |
Jean-Michel Trivi | 640adb3 | 2014-09-05 11:20:11 -0700 | [diff] [blame^] | 245 | if (mAudioAttributesParcel != NULL) { |
| 246 | mPlayer->setParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES, *mAudioAttributesParcel); |
| 247 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | mCurrentState = MEDIA_PLAYER_PREPARING; |
| 249 | return mPlayer->prepareAsync(); |
| 250 | } |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 251 | ALOGE("prepareAsync called in state %d", mCurrentState); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | return INVALID_OPERATION; |
| 253 | } |
| 254 | |
The Android Open Source Project | 65e731f | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 255 | // TODO: In case of error, prepareAsync provides the caller with 2 error codes, |
| 256 | // one defined in the Android framework and one provided by the implementation |
| 257 | // that generated the error. The sync version of prepare returns only 1 error |
| 258 | // code. |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | status_t MediaPlayer::prepare() |
| 260 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 261 | ALOGV("prepare"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | Mutex::Autolock _l(mLock); |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 263 | mLockThreadId = getThreadId(); |
| 264 | if (mPrepareSync) { |
| 265 | mLockThreadId = 0; |
| 266 | return -EALREADY; |
| 267 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | mPrepareSync = true; |
| 269 | status_t ret = prepareAsync_l(); |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 270 | if (ret != NO_ERROR) { |
| 271 | mLockThreadId = 0; |
| 272 | return ret; |
| 273 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | |
| 275 | if (mPrepareSync) { |
| 276 | mSignal.wait(mLock); // wait for prepare done |
| 277 | mPrepareSync = false; |
| 278 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 279 | ALOGV("prepare complete - status=%d", mPrepareStatus); |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 280 | mLockThreadId = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | return mPrepareStatus; |
| 282 | } |
| 283 | |
| 284 | status_t MediaPlayer::prepareAsync() |
| 285 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 286 | ALOGV("prepareAsync"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | Mutex::Autolock _l(mLock); |
| 288 | return prepareAsync_l(); |
| 289 | } |
| 290 | |
| 291 | status_t MediaPlayer::start() |
| 292 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 293 | ALOGV("start"); |
Chong Zhang | d88adb9 | 2014-07-23 11:43:46 -0700 | [diff] [blame] | 294 | |
| 295 | status_t ret = NO_ERROR; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | Mutex::Autolock _l(mLock); |
Chong Zhang | d88adb9 | 2014-07-23 11:43:46 -0700 | [diff] [blame] | 297 | |
| 298 | mLockThreadId = getThreadId(); |
| 299 | |
| 300 | if (mCurrentState & MEDIA_PLAYER_STARTED) { |
| 301 | ret = NO_ERROR; |
| 302 | } else if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) { |
| 304 | mPlayer->setLooping(mLoop); |
| 305 | mPlayer->setVolume(mLeftVolume, mRightVolume); |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 306 | mPlayer->setAuxEffectSendLevel(mSendLevel); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | mCurrentState = MEDIA_PLAYER_STARTED; |
Chong Zhang | d88adb9 | 2014-07-23 11:43:46 -0700 | [diff] [blame] | 308 | ret = mPlayer->start(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | if (ret != NO_ERROR) { |
| 310 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 311 | } else { |
| 312 | if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 313 | ALOGV("playback completed immediately following start()"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
Chong Zhang | d88adb9 | 2014-07-23 11:43:46 -0700 | [diff] [blame] | 316 | } else { |
| 317 | ALOGE("start called in state %d", mCurrentState); |
| 318 | ret = INVALID_OPERATION; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | } |
Chong Zhang | d88adb9 | 2014-07-23 11:43:46 -0700 | [diff] [blame] | 320 | |
| 321 | mLockThreadId = 0; |
| 322 | |
| 323 | return ret; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | status_t MediaPlayer::stop() |
| 327 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 328 | ALOGV("stop"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | Mutex::Autolock _l(mLock); |
| 330 | if (mCurrentState & MEDIA_PLAYER_STOPPED) return NO_ERROR; |
| 331 | if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | |
| 332 | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) ) { |
| 333 | status_t ret = mPlayer->stop(); |
| 334 | if (ret != NO_ERROR) { |
| 335 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 336 | } else { |
| 337 | mCurrentState = MEDIA_PLAYER_STOPPED; |
| 338 | } |
| 339 | return ret; |
| 340 | } |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 341 | ALOGE("stop called in state %d", mCurrentState); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | return INVALID_OPERATION; |
| 343 | } |
| 344 | |
| 345 | status_t MediaPlayer::pause() |
| 346 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 347 | ALOGV("pause"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | Mutex::Autolock _l(mLock); |
Marco Nelissen | 698f476 | 2010-02-26 13:16:23 -0800 | [diff] [blame] | 349 | if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE)) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | return NO_ERROR; |
| 351 | if ((mPlayer != 0) && (mCurrentState & MEDIA_PLAYER_STARTED)) { |
| 352 | status_t ret = mPlayer->pause(); |
| 353 | if (ret != NO_ERROR) { |
| 354 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 355 | } else { |
| 356 | mCurrentState = MEDIA_PLAYER_PAUSED; |
| 357 | } |
| 358 | return ret; |
| 359 | } |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 360 | ALOGE("pause called in state %d", mCurrentState); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | return INVALID_OPERATION; |
| 362 | } |
| 363 | |
| 364 | bool MediaPlayer::isPlaying() |
| 365 | { |
| 366 | Mutex::Autolock _l(mLock); |
| 367 | if (mPlayer != 0) { |
| 368 | bool temp = false; |
| 369 | mPlayer->isPlaying(&temp); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 370 | ALOGV("isPlaying: %d", temp); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 372 | ALOGE("internal/external state mismatch corrected"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | mCurrentState = MEDIA_PLAYER_PAUSED; |
| 374 | } |
| 375 | return temp; |
| 376 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 377 | ALOGV("isPlaying: no active player"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | return false; |
| 379 | } |
| 380 | |
| 381 | status_t MediaPlayer::getVideoWidth(int *w) |
| 382 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 383 | ALOGV("getVideoWidth"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | Mutex::Autolock _l(mLock); |
| 385 | if (mPlayer == 0) return INVALID_OPERATION; |
| 386 | *w = mVideoWidth; |
| 387 | return NO_ERROR; |
| 388 | } |
| 389 | |
| 390 | status_t MediaPlayer::getVideoHeight(int *h) |
| 391 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 392 | ALOGV("getVideoHeight"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | Mutex::Autolock _l(mLock); |
| 394 | if (mPlayer == 0) return INVALID_OPERATION; |
| 395 | *h = mVideoHeight; |
| 396 | return NO_ERROR; |
| 397 | } |
| 398 | |
| 399 | status_t MediaPlayer::getCurrentPosition(int *msec) |
| 400 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 401 | ALOGV("getCurrentPosition"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | Mutex::Autolock _l(mLock); |
| 403 | if (mPlayer != 0) { |
| 404 | if (mCurrentPosition >= 0) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 405 | ALOGV("Using cached seek position: %d", mCurrentPosition); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | *msec = mCurrentPosition; |
| 407 | return NO_ERROR; |
| 408 | } |
| 409 | return mPlayer->getCurrentPosition(msec); |
| 410 | } |
| 411 | return INVALID_OPERATION; |
| 412 | } |
| 413 | |
| 414 | status_t MediaPlayer::getDuration_l(int *msec) |
| 415 | { |
Andreas Huber | a4c5bc0 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 416 | ALOGV("getDuration_l"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE)); |
| 418 | if (mPlayer != 0 && isValidState) { |
Andreas Huber | a4c5bc0 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 419 | int durationMs; |
| 420 | status_t ret = mPlayer->getDuration(&durationMs); |
Andreas Huber | 2070254 | 2013-04-11 11:07:55 -0700 | [diff] [blame] | 421 | |
| 422 | if (ret != OK) { |
| 423 | // Do not enter error state just because no duration was available. |
| 424 | durationMs = -1; |
| 425 | ret = OK; |
| 426 | } |
| 427 | |
Andreas Huber | a4c5bc0 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 428 | if (msec) { |
| 429 | *msec = durationMs; |
| 430 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | return ret; |
| 432 | } |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 433 | ALOGE("Attempt to call getDuration without a valid mediaplayer"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | return INVALID_OPERATION; |
| 435 | } |
| 436 | |
| 437 | status_t MediaPlayer::getDuration(int *msec) |
| 438 | { |
| 439 | Mutex::Autolock _l(mLock); |
| 440 | return getDuration_l(msec); |
| 441 | } |
| 442 | |
| 443 | status_t MediaPlayer::seekTo_l(int msec) |
| 444 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 445 | ALOGV("seekTo %d", msec); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) { |
| 447 | if ( msec < 0 ) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 448 | ALOGW("Attempt to seek to invalid position: %d", msec); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | msec = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | } |
Andreas Huber | a4c5bc0 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 451 | |
| 452 | int durationMs; |
| 453 | status_t err = mPlayer->getDuration(&durationMs); |
| 454 | |
| 455 | if (err != OK) { |
| 456 | ALOGW("Stream has no duration and is therefore not seekable."); |
| 457 | return err; |
| 458 | } |
| 459 | |
| 460 | if (msec > durationMs) { |
| 461 | ALOGW("Attempt to seek to past end of file: request = %d, " |
| 462 | "durationMs = %d", |
| 463 | msec, |
| 464 | durationMs); |
| 465 | |
| 466 | msec = durationMs; |
| 467 | } |
| 468 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | // cache duration |
| 470 | mCurrentPosition = msec; |
| 471 | if (mSeekPosition < 0) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | mSeekPosition = msec; |
| 473 | return mPlayer->seekTo(msec); |
| 474 | } |
| 475 | else { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 476 | ALOGV("Seek in progress - queue up seekTo[%d]", msec); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | return NO_ERROR; |
| 478 | } |
| 479 | } |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 480 | ALOGE("Attempt to perform seekTo in wrong state: mPlayer=%p, mCurrentState=%u", mPlayer.get(), mCurrentState); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | return INVALID_OPERATION; |
| 482 | } |
| 483 | |
| 484 | status_t MediaPlayer::seekTo(int msec) |
| 485 | { |
Andreas Huber | 5cb07aa | 2009-03-24 20:48:51 -0700 | [diff] [blame] | 486 | mLockThreadId = getThreadId(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | Mutex::Autolock _l(mLock); |
Andreas Huber | 5cb07aa | 2009-03-24 20:48:51 -0700 | [diff] [blame] | 488 | status_t result = seekTo_l(msec); |
| 489 | mLockThreadId = 0; |
| 490 | |
| 491 | return result; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | } |
| 493 | |
Jamie Gennis | 61c7ef5 | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 494 | status_t MediaPlayer::reset_l() |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | mLoop = false; |
| 497 | if (mCurrentState == MEDIA_PLAYER_IDLE) return NO_ERROR; |
| 498 | mPrepareSync = false; |
| 499 | if (mPlayer != 0) { |
| 500 | status_t ret = mPlayer->reset(); |
| 501 | if (ret != NO_ERROR) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 502 | ALOGE("reset() failed with return code (%d)", ret); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 504 | } else { |
| 505 | mCurrentState = MEDIA_PLAYER_IDLE; |
| 506 | } |
James Dong | a1680bc | 2010-11-18 12:23:58 -0800 | [diff] [blame] | 507 | // setDataSource has to be called again to create a |
| 508 | // new mediaplayer. |
| 509 | mPlayer = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | return ret; |
| 511 | } |
| 512 | clear_l(); |
| 513 | return NO_ERROR; |
| 514 | } |
| 515 | |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 516 | status_t MediaPlayer::doSetRetransmitEndpoint(const sp<IMediaPlayer>& player) { |
| 517 | Mutex::Autolock _l(mLock); |
| 518 | |
| 519 | if (player == NULL) { |
| 520 | return UNKNOWN_ERROR; |
| 521 | } |
| 522 | |
| 523 | if (mRetransmitEndpointValid) { |
| 524 | return player->setRetransmitEndpoint(&mRetransmitEndpoint); |
| 525 | } |
| 526 | |
| 527 | return OK; |
| 528 | } |
| 529 | |
Jamie Gennis | 61c7ef5 | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 530 | status_t MediaPlayer::reset() |
| 531 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 532 | ALOGV("reset"); |
Jamie Gennis | 61c7ef5 | 2011-07-13 12:59:34 -0700 | [diff] [blame] | 533 | Mutex::Autolock _l(mLock); |
| 534 | return reset_l(); |
| 535 | } |
| 536 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 537 | status_t MediaPlayer::setAudioStreamType(audio_stream_type_t type) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 539 | ALOGV("MediaPlayer::setAudioStreamType"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | Mutex::Autolock _l(mLock); |
| 541 | if (mStreamType == type) return NO_ERROR; |
| 542 | if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | |
| 543 | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) { |
| 544 | // Can't change the stream type after prepare |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 545 | ALOGE("setAudioStream called in state %d", mCurrentState); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | return INVALID_OPERATION; |
| 547 | } |
| 548 | // cache |
| 549 | mStreamType = type; |
| 550 | return OK; |
| 551 | } |
| 552 | |
John Spurlock | de9453f | 2014-03-19 13:05:45 -0400 | [diff] [blame] | 553 | status_t MediaPlayer::getAudioStreamType(audio_stream_type_t *type) |
| 554 | { |
| 555 | ALOGV("getAudioStreamType"); |
| 556 | Mutex::Autolock _l(mLock); |
| 557 | *type = mStreamType; |
| 558 | return OK; |
| 559 | } |
| 560 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | status_t MediaPlayer::setLooping(int loop) |
| 562 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 563 | ALOGV("MediaPlayer::setLooping"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | Mutex::Autolock _l(mLock); |
| 565 | mLoop = (loop != 0); |
| 566 | if (mPlayer != 0) { |
| 567 | return mPlayer->setLooping(loop); |
| 568 | } |
| 569 | return OK; |
| 570 | } |
| 571 | |
| 572 | bool MediaPlayer::isLooping() { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 573 | ALOGV("isLooping"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | Mutex::Autolock _l(mLock); |
| 575 | if (mPlayer != 0) { |
| 576 | return mLoop; |
| 577 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 578 | ALOGV("isLooping: no active player"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | return false; |
| 580 | } |
| 581 | |
| 582 | status_t MediaPlayer::setVolume(float leftVolume, float rightVolume) |
| 583 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 584 | ALOGV("MediaPlayer::setVolume(%f, %f)", leftVolume, rightVolume); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | Mutex::Autolock _l(mLock); |
| 586 | mLeftVolume = leftVolume; |
| 587 | mRightVolume = rightVolume; |
| 588 | if (mPlayer != 0) { |
| 589 | return mPlayer->setVolume(leftVolume, rightVolume); |
| 590 | } |
| 591 | return OK; |
| 592 | } |
| 593 | |
Eric Laurent | a514bdb | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 594 | status_t MediaPlayer::setAudioSessionId(int sessionId) |
| 595 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 596 | ALOGV("MediaPlayer::setAudioSessionId(%d)", sessionId); |
Eric Laurent | a514bdb | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 597 | Mutex::Autolock _l(mLock); |
| 598 | if (!(mCurrentState & MEDIA_PLAYER_IDLE)) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 599 | ALOGE("setAudioSessionId called in state %d", mCurrentState); |
Eric Laurent | a514bdb | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 600 | return INVALID_OPERATION; |
| 601 | } |
| 602 | if (sessionId < 0) { |
| 603 | return BAD_VALUE; |
| 604 | } |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 605 | if (sessionId != mAudioSessionId) { |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 606 | AudioSystem::acquireAudioSessionId(sessionId, -1); |
| 607 | AudioSystem::releaseAudioSessionId(mAudioSessionId, -1); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 608 | mAudioSessionId = sessionId; |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 609 | } |
Eric Laurent | a514bdb | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 610 | return NO_ERROR; |
| 611 | } |
| 612 | |
| 613 | int MediaPlayer::getAudioSessionId() |
| 614 | { |
| 615 | Mutex::Autolock _l(mLock); |
| 616 | return mAudioSessionId; |
| 617 | } |
| 618 | |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 619 | status_t MediaPlayer::setAuxEffectSendLevel(float level) |
| 620 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 621 | ALOGV("MediaPlayer::setAuxEffectSendLevel(%f)", level); |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 622 | Mutex::Autolock _l(mLock); |
| 623 | mSendLevel = level; |
| 624 | if (mPlayer != 0) { |
| 625 | return mPlayer->setAuxEffectSendLevel(level); |
| 626 | } |
| 627 | return OK; |
| 628 | } |
| 629 | |
| 630 | status_t MediaPlayer::attachAuxEffect(int effectId) |
| 631 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 632 | ALOGV("MediaPlayer::attachAuxEffect(%d)", effectId); |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 633 | Mutex::Autolock _l(mLock); |
| 634 | if (mPlayer == 0 || |
| 635 | (mCurrentState & MEDIA_PLAYER_IDLE) || |
| 636 | (mCurrentState == MEDIA_PLAYER_STATE_ERROR )) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 637 | ALOGE("attachAuxEffect called in state %d", mCurrentState); |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 638 | return INVALID_OPERATION; |
| 639 | } |
| 640 | |
| 641 | return mPlayer->attachAuxEffect(effectId); |
| 642 | } |
| 643 | |
Jean-Michel Trivi | d9d7fa0 | 2014-06-24 08:01:46 -0700 | [diff] [blame] | 644 | // always call with lock held |
| 645 | status_t MediaPlayer::checkStateForKeySet_l(int key) |
| 646 | { |
| 647 | switch(key) { |
| 648 | case KEY_PARAMETER_AUDIO_ATTRIBUTES: |
| 649 | if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | |
| 650 | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) { |
| 651 | // Can't change the audio attributes after prepare |
| 652 | ALOGE("trying to set audio attributes called in state %d", mCurrentState); |
| 653 | return INVALID_OPERATION; |
| 654 | } |
| 655 | break; |
| 656 | default: |
| 657 | // parameter doesn't require player state check |
| 658 | break; |
| 659 | } |
| 660 | return OK; |
| 661 | } |
| 662 | |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 663 | status_t MediaPlayer::setParameter(int key, const Parcel& request) |
| 664 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 665 | ALOGV("MediaPlayer::setParameter(%d)", key); |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 666 | Mutex::Autolock _l(mLock); |
Jean-Michel Trivi | d9d7fa0 | 2014-06-24 08:01:46 -0700 | [diff] [blame] | 667 | if (checkStateForKeySet_l(key) != OK) { |
| 668 | return INVALID_OPERATION; |
| 669 | } |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 670 | if (mPlayer != NULL) { |
| 671 | return mPlayer->setParameter(key, request); |
| 672 | } |
Jean-Michel Trivi | 640adb3 | 2014-09-05 11:20:11 -0700 | [diff] [blame^] | 673 | switch (key) { |
| 674 | case KEY_PARAMETER_AUDIO_ATTRIBUTES: |
| 675 | // no player, save the marshalled audio attributes |
| 676 | if (mAudioAttributesParcel != NULL) { delete mAudioAttributesParcel; }; |
| 677 | mAudioAttributesParcel = new Parcel(); |
| 678 | mAudioAttributesParcel->appendFrom(&request, 0, request.dataSize()); |
| 679 | return OK; |
| 680 | default: |
| 681 | ALOGV("setParameter: no active player"); |
| 682 | return INVALID_OPERATION; |
| 683 | } |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | status_t MediaPlayer::getParameter(int key, Parcel *reply) |
| 687 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 688 | ALOGV("MediaPlayer::getParameter(%d)", key); |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 689 | Mutex::Autolock _l(mLock); |
| 690 | if (mPlayer != NULL) { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 691 | return mPlayer->getParameter(key, reply); |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 692 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 693 | ALOGV("getParameter: no active player"); |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 694 | return INVALID_OPERATION; |
| 695 | } |
| 696 | |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 697 | status_t MediaPlayer::setRetransmitEndpoint(const char* addrString, |
| 698 | uint16_t port) { |
| 699 | ALOGV("MediaPlayer::setRetransmitEndpoint(%s:%hu)", |
| 700 | addrString ? addrString : "(null)", port); |
| 701 | |
| 702 | Mutex::Autolock _l(mLock); |
| 703 | if ((mPlayer != NULL) || (mCurrentState != MEDIA_PLAYER_IDLE)) |
| 704 | return INVALID_OPERATION; |
| 705 | |
| 706 | if (NULL == addrString) { |
| 707 | mRetransmitEndpointValid = false; |
| 708 | return OK; |
| 709 | } |
| 710 | |
| 711 | struct in_addr saddr; |
| 712 | if(!inet_aton(addrString, &saddr)) { |
| 713 | return BAD_VALUE; |
| 714 | } |
| 715 | |
Glenn Kasten | be08f6a | 2013-12-19 09:09:33 -0800 | [diff] [blame] | 716 | memset(&mRetransmitEndpoint, 0, sizeof(mRetransmitEndpoint)); |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 717 | mRetransmitEndpoint.sin_family = AF_INET; |
| 718 | mRetransmitEndpoint.sin_addr = saddr; |
| 719 | mRetransmitEndpoint.sin_port = htons(port); |
| 720 | mRetransmitEndpointValid = true; |
| 721 | |
| 722 | return OK; |
| 723 | } |
| 724 | |
Gloria Wang | b483c47 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 725 | void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 727 | ALOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | bool send = true; |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 729 | bool locked = false; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | |
| 731 | // TODO: In the future, we might be on the same thread if the app is |
| 732 | // running in the same process as the media server. In that case, |
| 733 | // this will deadlock. |
Nicolas Catania | 6609518 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 734 | // |
Chong Zhang | d88adb9 | 2014-07-23 11:43:46 -0700 | [diff] [blame] | 735 | // The threadId hack below works around this for the care of prepare, |
| 736 | // seekTo and start within the same process. |
Andreas Huber | 5cb07aa | 2009-03-24 20:48:51 -0700 | [diff] [blame] | 737 | // FIXME: Remember, this is a hack, it's not even a hack that is applied |
| 738 | // consistently for all use-cases, this needs to be revisited. |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 739 | if (mLockThreadId != getThreadId()) { |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 740 | mLock.lock(); |
| 741 | locked = true; |
Nicolas Catania | 6609518 | 2009-06-11 16:33:49 -0700 | [diff] [blame] | 742 | } |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 743 | |
Eric Laurent | 3b26844 | 2010-08-03 07:49:49 -0700 | [diff] [blame] | 744 | // Allows calls from JNI in idle state to notify errors |
| 745 | if (!(msg == MEDIA_ERROR && mCurrentState == MEDIA_PLAYER_IDLE) && mPlayer == 0) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 746 | ALOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2); |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 747 | if (locked) mLock.unlock(); // release the lock when done. |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | return; |
| 749 | } |
| 750 | |
| 751 | switch (msg) { |
| 752 | case MEDIA_NOP: // interface test message |
| 753 | break; |
| 754 | case MEDIA_PREPARED: |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 755 | ALOGV("prepared"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | mCurrentState = MEDIA_PLAYER_PREPARED; |
| 757 | if (mPrepareSync) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 758 | ALOGV("signal application thread"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | mPrepareSync = false; |
| 760 | mPrepareStatus = NO_ERROR; |
| 761 | mSignal.signal(); |
| 762 | } |
| 763 | break; |
| 764 | case MEDIA_PLAYBACK_COMPLETE: |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 765 | ALOGV("playback complete"); |
Marco Nelissen | 1c1503c | 2010-09-17 15:04:01 -0700 | [diff] [blame] | 766 | if (mCurrentState == MEDIA_PLAYER_IDLE) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 767 | ALOGE("playback complete in idle state"); |
Marco Nelissen | 1c1503c | 2010-09-17 15:04:01 -0700 | [diff] [blame] | 768 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | if (!mLoop) { |
| 770 | mCurrentState = MEDIA_PLAYER_PLAYBACK_COMPLETE; |
| 771 | } |
| 772 | break; |
| 773 | case MEDIA_ERROR: |
The Android Open Source Project | 65e731f | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 774 | // Always log errors. |
| 775 | // ext1: Media framework error code. |
| 776 | // ext2: Implementation dependant error code. |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 777 | ALOGE("error (%d, %d)", ext1, ext2); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | mCurrentState = MEDIA_PLAYER_STATE_ERROR; |
| 779 | if (mPrepareSync) |
| 780 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 781 | ALOGV("signal application thread"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | mPrepareSync = false; |
| 783 | mPrepareStatus = ext1; |
| 784 | mSignal.signal(); |
| 785 | send = false; |
| 786 | } |
| 787 | break; |
The Android Open Source Project | 65e731f | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 788 | case MEDIA_INFO: |
| 789 | // ext1: Media framework error code. |
| 790 | // ext2: Implementation dependant error code. |
Andreas Huber | 145e68f | 2011-01-11 15:05:28 -0800 | [diff] [blame] | 791 | if (ext1 != MEDIA_INFO_VIDEO_TRACK_LAGGING) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 792 | ALOGW("info/warning (%d, %d)", ext1, ext2); |
Andreas Huber | 145e68f | 2011-01-11 15:05:28 -0800 | [diff] [blame] | 793 | } |
The Android Open Source Project | 65e731f | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 794 | break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | case MEDIA_SEEK_COMPLETE: |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 796 | ALOGV("Received seek complete"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | if (mSeekPosition != mCurrentPosition) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 798 | ALOGV("Executing queued seekTo(%d)", mSeekPosition); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | mSeekPosition = -1; |
| 800 | seekTo_l(mCurrentPosition); |
| 801 | } |
| 802 | else { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 803 | ALOGV("All seeks complete - return to regularly scheduled program"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | mCurrentPosition = mSeekPosition = -1; |
| 805 | } |
| 806 | break; |
| 807 | case MEDIA_BUFFERING_UPDATE: |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 808 | ALOGV("buffering %d", ext1); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | break; |
| 810 | case MEDIA_SET_VIDEO_SIZE: |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 811 | ALOGV("New video size %d x %d", ext1, ext2); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | mVideoWidth = ext1; |
| 813 | mVideoHeight = ext2; |
| 814 | break; |
Gloria Wang | b483c47 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 815 | case MEDIA_TIMED_TEXT: |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 816 | ALOGV("Received timed text message"); |
Gloria Wang | b483c47 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 817 | break; |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame] | 818 | case MEDIA_SUBTITLE_DATA: |
| 819 | ALOGV("Received subtitle data message"); |
| 820 | break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | default: |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 822 | ALOGV("unrecognized message: (%d, %d, %d)", msg, ext1, ext2); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | break; |
| 824 | } |
| 825 | |
| 826 | sp<MediaPlayerListener> listener = mListener; |
Jason Sams | 1af452f | 2009-03-24 18:45:22 -0700 | [diff] [blame] | 827 | if (locked) mLock.unlock(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | |
| 829 | // this prevents re-entrant calls into client code |
| 830 | if ((listener != 0) && send) { |
| 831 | Mutex::Autolock _l(mNotifyLock); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 832 | ALOGV("callback application"); |
Gloria Wang | b483c47 | 2011-04-11 17:23:27 -0700 | [diff] [blame] | 833 | listener->notify(msg, ext1, ext2, obj); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 834 | ALOGV("back from callback"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 838 | /*static*/ status_t MediaPlayer::decode( |
| 839 | const sp<IMediaHTTPService> &httpService, |
| 840 | const char* url, |
| 841 | uint32_t *pSampleRate, |
| 842 | int* pNumChannels, |
| 843 | audio_format_t* pFormat, |
| 844 | const sp<IMemoryHeap>& heap, |
| 845 | size_t *pSize) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 847 | ALOGV("decode(%s)", url); |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 848 | status_t status; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | const sp<IMediaPlayerService>& service = getMediaPlayerService(); |
| 850 | if (service != 0) { |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 851 | status = service->decode(httpService, url, pSampleRate, pNumChannels, pFormat, heap, pSize); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | } else { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 853 | ALOGE("Unable to locate media service"); |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 854 | status = DEAD_OBJECT; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 856 | return status; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | |
| 858 | } |
| 859 | |
James Dong | dd172fc | 2010-01-15 18:13:58 -0800 | [diff] [blame] | 860 | void MediaPlayer::died() |
| 861 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 862 | ALOGV("died"); |
James Dong | dd172fc | 2010-01-15 18:13:58 -0800 | [diff] [blame] | 863 | notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0); |
| 864 | } |
| 865 | |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 866 | /*static*/ status_t MediaPlayer::decode(int fd, int64_t offset, int64_t length, |
| 867 | uint32_t *pSampleRate, int* pNumChannels, |
| 868 | audio_format_t* pFormat, |
| 869 | const sp<IMemoryHeap>& heap, size_t *pSize) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | { |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 871 | ALOGV("decode(%d, %" PRId64 ", %" PRId64 ")", fd, offset, length); |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 872 | status_t status; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | const sp<IMediaPlayerService>& service = getMediaPlayerService(); |
| 874 | if (service != 0) { |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 875 | status = service->decode(fd, offset, length, pSampleRate, |
| 876 | pNumChannels, pFormat, heap, pSize); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | } else { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 878 | ALOGE("Unable to locate media service"); |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 879 | status = DEAD_OBJECT; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | } |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 881 | return status; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | |
| 883 | } |
| 884 | |
Marco Nelissen | 6b74d67 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 885 | status_t MediaPlayer::setNextMediaPlayer(const sp<MediaPlayer>& next) { |
| 886 | if (mPlayer == NULL) { |
| 887 | return NO_INIT; |
| 888 | } |
Marco Nelissen | b13820f | 2013-08-05 12:22:43 -0700 | [diff] [blame] | 889 | |
| 890 | if (next != NULL && !(next->mCurrentState & |
| 891 | (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE))) { |
| 892 | ALOGE("next player is not prepared"); |
| 893 | return INVALID_OPERATION; |
| 894 | } |
| 895 | |
Marco Nelissen | 6b74d67 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 896 | return mPlayer->setNextPlayer(next == NULL ? NULL : next->mPlayer); |
| 897 | } |
| 898 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | }; // namespace android |