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