VirtualBox

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


Ignore:
Timestamp:
Aug 19, 2022 7:45:57 AM (2 years ago)
Author:
vboxsync
Message:

Recording/Main: Optimization: Check if recording stream updates are needed at display implementation level already, should save quite a few unnecessary calls. bugref:10275

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

Legend:

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

    r96260 r96322  
    7070    bool IsLimitReached(void);
    7171    bool IsLimitReached(uint32_t uScreen, uint64_t msTimestamp);
     72    bool NeedsUpdate( uint32_t uScreen, uint64_t msTimestamp);
    7273
    7374    DECLCALLBACK(int) OnLimitReached(uint32_t uScreen, int rc);
  • trunk/src/VBox/Main/include/RecordingInternals.h

    r96285 r96322  
    454454int recordingCodecEncode(PRECORDINGCODEC pCodec, const PRECORDINGFRAME pFrame, size_t *pcEncoded, size_t *pcbEncoded);
    455455int recordingCodecFinalize(PRECORDINGCODEC pCodec);
    456 uint32_t recordingCodecGetWritable(PRECORDINGCODEC pCodec, uint64_t msTimestamp);
     456bool recordingCodecIsInitialized(const PRECORDINGCODEC pCodec);
     457uint32_t recordingCodecGetWritable(const PRECORDINGCODEC pCodec, uint64_t msTimestamp);
    457458#endif /* !MAIN_INCLUDED_RecordingInternals_h */
  • trunk/src/VBox/Main/include/RecordingStream.h

    r96260 r96322  
    130130#endif
    131131    PRECORDINGCODEC GetVideoCodec(void) { return &this->CodecVideo; };
     132
    132133    bool IsLimitReached(uint64_t msTimestamp) const;
    133134    bool IsReady(void) const;
     135    bool NeedsUpdate(uint64_t msTimestamp) const;
    134136
    135137public:
  • trunk/src/VBox/Main/src-client/DisplayImpl.cpp

    r94916 r96322  
    29942994            {
    29952995                if (!pDisplay->maRecordingEnabled[uScreenId])
     2996                    continue;
     2997
     2998                if (!pCtx->NeedsUpdate(uScreenId, tsNowMs))
    29962999                    continue;
    29973000
  • trunk/src/VBox/Main/src-client/Recording.cpp

    r96284 r96322  
    810810
    811811    return fLimitReached;
     812}
     813
     814/**
     815 * Returns if a specific screen needs to be fed with an update or not.
     816 *
     817 * @returns @c true if an update is needed, @c false if not.
     818 * @param   uScreen             Screen ID to retrieve update stats for.
     819 * @param   msTimestamp         Timestamp (PTS, in ms).
     820 */
     821bool RecordingContext::NeedsUpdate( uint32_t uScreen, uint64_t msTimestamp)
     822{
     823    lock();
     824
     825    bool fNeedsUpdate = false;
     826
     827    if (this->enmState == RECORDINGSTS_STARTED)
     828    {
     829        if (   recordingCodecIsInitialized(&CodecAudio)
     830            && recordingCodecGetWritable(&CodecAudio, msTimestamp) > 0)
     831        {
     832            fNeedsUpdate = true;
     833        }
     834
     835        if (!fNeedsUpdate)
     836        {
     837            const RecordingStream *pStream = getStreamInternal(uScreen);
     838            if (pStream)
     839                fNeedsUpdate = pStream->NeedsUpdate(msTimestamp);
     840        }
     841    }
     842
     843    unlock();
     844
     845    return fNeedsUpdate;
    812846}
    813847
  • trunk/src/VBox/Main/src-client/RecordingCodec.cpp

    r96288 r96322  
    852852
    853853/**
     854 * Returns whether the codec has been initialized or not.
     855 *
     856 * @returns \c true if initialized, or \c false if not.
     857 * @param   pCodec              Codec to return initialization status for.
     858 */
     859bool recordingCodecIsInitialized(const PRECORDINGCODEC pCodec)
     860{
     861    return pCodec->Ops.pfnInit != NULL; /* pfnInit acts as a beacon for initialization status. */
     862}
     863
     864/**
    854865 * Returns the number of writable bytes for a given timestamp.
    855866 *
     
    860871 * @param   msTimestamp         Timestamp (PTS, in ms) return number of writable bytes for.
    861872 */
    862 uint32_t recordingCodecGetWritable(PRECORDINGCODEC pCodec, uint64_t msTimestamp)
     873uint32_t recordingCodecGetWritable(const PRECORDINGCODEC pCodec, uint64_t msTimestamp)
    863874{
    864875    Log3Func(("%RU64 -- tsLastWrittenMs=%RU64 + uDelayMs=%RU32\n",
  • trunk/src/VBox/Main/src-client/RecordingStream.cpp

    r96284 r96322  
    283283
    284284/**
     285 * Returns if a recording stream needs to be fed with an update or not.
     286 *
     287 * @returns @c true if an update is needed, @c false if not.
     288 * @param   msTimestamp         Timestamp (PTS, in ms).
     289 */
     290bool RecordingStream::NeedsUpdate(uint64_t msTimestamp) const
     291{
     292    return recordingCodecGetWritable((const PRECORDINGCODEC)&CodecVideo, msTimestamp) > 0;
     293}
     294
     295/**
    285296 * Processes a recording stream.
    286297 * This function takes care of the actual encoding and writing of a certain stream.
     
    432443{
    433444    AssertPtrReturn(m_pCtx, VERR_WRONG_ORDER);
     445    AssertReturn(NeedsUpdate(msTimestamp), VINF_RECORDING_THROTTLED); /* We ASSUME that the caller checked that first. */
    434446
    435447    Log3Func(("cbData=%zu, msTimestamp=%RU64\n", cbData, msTimestamp));
     
    459471                                    uint32_t uSrcWidth, uint32_t uSrcHeight, uint8_t *puSrcData, uint64_t msTimestamp)
    460472{
     473    AssertPtrReturn(m_pCtx, VERR_WRONG_ORDER);
     474    AssertReturn(NeedsUpdate(msTimestamp), VINF_RECORDING_THROTTLED); /* We ASSUME that the caller checked that first. */
     475
    461476    lock();
    462477
    463478    Log3Func(("[%RU32 %RU32 %RU32 %RU32] msTimestamp=%RU64\n", x , y, uSrcWidth, uSrcHeight, msTimestamp));
    464 
    465     PRECORDINGCODEC pCodec = &this->CodecVideo;
    466479
    467480    PRECORDINGVIDEOFRAME pFrame = NULL;
     
    476489    do
    477490    {
    478         if (recordingCodecGetWritable(pCodec, msTimestamp) == 0)
    479         {
    480             vrc = VINF_RECORDING_THROTTLED; /* Respect maximum frames per second (FPS). */
    481             break;
    482         }
    483 
    484491        int xDiff = ((int)this->ScreenSettings.Video.ulWidth - (int)uSrcWidth) / 2;
    485492        uint32_t w = uSrcWidth;
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