blob: e4850f01dc50b310e4e3f6f2baf2cc48f5763d41 [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "NuPlayerDriver"
Kévin PETIT377b2ec2014-02-03 12:35:36 +000019#include <inttypes.h>
Andreas Huberf9334412010-12-15 15:17:42 -080020#include <utils/Log.h>
21
22#include "NuPlayerDriver.h"
23
24#include "NuPlayer.h"
Andreas Huber9575c962013-02-05 13:59:56 -080025#include "NuPlayerSource.h"
Andreas Huberf9334412010-12-15 15:17:42 -080026
Andreas Huber1aef2112011-01-04 14:01:29 -080027#include <media/stagefright/foundation/ADebug.h>
Andreas Huberf9334412010-12-15 15:17:42 -080028#include <media/stagefright/foundation/ALooper.h>
Andreas Huber9575c962013-02-05 13:59:56 -080029#include <media/stagefright/MetaData.h>
Andreas Huberf9334412010-12-15 15:17:42 -080030
31namespace android {
32
33NuPlayerDriver::NuPlayerDriver()
Andreas Huber9575c962013-02-05 13:59:56 -080034 : mState(STATE_IDLE),
Andreas Huberec0c5972013-02-05 14:47:13 -080035 mIsAsyncPrepare(false),
Andreas Huber9575c962013-02-05 13:59:56 -080036 mAsyncResult(UNKNOWN_ERROR),
Andreas Huber57a339c2012-12-03 11:18:00 -080037 mSetSurfaceInProgress(false),
Andreas Huber43c3e6c2011-01-05 12:17:08 -080038 mDurationUs(-1),
39 mPositionUs(-1),
Andreas Huber3fe62152011-09-16 15:09:22 -070040 mNumFramesTotal(0),
41 mNumFramesDropped(0),
Andreas Huber1aef2112011-01-04 14:01:29 -080042 mLooper(new ALooper),
Andreas Huber9575c962013-02-05 13:59:56 -080043 mPlayerFlags(0),
Andreas Hubera4af2142011-10-26 15:23:31 -070044 mAtEOS(false),
Andreas Huber43c3e6c2011-01-05 12:17:08 -080045 mStartupSeekTimeUs(-1) {
Andreas Huberf9334412010-12-15 15:17:42 -080046 mLooper->setName("NuPlayerDriver Looper");
47
48 mLooper->start(
49 false, /* runOnCallingThread */
50 true, /* canCallJava */
51 PRIORITY_AUDIO);
52
53 mPlayer = new NuPlayer;
54 mLooper->registerHandler(mPlayer);
55
Andreas Huber43c3e6c2011-01-05 12:17:08 -080056 mPlayer->setDriver(this);
Andreas Huberf9334412010-12-15 15:17:42 -080057}
58
59NuPlayerDriver::~NuPlayerDriver() {
60 mLooper->stop();
61}
62
63status_t NuPlayerDriver::initCheck() {
64 return OK;
65}
66
Andreas Huber9b80c2b2011-06-30 15:47:02 -070067status_t NuPlayerDriver::setUID(uid_t uid) {
68 mPlayer->setUID(uid);
69
70 return OK;
71}
72
Andreas Huberf9334412010-12-15 15:17:42 -080073status_t NuPlayerDriver::setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -080074 const sp<IMediaHTTPService> &httpService,
75 const char *url,
76 const KeyedVector<String8, String8> *headers) {
Andreas Huber9575c962013-02-05 13:59:56 -080077 Mutex::Autolock autoLock(mLock);
Andreas Huber43c3e6c2011-01-05 12:17:08 -080078
Andreas Huber9575c962013-02-05 13:59:56 -080079 if (mState != STATE_IDLE) {
80 return INVALID_OPERATION;
81 }
Andreas Huber5bc087c2010-12-23 10:27:40 -080082
Andreas Huber9575c962013-02-05 13:59:56 -080083 mState = STATE_SET_DATASOURCE_PENDING;
Andreas Huber43c3e6c2011-01-05 12:17:08 -080084
Andreas Huber1b86fe02014-01-29 11:13:26 -080085 mPlayer->setDataSourceAsync(httpService, url, headers);
Andreas Huber9575c962013-02-05 13:59:56 -080086
87 while (mState == STATE_SET_DATASOURCE_PENDING) {
88 mCondition.wait(mLock);
89 }
90
91 return mAsyncResult;
Andreas Huberf9334412010-12-15 15:17:42 -080092}
93
94status_t NuPlayerDriver::setDataSource(int fd, int64_t offset, int64_t length) {
Andreas Huber9575c962013-02-05 13:59:56 -080095 Mutex::Autolock autoLock(mLock);
Andreas Huberafed0e12011-09-20 15:39:58 -070096
Andreas Huber9575c962013-02-05 13:59:56 -080097 if (mState != STATE_IDLE) {
98 return INVALID_OPERATION;
99 }
Andreas Huberafed0e12011-09-20 15:39:58 -0700100
Andreas Huber9575c962013-02-05 13:59:56 -0800101 mState = STATE_SET_DATASOURCE_PENDING;
Andreas Huberafed0e12011-09-20 15:39:58 -0700102
Andreas Huber9575c962013-02-05 13:59:56 -0800103 mPlayer->setDataSourceAsync(fd, offset, length);
104
105 while (mState == STATE_SET_DATASOURCE_PENDING) {
106 mCondition.wait(mLock);
107 }
108
109 return mAsyncResult;
Andreas Huberf9334412010-12-15 15:17:42 -0800110}
111
112status_t NuPlayerDriver::setDataSource(const sp<IStreamSource> &source) {
Andreas Huber9575c962013-02-05 13:59:56 -0800113 Mutex::Autolock autoLock(mLock);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800114
Andreas Huber9575c962013-02-05 13:59:56 -0800115 if (mState != STATE_IDLE) {
116 return INVALID_OPERATION;
117 }
Andreas Huberf9334412010-12-15 15:17:42 -0800118
Andreas Huber9575c962013-02-05 13:59:56 -0800119 mState = STATE_SET_DATASOURCE_PENDING;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800120
Andreas Huber9575c962013-02-05 13:59:56 -0800121 mPlayer->setDataSourceAsync(source);
122
123 while (mState == STATE_SET_DATASOURCE_PENDING) {
124 mCondition.wait(mLock);
125 }
126
127 return mAsyncResult;
Andreas Huberf9334412010-12-15 15:17:42 -0800128}
129
Glenn Kasten11731182011-02-08 17:26:17 -0800130status_t NuPlayerDriver::setVideoSurfaceTexture(
Andy McFadden8ba01022012-12-18 09:46:54 -0800131 const sp<IGraphicBufferProducer> &bufferProducer) {
Andreas Huber57a339c2012-12-03 11:18:00 -0800132 Mutex::Autolock autoLock(mLock);
133
Andreas Huber9575c962013-02-05 13:59:56 -0800134 if (mSetSurfaceInProgress) {
Andreas Huber57a339c2012-12-03 11:18:00 -0800135 return INVALID_OPERATION;
136 }
137
Andreas Huber9575c962013-02-05 13:59:56 -0800138 switch (mState) {
139 case STATE_SET_DATASOURCE_PENDING:
140 case STATE_RESET_IN_PROGRESS:
141 return INVALID_OPERATION;
142
143 default:
144 break;
145 }
146
Andreas Huber57a339c2012-12-03 11:18:00 -0800147 mSetSurfaceInProgress = true;
148
Andy McFadden8ba01022012-12-18 09:46:54 -0800149 mPlayer->setVideoSurfaceTextureAsync(bufferProducer);
Andreas Huber57a339c2012-12-03 11:18:00 -0800150
151 while (mSetSurfaceInProgress) {
152 mCondition.wait(mLock);
153 }
Glenn Kasten11731182011-02-08 17:26:17 -0800154
155 return OK;
156}
157
Andreas Huberf9334412010-12-15 15:17:42 -0800158status_t NuPlayerDriver::prepare() {
Andreas Huber9575c962013-02-05 13:59:56 -0800159 Mutex::Autolock autoLock(mLock);
160 return prepare_l();
161}
162
163status_t NuPlayerDriver::prepare_l() {
164 switch (mState) {
165 case STATE_UNPREPARED:
166 mState = STATE_PREPARING;
Andreas Huberec0c5972013-02-05 14:47:13 -0800167
168 // Make sure we're not posting any notifications, success or
169 // failure information is only communicated through our result
170 // code.
171 mIsAsyncPrepare = false;
Andreas Huber9575c962013-02-05 13:59:56 -0800172 mPlayer->prepareAsync();
173 while (mState == STATE_PREPARING) {
174 mCondition.wait(mLock);
175 }
176 return (mState == STATE_PREPARED) ? OK : UNKNOWN_ERROR;
177 default:
178 return INVALID_OPERATION;
179 };
Andreas Huberf9334412010-12-15 15:17:42 -0800180}
181
182status_t NuPlayerDriver::prepareAsync() {
Andreas Huber9575c962013-02-05 13:59:56 -0800183 Mutex::Autolock autoLock(mLock);
Andreas Huberafed0e12011-09-20 15:39:58 -0700184
Andreas Huber9575c962013-02-05 13:59:56 -0800185 switch (mState) {
186 case STATE_UNPREPARED:
187 mState = STATE_PREPARING;
Andreas Huberec0c5972013-02-05 14:47:13 -0800188 mIsAsyncPrepare = true;
Andreas Huber9575c962013-02-05 13:59:56 -0800189 mPlayer->prepareAsync();
190 return OK;
191 default:
192 return INVALID_OPERATION;
193 };
Andreas Huberf9334412010-12-15 15:17:42 -0800194}
195
196status_t NuPlayerDriver::start() {
Andreas Huber9575c962013-02-05 13:59:56 -0800197 Mutex::Autolock autoLock(mLock);
198
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800199 switch (mState) {
Andreas Huber9575c962013-02-05 13:59:56 -0800200 case STATE_UNPREPARED:
201 {
202 status_t err = prepare_l();
203
204 if (err != OK) {
205 return err;
206 }
207
208 CHECK_EQ(mState, STATE_PREPARED);
209
210 // fall through
211 }
212
213 case STATE_PREPARED:
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800214 {
Andreas Hubera4af2142011-10-26 15:23:31 -0700215 mAtEOS = false;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800216 mPlayer->start();
217
218 if (mStartupSeekTimeUs >= 0) {
Andreas Huber2048d0c2011-07-15 16:25:41 -0700219 if (mStartupSeekTimeUs == 0) {
220 notifySeekComplete();
221 } else {
222 mPlayer->seekToAsync(mStartupSeekTimeUs);
223 }
224
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800225 mStartupSeekTimeUs = -1;
226 }
227 break;
228 }
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800229
Andreas Huber9575c962013-02-05 13:59:56 -0800230 case STATE_RUNNING:
231 break;
232
233 case STATE_PAUSED:
234 {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800235 mPlayer->resume();
236 break;
237 }
Andreas Huber9575c962013-02-05 13:59:56 -0800238
239 default:
240 return INVALID_OPERATION;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800241 }
242
Andreas Huber9575c962013-02-05 13:59:56 -0800243 mState = STATE_RUNNING;
Andreas Huberf9334412010-12-15 15:17:42 -0800244
245 return OK;
246}
247
248status_t NuPlayerDriver::stop() {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800249 return pause();
Andreas Huberf9334412010-12-15 15:17:42 -0800250}
251
252status_t NuPlayerDriver::pause() {
Andreas Huber9575c962013-02-05 13:59:56 -0800253 Mutex::Autolock autoLock(mLock);
254
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800255 switch (mState) {
Andreas Huber9575c962013-02-05 13:59:56 -0800256 case STATE_PAUSED:
257 case STATE_PREPARED:
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800258 return OK;
Andreas Huber9575c962013-02-05 13:59:56 -0800259
260 case STATE_RUNNING:
Lajos Molnarcbaffcf2013-08-14 18:30:38 -0700261 notifyListener(MEDIA_PAUSED);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800262 mPlayer->pause();
263 break;
Andreas Huber9575c962013-02-05 13:59:56 -0800264
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800265 default:
Andreas Huber9575c962013-02-05 13:59:56 -0800266 return INVALID_OPERATION;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800267 }
268
Andreas Huber9575c962013-02-05 13:59:56 -0800269 mState = STATE_PAUSED;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800270
Andreas Huberf9334412010-12-15 15:17:42 -0800271 return OK;
272}
273
274bool NuPlayerDriver::isPlaying() {
Andreas Huber9575c962013-02-05 13:59:56 -0800275 return mState == STATE_RUNNING && !mAtEOS;
Andreas Huberf9334412010-12-15 15:17:42 -0800276}
277
278status_t NuPlayerDriver::seekTo(int msec) {
Andreas Huber9575c962013-02-05 13:59:56 -0800279 Mutex::Autolock autoLock(mLock);
280
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800281 int64_t seekTimeUs = msec * 1000ll;
282
283 switch (mState) {
Andreas Huber9575c962013-02-05 13:59:56 -0800284 case STATE_PREPARED:
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800285 {
286 mStartupSeekTimeUs = seekTimeUs;
287 break;
288 }
Andreas Huber9575c962013-02-05 13:59:56 -0800289
290 case STATE_RUNNING:
291 case STATE_PAUSED:
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800292 {
Andreas Hubera4af2142011-10-26 15:23:31 -0700293 mAtEOS = false;
Lajos Molnarcbaffcf2013-08-14 18:30:38 -0700294 // seeks can take a while, so we essentially paused
295 notifyListener(MEDIA_PAUSED);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800296 mPlayer->seekToAsync(seekTimeUs);
297 break;
298 }
299
300 default:
Andreas Huber9575c962013-02-05 13:59:56 -0800301 return INVALID_OPERATION;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800302 }
303
304 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800305}
306
307status_t NuPlayerDriver::getCurrentPosition(int *msec) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800308 Mutex::Autolock autoLock(mLock);
309
310 if (mPositionUs < 0) {
311 *msec = 0;
312 } else {
313 *msec = (mPositionUs + 500ll) / 1000;
314 }
Andreas Huber5bc087c2010-12-23 10:27:40 -0800315
316 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800317}
318
319status_t NuPlayerDriver::getDuration(int *msec) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800320 Mutex::Autolock autoLock(mLock);
321
322 if (mDurationUs < 0) {
Andreas Huberd85929f2013-04-11 11:07:55 -0700323 return UNKNOWN_ERROR;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800324 }
Andreas Huber5bc087c2010-12-23 10:27:40 -0800325
Andreas Huberd85929f2013-04-11 11:07:55 -0700326 *msec = (mDurationUs + 500ll) / 1000;
327
Andreas Huber5bc087c2010-12-23 10:27:40 -0800328 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800329}
330
331status_t NuPlayerDriver::reset() {
Andreas Huber1aef2112011-01-04 14:01:29 -0800332 Mutex::Autolock autoLock(mLock);
Andreas Huber1aef2112011-01-04 14:01:29 -0800333
Andreas Huber9575c962013-02-05 13:59:56 -0800334 switch (mState) {
335 case STATE_IDLE:
336 return OK;
337
338 case STATE_SET_DATASOURCE_PENDING:
339 case STATE_RESET_IN_PROGRESS:
340 return INVALID_OPERATION;
341
Andreas Huberb5f28d42013-04-25 15:11:19 -0700342 case STATE_PREPARING:
343 {
344 CHECK(mIsAsyncPrepare);
345
346 notifyListener(MEDIA_PREPARED);
347 break;
348 }
349
Andreas Huber9575c962013-02-05 13:59:56 -0800350 default:
351 break;
352 }
353
Lajos Molnarcbaffcf2013-08-14 18:30:38 -0700354 notifyListener(MEDIA_STOPPED);
355
Andreas Huber9575c962013-02-05 13:59:56 -0800356 mState = STATE_RESET_IN_PROGRESS;
Andreas Huber1aef2112011-01-04 14:01:29 -0800357 mPlayer->resetAsync();
358
Andreas Huber9575c962013-02-05 13:59:56 -0800359 while (mState == STATE_RESET_IN_PROGRESS) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800360 mCondition.wait(mLock);
361 }
362
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800363 mDurationUs = -1;
364 mPositionUs = -1;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800365 mStartupSeekTimeUs = -1;
366
Andreas Huberf9334412010-12-15 15:17:42 -0800367 return OK;
368}
369
Andreas Huber84333e02014-02-07 15:36:10 -0800370status_t NuPlayerDriver::setLooping(int /* loop */) {
Andreas Huberf9334412010-12-15 15:17:42 -0800371 return INVALID_OPERATION;
372}
373
374player_type NuPlayerDriver::playerType() {
375 return NU_PLAYER;
376}
377
378status_t NuPlayerDriver::invoke(const Parcel &request, Parcel *reply) {
James Dong0d268a32012-08-31 12:18:27 -0700379 if (reply == NULL) {
380 ALOGE("reply is a NULL pointer");
381 return BAD_VALUE;
382 }
383
384 int32_t methodId;
385 status_t ret = request.readInt32(&methodId);
386 if (ret != OK) {
387 ALOGE("Failed to retrieve the requested method to invoke");
388 return ret;
389 }
390
391 switch (methodId) {
392 case INVOKE_ID_SET_VIDEO_SCALING_MODE:
393 {
394 int mode = request.readInt32();
395 return mPlayer->setVideoScalingMode(mode);
396 }
Andreas Huberd5e56232013-03-12 11:01:43 -0700397
Chong Zhangdcb89b32013-08-06 09:44:47 -0700398 case INVOKE_ID_GET_TRACK_INFO:
399 {
400 return mPlayer->getTrackInfo(reply);
401 }
402
403 case INVOKE_ID_SELECT_TRACK:
404 {
405 int trackIndex = request.readInt32();
406 return mPlayer->selectTrack(trackIndex, true /* select */);
407 }
408
409 case INVOKE_ID_UNSELECT_TRACK:
410 {
411 int trackIndex = request.readInt32();
412 return mPlayer->selectTrack(trackIndex, false /* select */);
413 }
414
James Dong0d268a32012-08-31 12:18:27 -0700415 default:
416 {
417 return INVALID_OPERATION;
418 }
419 }
Andreas Huberf9334412010-12-15 15:17:42 -0800420}
421
422void NuPlayerDriver::setAudioSink(const sp<AudioSink> &audioSink) {
423 mPlayer->setAudioSink(audioSink);
424}
425
Andreas Huber84333e02014-02-07 15:36:10 -0800426status_t NuPlayerDriver::setParameter(
427 int /* key */, const Parcel & /* request */) {
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700428 return INVALID_OPERATION;
429}
430
Andreas Huber84333e02014-02-07 15:36:10 -0800431status_t NuPlayerDriver::getParameter(int /* key */, Parcel * /* reply */) {
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700432 return INVALID_OPERATION;
433}
434
Andreas Huberf9334412010-12-15 15:17:42 -0800435status_t NuPlayerDriver::getMetadata(
Andreas Huber84333e02014-02-07 15:36:10 -0800436 const media::Metadata::Filter& /* ids */, Parcel *records) {
Andreas Huber9575c962013-02-05 13:59:56 -0800437 Mutex::Autolock autoLock(mLock);
438
439 using media::Metadata;
440
441 Metadata meta(records);
442
443 meta.appendBool(
444 Metadata::kPauseAvailable,
445 mPlayerFlags & NuPlayer::Source::FLAG_CAN_PAUSE);
446
447 meta.appendBool(
448 Metadata::kSeekBackwardAvailable,
449 mPlayerFlags & NuPlayer::Source::FLAG_CAN_SEEK_BACKWARD);
450
451 meta.appendBool(
452 Metadata::kSeekForwardAvailable,
453 mPlayerFlags & NuPlayer::Source::FLAG_CAN_SEEK_FORWARD);
454
455 meta.appendBool(
456 Metadata::kSeekAvailable,
457 mPlayerFlags & NuPlayer::Source::FLAG_CAN_SEEK);
458
459 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800460}
461
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800462void NuPlayerDriver::notifyResetComplete() {
Andreas Huber1aef2112011-01-04 14:01:29 -0800463 Mutex::Autolock autoLock(mLock);
Andreas Huber9575c962013-02-05 13:59:56 -0800464
465 CHECK_EQ(mState, STATE_RESET_IN_PROGRESS);
466 mState = STATE_IDLE;
Andreas Huber1aef2112011-01-04 14:01:29 -0800467 mCondition.broadcast();
468}
469
Andreas Huber57a339c2012-12-03 11:18:00 -0800470void NuPlayerDriver::notifySetSurfaceComplete() {
471 Mutex::Autolock autoLock(mLock);
Andreas Huber9575c962013-02-05 13:59:56 -0800472
Andreas Huber57a339c2012-12-03 11:18:00 -0800473 CHECK(mSetSurfaceInProgress);
474 mSetSurfaceInProgress = false;
Andreas Huber9575c962013-02-05 13:59:56 -0800475
Andreas Huber57a339c2012-12-03 11:18:00 -0800476 mCondition.broadcast();
477}
478
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800479void NuPlayerDriver::notifyDuration(int64_t durationUs) {
480 Mutex::Autolock autoLock(mLock);
481 mDurationUs = durationUs;
482}
483
484void NuPlayerDriver::notifyPosition(int64_t positionUs) {
485 Mutex::Autolock autoLock(mLock);
486 mPositionUs = positionUs;
487}
488
489void NuPlayerDriver::notifySeekComplete() {
Andreas Hubera4af2142011-10-26 15:23:31 -0700490 notifyListener(MEDIA_SEEK_COMPLETE);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800491}
492
Andreas Huber3fe62152011-09-16 15:09:22 -0700493void NuPlayerDriver::notifyFrameStats(
494 int64_t numFramesTotal, int64_t numFramesDropped) {
495 Mutex::Autolock autoLock(mLock);
496 mNumFramesTotal = numFramesTotal;
497 mNumFramesDropped = numFramesDropped;
498}
499
Andreas Huber84333e02014-02-07 15:36:10 -0800500status_t NuPlayerDriver::dump(
501 int fd, const Vector<String16> & /* args */) const {
Andreas Huber3fe62152011-09-16 15:09:22 -0700502 Mutex::Autolock autoLock(mLock);
503
504 FILE *out = fdopen(dup(fd), "w");
505
506 fprintf(out, " NuPlayer\n");
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000507 fprintf(out, " numFramesTotal(%" PRId64 "), numFramesDropped(%" PRId64 "), "
Andreas Huber3fe62152011-09-16 15:09:22 -0700508 "percentageDropped(%.2f)\n",
509 mNumFramesTotal,
510 mNumFramesDropped,
511 mNumFramesTotal == 0
512 ? 0.0 : (double)mNumFramesDropped / mNumFramesTotal);
513
514 fclose(out);
515 out = NULL;
516
517 return OK;
518}
519
Chong Zhangdcb89b32013-08-06 09:44:47 -0700520void NuPlayerDriver::notifyListener(
521 int msg, int ext1, int ext2, const Parcel *in) {
Andreas Hubera4af2142011-10-26 15:23:31 -0700522 if (msg == MEDIA_PLAYBACK_COMPLETE || msg == MEDIA_ERROR) {
523 mAtEOS = true;
524 }
525
Chong Zhangdcb89b32013-08-06 09:44:47 -0700526 sendEvent(msg, ext1, ext2, in);
Andreas Hubera4af2142011-10-26 15:23:31 -0700527}
528
Andreas Huber9575c962013-02-05 13:59:56 -0800529void NuPlayerDriver::notifySetDataSourceCompleted(status_t err) {
530 Mutex::Autolock autoLock(mLock);
531
532 CHECK_EQ(mState, STATE_SET_DATASOURCE_PENDING);
533
534 mAsyncResult = err;
535 mState = (err == OK) ? STATE_UNPREPARED : STATE_IDLE;
536 mCondition.broadcast();
537}
538
539void NuPlayerDriver::notifyPrepareCompleted(status_t err) {
540 Mutex::Autolock autoLock(mLock);
541
Andreas Huberb5f28d42013-04-25 15:11:19 -0700542 if (mState != STATE_PREPARING) {
543 // We were preparing asynchronously when the client called
544 // reset(), we sent a premature "prepared" notification and
545 // then initiated the reset. This notification is stale.
546 CHECK(mState == STATE_RESET_IN_PROGRESS || mState == STATE_IDLE);
547 return;
548 }
549
Andreas Huber9575c962013-02-05 13:59:56 -0800550 CHECK_EQ(mState, STATE_PREPARING);
551
552 mAsyncResult = err;
553
554 if (err == OK) {
Andreas Huberec0c5972013-02-05 14:47:13 -0800555 if (mIsAsyncPrepare) {
556 notifyListener(MEDIA_PREPARED);
557 }
Andreas Huber9575c962013-02-05 13:59:56 -0800558 mState = STATE_PREPARED;
559 } else {
Andreas Huberec0c5972013-02-05 14:47:13 -0800560 if (mIsAsyncPrepare) {
561 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
562 }
Andreas Huber9575c962013-02-05 13:59:56 -0800563 mState = STATE_UNPREPARED;
564 }
565
566 mCondition.broadcast();
567}
568
569void NuPlayerDriver::notifyFlagsChanged(uint32_t flags) {
570 Mutex::Autolock autoLock(mLock);
571
572 mPlayerFlags = flags;
573}
574
Andreas Huberf9334412010-12-15 15:17:42 -0800575} // namespace android