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

Commit 50f939d6 authored by hkuang's avatar hkuang
Browse files

Fix the bug that same video frame has been decoded twice during port reconfig.

This does not hurt normal video playback. But in adaptive playback,
this will lead to a little bit delay for some clips.

Bug: 17202935

Change-Id: I5af0a5911e28a1597c74d79960fac25faf72c9d2
parent b72726ba
Loading
Loading
Loading
Loading
+32 −32
Original line number Diff line number Diff line
@@ -23,9 +23,6 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaDefs.h>

#include "vpx/vpx_decoder.h"
#include "vpx/vpx_codec.h"
#include "vpx/vp8dx.h"

namespace android {

@@ -41,7 +38,8 @@ SoftVPX::SoftVPX(
            NULL /* profileLevels */, 0 /* numProfileLevels */,
            320 /* width */, 240 /* height */, callbacks, appData, component),
      mMode(codingType == OMX_VIDEO_CodingVP8 ? MODE_VP8 : MODE_VP9),
      mCtx(NULL) {
      mCtx(NULL),
      mImg(NULL) {
    initPorts(kNumBuffers, 768 * 1024 /* inputBufferSize */,
            kNumBuffers,
            codingType == OMX_VIDEO_CodingVP8 ? MEDIA_MIMETYPE_VIDEO_VP8 : MEDIA_MIMETYPE_VIDEO_VP9);
@@ -118,6 +116,7 @@ void SoftVPX::onQueueFilled(OMX_U32 /* portIndex */) {
            }
        }

        if (mImg == NULL) {
            if (vpx_codec_decode(
                        (vpx_codec_ctx_t *)mCtx,
                        inHeader->pBuffer + inHeader->nOffset,
@@ -129,15 +128,15 @@ void SoftVPX::onQueueFilled(OMX_U32 /* portIndex */) {
                notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
                return;
            }

            vpx_codec_iter_t iter = NULL;
        vpx_image_t *img = vpx_codec_get_frame((vpx_codec_ctx_t *)mCtx, &iter);
            mImg = vpx_codec_get_frame((vpx_codec_ctx_t *)mCtx, &iter);
        }

        if (img != NULL) {
            CHECK_EQ(img->fmt, IMG_FMT_I420);
        if (mImg != NULL) {
            CHECK_EQ(mImg->fmt, IMG_FMT_I420);

            uint32_t width = img->d_w;
            uint32_t height = img->d_h;
            uint32_t width = mImg->d_w;
            uint32_t height = mImg->d_h;

            if (width != mWidth || height != mHeight) {
                mWidth = width;
@@ -171,34 +170,35 @@ void SoftVPX::onQueueFilled(OMX_U32 /* portIndex */) {
            uint32_t buffer_stride = mIsAdaptive ? mAdaptiveMaxWidth : mWidth;
            uint32_t buffer_height = mIsAdaptive ? mAdaptiveMaxHeight : mHeight;

            const uint8_t *srcLine = (const uint8_t *)img->planes[PLANE_Y];
            const uint8_t *srcLine = (const uint8_t *)mImg->planes[PLANE_Y];
            uint8_t *dst = outHeader->pBuffer;
            for (size_t i = 0; i < buffer_height; ++i) {
                if (i < img->d_h) {
                    memcpy(dst, srcLine, img->d_w);
                    srcLine += img->stride[PLANE_Y];
                if (i < mImg->d_h) {
                    memcpy(dst, srcLine, mImg->d_w);
                    srcLine += mImg->stride[PLANE_Y];
                }
                dst += buffer_stride;
            }

            srcLine = (const uint8_t *)img->planes[PLANE_U];
            srcLine = (const uint8_t *)mImg->planes[PLANE_U];
            for (size_t i = 0; i < buffer_height / 2; ++i) {
                if (i < img->d_h / 2) {
                    memcpy(dst, srcLine, img->d_w / 2);
                    srcLine += img->stride[PLANE_U];
                if (i < mImg->d_h / 2) {
                    memcpy(dst, srcLine, mImg->d_w / 2);
                    srcLine += mImg->stride[PLANE_U];
                }
                dst += buffer_stride / 2;
            }

            srcLine = (const uint8_t *)img->planes[PLANE_V];
            srcLine = (const uint8_t *)mImg->planes[PLANE_V];
            for (size_t i = 0; i < buffer_height / 2; ++i) {
                if (i < img->d_h / 2) {
                    memcpy(dst, srcLine, img->d_w / 2);
                    srcLine += img->stride[PLANE_V];
                if (i < mImg->d_h / 2) {
                    memcpy(dst, srcLine, mImg->d_w / 2);
                    srcLine += mImg->stride[PLANE_V];
                }
                dst += buffer_stride / 2;
            }

            mImg = NULL;
            outInfo->mOwnedByUs = false;
            outQueue.erase(outQueue.begin());
            outInfo = NULL;
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@

#include "SoftVideoDecoderOMXComponent.h"

#include "vpx/vpx_decoder.h"
#include "vpx/vpx_codec.h"
#include "vpx/vp8dx.h"

namespace android {

struct SoftVPX : public SoftVideoDecoderOMXComponent {
@@ -47,6 +51,8 @@ private:

    void *mCtx;

    vpx_image_t *mImg;

    status_t initDecoder();

    DISALLOW_EVIL_CONSTRUCTORS(SoftVPX);