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

Commit 86b7f47a authored by James Dong's avatar James Dong
Browse files

Support platform and camera dependent recording start time offset

related-to-bug: 4390777

Change-Id: Icb52973ad4ac716f04fb103ef527915a966d06d5
parent 9b1e4f1a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ public:
    int32_t getTimeScale() const { return mTimeScale; }

    status_t setGeoData(int latitudex10000, int longitudex10000);
    void setStartTimeOffsetMs(int ms) { mStartTimeOffsetMs = ms; }
    int32_t getStartTimeOffsetMs() const { return mStartTimeOffsetMs; }

protected:
    virtual ~MPEG4Writer();
@@ -84,6 +86,7 @@ private:
    int mLatitudex10000;
    int mLongitudex10000;
    bool mAreGeoTagsAvailable;
    int32_t mStartTimeOffsetMs;

    Mutex mLock;

+9 −0
Original line number Diff line number Diff line
@@ -1453,6 +1453,12 @@ status_t StagefrightRecorder::setupMPEG4Recording(
        writer->setMaxFileSize(mMaxFileSizeBytes);
    }

    mStartTimeOffsetMs = mEncoderProfiles->getStartTimeOffsetMs(mCameraId);
    if (mStartTimeOffsetMs > 0) {
        reinterpret_cast<MPEG4Writer *>(writer.get())->
            setStartTimeOffsetMs(mStartTimeOffsetMs);
    }

    writer->setListener(mListener);
    *mediaWriter = writer;
    return OK;
@@ -1659,6 +1665,7 @@ status_t StagefrightRecorder::reset() {
    mAudioTimeScale  = -1;
    mVideoTimeScale  = -1;
    mCameraId        = 0;
    mStartTimeOffsetMs = -1;
    mVideoEncoderProfile = -1;
    mVideoEncoderLevel   = -1;
    mMaxFileDurationUs = 0;
@@ -1747,6 +1754,8 @@ status_t StagefrightRecorder::dump(
    result.append(buffer);
    snprintf(buffer, SIZE, "     Camera Id: %d\n", mCameraId);
    result.append(buffer);
    snprintf(buffer, SIZE, "     Start time offset (ms): %d\n", mStartTimeOffsetMs);
    result.append(buffer);
    snprintf(buffer, SIZE, "     Encoder: %d\n", mVideoEncoder);
    result.append(buffer);
    snprintf(buffer, SIZE, "     Encoder profile: %d\n", mVideoEncoderProfile);
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ private:
    int32_t mRotationDegrees;  // Clockwise
    int32_t mLatitudex10000;
    int32_t mLongitudex10000;
    int32_t mStartTimeOffsetMs;

    bool mCaptureTimeLapse;
    int64_t mTimeBetweenTimeLapseFrameCaptureUs;
+24 −10
Original line number Diff line number Diff line
@@ -260,7 +260,8 @@ MPEG4Writer::MPEG4Writer(const char *filename)
      mInterleaveDurationUs(1000000),
      mLatitudex10000(0),
      mLongitudex10000(0),
      mAreGeoTagsAvailable(false) {
      mAreGeoTagsAvailable(false),
      mStartTimeOffsetMs(-1) {

    mFd = open(filename, O_CREAT | O_LARGEFILE | O_TRUNC | O_RDWR);
    if (mFd >= 0) {
@@ -282,7 +283,8 @@ MPEG4Writer::MPEG4Writer(int fd)
      mInterleaveDurationUs(1000000),
      mLatitudex10000(0),
      mLongitudex10000(0),
      mAreGeoTagsAvailable(false) {
      mAreGeoTagsAvailable(false),
      mStartTimeOffsetMs(-1) {
}

MPEG4Writer::~MPEG4Writer() {
@@ -1425,10 +1427,15 @@ status_t MPEG4Writer::Track::start(MetaData *params) {
         * session, and it also helps eliminate the "recording" sound for
         * camcorder applications.
         *
         * Ideally, this platform-specific value should be defined
         * in media_profiles.xml file
         * If client does not set the start time offset, we fall back to
         * use the default initial delay value.
         */
        startTimeUs += kInitialDelayTimeUs;
        int64_t startTimeOffsetUs = mOwner->getStartTimeOffsetMs() * 1000LL;
        if (startTimeOffsetUs < 0) {  // Start time offset was not set
            startTimeOffsetUs = kInitialDelayTimeUs;
        }
        startTimeUs += startTimeOffsetUs;
        LOGI("Start time offset: %lld us", startTimeOffsetUs);
    }

    meta->setInt64(kKeyTime, startTimeUs);
@@ -2234,13 +2241,20 @@ void MPEG4Writer::Track::sendTrackSummary(bool hasMultipleTracks) {
                    trackNum | MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES,
                    mNumSamples);

    {
        // The system delay time excluding the requested initial delay that
        // is used to eliminate the recording sound.
        int64_t startTimeOffsetUs = mOwner->getStartTimeOffsetMs() * 1000LL;
        if (startTimeOffsetUs < 0) {  // Start time offset was not set
            startTimeOffsetUs = kInitialDelayTimeUs;
        }
        int64_t initialDelayUs =
        mFirstSampleTimeRealUs - mStartTimeRealUs - kInitialDelayTimeUs;
            mFirstSampleTimeRealUs - mStartTimeRealUs - startTimeOffsetUs;

        mOwner->notify(MEDIA_RECORDER_TRACK_EVENT_INFO,
                    trackNum | MEDIA_RECORDER_TRACK_INFO_INITIAL_DELAY_MS,
                    (initialDelayUs) / 1000);
    }

    if (hasMultipleTracks) {
        mOwner->notify(MEDIA_RECORDER_TRACK_EVENT_INFO,