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

Commit b239bdd1 authored by Umang Saini's avatar Umang Saini Committed by Wonsik Kim
Browse files

codec2: Handle inBuffer with non-zero offset

Bug: 74770949
Test: setprop debug.stagefright.ccodec true
Test: stagefright -S -N c2.google.mpeg2.decoder /sdcard/clips/bbb.mp4
Test: stagefright -S -N c2.google.mpeg4.decoder /sdcard/clips/mpeg4.mp4
Test: stagefright -S -N c2.google.h263.decoder /sdcard/clips/h263.3gp
Test: audioloop -N c2.google.flac.encoder -M audio/flac

Change-Id: I477dc2aa9ec6d8399eed104a37bc92cbd4f06095
parent 4fa0e6cc
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -181,11 +181,13 @@ void C2SoftFlacEnc::process(

    mEncoderWriteData = true;
    mEncoderReturnedNbBytes = 0;
    while (inOffset < inSize) {
        size_t processSize = MIN(kInBlockSize * mNumChannels * sizeof(int16_t), (inSize - inOffset));
    size_t inPos = 0;
    const uint8_t *inPtr = rView.data() + inOffset;
    while (inPos < inSize) {
        size_t processSize = MIN(kInBlockSize * mNumChannels * sizeof(int16_t), (inSize - inPos));
        const unsigned nbInputFrames = processSize / (mNumChannels * sizeof(int16_t));
        const unsigned nbInputSamples = processSize / sizeof(int16_t);
        const int16_t *pcm16 = reinterpret_cast<const int16_t *>(rView.data() + inOffset);
        const int16_t *pcm16 = reinterpret_cast<const int16_t *>(inPtr + inPos);
        ALOGV("about to encode %zu bytes", processSize);

        for (unsigned i = 0; i < nbInputSamples; i++) {
@@ -201,7 +203,7 @@ void C2SoftFlacEnc::process(
            mOutputBlock.reset();
            return;
        }
        inOffset += processSize;
        inPos += processSize;
    }
    if (eos && !drain(DRAIN_COMPONENT_WITH_EOS, pool)) {
        ALOGE("error encountered during encoding");
+7 −6
Original line number Diff line number Diff line
@@ -371,7 +371,8 @@ void C2SoftMpeg4Dec::process(
        }
    }

    while (inOffset < inSize) {
    size_t inPos = 0;
    while (inPos < inSize) {
        c2_status_t err = ensureDecoderState(pool);
        if (C2_OK != err) {
            mSignalledError = true;
@@ -401,7 +402,7 @@ void C2SoftMpeg4Dec::process(

        // Need to check if header contains new info, e.g., width/height, etc.
        VopHeaderInfo header_info;
        uint32_t useExtTimestamp = (inOffset == 0);
        uint32_t useExtTimestamp = (inPos == 0);
        int32_t tmpInSize = (int32_t)inSize;
        uint8_t *bitstreamTmp = bitstream;
        uint32_t timestamp = workIndex;
@@ -442,12 +443,12 @@ void C2SoftMpeg4Dec::process(
        (void)copyOutputBufferToYV12Frame(outputBufferY, mOutputBuffer[mNumSamplesOutput & 1],
                                          wView.width(), align(mWidth, 16), mWidth, mHeight);

        inOffset += inSize - (size_t)tmpInSize;
        inPos += inSize - (size_t)tmpInSize;
        finishWork(workIndex, work);
        ++mNumSamplesOutput;
        if (inSize - inOffset) {
            ALOGD("decoded frame, ignoring further trailing bytes %zu",
                   inSize - (size_t)tmpInSize);
        if (inSize - inPos != 0) {
            ALOGD("decoded frame, ignoring further trailing bytes %d",
                  (int)inSize - (int)inPos);
            break;
        }
    }
+7 −6
Original line number Diff line number Diff line
@@ -352,7 +352,7 @@ bool C2SoftMpeg2Dec::setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip,
    if (inBuffer) {
        ps_decode_ip->u4_ts = tsMarker;
        ps_decode_ip->pv_stream_buffer = const_cast<uint8_t *>(inBuffer->data() + inOffset);
        ps_decode_ip->u4_num_Bytes = inSize - inOffset;
        ps_decode_ip->u4_num_Bytes = inSize;
    } else {
        ps_decode_ip->u4_ts = 0;
        ps_decode_ip->pv_stream_buffer = nullptr;
@@ -630,7 +630,8 @@ void C2SoftMpeg2Dec::process(
    ALOGV("in buffer attr. size %zu timestamp %d frameindex %d, flags %x",
          inSize, (int)work->input.ordinal.timestamp.peeku(),
          (int)work->input.ordinal.frameIndex.peeku(), work->input.flags);
    while (inOffset < inSize) {
    size_t inPos = 0;
    while (inPos < inSize) {
        if (C2_OK != ensureDecoderState(pool)) {
            mSignalledError = true;
            work->result = C2_CORRUPTED;
@@ -646,7 +647,7 @@ void C2SoftMpeg2Dec::process(
        ivd_video_decode_ip_t s_decode_ip;
        ivd_video_decode_op_t s_decode_op;
        if (!setDecodeArgs(&s_decode_ip, &s_decode_op, &rView, &wView,
                           inOffset, inSize, workIndex)) {
                           inOffset + inPos, inSize - inPos, workIndex)) {
            mSignalledError = true;
            work->result = C2_CORRUPTED;
            return;
@@ -693,10 +694,10 @@ void C2SoftMpeg2Dec::process(
        if (s_decode_op.u4_output_present) {
            finishWork(s_decode_op.u4_ts, work);
        }
        inOffset += s_decode_op.u4_num_bytes_consumed;
        if (hasPicture && (inSize - inOffset)) {
        inPos += s_decode_op.u4_num_bytes_consumed;
        if (hasPicture && (inSize - inPos) != 0) {
            ALOGD("decoded frame in current access nal, ignoring further trailing bytes %d",
                  (int)inSize - (int)inOffset);
                  (int)inSize - (int)inPos);
            break;
        }
    }