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

Commit 1c23036f authored by Harish Mahendrakar's avatar Harish Mahendrakar Committed by android-build-merger
Browse files

Merge "OggWriter: Support format without CSD for opus" into qt-dev

am: b365706b

Change-Id: Ifb369a5cafbe82931d2f03d2957de782fdb0c6fa
parents 38639f13 b365706b
Loading
Loading
Loading
Loading
+41 −8
Original line number Original line Diff line number Diff line
@@ -52,6 +52,7 @@ namespace android {


OggWriter::OggWriter(int fd)
OggWriter::OggWriter(int fd)
      : mFd(dup(fd)),
      : mFd(dup(fd)),
        mHaveAllCodecSpecificData(false),
        mInitCheck(mFd < 0 ? NO_INIT : OK) {
        mInitCheck(mFd < 0 ? NO_INIT : OK) {
    // empty
    // empty
}
}
@@ -115,17 +116,26 @@ status_t OggWriter::addSource(const sp<MediaSource>& source) {


    mSampleRate = sampleRate;
    mSampleRate = sampleRate;
    uint32_t type;
    uint32_t type;
    const void *header_data;
    const void *header_data = NULL;
    size_t packet_size;
    size_t packet_size = 0;

    if (!source->getFormat()->findData(kKeyOpusHeader, &type, &header_data, &packet_size)) {
    if (!source->getFormat()->findData(kKeyOpusHeader, &type, &header_data, &packet_size)) {
        ALOGE("opus header not found");
        ALOGV("opus header not found in format");
        return UNKNOWN_ERROR;
    } else if (header_data && packet_size) {
        writeOggHeaderPackets((unsigned char *)header_data, packet_size);
    } else {
        ALOGD("ignoring incomplete opus header data in format");
    }
    }


    mSource = source;
    return OK;
}

status_t OggWriter::writeOggHeaderPackets(unsigned char *buf, size_t size) {
    ogg_packet op;
    ogg_packet op;
    ogg_page og;
    ogg_page og;
    op.packet = (unsigned char *)header_data;
    op.packet = buf;
    op.bytes = packet_size;
    op.bytes = size;
    op.b_o_s = 1;
    op.b_o_s = 1;
    op.e_o_s = 0;
    op.e_o_s = 0;
    op.granulepos = 0;
    op.granulepos = 0;
@@ -169,8 +179,8 @@ status_t OggWriter::addSource(const sp<MediaSource>& source) {
        write(mFd, og.body, og.body_len);
        write(mFd, og.body, og.body_len);
    }
    }


    mSource = source;
    free(comments);
    free(comments);
    mHaveAllCodecSpecificData = true;
    return OK;
    return OK;
}
}


@@ -301,12 +311,35 @@ status_t OggWriter::threadFunc() {
             && isCodecSpecific)
             && isCodecSpecific)
            || IsOpusHeader((uint8_t*)buffer->data() + buffer->range_offset(),
            || IsOpusHeader((uint8_t*)buffer->data() + buffer->range_offset(),
                         buffer->range_length())) {
                         buffer->range_length())) {
            ALOGV("Drop codec specific info buffer");
            if (mHaveAllCodecSpecificData == false) {
                size_t opusHeadSize = 0;
                size_t codecDelayBufSize = 0;
                size_t seekPreRollBufSize = 0;
                void *opusHeadBuf = NULL;
                void *codecDelayBuf = NULL;
                void *seekPreRollBuf = NULL;
                GetOpusHeaderBuffers((uint8_t*)buffer->data() + buffer->range_offset(),
                                    buffer->range_length(), &opusHeadBuf,
                                    &opusHeadSize, &codecDelayBuf,
                                    &codecDelayBufSize, &seekPreRollBuf,
                                    &seekPreRollBufSize);
                writeOggHeaderPackets((unsigned char *)opusHeadBuf, opusHeadSize);
            } else {
                ALOGV("ignoring later copy of CSD contained in info buffer");
            }
            buffer->release();
            buffer->release();
            buffer = nullptr;
            buffer = nullptr;
            continue;
            continue;
        }
        }


        if (mHaveAllCodecSpecificData == false) {
            ALOGE("Did not get valid opus header before first sample data");
            buffer->release();
            buffer = nullptr;
            err = ERROR_MALFORMED;
            break;
        }

        int64_t timestampUs;
        int64_t timestampUs;
        CHECK(buffer->meta_data().findInt64(kKeyTime, &timestampUs));
        CHECK(buffer->meta_data().findInt64(kKeyTime, &timestampUs));
        if (timestampUs > mEstimatedDurationUs) {
        if (timestampUs > mEstimatedDurationUs) {
+3 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ protected:


private:
private:
    int mFd;
    int mFd;
    bool mHaveAllCodecSpecificData;
    status_t mInitCheck;
    status_t mInitCheck;
    sp<MediaSource> mSource;
    sp<MediaSource> mSource;
    bool mStarted = false;
    bool mStarted = false;
@@ -66,6 +67,8 @@ private:


    OggWriter(const OggWriter&);
    OggWriter(const OggWriter&);
    OggWriter& operator=(const OggWriter&);
    OggWriter& operator=(const OggWriter&);

    status_t writeOggHeaderPackets(unsigned char *buf, size_t size);
};
};


}  // namespace android
}  // namespace android