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

Commit 4162df40 authored by Leena Winterrowd's avatar Leena Winterrowd Committed by Steve Kondik
Browse files

stagefright: Correct timescale in MvHd for HFR

Either timescale or duration must be modified to show the correct
HFR clip duration. Since duration is also queried by the record
timer, modify timescale instead.

CRs-Fixed: 662909
Change-Id: I6b744b4048b7a2d0bb70e2e3a102385a312bf81b
parent 185214b2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ private:
    int mLongitudex10000;
    bool mAreGeoTagsAvailable;
    int32_t mStartTimeOffsetMs;
    int mHFRRatio;

    Mutex mLock;

+9 −5
Original line number Diff line number Diff line
@@ -352,7 +352,8 @@ MPEG4Writer::MPEG4Writer(const char *filename)
      mLatitudex10000(0),
      mLongitudex10000(0),
      mAreGeoTagsAvailable(false),
      mStartTimeOffsetMs(-1) {
      mStartTimeOffsetMs(-1),
      mHFRRatio(1) {

    mFd = open(filename, O_CREAT | O_LARGEFILE | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
    if (mFd >= 0) {
@@ -377,7 +378,8 @@ MPEG4Writer::MPEG4Writer(int fd)
      mLatitudex10000(0),
      mLongitudex10000(0),
      mAreGeoTagsAvailable(false),
      mStartTimeOffsetMs(-1) {
      mStartTimeOffsetMs(-1),
      mHFRRatio(1) {
}

MPEG4Writer::~MPEG4Writer() {
@@ -473,6 +475,8 @@ status_t MPEG4Writer::addSource(const sp<MediaSource> &source) {
    Track *track = new Track(this, source, 1 + mTracks.size());
    mTracks.push_back(track);

    mHFRRatio = ExtendedUtils::HFR::getHFRRatio(meta);

    return OK;
}

@@ -940,7 +944,7 @@ void MPEG4Writer::writeMvhdBox(int64_t durationUs) {
    writeInt32(0);             // version=0, flags=0
    writeInt32(now);           // creation time
    writeInt32(now);           // modification time
    writeInt32(mTimeScale);    // mvhd timescale
    writeInt32(mTimeScale / mHFRRatio);    // mvhd timescale
    int32_t duration = (durationUs * mTimeScale + 5E5) / 1E6;
    writeInt32(duration);
    writeInt32(0x10000);       // rate: 1.0
@@ -2648,7 +2652,7 @@ void MPEG4Writer::Track::bufferChunk(int64_t timestampUs) {
}

int64_t MPEG4Writer::Track::getDurationUs() const {
    return mTrackDurationUs * mHFRRatio;
    return mTrackDurationUs;
}

int64_t MPEG4Writer::Track::getEstimatedTrackSizeBytes() const {
@@ -2973,7 +2977,7 @@ void MPEG4Writer::Track::writeMdhdBox(uint32_t now) {

    int32_t timeScale = mTimeScale / mHFRRatio;
    mOwner->writeInt32(timeScale);    // media timescale
    int32_t mdhdDuration = (trakDurationUs * timeScale + 5E5) / 1E6;
    int32_t mdhdDuration = (trakDurationUs * mTimeScale + 5E5) / 1E6;
    mOwner->writeInt32(mdhdDuration);  // use media timescale
    // Language follows the three letter standard ISO-639-2/T
    // 'e', 'n', 'g' for "English", for instance.