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

Commit 51b3174a authored by Surajit Podder's avatar Surajit Podder Committed by Steve Kondik
Browse files

video: Use boot clock for recording start time

Camera HAL3 uses boot time for buffer timestamp, rather
than system monotonic time. This leads to issues as
framework uses system monotonic time as reference start
time for timestamp adjustment.

Add change to use boot time for reference start time.

CRs-Fixed: 946735

Change-Id: Id0af9c8aed1a983095275ac03f7f59abc31594cc
parent 7262eae1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ enum {
    kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
    kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
    kKeyTime              = 'time',  // int64_t (usecs)
    kKeyTimeBoot          = 'timb',  // int64_t (usecs)
    kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
    kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
    kKeyTargetTime        = 'tarT',  // int64_t (usecs)
+2 −0
Original line number Diff line number Diff line
@@ -1814,6 +1814,8 @@ status_t StagefrightRecorder::setupMPEG4orWEBMRecording() {
void StagefrightRecorder::setupMPEG4orWEBMMetaData(sp<MetaData> *meta) {
    int64_t startTimeUs = systemTime() / 1000;
    (*meta)->setInt64(kKeyTime, startTimeUs);
    int64_t startTimeBootUs = systemTime(SYSTEM_TIME_BOOTTIME) / 1000;
    (*meta)->setInt64(kKeyTimeBoot, startTimeBootUs);
    (*meta)->setInt32(kKeyFileType, mOutputFormat);
    (*meta)->setInt32(kKeyBitRate, mTotalBitRate);
    if (mMovieTimeScale > 0) {
+9 −1
Original line number Diff line number Diff line
@@ -701,7 +701,15 @@ status_t CameraSource::start(MetaData *meta) {

    if (meta) {
        int64_t startTimeUs;
        if (meta->findInt64(kKeyTime, &startTimeUs)) {

        auto key = kKeyTimeBoot;
        char value[PROPERTY_VALUE_MAX];
        if (property_get("media.camera.ts.monotonic", value, "0") &&
            atoi(value)) {
            key = kKeyTime;
        }

        if (meta->findInt64(key, &startTimeUs)) {
            mStartTimeUs = startTimeUs;
        }

+10 −0
Original line number Diff line number Diff line
@@ -1837,9 +1837,16 @@ status_t MPEG4Writer::Track::start(MetaData *params) {
    }

    int64_t startTimeUs;

    if (params == NULL || !params->findInt64(kKeyTime, &startTimeUs)) {
        startTimeUs = 0;
    }

    int64_t startTimeBootUs;
    if (params == NULL || !params->findInt64(kKeyTimeBoot, &startTimeBootUs)) {
        startTimeBootUs = 0;
    }

    mStartTimeRealUs = startTimeUs;

    int32_t rotationDegrees;
@@ -1850,6 +1857,7 @@ status_t MPEG4Writer::Track::start(MetaData *params) {
    initTrackingProgressStatus(params);

    sp<MetaData> meta = new MetaData;

    if (mOwner->isRealTimeRecording() && mOwner->numTracks() > 1) {
        /*
         * This extra delay of accepting incoming audio/video signals
@@ -1865,10 +1873,12 @@ status_t MPEG4Writer::Track::start(MetaData *params) {
            startTimeOffsetUs = kInitialDelayTimeUs;
        }
        startTimeUs += startTimeOffsetUs;
        startTimeBootUs += startTimeOffsetUs;
        ALOGI("Start time offset: %" PRId64 " us", startTimeOffsetUs);
    }

    meta->setInt64(kKeyTime, startTimeUs);
    meta->setInt64(kKeyTimeBoot, startTimeBootUs);

    status_t err = mSource->start(meta.get());
    if (err != OK) {
+9 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <media/stagefright/Utils.h>
#include <OMX_Core.h>
#include <stagefright/AVExtensions.h>
#include <cutils/properties.h>

namespace android {

@@ -663,8 +664,15 @@ status_t MediaCodecSource::onStart(MetaData *params) {
    status_t err = OK;

    if (mFlags & FLAG_USE_SURFACE_INPUT) {
        auto key = kKeyTimeBoot;
        char value[PROPERTY_VALUE_MAX];
        if (property_get("media.camera.ts.monotonic", value, "0") &&
            atoi(value)) {
            key = kKeyTime;
        }

        int64_t startTimeUs;
        if (!params || !params->findInt64(kKeyTime, &startTimeUs)) {
        if (!params || !params->findInt64(key, &startTimeUs)) {
            startTimeUs = -1ll;
        }
        resume(startTimeUs);