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

Commit cb04a1f3 authored by Chih-Chung Chang's avatar Chih-Chung Chang
Browse files

Speed up thumbnail generation.

We don't need to have precise position for thumbnails, so we add
a tolerance parameter to the decoder. The decoder can return an
earlier frame within the tolerance time given.

Change-Id: I0a49ed6b03f8c3264606e4143dd5ecf48e9d0f62
parent 37d81ac3
Loading
Loading
Loading
Loading
+7 −39
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ M4OSA_ERR videoBrowserCreate(
                    err = pContext->m_pDecoder->m_pFctCreate(
                            &pContext->m_pDecoderCtx,
                            pContext->m_pStreamHandler,
                            pContext->m_3gpReader,
                            pContext->m_3gpData,
                            &pContext->m_accessUnit,
                            pContext->m_pCodecLoaderContext) ;
@@ -284,6 +285,7 @@ M4OSA_ERR videoBrowserCreate(
                    err = pContext->m_pDecoder->m_pFctCreate(
                            &pContext->m_pDecoderCtx,
                            pContext->m_pStreamHandler,
                            pContext->m_3gpReader,
                            pContext->m_3gpData,
                            &pContext->m_accessUnit,
                            pContext->m_pCodecLoaderContext) ;
@@ -435,9 +437,12 @@ videoBrowserCleanUp_cleanUp:
* @param        pContext     (IN) : Video browser context
* @param        pTime        (IN/OUT) : Pointer on the time to reach. Updated
*                                       by this function with the reached time
* @param        tolerance    (IN) :  We may decode an earlier frame within the tolerance.
*                                    The time difference is specified in milliseconds.
* @return       M4NO_ERROR / M4ERR_PARAMETER / M4ERR_STATE / M4ERR_ALLOC
******************************************************************************/
M4OSA_ERR videoBrowserPrepareFrame(M4OSA_Context pContext, M4OSA_UInt32* pTime)
M4OSA_ERR videoBrowserPrepareFrame(M4OSA_Context pContext, M4OSA_UInt32* pTime,
    M4OSA_UInt32 tolerance)
{
    VideoBrowserContext* pC = (VideoBrowserContext*)pContext;
    M4OSA_ERR err = M4NO_ERROR;
@@ -481,51 +486,14 @@ M4OSA_ERR videoBrowserPrepareFrame(M4OSA_Context pContext, M4OSA_UInt32* pTime)
        bJumpNeeded = M4OSA_TRUE;
    }

    if (M4OSA_TRUE == bJumpNeeded)
    {
        rapTime = targetTime;
        /*--- Retrieve the previous RAP time ---*/
        err = pC->m_3gpReader->m_pFctGetPrevRapTime(
                pC->m_pReaderCtx, pC->m_pStreamHandler, &rapTime);

        CHECK_ERR(videoBrowserPrepareFrame, err);

        jumpTime = rapTime;

        err = pC->m_3gpReader->m_pFctJump(pC->m_pReaderCtx,
                                          pC->m_pStreamHandler,
                                          (M4OSA_Int32*)&jumpTime);
        CHECK_ERR(videoBrowserPrepareFrame, err);
    }

    timeMS = (M4_MediaTime)targetTime;
    err = pC->m_pDecoder->m_pFctDecode(
        pC->m_pDecoderCtx, &timeMS, bJumpNeeded);

    if ((err != M4NO_ERROR) && (err != M4WAR_NO_MORE_AU))
    {
        return err;
    }

    // FIXME:
    // Not sure that I understand why we need a second jump logic here
    if ((timeMS >= pC->m_currentCTS) && (M4OSA_TRUE == isBackward))
    {
        jumpTime = rapTime;
        err = pC->m_3gpReader->m_pFctJump(
            pC->m_pReaderCtx, pC->m_pStreamHandler, (M4OSA_Int32*)&jumpTime);

        CHECK_ERR(videoBrowserPrepareFrame, err);

        timeMS = (M4_MediaTime)rapTime;
        err = pC->m_pDecoder->m_pFctDecode(
            pC->m_pDecoderCtx, &timeMS, M4OSA_TRUE);
        pC->m_pDecoderCtx, &timeMS, bJumpNeeded, tolerance);

    if ((err != M4NO_ERROR) && (err != M4WAR_NO_MORE_AU))
    {
        return err;
    }
    }

    err = pC->m_pDecoder->m_pFctRender(
        pC->m_pDecoderCtx, &timeMS, pC->m_outputPlane, M4OSA_TRUE);
+2 −1
Original line number Diff line number Diff line
@@ -133,7 +133,8 @@ M4OSA_ERR videoBrowserCleanUp(M4OSA_Context pContext) ;
*                                     this function with the reached time
* @return       M4NO_ERROR / M4ERR_PARAMETER / M4ERR_STATE / M4ERR_ALLOC
******************************************************************************/
M4OSA_ERR videoBrowserPrepareFrame(M4OSA_Context pContext, M4OSA_UInt32* pTime);
M4OSA_ERR videoBrowserPrepareFrame(M4OSA_Context pContext, M4OSA_UInt32* pTime,
        M4OSA_UInt32 tolerance);

/******************************************************************************
* @brief        This function sets the size and the position of the display.
+5 −4
Original line number Diff line number Diff line
@@ -763,7 +763,7 @@ static int videoEditor_renderPreviewFrame(JNIEnv* pEnv,
            ClipProperties.uiVideoWidth,
            pContext->pEditSettings->pClipList[iCurrentClipIndex]->\
            ClipProperties.uiVideoHeight,
            &tnTimeMs);
            &tnTimeMs, 0);
        if (result != M4NO_ERROR) {
            free(pixelArray);
            ThumbnailClose(tnContext);
@@ -991,7 +991,7 @@ static int videoEditor_renderMediaItemPreviewFrame(JNIEnv* pEnv,

    result = ThumbnailGetPixels16(tnContext, (M4OSA_Int16 *)pixelArray,
                                                frameWidth,
                                                frameHeight, &timeMs);
                                                frameHeight, &timeMs, 0);
    if (result != M4NO_ERROR) {
        free(pixelArray);
        ThumbnailClose(tnContext);
@@ -2132,7 +2132,7 @@ static int videoEditor_getPixels(

    m_dst32 = env->GetIntArrayElements(pixelArray, NULL);

    err = ThumbnailGetPixels32(mContext, (M4OSA_Int32 *)m_dst32, width,height,&timeMS);
    err = ThumbnailGetPixels32(mContext, (M4OSA_Int32 *)m_dst32, width,height,&timeMS,0);
    if (err != M4NO_ERROR ) {
        if (env != NULL) {
            jniThrowException(env, "java/lang/RuntimeException",\
@@ -2194,9 +2194,10 @@ static int videoEditor_getPixelsList(

    m_dst32 = env->GetIntArrayElements(pixelArray, NULL);

    M4OSA_UInt32 tolerance = deltatimeMS / 2;
    do {
        err = ThumbnailGetPixels32(mContext, ((M4OSA_Int32 *)m_dst32 + arrayOffset),
            width,height,&timeMS);
            width,height,&timeMS, tolerance);
        if (err != M4NO_ERROR ) {
            if (env != NULL) {
                jniThrowException(env, "java/lang/RuntimeException",\
+10 −7
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ typedef struct
M4OSA_ERR ThumbnailGetPixels(const M4OSA_Context pContext,
                             M4OSA_Int32* pixelArray,
                             M4OSA_UInt32 width, M4OSA_UInt32 height,
                             M4OSA_UInt32* pTimeMS);
                             M4OSA_UInt32* pTimeMS, M4OSA_UInt32 tolerance);


/**
@@ -219,7 +219,7 @@ ThumbnailOpen_cleanUp:
M4OSA_ERR ThumbnailGetPixels(const M4OSA_Context pContext,
                             M4OSA_Int32* pixelArray,
                             M4OSA_UInt32 width, M4OSA_UInt32 height,
                             M4OSA_UInt32* pTimeMS)
                             M4OSA_UInt32* pTimeMS, M4OSA_UInt32 tolerance)
{
    M4OSA_ERR err;

@@ -249,7 +249,7 @@ M4OSA_ERR ThumbnailGetPixels(const M4OSA_Context pContext,
        pC->m_previousTime = *pTimeMS;
    }

    err = videoBrowserPrepareFrame(pC->m_pVideoBrowser, pTimeMS);
    err = videoBrowserPrepareFrame(pC->m_pVideoBrowser, pTimeMS, tolerance);
    CHECK_ERR(ThumbnailGetPixels, err);

    if (pC->m_bRender != M4OSA_TRUE) {
@@ -264,7 +264,8 @@ ThumbnailGetPixels_cleanUp:

M4OSA_ERR ThumbnailGetPixels32(const M4OSA_Context pContext,
                         M4OSA_Int32* pixelArray, M4OSA_UInt32 width,
                         M4OSA_UInt32 height, M4OSA_UInt32* timeMS)
                         M4OSA_UInt32 height, M4OSA_UInt32* timeMS,
                         M4OSA_UInt32 tolerance)
{

    M4OSA_ERR err = M4NO_ERROR;
@@ -277,7 +278,7 @@ M4OSA_ERR ThumbnailGetPixels32(const M4OSA_Context pContext,
    pC->m_dst16 = NULL;
    pC->m_dst32 = pixelArray;

    err = ThumbnailGetPixels(pContext, pixelArray, width, height, timeMS);
    err = ThumbnailGetPixels(pContext, pixelArray, width, height, timeMS, tolerance);

ThumbnailGetPixels32_cleanUp:

@@ -286,7 +287,8 @@ ThumbnailGetPixels32_cleanUp:

M4OSA_ERR ThumbnailGetPixels16(const M4OSA_Context pContext,
                         M4OSA_Int16* pixelArray, M4OSA_UInt32 width,
                         M4OSA_UInt32 height, M4OSA_UInt32* timeMS)
                         M4OSA_UInt32 height, M4OSA_UInt32* timeMS,
                         M4OSA_UInt32 tolerance)
{
    M4OSA_ERR err = M4NO_ERROR;

@@ -298,7 +300,8 @@ M4OSA_ERR ThumbnailGetPixels16(const M4OSA_Context pContext,
    pC->m_dst16 = pixelArray;
    pC->m_dst32 = NULL;

    err = ThumbnailGetPixels(pContext, (M4OSA_Int32*)pixelArray, width, height, timeMS);
    err = ThumbnailGetPixels(pContext, (M4OSA_Int32*)pixelArray, width, height,
            timeMS, tolerance);

ThumbnailGetPixels16_cleanUp:

+4 −2
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ M4OSA_ERR ThumbnailOpen(M4OSA_Context *pPContext,
*/
M4OSA_ERR ThumbnailGetPixels32(const M4OSA_Context pContext,
                             M4OSA_Int32* pixelArray, M4OSA_UInt32 width,
                             M4OSA_UInt32 height, M4OSA_UInt32 *timeMS);
                             M4OSA_UInt32 height, M4OSA_UInt32 *timeMS,
                             M4OSA_UInt32 tolerance);

/**
 ************************************************************************
@@ -63,7 +64,8 @@ M4OSA_ERR ThumbnailGetPixels32(const M4OSA_Context pContext,
*/
M4OSA_ERR ThumbnailGetPixels16(const M4OSA_Context pContext,
                             M4OSA_Int16* pixelArray, M4OSA_UInt32 width,
                             M4OSA_UInt32 height, M4OSA_UInt32 *timeMS);
                             M4OSA_UInt32 height, M4OSA_UInt32 *timeMS,
                             M4OSA_UInt32 tolerance);

/**
 ************************************************************************