blob: 5dd8c02f4cfdfba200ef4b4ab0944574e5a9ee4b [file] [log] [blame]
Glenn Kasten99e53b82012-01-19 08:59:58 -08001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
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 Project89fa4ad2009-03-03 19:31:44 -080020
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080021#include <fcntl.h>
Mark Salyzyn34fb2962014-06-18 16:30:56 -070022#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 Project89fa4ad2009-03-03 19:31:44 -080028
Mathias Agopian75624082009-05-19 19:08:10 -070029#include <binder/IServiceManager.h>
30#include <binder/IPCThreadState.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080031
Mathias Agopianb1e7cd12013-02-14 17:11:27 -080032#include <gui/Surface.h>
Jamie Gennis61c7ef52011-07-13 12:59:34 -070033
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080034#include <media/mediaplayer.h>
Glenn Kastena3f1fa32012-01-18 14:54:46 -080035#include <media/AudioSystem.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036
Mathias Agopian75624082009-05-19 19:08:10 -070037#include <binder/MemoryBase.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080038
Andreas Huber2db84552010-01-28 11:19:57 -080039#include <utils/KeyedVector.h>
40#include <utils/String8.h>
41
Dima Zavin64760242011-05-11 14:15:23 -070042#include <system/audio.h>
Jamie Gennis61c7ef52011-07-13 12:59:34 -070043#include <system/window.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070044
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080045namespace android {
46
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080047MediaPlayer::MediaPlayer()
48{
Steve Block3856b092011-10-20 11:56:00 +010049 ALOGV("constructor");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080050 mListener = NULL;
51 mCookie = NULL;
Dima Zavinfce7a472011-04-19 22:30:36 -070052 mStreamType = AUDIO_STREAM_MUSIC;
Jean-Michel Trivi640adb32014-09-05 11:20:11 -070053 mAudioAttributesParcel = NULL;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080054 mCurrentPosition = -1;
55 mSeekPosition = -1;
56 mCurrentState = MEDIA_PLAYER_IDLE;
57 mPrepareSync = false;
58 mPrepareStatus = NO_ERROR;
59 mLoop = false;
60 mLeftVolume = mRightVolume = 1.0;
61 mVideoWidth = mVideoHeight = 0;
Wei Jia98160162015-02-04 17:01:11 -080062 mPlaybackRate = 1.0;
Jason Sams1af452f2009-03-24 18:45:22 -070063 mLockThreadId = 0;
Eric Laurentde3f8392014-07-27 18:38:22 -070064 mAudioSessionId = AudioSystem::newAudioUniqueId();
Marco Nelissend457c972014-02-11 08:47:07 -080065 AudioSystem::acquireAudioSessionId(mAudioSessionId, -1);
Eric Laurent8c563ed2010-10-07 18:23:03 -070066 mSendLevel = 0;
John Grossmanc795b642012-02-22 15:38:35 -080067 mRetransmitEndpointValid = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080068}
69
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080070MediaPlayer::~MediaPlayer()
71{
Steve Block3856b092011-10-20 11:56:00 +010072 ALOGV("destructor");
Jean-Michel Trivi640adb32014-09-05 11:20:11 -070073 if (mAudioAttributesParcel != NULL) {
74 delete mAudioAttributesParcel;
75 mAudioAttributesParcel = NULL;
76 }
Marco Nelissend457c972014-02-11 08:47:07 -080077 AudioSystem::releaseAudioSessionId(mAudioSessionId, -1);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078 disconnect();
79 IPCThreadState::self()->flushCommands();
80}
81
82void MediaPlayer::disconnect()
83{
Steve Block3856b092011-10-20 11:56:00 +010084 ALOGV("disconnect");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080085 sp<IMediaPlayer> p;
86 {
87 Mutex::Autolock _l(mLock);
88 p = mPlayer;
89 mPlayer.clear();
90 }
91
92 if (p != 0) {
93 p->disconnect();
94 }
95}
96
97// always call with lock held
98void MediaPlayer::clear_l()
99{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800100 mCurrentPosition = -1;
101 mSeekPosition = -1;
102 mVideoWidth = mVideoHeight = 0;
John Grossmanc795b642012-02-22 15:38:35 -0800103 mRetransmitEndpointValid = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104}
105
106status_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener)
107{
Steve Block3856b092011-10-20 11:56:00 +0100108 ALOGV("setListener");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800109 Mutex::Autolock _l(mLock);
110 mListener = listener;
111 return NO_ERROR;
112}
113
114
Dave Burked681bbb2011-08-30 14:39:17 +0100115status_t MediaPlayer::attachNewPlayer(const sp<IMediaPlayer>& player)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800116{
117 status_t err = UNKNOWN_ERROR;
118 sp<IMediaPlayer> p;
119 { // scope for the lock
120 Mutex::Autolock _l(mLock);
121
Marco Nelissen83ff1432010-03-10 10:53:16 -0800122 if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) ||
123 (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) {
Steve Block29357bc2012-01-06 19:20:56 +0000124 ALOGE("attachNewPlayer called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125 return INVALID_OPERATION;
126 }
127
128 clear_l();
129 p = mPlayer;
130 mPlayer = player;
131 if (player != 0) {
132 mCurrentState = MEDIA_PLAYER_INITIALIZED;
133 err = NO_ERROR;
134 } else {
Masaki Muranakaf65fa172013-06-06 09:36:34 +0000135 ALOGE("Unable to create media player");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136 }
137 }
138
139 if (p != 0) {
140 p->disconnect();
141 }
142
143 return err;
144}
145
Andreas Huber2db84552010-01-28 11:19:57 -0800146status_t MediaPlayer::setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -0800147 const sp<IMediaHTTPService> &httpService,
Andreas Huber2db84552010-01-28 11:19:57 -0800148 const char *url, const KeyedVector<String8, String8> *headers)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800149{
Steve Block3856b092011-10-20 11:56:00 +0100150 ALOGV("setDataSource(%s)", url);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800151 status_t err = BAD_VALUE;
152 if (url != NULL) {
153 const sp<IMediaPlayerService>& service(getMediaPlayerService());
154 if (service != 0) {
Glenn Kastenf37971f2012-02-03 11:06:53 -0800155 sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
John Grossmanc795b642012-02-22 15:38:35 -0800156 if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
Andreas Huber1b86fe02014-01-29 11:13:26 -0800157 (NO_ERROR != player->setDataSource(httpService, url, headers))) {
Dave Burke06620672011-09-06 20:39:47 +0100158 player.clear();
Dave Burked681bbb2011-08-30 14:39:17 +0100159 }
Dave Burke06620672011-09-06 20:39:47 +0100160 err = attachNewPlayer(player);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800161 }
162 }
163 return err;
164}
165
166status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length)
167{
Mark Salyzyn34fb2962014-06-18 16:30:56 -0700168 ALOGV("setDataSource(%d, %" PRId64 ", %" PRId64 ")", fd, offset, length);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800169 status_t err = UNKNOWN_ERROR;
170 const sp<IMediaPlayerService>& service(getMediaPlayerService());
171 if (service != 0) {
Glenn Kastenf37971f2012-02-03 11:06:53 -0800172 sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
John Grossmanc795b642012-02-22 15:38:35 -0800173 if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
174 (NO_ERROR != player->setDataSource(fd, offset, length))) {
Dave Burke06620672011-09-06 20:39:47 +0100175 player.clear();
Dave Burked681bbb2011-08-30 14:39:17 +0100176 }
Dave Burke06620672011-09-06 20:39:47 +0100177 err = attachNewPlayer(player);
Dave Burked681bbb2011-08-30 14:39:17 +0100178 }
179 return err;
180}
181
182status_t MediaPlayer::setDataSource(const sp<IStreamSource> &source)
183{
Steve Block3856b092011-10-20 11:56:00 +0100184 ALOGV("setDataSource");
Dave Burked681bbb2011-08-30 14:39:17 +0100185 status_t err = UNKNOWN_ERROR;
186 const sp<IMediaPlayerService>& service(getMediaPlayerService());
187 if (service != 0) {
Glenn Kastenf37971f2012-02-03 11:06:53 -0800188 sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
John Grossmanc795b642012-02-22 15:38:35 -0800189 if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
190 (NO_ERROR != player->setDataSource(source))) {
Dave Burke06620672011-09-06 20:39:47 +0100191 player.clear();
Dave Burked681bbb2011-08-30 14:39:17 +0100192 }
Dave Burke06620672011-09-06 20:39:47 +0100193 err = attachNewPlayer(player);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800194 }
195 return err;
196}
197
Nicolas Catania1d187f12009-05-12 23:25:55 -0700198status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply)
199{
200 Mutex::Autolock _l(mLock);
Nicolas Catania40234932010-03-10 10:41:04 -0800201 const bool hasBeenInitialized =
202 (mCurrentState != MEDIA_PLAYER_STATE_ERROR) &&
203 ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE);
204 if ((mPlayer != NULL) && hasBeenInitialized) {
Mark Salyzyn34fb2962014-06-18 16:30:56 -0700205 ALOGV("invoke %zu", request.dataSize());
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700206 return mPlayer->invoke(request, reply);
Nicolas Catania1d187f12009-05-12 23:25:55 -0700207 }
Steve Block29357bc2012-01-06 19:20:56 +0000208 ALOGE("invoke failed: wrong state %X", mCurrentState);
Nicolas Catania1d187f12009-05-12 23:25:55 -0700209 return INVALID_OPERATION;
210}
211
Nicolas Cataniaa7e0e8b2009-07-08 08:57:42 -0700212status_t MediaPlayer::setMetadataFilter(const Parcel& filter)
213{
Steve Blockb8a80522011-12-20 16:23:08 +0000214 ALOGD("setMetadataFilter");
Nicolas Catania8e1b6cc2009-07-09 09:21:33 -0700215 Mutex::Autolock lock(mLock);
216 if (mPlayer == NULL) {
Nicolas Cataniaa7e0e8b2009-07-08 08:57:42 -0700217 return NO_INIT;
218 }
219 return mPlayer->setMetadataFilter(filter);
220}
Nicolas Catania1d187f12009-05-12 23:25:55 -0700221
Nicolas Catania8e1b6cc2009-07-09 09:21:33 -0700222status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata)
223{
Steve Blockb8a80522011-12-20 16:23:08 +0000224 ALOGD("getMetadata");
Nicolas Catania8e1b6cc2009-07-09 09:21:33 -0700225 Mutex::Autolock lock(mLock);
226 if (mPlayer == NULL) {
227 return NO_INIT;
228 }
229 return mPlayer->getMetadata(update_only, apply_filter, metadata);
230}
231
Glenn Kasten11731182011-02-08 17:26:17 -0800232status_t MediaPlayer::setVideoSurfaceTexture(
Andy McFadden484566c2012-12-18 09:46:54 -0800233 const sp<IGraphicBufferProducer>& bufferProducer)
Glenn Kasten11731182011-02-08 17:26:17 -0800234{
Steve Block3856b092011-10-20 11:56:00 +0100235 ALOGV("setVideoSurfaceTexture");
Glenn Kasten11731182011-02-08 17:26:17 -0800236 Mutex::Autolock _l(mLock);
237 if (mPlayer == 0) return NO_INIT;
Andy McFadden484566c2012-12-18 09:46:54 -0800238 return mPlayer->setVideoSurfaceTexture(bufferProducer);
Glenn Kasten11731182011-02-08 17:26:17 -0800239}
240
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800241// must call with lock held
242status_t MediaPlayer::prepareAsync_l()
243{
Glenn Kastenb187de12014-12-30 08:18:15 -0800244 if ( (mPlayer != 0) && ( mCurrentState & (MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800245 mPlayer->setAudioStreamType(mStreamType);
Jean-Michel Trivi640adb32014-09-05 11:20:11 -0700246 if (mAudioAttributesParcel != NULL) {
247 mPlayer->setParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES, *mAudioAttributesParcel);
248 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800249 mCurrentState = MEDIA_PLAYER_PREPARING;
250 return mPlayer->prepareAsync();
251 }
Steve Block29357bc2012-01-06 19:20:56 +0000252 ALOGE("prepareAsync called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800253 return INVALID_OPERATION;
254}
255
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700256// TODO: In case of error, prepareAsync provides the caller with 2 error codes,
257// one defined in the Android framework and one provided by the implementation
258// that generated the error. The sync version of prepare returns only 1 error
259// code.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800260status_t MediaPlayer::prepare()
261{
Steve Block3856b092011-10-20 11:56:00 +0100262 ALOGV("prepare");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800263 Mutex::Autolock _l(mLock);
Jason Sams1af452f2009-03-24 18:45:22 -0700264 mLockThreadId = getThreadId();
265 if (mPrepareSync) {
266 mLockThreadId = 0;
267 return -EALREADY;
268 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800269 mPrepareSync = true;
270 status_t ret = prepareAsync_l();
Jason Sams1af452f2009-03-24 18:45:22 -0700271 if (ret != NO_ERROR) {
272 mLockThreadId = 0;
273 return ret;
274 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275
276 if (mPrepareSync) {
277 mSignal.wait(mLock); // wait for prepare done
278 mPrepareSync = false;
279 }
Steve Block3856b092011-10-20 11:56:00 +0100280 ALOGV("prepare complete - status=%d", mPrepareStatus);
Jason Sams1af452f2009-03-24 18:45:22 -0700281 mLockThreadId = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800282 return mPrepareStatus;
283}
284
285status_t MediaPlayer::prepareAsync()
286{
Steve Block3856b092011-10-20 11:56:00 +0100287 ALOGV("prepareAsync");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800288 Mutex::Autolock _l(mLock);
289 return prepareAsync_l();
290}
291
292status_t MediaPlayer::start()
293{
Steve Block3856b092011-10-20 11:56:00 +0100294 ALOGV("start");
Chong Zhangd88adb92014-07-23 11:43:46 -0700295
296 status_t ret = NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800297 Mutex::Autolock _l(mLock);
Chong Zhangd88adb92014-07-23 11:43:46 -0700298
299 mLockThreadId = getThreadId();
300
301 if (mCurrentState & MEDIA_PLAYER_STARTED) {
302 ret = NO_ERROR;
303 } else if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED |
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800304 MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) {
305 mPlayer->setLooping(mLoop);
306 mPlayer->setVolume(mLeftVolume, mRightVolume);
Eric Laurent2beeb502010-07-16 07:43:46 -0700307 mPlayer->setAuxEffectSendLevel(mSendLevel);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800308 mCurrentState = MEDIA_PLAYER_STARTED;
Chong Zhangd88adb92014-07-23 11:43:46 -0700309 ret = mPlayer->start();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800310 if (ret != NO_ERROR) {
311 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
312 } else {
313 if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) {
Steve Block3856b092011-10-20 11:56:00 +0100314 ALOGV("playback completed immediately following start()");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800315 }
316 }
Chong Zhangd88adb92014-07-23 11:43:46 -0700317 } else {
318 ALOGE("start called in state %d", mCurrentState);
319 ret = INVALID_OPERATION;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800320 }
Chong Zhangd88adb92014-07-23 11:43:46 -0700321
322 mLockThreadId = 0;
323
324 return ret;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800325}
326
327status_t MediaPlayer::stop()
328{
Steve Block3856b092011-10-20 11:56:00 +0100329 ALOGV("stop");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800330 Mutex::Autolock _l(mLock);
331 if (mCurrentState & MEDIA_PLAYER_STOPPED) return NO_ERROR;
332 if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED |
333 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) ) {
334 status_t ret = mPlayer->stop();
335 if (ret != NO_ERROR) {
336 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
337 } else {
338 mCurrentState = MEDIA_PLAYER_STOPPED;
339 }
340 return ret;
341 }
Steve Block29357bc2012-01-06 19:20:56 +0000342 ALOGE("stop called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800343 return INVALID_OPERATION;
344}
345
346status_t MediaPlayer::pause()
347{
Steve Block3856b092011-10-20 11:56:00 +0100348 ALOGV("pause");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800349 Mutex::Autolock _l(mLock);
Marco Nelissen698f4762010-02-26 13:16:23 -0800350 if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE))
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800351 return NO_ERROR;
352 if ((mPlayer != 0) && (mCurrentState & MEDIA_PLAYER_STARTED)) {
353 status_t ret = mPlayer->pause();
354 if (ret != NO_ERROR) {
355 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
356 } else {
357 mCurrentState = MEDIA_PLAYER_PAUSED;
358 }
359 return ret;
360 }
Steve Block29357bc2012-01-06 19:20:56 +0000361 ALOGE("pause called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800362 return INVALID_OPERATION;
363}
364
365bool MediaPlayer::isPlaying()
366{
367 Mutex::Autolock _l(mLock);
368 if (mPlayer != 0) {
369 bool temp = false;
370 mPlayer->isPlaying(&temp);
Steve Block3856b092011-10-20 11:56:00 +0100371 ALOGV("isPlaying: %d", temp);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800372 if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) {
Steve Block29357bc2012-01-06 19:20:56 +0000373 ALOGE("internal/external state mismatch corrected");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800374 mCurrentState = MEDIA_PLAYER_PAUSED;
375 }
376 return temp;
377 }
Steve Block3856b092011-10-20 11:56:00 +0100378 ALOGV("isPlaying: no active player");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800379 return false;
380}
381
Wei Jia98160162015-02-04 17:01:11 -0800382status_t MediaPlayer::setPlaybackRate(float rate)
383{
384 ALOGV("setPlaybackRate: %f", rate);
385 if (rate <= 0.0) {
386 return BAD_VALUE;
387 }
388 Mutex::Autolock _l(mLock);
389 if (mPlayer != 0) {
390 if (mPlaybackRate == rate) {
391 return NO_ERROR;
392 }
393 mPlaybackRate = rate;
394 return mPlayer->setPlaybackRate(rate);
395 }
396 ALOGV("setPlaybackRate: no active player");
397 return INVALID_OPERATION;
398}
399
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800400status_t MediaPlayer::getVideoWidth(int *w)
401{
Steve Block3856b092011-10-20 11:56:00 +0100402 ALOGV("getVideoWidth");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800403 Mutex::Autolock _l(mLock);
404 if (mPlayer == 0) return INVALID_OPERATION;
405 *w = mVideoWidth;
406 return NO_ERROR;
407}
408
409status_t MediaPlayer::getVideoHeight(int *h)
410{
Steve Block3856b092011-10-20 11:56:00 +0100411 ALOGV("getVideoHeight");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800412 Mutex::Autolock _l(mLock);
413 if (mPlayer == 0) return INVALID_OPERATION;
414 *h = mVideoHeight;
415 return NO_ERROR;
416}
417
418status_t MediaPlayer::getCurrentPosition(int *msec)
419{
Steve Block3856b092011-10-20 11:56:00 +0100420 ALOGV("getCurrentPosition");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800421 Mutex::Autolock _l(mLock);
422 if (mPlayer != 0) {
423 if (mCurrentPosition >= 0) {
Steve Block3856b092011-10-20 11:56:00 +0100424 ALOGV("Using cached seek position: %d", mCurrentPosition);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800425 *msec = mCurrentPosition;
426 return NO_ERROR;
427 }
428 return mPlayer->getCurrentPosition(msec);
429 }
430 return INVALID_OPERATION;
431}
432
433status_t MediaPlayer::getDuration_l(int *msec)
434{
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800435 ALOGV("getDuration_l");
Glenn Kastenb187de12014-12-30 08:18:15 -0800436 bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED |
437 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800438 if (mPlayer != 0 && isValidState) {
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800439 int durationMs;
440 status_t ret = mPlayer->getDuration(&durationMs);
Andreas Huber20702542013-04-11 11:07:55 -0700441
442 if (ret != OK) {
443 // Do not enter error state just because no duration was available.
444 durationMs = -1;
445 ret = OK;
446 }
447
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800448 if (msec) {
449 *msec = durationMs;
450 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800451 return ret;
452 }
Steve Block29357bc2012-01-06 19:20:56 +0000453 ALOGE("Attempt to call getDuration without a valid mediaplayer");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800454 return INVALID_OPERATION;
455}
456
457status_t MediaPlayer::getDuration(int *msec)
458{
459 Mutex::Autolock _l(mLock);
460 return getDuration_l(msec);
461}
462
463status_t MediaPlayer::seekTo_l(int msec)
464{
Steve Block3856b092011-10-20 11:56:00 +0100465 ALOGV("seekTo %d", msec);
Glenn Kastenb187de12014-12-30 08:18:15 -0800466 if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED |
467 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800468 if ( msec < 0 ) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000469 ALOGW("Attempt to seek to invalid position: %d", msec);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800470 msec = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800471 }
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800472
473 int durationMs;
474 status_t err = mPlayer->getDuration(&durationMs);
475
476 if (err != OK) {
477 ALOGW("Stream has no duration and is therefore not seekable.");
478 return err;
479 }
480
481 if (msec > durationMs) {
482 ALOGW("Attempt to seek to past end of file: request = %d, "
483 "durationMs = %d",
484 msec,
485 durationMs);
486
487 msec = durationMs;
488 }
489
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800490 // cache duration
491 mCurrentPosition = msec;
492 if (mSeekPosition < 0) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800493 mSeekPosition = msec;
494 return mPlayer->seekTo(msec);
495 }
496 else {
Steve Block3856b092011-10-20 11:56:00 +0100497 ALOGV("Seek in progress - queue up seekTo[%d]", msec);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800498 return NO_ERROR;
499 }
500 }
Glenn Kastenb187de12014-12-30 08:18:15 -0800501 ALOGE("Attempt to perform seekTo in wrong state: mPlayer=%p, mCurrentState=%u", mPlayer.get(),
502 mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800503 return INVALID_OPERATION;
504}
505
506status_t MediaPlayer::seekTo(int msec)
507{
Andreas Huber5cb07aa2009-03-24 20:48:51 -0700508 mLockThreadId = getThreadId();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800509 Mutex::Autolock _l(mLock);
Andreas Huber5cb07aa2009-03-24 20:48:51 -0700510 status_t result = seekTo_l(msec);
511 mLockThreadId = 0;
512
513 return result;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800514}
515
Jamie Gennis61c7ef52011-07-13 12:59:34 -0700516status_t MediaPlayer::reset_l()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800517{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800518 mLoop = false;
519 if (mCurrentState == MEDIA_PLAYER_IDLE) return NO_ERROR;
520 mPrepareSync = false;
521 if (mPlayer != 0) {
522 status_t ret = mPlayer->reset();
523 if (ret != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000524 ALOGE("reset() failed with return code (%d)", ret);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800525 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
526 } else {
527 mCurrentState = MEDIA_PLAYER_IDLE;
528 }
James Donga1680bc2010-11-18 12:23:58 -0800529 // setDataSource has to be called again to create a
530 // new mediaplayer.
531 mPlayer = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800532 return ret;
533 }
534 clear_l();
535 return NO_ERROR;
536}
537
John Grossmanc795b642012-02-22 15:38:35 -0800538status_t MediaPlayer::doSetRetransmitEndpoint(const sp<IMediaPlayer>& player) {
539 Mutex::Autolock _l(mLock);
540
541 if (player == NULL) {
542 return UNKNOWN_ERROR;
543 }
544
545 if (mRetransmitEndpointValid) {
546 return player->setRetransmitEndpoint(&mRetransmitEndpoint);
547 }
548
549 return OK;
550}
551
Jamie Gennis61c7ef52011-07-13 12:59:34 -0700552status_t MediaPlayer::reset()
553{
Steve Block3856b092011-10-20 11:56:00 +0100554 ALOGV("reset");
Jamie Gennis61c7ef52011-07-13 12:59:34 -0700555 Mutex::Autolock _l(mLock);
556 return reset_l();
557}
558
Glenn Kastenfff6d712012-01-12 16:38:12 -0800559status_t MediaPlayer::setAudioStreamType(audio_stream_type_t type)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800560{
Steve Block3856b092011-10-20 11:56:00 +0100561 ALOGV("MediaPlayer::setAudioStreamType");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800562 Mutex::Autolock _l(mLock);
563 if (mStreamType == type) return NO_ERROR;
564 if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED |
565 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) {
566 // Can't change the stream type after prepare
Steve Block29357bc2012-01-06 19:20:56 +0000567 ALOGE("setAudioStream called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800568 return INVALID_OPERATION;
569 }
570 // cache
571 mStreamType = type;
572 return OK;
573}
574
John Spurlockde9453f2014-03-19 13:05:45 -0400575status_t MediaPlayer::getAudioStreamType(audio_stream_type_t *type)
576{
577 ALOGV("getAudioStreamType");
578 Mutex::Autolock _l(mLock);
579 *type = mStreamType;
580 return OK;
581}
582
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800583status_t MediaPlayer::setLooping(int loop)
584{
Steve Block3856b092011-10-20 11:56:00 +0100585 ALOGV("MediaPlayer::setLooping");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800586 Mutex::Autolock _l(mLock);
587 mLoop = (loop != 0);
588 if (mPlayer != 0) {
589 return mPlayer->setLooping(loop);
590 }
591 return OK;
592}
593
594bool MediaPlayer::isLooping() {
Steve Block3856b092011-10-20 11:56:00 +0100595 ALOGV("isLooping");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800596 Mutex::Autolock _l(mLock);
597 if (mPlayer != 0) {
598 return mLoop;
599 }
Steve Block3856b092011-10-20 11:56:00 +0100600 ALOGV("isLooping: no active player");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800601 return false;
602}
603
604status_t MediaPlayer::setVolume(float leftVolume, float rightVolume)
605{
Steve Block3856b092011-10-20 11:56:00 +0100606 ALOGV("MediaPlayer::setVolume(%f, %f)", leftVolume, rightVolume);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800607 Mutex::Autolock _l(mLock);
608 mLeftVolume = leftVolume;
609 mRightVolume = rightVolume;
610 if (mPlayer != 0) {
611 return mPlayer->setVolume(leftVolume, rightVolume);
612 }
613 return OK;
614}
615
Eric Laurenta514bdb2010-06-21 09:27:30 -0700616status_t MediaPlayer::setAudioSessionId(int sessionId)
617{
Steve Block3856b092011-10-20 11:56:00 +0100618 ALOGV("MediaPlayer::setAudioSessionId(%d)", sessionId);
Eric Laurenta514bdb2010-06-21 09:27:30 -0700619 Mutex::Autolock _l(mLock);
620 if (!(mCurrentState & MEDIA_PLAYER_IDLE)) {
Steve Block29357bc2012-01-06 19:20:56 +0000621 ALOGE("setAudioSessionId called in state %d", mCurrentState);
Eric Laurenta514bdb2010-06-21 09:27:30 -0700622 return INVALID_OPERATION;
623 }
624 if (sessionId < 0) {
625 return BAD_VALUE;
626 }
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700627 if (sessionId != mAudioSessionId) {
Marco Nelissend457c972014-02-11 08:47:07 -0800628 AudioSystem::acquireAudioSessionId(sessionId, -1);
629 AudioSystem::releaseAudioSessionId(mAudioSessionId, -1);
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700630 mAudioSessionId = sessionId;
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700631 }
Eric Laurenta514bdb2010-06-21 09:27:30 -0700632 return NO_ERROR;
633}
634
635int MediaPlayer::getAudioSessionId()
636{
637 Mutex::Autolock _l(mLock);
638 return mAudioSessionId;
639}
640
Eric Laurent2beeb502010-07-16 07:43:46 -0700641status_t MediaPlayer::setAuxEffectSendLevel(float level)
642{
Steve Block3856b092011-10-20 11:56:00 +0100643 ALOGV("MediaPlayer::setAuxEffectSendLevel(%f)", level);
Eric Laurent2beeb502010-07-16 07:43:46 -0700644 Mutex::Autolock _l(mLock);
645 mSendLevel = level;
646 if (mPlayer != 0) {
647 return mPlayer->setAuxEffectSendLevel(level);
648 }
649 return OK;
650}
651
652status_t MediaPlayer::attachAuxEffect(int effectId)
653{
Steve Block3856b092011-10-20 11:56:00 +0100654 ALOGV("MediaPlayer::attachAuxEffect(%d)", effectId);
Eric Laurent2beeb502010-07-16 07:43:46 -0700655 Mutex::Autolock _l(mLock);
656 if (mPlayer == 0 ||
657 (mCurrentState & MEDIA_PLAYER_IDLE) ||
658 (mCurrentState == MEDIA_PLAYER_STATE_ERROR )) {
Steve Block29357bc2012-01-06 19:20:56 +0000659 ALOGE("attachAuxEffect called in state %d", mCurrentState);
Eric Laurent2beeb502010-07-16 07:43:46 -0700660 return INVALID_OPERATION;
661 }
662
663 return mPlayer->attachAuxEffect(effectId);
664}
665
Jean-Michel Trivid9d7fa02014-06-24 08:01:46 -0700666// always call with lock held
667status_t MediaPlayer::checkStateForKeySet_l(int key)
668{
669 switch(key) {
670 case KEY_PARAMETER_AUDIO_ATTRIBUTES:
671 if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED |
672 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) {
673 // Can't change the audio attributes after prepare
674 ALOGE("trying to set audio attributes called in state %d", mCurrentState);
675 return INVALID_OPERATION;
676 }
677 break;
678 default:
679 // parameter doesn't require player state check
680 break;
681 }
682 return OK;
683}
684
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700685status_t MediaPlayer::setParameter(int key, const Parcel& request)
686{
Steve Block3856b092011-10-20 11:56:00 +0100687 ALOGV("MediaPlayer::setParameter(%d)", key);
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700688 Mutex::Autolock _l(mLock);
Jean-Michel Trivid9d7fa02014-06-24 08:01:46 -0700689 if (checkStateForKeySet_l(key) != OK) {
690 return INVALID_OPERATION;
691 }
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700692 if (mPlayer != NULL) {
693 return mPlayer->setParameter(key, request);
694 }
Jean-Michel Trivi640adb32014-09-05 11:20:11 -0700695 switch (key) {
696 case KEY_PARAMETER_AUDIO_ATTRIBUTES:
697 // no player, save the marshalled audio attributes
698 if (mAudioAttributesParcel != NULL) { delete mAudioAttributesParcel; };
699 mAudioAttributesParcel = new Parcel();
700 mAudioAttributesParcel->appendFrom(&request, 0, request.dataSize());
701 return OK;
702 default:
703 ALOGV("setParameter: no active player");
704 return INVALID_OPERATION;
705 }
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700706}
707
708status_t MediaPlayer::getParameter(int key, Parcel *reply)
709{
Steve Block3856b092011-10-20 11:56:00 +0100710 ALOGV("MediaPlayer::getParameter(%d)", key);
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700711 Mutex::Autolock _l(mLock);
712 if (mPlayer != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700713 return mPlayer->getParameter(key, reply);
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700714 }
Steve Block3856b092011-10-20 11:56:00 +0100715 ALOGV("getParameter: no active player");
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700716 return INVALID_OPERATION;
717}
718
John Grossmanc795b642012-02-22 15:38:35 -0800719status_t MediaPlayer::setRetransmitEndpoint(const char* addrString,
720 uint16_t port) {
721 ALOGV("MediaPlayer::setRetransmitEndpoint(%s:%hu)",
722 addrString ? addrString : "(null)", port);
723
724 Mutex::Autolock _l(mLock);
725 if ((mPlayer != NULL) || (mCurrentState != MEDIA_PLAYER_IDLE))
726 return INVALID_OPERATION;
727
728 if (NULL == addrString) {
729 mRetransmitEndpointValid = false;
730 return OK;
731 }
732
733 struct in_addr saddr;
734 if(!inet_aton(addrString, &saddr)) {
735 return BAD_VALUE;
736 }
737
Glenn Kastenbe08f6a2013-12-19 09:09:33 -0800738 memset(&mRetransmitEndpoint, 0, sizeof(mRetransmitEndpoint));
John Grossmanc795b642012-02-22 15:38:35 -0800739 mRetransmitEndpoint.sin_family = AF_INET;
740 mRetransmitEndpoint.sin_addr = saddr;
741 mRetransmitEndpoint.sin_port = htons(port);
742 mRetransmitEndpointValid = true;
743
744 return OK;
745}
746
Gloria Wangb483c472011-04-11 17:23:27 -0700747void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800748{
Steve Block3856b092011-10-20 11:56:00 +0100749 ALOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800750 bool send = true;
Jason Sams1af452f2009-03-24 18:45:22 -0700751 bool locked = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800752
753 // TODO: In the future, we might be on the same thread if the app is
754 // running in the same process as the media server. In that case,
755 // this will deadlock.
Nicolas Catania66095182009-06-11 16:33:49 -0700756 //
Chong Zhangd88adb92014-07-23 11:43:46 -0700757 // The threadId hack below works around this for the care of prepare,
758 // seekTo and start within the same process.
Andreas Huber5cb07aa2009-03-24 20:48:51 -0700759 // FIXME: Remember, this is a hack, it's not even a hack that is applied
760 // consistently for all use-cases, this needs to be revisited.
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700761 if (mLockThreadId != getThreadId()) {
Jason Sams1af452f2009-03-24 18:45:22 -0700762 mLock.lock();
763 locked = true;
Nicolas Catania66095182009-06-11 16:33:49 -0700764 }
Jason Sams1af452f2009-03-24 18:45:22 -0700765
Eric Laurent3b268442010-08-03 07:49:49 -0700766 // Allows calls from JNI in idle state to notify errors
767 if (!(msg == MEDIA_ERROR && mCurrentState == MEDIA_PLAYER_IDLE) && mPlayer == 0) {
Steve Block3856b092011-10-20 11:56:00 +0100768 ALOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2);
Jason Sams1af452f2009-03-24 18:45:22 -0700769 if (locked) mLock.unlock(); // release the lock when done.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800770 return;
771 }
772
773 switch (msg) {
774 case MEDIA_NOP: // interface test message
775 break;
776 case MEDIA_PREPARED:
Steve Block3856b092011-10-20 11:56:00 +0100777 ALOGV("prepared");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800778 mCurrentState = MEDIA_PLAYER_PREPARED;
779 if (mPrepareSync) {
Steve Block3856b092011-10-20 11:56:00 +0100780 ALOGV("signal application thread");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800781 mPrepareSync = false;
782 mPrepareStatus = NO_ERROR;
783 mSignal.signal();
784 }
785 break;
786 case MEDIA_PLAYBACK_COMPLETE:
Steve Block3856b092011-10-20 11:56:00 +0100787 ALOGV("playback complete");
Marco Nelissen1c1503c2010-09-17 15:04:01 -0700788 if (mCurrentState == MEDIA_PLAYER_IDLE) {
Steve Block29357bc2012-01-06 19:20:56 +0000789 ALOGE("playback complete in idle state");
Marco Nelissen1c1503c2010-09-17 15:04:01 -0700790 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800791 if (!mLoop) {
792 mCurrentState = MEDIA_PLAYER_PLAYBACK_COMPLETE;
793 }
794 break;
795 case MEDIA_ERROR:
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700796 // Always log errors.
797 // ext1: Media framework error code.
798 // ext2: Implementation dependant error code.
Steve Block29357bc2012-01-06 19:20:56 +0000799 ALOGE("error (%d, %d)", ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800800 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
801 if (mPrepareSync)
802 {
Steve Block3856b092011-10-20 11:56:00 +0100803 ALOGV("signal application thread");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800804 mPrepareSync = false;
805 mPrepareStatus = ext1;
806 mSignal.signal();
807 send = false;
808 }
809 break;
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700810 case MEDIA_INFO:
811 // ext1: Media framework error code.
812 // ext2: Implementation dependant error code.
Andreas Huber145e68f2011-01-11 15:05:28 -0800813 if (ext1 != MEDIA_INFO_VIDEO_TRACK_LAGGING) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000814 ALOGW("info/warning (%d, %d)", ext1, ext2);
Andreas Huber145e68f2011-01-11 15:05:28 -0800815 }
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700816 break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800817 case MEDIA_SEEK_COMPLETE:
Steve Block3856b092011-10-20 11:56:00 +0100818 ALOGV("Received seek complete");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800819 if (mSeekPosition != mCurrentPosition) {
Steve Block3856b092011-10-20 11:56:00 +0100820 ALOGV("Executing queued seekTo(%d)", mSeekPosition);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800821 mSeekPosition = -1;
822 seekTo_l(mCurrentPosition);
823 }
824 else {
Steve Block3856b092011-10-20 11:56:00 +0100825 ALOGV("All seeks complete - return to regularly scheduled program");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800826 mCurrentPosition = mSeekPosition = -1;
827 }
828 break;
829 case MEDIA_BUFFERING_UPDATE:
Steve Block3856b092011-10-20 11:56:00 +0100830 ALOGV("buffering %d", ext1);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800831 break;
832 case MEDIA_SET_VIDEO_SIZE:
Steve Block3856b092011-10-20 11:56:00 +0100833 ALOGV("New video size %d x %d", ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800834 mVideoWidth = ext1;
835 mVideoHeight = ext2;
836 break;
Gloria Wangb483c472011-04-11 17:23:27 -0700837 case MEDIA_TIMED_TEXT:
Steve Block3856b092011-10-20 11:56:00 +0100838 ALOGV("Received timed text message");
Gloria Wangb483c472011-04-11 17:23:27 -0700839 break;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700840 case MEDIA_SUBTITLE_DATA:
841 ALOGV("Received subtitle data message");
842 break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800843 default:
Steve Block3856b092011-10-20 11:56:00 +0100844 ALOGV("unrecognized message: (%d, %d, %d)", msg, ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800845 break;
846 }
847
848 sp<MediaPlayerListener> listener = mListener;
Jason Sams1af452f2009-03-24 18:45:22 -0700849 if (locked) mLock.unlock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800850
851 // this prevents re-entrant calls into client code
852 if ((listener != 0) && send) {
853 Mutex::Autolock _l(mNotifyLock);
Steve Block3856b092011-10-20 11:56:00 +0100854 ALOGV("callback application");
Gloria Wangb483c472011-04-11 17:23:27 -0700855 listener->notify(msg, ext1, ext2, obj);
Steve Block3856b092011-10-20 11:56:00 +0100856 ALOGV("back from callback");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800857 }
858}
859
James Dongdd172fc2010-01-15 18:13:58 -0800860void MediaPlayer::died()
861{
Steve Block3856b092011-10-20 11:56:00 +0100862 ALOGV("died");
James Dongdd172fc2010-01-15 18:13:58 -0800863 notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0);
864}
865
Marco Nelissen6b74d672012-02-28 16:07:44 -0800866status_t MediaPlayer::setNextMediaPlayer(const sp<MediaPlayer>& next) {
867 if (mPlayer == NULL) {
868 return NO_INIT;
869 }
Marco Nelissenb13820f2013-08-05 12:22:43 -0700870
871 if (next != NULL && !(next->mCurrentState &
872 (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE))) {
873 ALOGE("next player is not prepared");
874 return INVALID_OPERATION;
875 }
876
Marco Nelissen6b74d672012-02-28 16:07:44 -0800877 return mPlayer->setNextPlayer(next == NULL ? NULL : next->mPlayer);
878}
879
Glenn Kasten40bc9062015-03-20 09:09:33 -0700880} // namespace android