Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9fef8d45 authored by Andreas Huber's avatar Andreas Huber
Browse files

Converter now takes the desired _output_ format instead of the

input format, allowing control over the type of encoding.

Change-Id: Iaaa1a825f447ea130e373bbd8e5dc96f2762db18
parent 63e9f73c
Loading
Loading
Loading
Loading
+19 −28
Original line number Diff line number Diff line
@@ -40,14 +40,13 @@ namespace android {
Converter::Converter(
        const sp<AMessage> &notify,
        const sp<ALooper> &codecLooper,
        const sp<AMessage> &format,
        bool usePCMAudio)
        const sp<AMessage> &outputFormat)
    : mInitCheck(NO_INIT),
      mNotify(notify),
      mCodecLooper(codecLooper),
      mInputFormat(format),
      mOutputFormat(outputFormat),
      mIsVideo(false),
      mIsPCMAudio(usePCMAudio),
      mIsPCMAudio(false),
      mNeedToManuallyPrependSPSPPS(false),
      mDoMoreWorkPending(false)
#if ENABLE_SILENCE_DETECTION
@@ -58,14 +57,14 @@ Converter::Converter(
      ,mNumFramesToDrop(0)
    {
    AString mime;
    CHECK(mInputFormat->findString("mime", &mime));
    CHECK(mOutputFormat->findString("mime", &mime));

    if (!strncasecmp("video/", mime.c_str(), 6)) {
        mIsVideo = true;
    } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_RAW, mime.c_str())) {
        mIsPCMAudio = true;
    }

    CHECK(!usePCMAudio || !mIsVideo);

    mInitCheck = initEncoder();

    if (mInitCheck != OK) {
@@ -152,23 +151,10 @@ int32_t Converter::GetInt32Property(
}

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();
    }
    CHECK(mOutputFormat->findString("mime", &outputMIME));

    bool isAudio = !strncasecmp(outputMIME.c_str(), "audio/", 6);

    if (!mIsPCMAudio) {
        mEncoder = MediaCodec::CreateByType(
@@ -179,14 +165,10 @@ status_t Converter::initEncoder() {
        }
    }

    mOutputFormat = mInputFormat->dup();

    if (mIsPCMAudio) {
        return OK;
    }

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

    int32_t audioBitrate = GetInt32Property("media.wfd.audio-bitrate", 128000);
    int32_t videoBitrate = GetInt32Property("media.wfd.video-bitrate", 5000000);
    mPrevVideoBitrate = videoBitrate;
@@ -427,7 +409,7 @@ void Converter::onMessageReceived(const sp<AMessage> &msg) {
            releaseEncoder();

            AString mime;
            CHECK(mInputFormat->findString("mime", &mime));
            CHECK(mOutputFormat->findString("mime", &mime));
            ALOGI("encoder (%s) shut down.", mime.c_str());
            break;
        }
@@ -679,6 +661,15 @@ status_t Converter::doMoreWork() {
            notify->setInt32("what", kWhatEOS);
            notify->post();
        } else {
#if 0
            if (mIsVideo) {
                int32_t videoBitrate = GetInt32Property(
                        "media.wfd.video-bitrate", 5000000);

                setVideoBitrate(videoBitrate);
            }
#endif

            sp<ABuffer> buffer;
            sp<ABuffer> outbuf = mEncoderOutputBuffers.itemAt(bufferIndex);

+4 −7
Original line number Diff line number Diff line
@@ -33,11 +33,9 @@ struct MediaCodec;
// media access unit of a different format.
// Right now this'll convert raw video into H.264 and raw audio into AAC.
struct Converter : public AHandler {
    Converter(
            const sp<AMessage> &notify,
    Converter(const sp<AMessage> &notify,
              const sp<ALooper> &codecLooper,
            const sp<AMessage> &format,
            bool usePCMAudio);
              const sp<AMessage> &outputFormat);

    status_t initCheck() const;

@@ -84,10 +82,9 @@ private:
    status_t mInitCheck;
    sp<AMessage> mNotify;
    sp<ALooper> mCodecLooper;
    sp<AMessage> mInputFormat;
    sp<AMessage> mOutputFormat;
    bool mIsVideo;
    bool mIsPCMAudio;
    sp<AMessage> mOutputFormat;
    bool mNeedToManuallyPrependSPSPPS;

    sp<MediaCodec> mEncoder;
+7 −2
Original line number Diff line number Diff line
@@ -937,6 +937,7 @@ status_t WifiDisplaySource::PlaybackSession::addSource(
    CHECK_EQ(err, (status_t)OK);

    if (isVideo) {
        format->setString("mime", MEDIA_MIMETYPE_VIDEO_AVC);
        format->setInt32("store-metadata-in-buffers", true);
        format->setInt32("store-metadata-in-buffers-output", (mHDCP != NULL));
        format->setInt32(
@@ -944,13 +945,17 @@ status_t WifiDisplaySource::PlaybackSession::addSource(
        format->setInt32("profile-idc", profileIdc);
        format->setInt32("level-idc", levelIdc);
        format->setInt32("constraint-set", constraintSet);
    } else {
        format->setString(
                "mime",
                usePCMAudio
                    ? MEDIA_MIMETYPE_AUDIO_RAW : MEDIA_MIMETYPE_AUDIO_AAC);
    }

    notify = new AMessage(kWhatConverterNotify, id());
    notify->setSize("trackIndex", trackIndex);

    sp<Converter> converter =
        new Converter(notify, codecLooper, format, usePCMAudio);
    sp<Converter> converter = new Converter(notify, codecLooper, format);

    err = converter->initCheck();
    if (err != OK) {