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

Commit f293e928 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Use monotonic system time instead of gettimeofday

to avoid overflows when the clock changes during video decoding.

Bug: 33796695
Change-Id: Ie050c188915e80ab869721eca80249f975b4ea20
parent dcc65c73
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -27,11 +27,10 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaDefs.h>
#include <OMX_VideoExt.h>
#include <inttypes.h>

namespace android {

#define PRINT_TIME  ALOGV

#define componentName                   "video_decoder.avc"
#define codingType                      OMX_VIDEO_CodingAVC
#define CODEC_MIME_TYPE                 MEDIA_MIMETYPE_VIDEO_AVC
@@ -78,7 +77,7 @@ SoftAVC::SoftAVC(
            1 /* numMinInputBuffers */, kNumBuffers, INPUT_BUF_SIZE,
            1 /* numMinOutputBuffers */, kNumBuffers, CODEC_MIME_TYPE);

    GETTIME(&mTimeStart, NULL);
    mTimeStart = mTimeEnd = systemTime();

    // If input dump is enabled, then open create an empty file
    GENERATE_FILE_NAMES();
@@ -173,8 +172,7 @@ status_t SoftAVC::resetPlugin() {
    memset(mTimeStampsValid, 0, sizeof(mTimeStampsValid));

    /* Initialize both start and end times */
    gettimeofday(&mTimeStart, NULL);
    gettimeofday(&mTimeEnd, NULL);
    mTimeStart = mTimeEnd = systemTime();

    return OK;
}
@@ -558,7 +556,7 @@ void SoftAVC::onQueueFilled(OMX_U32 portIndex) {
        {
            ivd_video_decode_ip_t s_dec_ip;
            ivd_video_decode_op_t s_dec_op;
            WORD32 timeDelay, timeTaken;
            nsecs_t timeDelay, timeTaken;
            size_t sizeY, sizeUV;

            if (!setDecodeArgs(&s_dec_ip, &s_dec_op, inHeader, outHeader, timeStampIx)) {
@@ -570,10 +568,10 @@ void SoftAVC::onQueueFilled(OMX_U32 portIndex) {
            // If input dump is enabled, then write to file
            DUMP_TO_FILE(mInFile, s_dec_ip.pv_stream_buffer, s_dec_ip.u4_num_Bytes, mInputOffset);

            GETTIME(&mTimeStart, NULL);
            mTimeStart = systemTime();
            /* Compute time elapsed between end of previous decode()
             * to start of current decode() */
            TIME_DIFF(mTimeEnd, mTimeStart, timeDelay);
            timeDelay = mTimeStart - mTimeEnd;

            IV_API_CALL_STATUS_T status;
            status = ivdec_api_function(mCodecCtx, (void *)&s_dec_ip, (void *)&s_dec_op);
@@ -601,11 +599,12 @@ void SoftAVC::onQueueFilled(OMX_U32 portIndex) {

            getVUIParams();

            GETTIME(&mTimeEnd, NULL);
            mTimeEnd = systemTime();
            /* Compute time taken for decode() */
            TIME_DIFF(mTimeStart, mTimeEnd, timeTaken);
            timeTaken = mTimeEnd - mTimeStart;

            PRINT_TIME("timeTaken=%6d delay=%6d numBytes=%6d", timeTaken, timeDelay,
            ALOGV("timeTaken=%6lldus delay=%6lldus numBytes=%6d",
                    (long long) (timeTaken / 1000ll), (long long) (timeDelay / 1000ll),
                   s_dec_op.u4_num_bytes_consumed);
            if (s_dec_op.u4_frame_decoded_flag && !mFlushNeeded) {
                mFlushNeeded = true;
+4 −13
Original line number Diff line number Diff line
@@ -41,14 +41,6 @@ namespace android {
/** Used to remove warnings about unused parameters */
#define UNUSED(x) ((void)(x))

/** Get time */
#define GETTIME(a, b) gettimeofday(a, b);

/** Compute difference between start and end */
#define TIME_DIFF(start, end, diff) \
    diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
            ((end).tv_usec - (start).tv_usec);

struct SoftAVC : public SoftVideoDecoderOMXComponent {
    SoftAVC(const char *name, const OMX_CALLBACKTYPE *callbacks,
            OMX_PTR appData, OMX_COMPONENTTYPE **component);
@@ -70,8 +62,8 @@ private:

    size_t mNumCores;            // Number of cores to be uesd by the codec

    struct timeval mTimeStart;   // Time at the start of decode()
    struct timeval mTimeEnd;     // Time at the end of decode()
    nsecs_t mTimeStart;   // Time at the start of decode()
    nsecs_t mTimeEnd;     // Time at the end of decode()

    // Internal buffer to be used to flush out the buffers from decoder
    uint8_t *mFlushOutBuffer;
@@ -129,10 +121,9 @@ private:
#define INPUT_DUMP_EXT      "h264"

#define GENERATE_FILE_NAMES() {                         \
    GETTIME(&mTimeStart, NULL);                         \
    strcpy(mInFile, "");                                \
    sprintf(mInFile, "%s_%ld.%ld.%s", INPUT_DUMP_PATH,  \
            mTimeStart.tv_sec, mTimeStart.tv_usec,      \
    sprintf(mInFile, "%s_%lld.%s", INPUT_DUMP_PATH,     \
            (long long) mTimeStart,                     \
            INPUT_DUMP_EXT);                            \
}