Ejemplo n.º 1
0
PlayerCommand* PlayerDriver::DoProcessQueue(status_t& ret)
{
    PlayerCommand* ec = dequeueCommand();
	printf("HelixOverWebkit [%s] [%s] [%d] ec %p, ec->command() %d\n", __FILE__, __FUNCTION__, __LINE__, ec, (ec == NULL)?-1: ec->command());
    if (ec)
    {
        switch(ec->command())
        {
        case PlayerCommand::PLAYER_SET_DATA_SOURCE:
            ret = handleSetDataSource(static_cast<PlayerSetDataSource*>(ec));
            break;

        case PlayerCommand::PLAYER_PREPARE:
            ret = handlePrepare(static_cast<PlayerPrepare*>(ec));
            break;

        case PlayerCommand::PLAYER_START:
            ret = handleStart(static_cast<PlayerStart*>(ec));
            break;

        case PlayerCommand::PLAYER_STOP:
            ret = handleStop(static_cast<PlayerStop*>(ec));
            break;

        case PlayerCommand::PLAYER_PAUSE:
            ret = handlePause(static_cast<PlayerPause*>(ec));
            break;

        case PlayerCommand::PLAYER_SEEK:
            ret = handleSeek(static_cast<PlayerSeek*>(ec));
            break;

        case PlayerCommand::PLAYER_GET_POSITION:
            ret = handleGetPosition(static_cast<PlayerGetPosition*>(ec));
            break;

        case PlayerCommand::PLAYER_RESET:
            ret = handleReset(static_cast<PlayerReset*>(ec));
            break;

        case PlayerCommand::PLAYER_QUIT:
            ret = handleQuit(static_cast<PlayerQuit*>(ec));
            break;

        default:
            //cout << "Unexpected command %d" <<  ec->command();
            break;
        }
    }
    return ec;
}
void PlayerDriver::CommandCompleted(const PVCmdResponse& aResponse)
{
    LOGV("CommandCompleted");
    int status = aResponse.GetCmdStatus();

    if (mDoLoop) {
        mDoLoop = false;
        RunIfNotReady();
        return;
    }

    PlayerCommand* ec = static_cast<PlayerCommand*>(aResponse.GetContext());
    LOGV("Command %d status=%d", ec ? ec->command(): 0, status);
    if (ec == NULL) return;

    // FIXME: Ignore non-fatal seek errors because pvPlayerEngine returns these errors and retains it's state.
    if (mSeekPending) {
        mSeekPending = false;
        if ( ( (status == PVMFErrArgument) || (status == PVMFErrInvalidState) || (status == PVMFErrNotSupported) ) ) {
            LOGV("Ignoring error during seek");
            status = PVMFSuccess;
        }
    }

    if (status == PVMFSuccess) {
        switch(ec->command()) {
        case PlayerCommand::PLAYER_PREPARE:
            LOGV("PLAYER_PREPARE complete mDownloadContextData=%p, mDataReadyReceived=%d", mDownloadContextData, mDataReadyReceived);
            mPrepareDone = true;
            // If we are streaming from the network, we
            // have to wait until the first PVMFInfoDataReady
            // is sent to notify the user that it is okay to
            // begin playback.  If it is a local file, just
            // send it now at the completion of Prepare().
            if ((mDownloadContextData == NULL) || mDataReadyReceived){
                mPvPlayer->sendEvent(MEDIA_PREPARED);
            }
            break;

        case PlayerCommand::PLAYER_GET_DURATION:
            handleGetDurationComplete(static_cast<PlayerGetDuration*>(ec));
            break;

        case PlayerCommand::PLAYER_PAUSE:
            LOGV("pause complete");
            break;

        case PlayerCommand::PLAYER_SEEK:
            mPvPlayer->sendEvent(MEDIA_SEEK_COMPLETE);
            break;

        default: /* shut up gcc */
            break;
        }

        // Call the user's requested completion function
        ec->complete(NO_ERROR, false);
    } else if (status == PVMFErrCancelled) {
        // Ignore cancelled command return status (PVMFErrCancelled), since it is not an error.
        LOGE("Command (%d) was cancelled", ec->command());
        status = PVMFSuccess;
        ec->complete(NO_ERROR, true);
    } else {  
        // error occurred
        if (status >= 0) status = -1;
        mPvPlayer->sendEvent(MEDIA_ERROR, status);
        ec->complete(UNKNOWN_ERROR, false);
    }

    delete ec;
}
// The OSCL scheduler calls this when we get to run (this should happen only
// when a command has been enqueued for us).
void PlayerDriver::Run()
{
    if (mDoLoop) {
        mEndOfData = false;
        PVPPlaybackPosition begin, end;
        begin.iIndeterminate = false;
        begin.iPosUnit = PVPPBPOSUNIT_SEC;
        begin.iPosValue.sec_value = 0;
        begin.iMode = PVPPBPOS_MODE_NOW;
        end.iIndeterminate = true;
        mPlayer->SetPlaybackRange(begin, end, false, NULL);
        mPlayer->Resume();
        return;
    }

    PVPlayerState state = PVP_STATE_ERROR;
    if ((mPlayer->GetPVPlayerStateSync(state) == PVMFSuccess))
    {
        if(state == PVP_STATE_ERROR)
        {
            return;
        }
    }


    PlayerCommand* ec;

    ec = dequeueCommand();
    if (ec) {
        LOGV("Send player command: %d", ec->command());

        switch(ec->command()) {
        case PlayerCommand::PLAYER_SETUP:
            handleSetup(static_cast<PlayerSetup*>(ec));
            break;

        case PlayerCommand::PLAYER_SET_DATA_SOURCE:
            handleSetDataSource(static_cast<PlayerSetDataSource*>(ec));
            break;

        case PlayerCommand::PLAYER_SET_VIDEO_SURFACE:
            handleSetVideoSurface(static_cast<PlayerSetVideoSurface*>(ec));
            break;

        case PlayerCommand::PLAYER_SET_AUDIO_SINK:
            handleSetAudioSink(static_cast<PlayerSetAudioSink*>(ec));
            break;

        case PlayerCommand::PLAYER_INIT:
            handleInit(static_cast<PlayerInit*>(ec));
            break;

        case PlayerCommand::PLAYER_PREPARE:
            handlePrepare(static_cast<PlayerPrepare*>(ec));
            break;

        case PlayerCommand::PLAYER_START:
            handleStart(static_cast<PlayerStart*>(ec));
            break;

        case PlayerCommand::PLAYER_STOP:
            handleStop(static_cast<PlayerStop*>(ec));
            break;

        case PlayerCommand::PLAYER_PAUSE:
            handlePause(static_cast<PlayerPause*>(ec));
            break;

        case PlayerCommand::PLAYER_SEEK:
            handleSeek(static_cast<PlayerSeek*>(ec));
            break;

        case PlayerCommand::PLAYER_GET_POSITION:
            handleGetPosition(static_cast<PlayerGetPosition*>(ec));
            FinishSyncCommand(ec);
            return;

        case PlayerCommand::PLAYER_GET_STATUS:
            handleGetStatus(static_cast<PlayerGetStatus*>(ec));
            FinishSyncCommand(ec);
            return;

        case PlayerCommand::PLAYER_GET_DURATION:
            handleGetDuration(static_cast<PlayerGetDuration*>(ec));
            break;

        case PlayerCommand::PLAYER_REMOVE_DATA_SOURCE:
            handleRemoveDataSource(static_cast<PlayerRemoveDataSource*>(ec));
            break;

        case PlayerCommand::PLAYER_CANCEL_ALL_COMMANDS:
            handleCancelAllCommands(static_cast<PlayerCancelAllCommands*>(ec));
            break;

        case PlayerCommand::PLAYER_RESET:
            handleReset(static_cast<PlayerReset*>(ec));
            break;

        case PlayerCommand::PLAYER_QUIT:
            handleQuit(static_cast<PlayerQuit*>(ec));
            return;

        case PlayerCommand::PLAYER_SET_LOOP:
            mIsLooping = static_cast<PlayerSetLoop*>(ec)->loop();
            FinishSyncCommand(ec);
            return;

        default:
            LOGE("Unexpected command %d", ec->command());
            break;
        }
    }

}