VirtualBox

Changeset 75041 in vbox


Ignore:
Timestamp:
Oct 24, 2018 1:57:34 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126084
Message:

VideoRec/WebMWriter: Fixed the relative timecode handling when starting recording a VM which already is running.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/WebMWriter.h

    r75033 r75041  
    363363        /** Absolute timecode (in ms) when this cluster starts. */
    364364        WebMTimecodeAbs tcAbsStartMs;
     365        /** Absolute timecode (in ms) of when last written to this cluster. */
     366        WebMTimecodeAbs tcAbsLastWrittenMs;
    365367        /** Number of (simple) blocks in this cluster. */
    366368        uint64_t        cBlocks;
  • trunk/src/VBox/Main/src-client/WebMWriter.cpp

    r75031 r75041  
    441441        const WebMTimecodeAbs tcAbsPTS = a_pBlock->Data.tcAbsPTSMs;
    442442
    443         /* Check if the current segment already has been started.
    444          * If not, use the current (absolute) time stamp for it. */
    445         if (CurSeg.tcAbsStartMs == 0)
    446         {
    447             CurSeg.tcAbsStartMs = tcAbsPTS;
    448             LogFunc(("Segment started @ %RU64ms\n", CurSeg.tcAbsStartMs));
    449         }
    450 
    451443        /* See if we already have an entry for the specified timecode in our queue. */
    452444        WebMBlockMap::iterator itQueue = CurSeg.queueBlocks.Map.find(tcAbsPTS);
     
    464456        }
    465457
    466         processQueue(&CurSeg.queueBlocks, false /* fForce */);
     458        rc = processQueue(&CurSeg.queueBlocks, false /* fForce */);
    467459    }
    468460    catch(...)
     
    496488        && tcAbsPTSMs <= a_pTrack->tcAbsLastWrittenMs)
    497489    {
     490        AssertFailed(); /* Should never happen. */
    498491        tcAbsPTSMs = a_pTrack->tcAbsLastWrittenMs + 1;
    499492    }
     
    646639        bool fClusterStart = false;
    647640
     641        /* If the current segment does not have any clusters (yet),
     642         * take the first absolute PTS as the starting point for that segment. */
     643        if (CurSeg.cClusters == 0)
     644        {
     645            CurSeg.tcAbsStartMs = mapAbsPTSMs;
     646            fClusterStart = true;
     647        }
     648
    648649        /* No blocks written yet? Start a new cluster. */
    649650        if (Cluster.cBlocks == 0)
     
    661662            && !mapBlocks.fClusterStarted)
    662663        {
     664            /* Last written timecode of the current cluster. */
     665            uint64_t tcAbsClusterLastWrittenMs;
     666
    663667            if (Cluster.fOpen) /* Close current cluster first. */
    664668            {
    665                 /* Make sure that the current cluster contained some data.  */
     669                Log2Func(("[C%RU64] End @ %RU64ms (duration = %RU64ms)\n",
     670                          Cluster.uID, Cluster.tcAbsLastWrittenMs, Cluster.tcAbsLastWrittenMs - Cluster.tcAbsStartMs));
     671
     672                /* Make sure that the current cluster contained some data. */
    666673                Assert(Cluster.offStart);
    667674                Assert(Cluster.cBlocks);
     675
     676                /* Save the last written timecode of the current cluster before closing it. */
     677                tcAbsClusterLastWrittenMs = Cluster.tcAbsLastWrittenMs;
    668678
    669679                subEnd(MkvElem_Cluster);
    670680                Cluster.fOpen = false;
    671681            }
    672 
    673             Cluster.fOpen        = true;
    674             Cluster.uID          = CurSeg.cClusters;
    675             Cluster.tcAbsStartMs = mapAbsPTSMs;
    676             Cluster.offStart     = RTFileTell(getFile());
    677             Cluster.cBlocks      = 0;
     682            else /* First cluster ever? Use the segment's starting timecode. */
     683                tcAbsClusterLastWrittenMs = CurSeg.tcAbsStartMs;
     684
     685            Assert(tcAbsClusterLastWrittenMs >= CurSeg.tcAbsStartMs);
     686
     687            Cluster.fOpen              = true;
     688            Cluster.uID                = CurSeg.cClusters;
     689            /* Use the last written timecode of the former cluster as starting point. */
     690            Cluster.tcAbsStartMs       = tcAbsClusterLastWrittenMs;
     691            Cluster.tcAbsLastWrittenMs = Cluster.tcAbsStartMs;
     692            Cluster.offStart           = RTFileTell(getFile());
     693            Cluster.cBlocks            = 0;
    678694
    679695            Log2Func(("[C%RU64] Start @ %RU64ms (map TC is %RU64) / %RU64 bytes\n",
     
    693709
    694710            subStart(MkvElem_Cluster)
    695                 .serializeUnsignedInteger(MkvElem_Timecode, Cluster.tcAbsStartMs);
     711                .serializeUnsignedInteger(MkvElem_Timecode, Cluster.tcAbsStartMs - CurSeg.tcAbsStartMs);
    696712
    697713            CurSeg.cClusters++;
     
    699715            mapBlocks.fClusterStarted = true;
    700716        }
     717
     718        Log2Func(("[C%RU64] SegTcAbsStartMs=%RU64, ClusterTcAbsStartMs=%RU64, ClusterTcAbsLastWrittenMs=%RU64, mapAbsPTSMs=%RU64\n",
     719                   Cluster.uID, CurSeg.tcAbsStartMs, Cluster.tcAbsStartMs, Cluster.tcAbsLastWrittenMs, mapAbsPTSMs));
    701720
    702721        /* Iterate through all blocks related to the current timecode. */
     
    717736
    718737            Cluster.cBlocks++;
     738            Cluster.tcAbsLastWrittenMs = pBlock->Data.tcAbsPTSMs;
    719739
    720740            pTrack->cTotalBlocks++;
    721             pTrack->tcAbsLastWrittenMs = pBlock->Data.tcAbsPTSMs;
     741            pTrack->tcAbsLastWrittenMs = Cluster.tcAbsLastWrittenMs;
    722742
    723743            if (CurSeg.tcAbsLastWrittenMs < pTrack->tcAbsLastWrittenMs)
     
    730750            {
    731751                /* Insert cue points for all tracks if a new cluster has been started. */
    732                 WebMCuePoint *pCuePoint = new WebMCuePoint(CurSeg.tcAbsLastWrittenMs);
     752                WebMCuePoint *pCuePoint = new WebMCuePoint(Cluster.tcAbsLastWrittenMs);
    733753
    734754                WebMTracks::iterator itTrack = CurSeg.mapTracks.begin();
     
    847867        CurSeg.offSeekInfo = RTFileTell(getFile());
    848868
    849     LogFunc(("Seek Headeder @ %RU64\n", CurSeg.offSeekInfo));
     869    LogFunc(("Seek Header @ %RU64\n", CurSeg.offSeekInfo));
    850870
    851871    subStart(MkvElem_SeekHead);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette