VirtualBox

Changeset 68850 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Sep 25, 2017 10:49:29 AM (7 years ago)
Author:
vboxsync
Message:

VideoRec: Update on syncing with audio data.

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

Legend:

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

    r68798 r68850  
    140140#ifdef VBOX_WITH_AUDIO_VIDEOREC
    141141    AudioVideoRec *i_audioVideoRecGet() const { return mAudioVideoRec; }
    142     HRESULT i_audioVideoRecSendAudio(const void *pvData, size_t cbData, uint64_t uTimestampMs);
     142    HRESULT i_audioVideoRecSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs);
    143143#endif
    144144
  • trunk/src/VBox/Main/include/DisplayImpl.h

    r68798 r68850  
    212212    bool i_videoCaptureStarted(void);
    213213    int  i_videoCaptureInvalidate(void);
    214     int  i_videoCaptureSendAudio(const void *pvData, size_t cbData, uint64_t uTimestampMs);
     214    int  i_videoCaptureSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs);
    215215    int  i_videoCaptureStart(void);
    216216    void i_videoCaptureStop(void);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r68828 r68850  
    67526752 * @param   pvData              Audio data to send.
    67536753 * @param   cbData              Size (in bytes) of audio data to send.
    6754  * @param   uTimestampMs        Time stamp (in ms) of audio data.
    6755  */
    6756 HRESULT Console::i_audioVideoRecSendAudio(const void *pvData, size_t cbData, uint64_t uTimestampMs)
     6754 * @param   uDurationMs         Duration (in ms) of audio data.
     6755 */
     6756HRESULT Console::i_audioVideoRecSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs)
    67576757{
    67586758    if (mDisplay)
    67596759    {
    6760         int rc2 = mDisplay->i_videoCaptureSendAudio(pvData, cbData, uTimestampMs);
     6760        int rc2 = mDisplay->i_videoCaptureSendAudio(pvData, cbData, uDurationMs);
    67616761        AssertRC(rc2);
    67626762    }
  • trunk/src/VBox/Main/src-client/DrvAudioVideoRec.cpp

    r68797 r68850  
    758758            cbDst = RT_MIN((uint32_t)cbWritten, cbDst); /* Update cbDst to actual bytes encoded (written). */
    759759
     760            Assert(cEncFrames == 1); /* At the moment we encode exactly *one* frame per frame. */
     761
     762            const uint64_t uDurationMs = pSink->Codec.Opus.msFrame * cEncFrames;
     763
    760764            switch (pSink->Con.Parms.enmType)
    761765            {
    762766                case AVRECCONTAINERTYPE_MAIN_CONSOLE:
    763767                {
    764                     HRESULT hr = pSink->Con.Main.pConsole->i_audioVideoRecSendAudio(abDst, cbDst, RTTimeMilliTS() /* Now */);
     768                    HRESULT hr = pSink->Con.Main.pConsole->i_audioVideoRecSendAudio(abDst, cbDst, uDurationMs);
    765769                    Assert(hr == S_OK);
    766770                    RT_NOREF(hr);
     
    771775                case AVRECCONTAINERTYPE_WEBM:
    772776                {
    773                     WebMWriter::BlockData_Opus blockData = { abDst, cbDst, RTTimeMilliTS() };
     777                    WebMWriter::BlockData_Opus blockData = { abDst, cbDst, uDurationMs };
    774778                    rc = pSink->Con.WebM.pWebM->WriteBlock(pSink->Con.WebM.uTrack, &blockData, sizeof(blockData));
    775779                    AssertRC(rc);
  • trunk/src/VBox/Main/src-client/EbmlWriter.cpp

    r68811 r68850  
    401401            , uTrack(a_uTrack)
    402402            , offUUID(a_offID)
    403             , cTotalClusters(0)
    404403            , cTotalBlocks(0)
     404            , tcLastWriteMs(0)
    405405        {
    406406            uUUID = RTRandU32();
     
    440440         *  Needed to write the hash sum within the footer. */
    441441        uint64_t      offUUID;
    442         /** Total number of clusters. */
    443         uint64_t      cTotalClusters;
    444442        /** Total number of blocks. */
    445443        uint64_t      cTotalBlocks;
     444        /** Timecode (in ms) of last write. */
     445        uint64_t      tcLastWriteMs;
    446446    };
    447447
     
    473473            , fOpen(false)
    474474            , tcStartMs(0)
    475             , tcEndMs(0)
     475            , tcLastWriteMs(0)
    476476            , cBlocks(0) { }
    477477
     
    485485        /** Timecode (in ms) when starting this cluster. */
    486486        uint64_t      tcStartMs;
    487         /** Timecode (in ms) when this cluster ends. */
    488         uint64_t      tcEndMs;
     487        /** Timecode (in ms) of last write. */
     488        uint64_t      tcLastWriteMs;
    489489        /** Number of (simple) blocks in this cluster. */
    490490        uint64_t      cBlocks;
     
    499499    {
    500500        WebMSegment(void)
    501             : tcStart(0)
    502             , tcEnd(0)
     501            : tcStartMs(0)
     502            , tcLastWriteMs(0)
    503503            , offStart(0)
    504504            , offInfo(0)
     
    515515        uint64_t                        uTimecodeScaleFactor;
    516516
    517         /** Timecode when starting this segment. */
    518         uint64_t                        tcStart;
    519         /** Timecode when this segment ended. */
    520         uint64_t                        tcEnd;
     517        /** Timecode (in ms) when starting this segment. */
     518        uint64_t                        tcStartMs;
     519        /** Timecode (in ms) of last write. */
     520        uint64_t                        tcLastWriteMs;
    521521
    522522        /** Absolute offset (in bytes) of CurSeg. */
     
    532532        /** List of cue points. Needed for seeking table. */
    533533        std::list<WebMCuePoint>         lstCues;
     534
     535        /** Total number of clusters. */
     536        uint64_t                        cClusters;
    534537
    535538        /** Map of tracks.
     
    771774        uint64_t tcPTSMs = a_pPkt->data.frame.pts * 1000
    772775                         * (uint64_t) a_pCfg->g_timebase.num / a_pCfg->g_timebase.den;
     776        /* Sanity. */
     777        Assert(tcPTSMs);
     778        //Assert(tcPTSMs >= Cluster.tcLastWriteMs);
    773779
    774780        if (   tcPTSMs
    775             && tcPTSMs <= CurSeg.CurCluster.tcEndMs)
    776         {
    777             tcPTSMs = CurSeg.CurCluster.tcEndMs + 1;
     781            && tcPTSMs <= a_pTrack->tcLastWriteMs)
     782        {
     783            tcPTSMs = a_pTrack->tcLastWriteMs + 1;
    778784        }
    779785
     
    788794        if (tcPTSMs > VBOX_WEBM_CLUSTER_MAX_LEN_MS)
    789795        {
    790             tcPTSMs = 0;
     796            LogFunc(("[T%RU8C%RU64] Exceeded max length (%RU64ms)\n",
     797                     a_pTrack->uTrack, Cluster.uID, VBOX_WEBM_CLUSTER_MAX_LEN_MS));
     798
     799            /* Note: Do not reset the PTS here -- the new cluster starts time-wise
     800             *       where the old cluster left off. */
    791801
    792802            fClusterStart = true;
     
    805815
    806816            Cluster.fOpen      = true;
    807             Cluster.uID        = a_pTrack->cTotalClusters;
     817            Cluster.uID        = CurSeg.cClusters;
    808818            Cluster.tcStartMs  = tcPTSMs;
    809819            Cluster.offCluster = RTFileTell(m_Ebml.getFile());
    810820            Cluster.cBlocks    = 0;
     821
     822            if (CurSeg.cClusters)
     823                AssertMsg(Cluster.tcStartMs, ("[T%RU8C%RU64] @ %RU64 start is 0 which is invalid\n",
     824                                              a_pTrack->uTrack, Cluster.uID, Cluster.offCluster));
    811825
    812826            LogFunc(("[T%RU8C%RU64] Start @ %RU64ms / %RU64 bytes\n",
     
    823837            }
    824838
    825             a_pTrack->cTotalClusters++;
    826         }
    827 
    828         Cluster.tcEndMs = tcPTSMs;
     839            CurSeg.cClusters++;
     840        }
     841
     842        Cluster.tcLastWriteMs = tcPTSMs;
    829843        Cluster.cBlocks++;
    830844
    831         if (CurSeg.tcEnd < Cluster.tcEndMs)
    832             CurSeg.tcEnd = Cluster.tcEndMs;
     845        a_pTrack->tcLastWriteMs = tcPTSMs;
     846
     847        if (CurSeg.tcLastWriteMs < a_pTrack->tcLastWriteMs)
     848            CurSeg.tcLastWriteMs = a_pTrack->tcLastWriteMs;
    833849
    834850        /* Calculate the block's timecode, which is relative to the cluster's starting timecode. */
    835851        uint16_t tcBlockMs = static_cast<uint16_t>(tcPTSMs - Cluster.tcStartMs);
    836852
    837         Log2Func(("tcPTSMs=%RU64, tcBlockMs=%RU64\n", tcPTSMs, tcBlockMs));
    838 
    839         Log2Func(("[C%RU64] cBlocks=%RU64, tcStartMs=%RU64, tcEndMs=%RU64 (%zums)\n",
    840                   Cluster.uID, Cluster.cBlocks, Cluster.tcStartMs, Cluster.tcEndMs, Cluster.tcEndMs - Cluster.tcStartMs));
     853        Log2Func(("[T%RU8C%RU64] tcPTSMs=%RU64, (%RU64ms)\n", a_pTrack->uTrack, Cluster.uID, tcPTSMs, tcBlockMs));
    841854
    842855        uint8_t fFlags = 0;
     
    852865#ifdef VBOX_WITH_LIBOPUS
    853866    /* Audio blocks that have same absolute timecode as video blocks SHOULD be written before the video blocks. */
    854     int writeBlockOpus(WebMTrack *a_pTrack, const void *pvData, size_t cbData, uint64_t uTimeStampMs)
     867    int writeBlockOpus(WebMTrack *a_pTrack, const void *pvData, size_t cbData, uint64_t uDurationMs)
    855868    {
    856869        AssertPtrReturn(a_pTrack, VERR_INVALID_POINTER);
    857870        AssertPtrReturn(pvData,   VERR_INVALID_POINTER);
    858871        AssertReturn(cbData,      VERR_INVALID_PARAMETER);
    859 
    860         RT_NOREF(uTimeStampMs);
    861872
    862873        WebMCluster &Cluster = CurSeg.CurCluster;
     
    867878         *     Raw Timecode = (Block timecode + Cluster timecode) * TimecodeScaleFactor
    868879         */
    869         uint64_t tcPTSMs  = Cluster.tcStartMs + (Cluster.cBlocks * 20 /*ms */);
     880        uint64_t tcPTSMs = CurSeg.tcLastWriteMs + uDurationMs;
     881
     882        /* Sanity. */
     883        Assert(tcPTSMs);
     884        //Assert(tcPTSMs >= Cluster.tcLastWriteMs);
    870885
    871886        /* Whether to start a new cluster or not. */
    872887        bool fClusterStart = false;
    873 
    874         if (a_pTrack->cTotalBlocks == 0)
    875             fClusterStart = true;
    876888
    877889        /* Did we reach the maximum a cluster can hold? Use a new cluster then. */
     
    888900
    889901            Cluster.fOpen      = true;
    890             Cluster.uID        = a_pTrack->cTotalClusters;
    891             Cluster.tcStartMs  = Cluster.tcEndMs;
     902            Cluster.uID        = CurSeg.cClusters;
     903            Cluster.tcStartMs  = Cluster.tcLastWriteMs;
    892904            Cluster.offCluster = RTFileTell(m_Ebml.getFile());
    893905            Cluster.cBlocks    = 0;
     906
     907            if (CurSeg.cClusters)
     908                AssertMsg(Cluster.tcStartMs, ("[T%RU8C%RU64] @ %RU64 start is 0 which is invalid\n",
     909                                              a_pTrack->uTrack, Cluster.uID, Cluster.offCluster));
    894910
    895911            LogFunc(("[T%RU8C%RU64] Start @ %RU64ms / %RU64 bytes\n",
     
    903919                  .serializeUnsignedInteger(MkvElem_Timecode, Cluster.tcStartMs);
    904920
    905             a_pTrack->cTotalClusters++;
    906         }
    907 
    908         Cluster.tcEndMs = tcPTSMs;
     921            CurSeg.cClusters++;
     922        }
     923
     924        Cluster.tcLastWriteMs = tcPTSMs;
    909925        Cluster.cBlocks++;
    910926
    911         if (CurSeg.tcEnd < Cluster.tcEndMs)
    912             CurSeg.tcEnd = Cluster.tcEndMs;
     927        a_pTrack->tcLastWriteMs = tcPTSMs;
     928
     929        if (CurSeg.tcLastWriteMs < a_pTrack->tcLastWriteMs)
     930            CurSeg.tcLastWriteMs = a_pTrack->tcLastWriteMs;
    913931
    914932        /* Calculate the block's timecode, which is relative to the cluster's starting timecode. */
    915933        uint16_t tcBlockMs = static_cast<uint16_t>(tcPTSMs - Cluster.tcStartMs);
    916934
    917         Log2Func(("tcPTSMs=%RU64, tcBlockMs=%RU64\n", tcPTSMs, tcBlockMs));
    918 
    919         Log2Func(("[C%RU64] cBlocks=%RU64, tcStartMs=%RU64, tcEndMs=%RU64 (%zums)\n",
    920                   Cluster.uID, Cluster.cBlocks, Cluster.tcStartMs, Cluster.tcEndMs, Cluster.tcEndMs - Cluster.tcStartMs));
     935        Log2Func(("[T%RU8C%RU64] tcPTSMs=%RU64, (%RU64ms)\n", a_pTrack->uTrack, Cluster.uID, tcPTSMs, tcBlockMs));
    921936
    922937        return writeSimpleBlockInternal(a_pTrack, tcBlockMs,
     
    954969                    Assert(cbData == sizeof(WebMWriter::BlockData_Opus));
    955970                    WebMWriter::BlockData_Opus *pData = (WebMWriter::BlockData_Opus *)pvData;
    956                     rc = writeBlockOpus(pTrack, pData->pvData, pData->cbData, pData->uTimestampMs);
     971                    rc = writeBlockOpus(pTrack, pData->pvData, pData->cbData, pData->uDurationMs);
    957972                }
    958973                else
     
    11131128        RTStrPrintf(szApp, sizeof(szApp), VBOX_PRODUCT " %sr%u", VBOX_VERSION_STRING, RTBldCfgRevision());
    11141129
    1115         const uint64_t tcDuration = CurSeg.tcEnd - CurSeg.tcStart;
     1130        const uint64_t tcDuration = CurSeg.tcLastWriteMs - CurSeg.tcStartMs;
    11161131
    11171132        if (!CurSeg.lstCues.empty())
  • trunk/src/VBox/Main/src-client/EbmlWriter.h

    r68796 r68850  
    8686        /** Size (in bytes) of encoded Opus audio data. */
    8787        size_t      cbData;
    88         /** Timestamp (in ms). */
    89         uint64_t    uTimestampMs;
     88        /** Duration (in ms) of encoded Opus audio data. */
     89        uint64_t    uDurationMs;
    9090    };
    9191#endif /* VBOX_WITH_LIBOPUS */
  • trunk/src/VBox/Main/src-client/VideoRec.cpp

    r68806 r68850  
    6767#ifdef DEBUG_andy
    6868/** Enables dumping audio / video data for debugging reasons. */
    69 # define VBOX_VIDEOREC_DUMP
     69//# define VBOX_VIDEOREC_DUMP
    7070#endif
    7171
Note: See TracChangeset for help on using the changeset viewer.

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