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