zoukankan      html  css  js  c++  java
  • android wifidisplay生成I 帧的相关代码

    wifidisplayframeworksavmedialibstagefrightwifi-displaysourceConverter.cpp

     

    status_t Converter::initEncoder() {
        AString inputMIME;
        CHECK(mInputFormat->findString("mime", &inputMIME));

        AString outputMIME;
        bool isAudio = false;
        if (!strcasecmp(inputMIME.c_str(), MEDIA_MIMETYPE_AUDIO_RAW)) {
            if (mIsPCMAudio) {
                outputMIME = MEDIA_MIMETYPE_AUDIO_RAW;
            } else {
                outputMIME = MEDIA_MIMETYPE_AUDIO_AAC;
            }
            isAudio = true;
        } else if (!strcasecmp(inputMIME.c_str(), MEDIA_MIMETYPE_VIDEO_RAW)) {
            outputMIME = MEDIA_MIMETYPE_VIDEO_AVC;
        } else {
            TRESPASS();
        }

        if (!mIsPCMAudio) {
            mEncoder = MediaCodec::CreateByType(
                    mCodecLooper, outputMIME.c_str(), true /* encoder */);

            if (mEncoder == NULL) {
                return ERROR_UNSUPPORTED;
            }
        }

        mOutputFormat = mInputFormat->dup();

        if (mIsPCMAudio) {
            return OK;
        }

        mOutputFormat->setString("mime", outputMIME.c_str());

        int32_t audioBitrate = getBitrate("media.wfd.audio-bitrate", 128000);
        int32_t videoBitrate = getBitrate("media.wfd.video-bitrate", 2* 1024 * 1024);

        ALOGI("using audio bitrate of %d bps, video bitrate of %d bps",
              audioBitrate, videoBitrate);

        if (isAudio) {
            mOutputFormat->setInt32("bitrate", audioBitrate);
        } else {
            mOutputFormat->setInt32("bitrate", videoBitrate);
    /*
    typedef enum OMX_VIDEO_CONTROLRATETYPE {
        OMX_Video_ControlRateDisable,
        OMX_Video_ControlRateVariable,
        OMX_Video_ControlRateConstant,
    */   
            mOutputFormat->setInt32("bitrate-mode", OMX_Video_ControlRateConstant);
            mOutputFormat->setInt32("frame-rate", 25);
            mOutputFormat->setInt32("i-frame-interval", 1);  // Iframes every 15 secs
        //        OMX_VIDEO_AVCProfileBaseline = 0x01,   /**< Baseline profile */
         mOutputFormat->setInt32("profile", OMX_VIDEO_AVCProfileBaseline);
        //    OMX_VIDEO_AVCLevel4   = 0x800,    /**< Level 4 */
            mOutputFormat->setInt32("level",OMX_VIDEO_AVCLevel4);

            // Configure encoder to use intra macroblock refresh mode
        //    mOutputFormat->setInt32("intra-refresh-mode", OMX_VIDEO_IntraRefreshCyclic);

            int width, height, mbs;
            if (!mOutputFormat->findInt32("width", &width)
                    || !mOutputFormat->findInt32("height", &height)) {
                return ERROR_UNSUPPORTED;
            }

            // Update macroblocks in a cyclic fashion with 10% of all MBs within
            // frame gets updated at one time. It takes about 10 frames to
            // completely update a whole video frame. If the frame rate is 30,
            // it takes about 333 ms in the best case (if next frame is not an IDR)
            // to recover from a lost/corrupted packet.
            mbs = (((width + 15) / 16) * ((height + 15) / 16) * 10) / 100;
            mOutputFormat->setInt32("intra-refresh-CIR-mbs", mbs);
        }

        ALOGV("output format is '%s'", mOutputFormat->debugString(0).c_str());

        mNeedToManuallyPrependSPSPPS = false;

        status_t err = NO_INIT;

        if (!isAudio) {
            sp<AMessage> tmp = mOutputFormat->dup();
            tmp->setInt32("prepend-sps-pps-to-idr-frames", 1);

            err = mEncoder->configure(
                    tmp,
                    NULL /* nativeWindow */,
                    NULL /* crypto */,
                    MediaCodec::CONFIGURE_FLAG_ENCODE);

            if (err == OK) {
                // Encoder supported prepending SPS/PPS, we don't need to emulate
                // it.
                mOutputFormat = tmp;
            } else {
                mNeedToManuallyPrependSPSPPS = true;

                ALOGI("We going to manually prepend SPS and PPS to IDR frames.");
            }
        }

        if (err != OK) {
            // We'll get here for audio or if we failed to configure the encoder
            // to automatically prepend SPS/PPS in the case of video.

            err = mEncoder->configure(
                        mOutputFormat,
                        NULL /* nativeWindow */,
                        NULL /* crypto */,
                        MediaCodec::CONFIGURE_FLAG_ENCODE);
        }

        if (err != OK) {
            return err;
        }

        err = mEncoder->start();

        if (err != OK) {
            return err;
        }

        err = mEncoder->getInputBuffers(&mEncoderInputBuffers);

        if (err != OK) {
            return err;
        }

        return mEncoder->getOutputBuffers(&mEncoderOutputBuffers);
    }

    frameworksavmedialibstagefrightwifi-displaysourceMediaPuller.cpp

    case kWhatPull:
    {
        int32_t generation;
        CHECK(msg->findInt32("generation", &generation));

        if (generation != mPullGeneration) {
            break;
        }

        MediaBuffer *mbuf;
        status_t err = mSource->read(&mbuf);

        if (mPaused) {
            if (err == OK) {
                mbuf->release();
                mbuf = NULL;
            }

            schedulePull();
            break;
        }

        if (err != OK) {
            if (err == ERROR_END_OF_STREAM) {
                ALOGI("stream ended.");
            } else {
                ALOGE("error %d reading stream.", err);
            }

            sp<AMessage> notify = mNotify->dup();
            notify->setInt32("what", kWhatEOS);
            notify->post();
        } else {
            int64_t timeUs;
            CHECK(mbuf->meta_data()->findInt64(kKeyTime, &timeUs));

  • 相关阅读:
    MVC模式-----struts2框架(2)
    MVC模式-----struts2框架
    html的<h>标签
    jsp脚本元素
    LeetCode "Paint House"
    LeetCode "Longest Substring with At Most Two Distinct Characters"
    LeetCode "Graph Valid Tree"
    LeetCode "Shortest Word Distance"
    LeetCode "Verify Preorder Sequence in Binary Search Tree"
    LeetCode "Binary Tree Upside Down"
  • 原文地址:https://www.cnblogs.com/pengxinglove/p/5558714.html
Copyright © 2011-2022 走看看