status_t FFMPlayer
::start()
{
int status
= getCurrentStatus();
if (status
== PLAYER_PREPARED) {
if (mMessageQ
.get()
!= NULL) {
enqueueMessage(
new MessageStart(
NULL));
return OK;
}
}
else {
if(
!isNetworkProtocol()
&& isPlayerEndOfStream()
&& checkConsumeAll()) {
ALOGD(
"resume: end of stream seekto 0");
modifyFlags(AT_EOS, CLEAR);
setPlayerEndOfStream(
false);
doSeekto(
0,
true);
}
recordResumeTime();
return resume();
}
return UNKNOWN_ERROR;
}
MessageStart(complete_cb cb):RkMessage(CMD_START,cb) {};
RkMessage(int t,complete_cb cb,
void* userdata
=0):mType(t),mCb(cb),mUserData(userdata),mWhenUs(
0) {}
status_t FFMPlayer
::doStart()
{
if (getCurrentStatus()
== PLAYER_PREPARED) {
setCurrentStatus(PLAYER_STARTED);
modifyFlags(FIRST_FRAME,
SET);
modifyFlags(PLAYING,
SET);
if(mNoBlankDisplay){
allocDecoderBuffer(mNewAllocMode);
}
RECSTACK3(CALLSTACK_ID_SWITCH_CH,
"AllocBuffer", GetNowUs());
SAFE_CALL_START(mAudioPlayer);
if (pfrmanager) {
pfrmanager
->start(this);
pfrmanager
->play();
}
SAFE_CALL_STARTASYNC(mDecoderVideo);
ALOGD(
"doStart(): mSeekTimeUs = %lld",mSeekTimeUs);
if (mSeekTimeUs
>= 0) {
if (mHevcTsFlag
== true) {
doSeekto(
0,
true);
}
else {
doSeekto(mSeekTimeUs);
}
}
}
else {
return INVALID_OPERATION;
}
ALOGD(
"doStart ok");
return OK;
}
status_t FFMPlayer
::resume()
{
if(mSeekToDuration) {
ALOGE(
"resume: already seek to eof, don't resume");
return NO_ERROR;
}
enqueueMessage(
new MessageResume(
NULL, OP_UI));
return NO_ERROR;
}
status_t FFMPlayer
::stop()
{
int status
= getCurrentStatus();
if (status
== PLAYER_STOPPED) {
return NO_ERROR;
}
if ((status
== PLAYER_PREPARING)
||(status
== PLAYER_PREPARED)
|| (status
== PLAYER_STARTED)
||(status
== PLAYER_PAUSED)
|| (status
== PLAYER_PLAYBACK_COMPLETE)
|| !mPlayer_sisExited) {
stop_l();
}
return NO_ERROR;
}
status_t FFMPlayer
::stop_l()
{
enqueueMessage(
new MessageStop(
NULL));
ALOGD(
"doRelease() clearQueue************");
if (mMessageQ
.get()
!= NULL) {
mMessageQ
->clearQueue();
}
ALOGD(
"stop_l:MessageStop down");
dumpStatus();
if (mMediaSource
!= NULL) {
mMediaSource
->setExit(
true);
}
ALOGD(
"stop_l : create CancelThread");
if (mCancelThreadStatus
< 0) {
Mutex
::Autolock l(mCancelThreadLock);
mCancelThreadStatus
= pthread_create(
&mCancelThread,
NULL, CancelThread, (
void*)this);
mCancelThreadCond
.wait(mCancelThreadLock);
}
ALOGD(
"stop_l :CancelThread create ok");
if (mBufferingStatus
>= 0) {
int ret
= 0;
if ((ret
=pthread_join(mBufferingThread,
NULL))
!= 0) {
ALOGE(
"Couldn't cancel onBuffering player thread ret=%s", strerror(ret));
}
mBufferingStatus
= -1;
}
ALOGD(
"stop_l buffer thread quit");
mPlayer_sisExited
= true;
return OK;
}
void* FFMPlayer
::CancelThread(
void* ptr)
{
FFMPlayer
*player
= (FFMPlayer
*)ptr;
ALOGD(
"CancelThread start");
if (player
->mReadThreadStatus
>= 0) {
if (pthread_join(player
->mReadThread,
NULL)
!= 0) {
ALOGE(
"Couldn't cancel mReadThread");
}
player
->mReadThreadStatus
= -1;
AUTO_LOCK_BEGIN(player
->mMsgQueueLock);
if (player
->mMessageQ
.get()
!= NULL && player
->mPlayer_sisExited) {
player
->mMsgQueueCond
.wait(player
->mMsgQueueLock);
}
AUTO_LOCK_END(player
->mMsgQueueLock);
player
->closeContext();
ALOGD(
"CancelThread end");
}
SAFE_DELETE(player
->pfrmanager);
player
->doInit();
ALOGD(
"CancelThread return");
return NULL;
}