从上层调用到NuPlayerDriver的构造函数

xiaoxiao2021-03-01  4

……和从上层调用到RTMediaPlayer类似。 frameworks\base\media\java\android\media:MediaPlayer public MediaPlayer() { ……        native_setup(new WeakReference(this)); } frameworks\base\media\jni:android_media_MediaPlayer static void android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this) {    sp mp = new MediaPlayer(); } frameworks\av\media\libmedia:MediaPlayer.cpp MediaPlayer::MediaPlayer() {    ALOGV(“constructor”);    mListener = NULL;    mCookie = NULL;    mStreamType = AUDIO_STREAM_MUSIC;    mAudioAttributesParcel = NULL;    mCurrentPosition = -1;    mCurrentSeekMode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC;    mSeekPosition = -1;    mSeekMode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC;    mCurrentState = MEDIA_PLAYER_IDLE;    mPrepareSync = false;    mPrepareStatus = NO_ERROR;    mLoop = false;    mLeftVolume = mRightVolume = 1.0;    mVideoWidth = mVideoHeight = 0;    mLockThreadId = 0;    mAudioSessionId = (audio_session_t) AudioSystem::newAudioUniqueId(AUDIO_UNIQUE_ID_USE_SESSION);    AudioSystem::acquireAudioSessionId(mAudioSessionId, -1);    mSendLevel = 0;    mRetransmitEndpointValid = false; } .java中的setDataSource最终会调用到MediaPlayer.cpp的setDataSource 会去调用下面的函数: class NuPlayerFactory : public MediaPlayerFactory::IFactory {    ……        virtual sp createPlayer(pid_t pid) {        ALOGV(” create NuPlayer”);        return new NuPlayerDriver(pid);   } }; 构造函数: NuPlayerDriver::NuPlayerDriver(pid_t pid)   : mState(STATE_IDLE),//状态 ……      mLooper(new ALooper),      mPlayer(new NuPlayer(pid)), ……    ALOGD(“NuPlayerDriver(%p) created, clientPid(%d)”, this, pid);    mLooper->setName(“NuPlayerDriver Looper”); ​    // set up an analytics record    mAnalyticsItem = new MediaAnalyticsItem(kKeyPlayer);    mAnalyticsItem->generateSessionID(); ​    mLooper->start(            false, /* runOnCallingThread */            true,  /* canCallJava */            PRIORITY_AUDIO); ​    mLooper->registerHandler(mPlayer); ​    mPlayer->setDriver(this); } 首先关注NuPlayer的状态有哪些:

再关注new的ALooper

再关注new的NuPlayer 这里创建了NuPlayer赋值给mPlayer  再mLooper->start,会:    mThread = new LooperThread(this, canCallJava); ​    status_t err = mThread->run(            mName.empty() ? “ALooper” : mName.c_str(), priority); 再mPlayer->setDriver(this); mPlayer持有NuPlayerDriver实例

转载请注明原文地址: https://www.6miu.com/read-4150175.html

最新回复(0)