ScreenMirror buffer ->codec编码传输流程


  1.  SurfaceMediaSource::read()锁控制从IGraphicBufferConsumer处读取buffer,当graphic产生数据
    Overrun时等待

     while (mStarted && mNumPendingBuffers == mMaxAcquiredBufferCount) {

           mMediaBuffersAvailableCondition.wait(mMutex);

        }

  2. MediaPuller拿到该buffer后
    status_t err = mSource->read(&mbuf);

    notify->setInt32("what", kWhatAccessUnit);

    notify->setBuffer("accessUnit", accessUnit);

    notify->post();


  3. Converter 接收CHECK_EQ(what, MediaPuller::kWhatAccessUnit);

    mInputBufferQueue.push_back(accessUnit);

    feedEncoderInputBuffers();


  4. Converter::feedEncoderInputBuffers() 中拷贝buffer数据到codec的mEncoderInputBuffers
    通过这个while循环来等待拷贝

    while (!mInputBufferQueue.empty()&& !mAvailEncoderInputIndices.empty()){


    memcpy(mEncoderInputBuffers.itemAt(bufferIndex)->data(),

                       buffer->data(),

                       buffer->size());

   

    status_t err = mEncoder->queueInputBuffer(

                bufferIndex, 0, (buffer == NULL) ? 0 : buffer->size(),

                timeUs, flags);


5. 上面流程传递的是主要是共享内存buffer_handle_t,当codec 完成ACodec::BaseState::onOMXEmptyBufferDone后

 

 // We're in "store-metadata-in-buffers" mode, the underlying

    // OMX component had access to data that's implicitly refcounted

    // by this "MediaBuffer" object. Now that the OMX component has

    // told us that it's done with the input buffer, we can decrement

    // the mediaBuffer's reference count.

    info->mData->setMediaBufferBase(NULL);

    才通知SurfaceMediaSource::signalBufferReturned()让graphic consumer来真正释放

     mConsumer->releaseBuffer();


Stack 信息

     

 #06 pc 000f4583  /system/lib/libstagefright.so (android::SurfaceMediaSource::signalBufferReturned(android::MediaBuffer*)+38) 

 #07 pc 000f45a5  /system/lib/libstagefright.so (non-virtual thunk to android::SurfaceMediaSource::signalBufferReturned(android::MediaBuffer*)+4) 

 #08 pc 0000b011  /system/lib/libstagefright_foundation.so (android::ABuffer::setMediaBufferBase(android::MediaBufferBase*)+16) 

 #09 pc 0008adeb  /system/lib/libstagefright.so (android::ACodec::BaseState::onOMXEmptyBufferDone(unsigned int, int)+78) 

 #10 pc 0008aab5  /system/lib/libstagefright.so (android::ACodec::BaseState::onOMXMessage(android::sp<android::AMessage> const&)+228) 

 #11 pc 0008a731  /system/lib/libstagefright.so (android::ACodec::BaseState::onMessageReceived(android::sp<android::AMessage> const&)+744) 

 #12 pc 0008e779  /system/lib/libstagefright.so (android::ACodec::ExecutingState::onMessageReceived(android::sp<android::AMessage> const&)+508) 

 #13 pc 0000b5a1  /system/lib/libstagefright_foundation.so (android::AHierarchicalStateMachine::handleMessage(android::sp<android::AMessage> const&)+64) 

 #14 pc 0008a917  /system/lib/libstagefright.so (android::ACodec::BaseState::onOMXMessageList(android::sp<android::AMessage> const&)+106) 

 #15 pc 0008a5e7  /system/lib/libstagefright.so (android::ACodec::BaseState::onMessageReceived(android::sp<android::AMessage> const&)+414) 

 #16 pc 0008e779  /system/lib/libstagefright.so (android::ACodec::ExecutingState::onMessageReceived(android::sp<android::AMessage> const&)+508)



链接一篇关于buffer_handle_t 共享内存的介绍

http://blog.csdn.net/andyhuabing/article/details/7489776

你可能感兴趣的:(android,screen,mirror)