VirtualBox

Changeset 96229 in vbox for trunk/src/VBox/Main/include


Ignore:
Timestamp:
Aug 16, 2022 3:41:39 PM (2 years ago)
Author:
vboxsync
Message:

Recording/Main: Decoupled the WebM writer class from codec dependencies. Various bugfixes. bugref:10275

Location:
trunk/src/VBox/Main/include
Files:
4 edited

Legend:

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

    r95645 r96229  
    3838    RecordingContext();
    3939
    40     RecordingContext(Console *ptrConsole, const settings::RecordingSettings &settings);
     40    RecordingContext(Console *ptrConsole, const settings::RecordingSettings &Settings);
    4141
    4242    virtual ~RecordingContext(void);
     
    4747    RecordingStream *GetStream(unsigned uScreen) const;
    4848    size_t GetStreamCount(void) const;
     49#ifdef VBOX_WITH_AUDIO_RECORDING
     50    PRECORDINGCODEC GetCodecAudio(void) { return &this->CodecAudio; }
     51#endif
    4952
    50     int Create(Console *pConsole, const settings::RecordingSettings &settings);
     53    int Create(Console *pConsole, const settings::RecordingSettings &Settings);
    5154    void Destroy(void);
    5255
     
    7275protected:
    7376
    74     int createInternal(Console *ptrConsole, const settings::RecordingSettings &settings);
     77    int createInternal(Console *ptrConsole, const settings::RecordingSettings &Settings);
    7578    int startInternal(void);
    7679    int stopInternal(void);
     
    8083    RecordingStream *getStreamInternal(unsigned uScreen) const;
    8184
     85    int writeCommonData(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags);
     86
    8287    int lock(void);
    8388    int unlock(void);
     
    8691
    8792    int threadNotify(void);
     93
     94protected:
     95
     96    int audioInit(const settings::RecordingScreenSettings &screenSettings);
     97
     98    static DECLCALLBACK(int) audioCodecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser);
    8899
    89100protected:
     
    107118    Console                     *pConsole;
    108119    /** Used recording configuration. */
    109     settings::RecordingSettings  Settings;
     120    settings::RecordingSettings  m_Settings;
    110121    /** The current state. */
    111122    RECORDINGSTS                 enmState;
     
    116127    /** Shutdown indicator. */
    117128    bool                         fShutdown;
    118     /** Worker thread. */
     129    /** Encoding worker thread. */
    119130    RTTHREAD                     Thread;
    120131    /** Vector of current recording streams.
     
    125136    /** Timestamp (in ms) of when recording has been started. */
    126137    uint64_t                     tsStartMs;
     138#ifdef VBOX_WITH_AUDIO_RECORDING
     139    /** Audio codec to use.
     140     *
     141     *  We multiplex audio data from this recording context to all streams,
     142     *  to avoid encoding the same audio data for each stream. We ASSUME that
     143     *  all audio data of a VM will be the same for each stream at a given
     144     *  point in time. */
     145    RECORDINGCODEC               CodecAudio;
     146#endif /* VBOX_WITH_AUDIO_RECORDING */
    127147    /** Block map of common blocks which need to get multiplexed
    128148     *  to all recording streams. This common block maps should help
  • trunk/src/VBox/Main/include/RecordingInternals.h

    r96178 r96229  
    122122     * @param   pCodec              Codec instance to use.
    123123     * @param   pFrame              Pointer to frame data to encode.
    124      * @param   pvDst               Where to store the encoded data on success.
    125      * @param   cbDst               Size (in bytes) of \a pvDst.
    126124     * @param   pcEncoded           Where to return the number of encoded blocks in \a pvDst on success. Optional.
    127125     * @param   pcbEncoded          Where to return the number of encoded bytes in \a pvDst on success. Optional.
    128126     */
    129     DECLCALLBACKMEMBER(int, pfnEncode,       (PRECORDINGCODEC pCodec, const PRECORDINGFRAME pFrame, void *pvDst, size_t cbDst, size_t *pcEncoded, size_t *pcbEncoded));
     127    DECLCALLBACKMEMBER(int, pfnEncode,       (PRECORDINGCODEC pCodec, const PRECORDINGFRAME pFrame, size_t *pcEncoded, size_t *pcbEncoded));
    130128
    131129    /**
     
    138136} RECORDINGCODECOPS, *PRECORDINGCODECOPS;
    139137
     138/** No encoding flags set. */
     139#define RECORDINGCODEC_ENC_F_NONE               UINT32_C(0)
     140/** Data block is a key block. */
     141#define RECORDINGCODEC_ENC_F_BLOCK_IS_KEY       RT_BIT_32(0)
     142/** Data block is invisible. */
     143#define RECORDINGCODEC_ENC_F_BLOCK_IS_INVISIBLE RT_BIT_32(1)
     144/** Encoding flags valid mask. */
     145#define RECORDINGCODEC_ENC_F_VALID_MASK         0x1
     146
    140147/**
    141148 * Structure for keeping a codec callback table.
     
    143150typedef struct RECORDINGCODECCALLBACKS
    144151{
    145     DECLCALLBACKMEMBER(int, pfnWriteData, (PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, void *pvUser));
     152    /**
     153     * Callback for notifying that encoded data has been written.
     154     *
     155     * @returns VBox status code.
     156     * @param   pCodec          Pointer to codec instance which has written the data.
     157     * @param   pvData          Pointer to written data (encoded).
     158     * @param   cbData          Size (in bytes) of \a pvData.
     159     * @param   msAbsPTS        Absolute PTS (in ms) of the written data.
     160     * @param   uFlags          Encoding flags of type RECORDINGCODEC_ENC_F_XXX.
     161     * @param   pvUser          User-supplied pointer.
     162     */
     163    DECLCALLBACKMEMBER(int, pfnWriteData, (PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser));
    146164    /** User-supplied data pointer. */
    147     void                       *pvUser;
     165    void                   *pvUser;
    148166} RECORDINGCODECCALLBACKS, *PRECORDINGCODECCALLBACKS;
    149167
     
    186204     *  Set to 0 to use a variable bit rate (VBR) (if available, otherwise fall back to CBR). */
    187205    uint32_t                    uBitrate;
    188     /** Time (in ms) an (encoded) frame takes.
     206    /** Time (in ms) the encoder expects us to send data to encode.
    189207     *
    190208     *  For Opus, valid frame sizes are:
     
    196214     *  40           1920
    197215     *  60           2880
     216     *
     217     *  For Vorbis, valid frame sizes are powers of two from 64 to 8192 bytes.
    198218     */
    199219    uint32_t                    msFrame;
    200     /** The frame size in bytes (based on msFrame). */
     220    /** The frame size in bytes (based on \a msFrame). */
    201221    uint32_t                    cbFrame;
    202     /** The frame size in samples per frame (based on msFrame). */
     222    /** The frame size in samples per frame (based on \a msFrame). */
    203223    uint32_t                    csFrame;
    204224} RECORDINGCODECPARMS, *PRECORDINGCODECPARMS;
     
    258278
    259279/**
     280 * Structure for keeping a codec's internal state.
     281 */
     282typedef struct RECORDINGCODECSTATE
     283{
     284    /** Timestamp (in ms, absolute) of the last frame was encoded. */
     285    uint64_t            tsLastWrittenMs;
     286    /** Number of encoding errors. */
     287    uint64_t            cEncErrors;
     288} RECORDINGCODECSTATE;
     289/** Pointer to an internal encoder state. */
     290typedef RECORDINGCODECSTATE *PRECORDINGCODECSTATE;
     291
     292/**
    260293 * Structure for keeping codec-specific data.
    261294 */
     
    268301    /** Generic codec parameters. */
    269302    RECORDINGCODECPARMS         Parms;
     303    /** Generic codec parameters. */
     304    RECORDINGCODECSTATE         State;
    270305
    271306#ifdef VBOX_WITH_LIBVPX
     
    288323#endif /* VBOX_WITH_AUDIO_RECORDING */
    289324
    290     /** Timestamp (in ms) of the last frame was encoded. */
    291     uint64_t            uLastTimeStampMs;
    292     /** Number of encoding errors. */
    293     uint64_t            cEncErrors;
     325    /** Internal scratch buffer for en-/decoding steps. */
     326    void               *pvScratch;
     327    /** Size (in bytes) of \a pvScratch. */
     328    uint32_t            cbScratch;
    294329
    295330#ifdef VBOX_WITH_STATISTICS /** @todo Register these values with STAM. */
     
    300335        /** Total time (in ms) of already encoded audio data. */
    301336        uint64_t        msEncTotal;
    302     } Stats;
     337    } STAM;
    303338#endif
    304339} RECORDINGCODEC, *PRECORDINGCODEC;
     
    395430        : enmType(RECORDINGBLOCKTYPE_UNKNOWN)
    396431        , cRefs(0)
     432        , uFlags(RECORDINGCODEC_ENC_F_NONE)
    397433        , pvData(NULL)
    398434        , cbData(0) { }
     
    434470    /** Number of references held of this block. */
    435471    uint16_t           cRefs;
     472    /** Block flags of type RECORDINGCODEC_ENC_F_XXX. */
     473    uint64_t           uFlags;
    436474    /** The (absolute) timestamp (in ms, PTS) of this block. */
    437475    uint64_t           msTimestamp;
     
    449487int recordingCodecInit(const PRECORDINGCODEC pCodec, const PRECORDINGCODECCALLBACKS pCallbacks, const settings::RecordingScreenSettings &Settings);
    450488int recordingCodecDestroy(PRECORDINGCODEC pCodec);
    451 int recordingCodecEncode(PRECORDINGCODEC pCodec, const PRECORDINGFRAME pFrame, void *pvDst, size_t cbDst, size_t *pcEncoded, size_t *pcbEncoded);
     489int recordingCodecEncode(PRECORDINGCODEC pCodec, const PRECORDINGFRAME pFrame, size_t *pcEncoded, size_t *pcbEncoded);
    452490int recordingCodecFinalize(PRECORDINGCODEC pCodec);
    453491#endif /* !MAIN_INCLUDED_RecordingInternals_h */
  • trunk/src/VBox/Main/include/RecordingStream.h

    r96179 r96229  
    126126    uint16_t GetID(void) const { return this->uScreenID; };
    127127#ifdef VBOX_WITH_AUDIO_RECORDING
    128     PRECORDINGCODEC GetAudioCodec(void) { return &this->CodecAudio; };
     128    PRECORDINGCODEC GetAudioCodec(void) { return this->pCodecAudio; };
    129129#endif
    130130    PRECORDINGCODEC GetVideoCodec(void) { return &this->CodecVideo; };
     
    132132    bool IsReady(void) const;
    133133
     134public:
     135
     136    static DECLCALLBACK(int) codecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser);
     137
    134138protected:
    135139
    136     static DECLCALLBACK(int) codecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, void *pvUser);
    137 
    138 protected:
    139 
    140     int open(const settings::RecordingScreenSettings &Settings);
     140    int open(const settings::RecordingScreenSettings &screenSettings);
    141141    int close(void);
    142142
    143     int initInternal(RecordingContext *pCtx, uint32_t uScreen, const settings::RecordingScreenSettings &Settings);
     143    int initInternal(RecordingContext *pCtx, uint32_t uScreen, const settings::RecordingScreenSettings &screenSettings);
    144144    int uninitInternal(void);
    145145
    146     int initVideo(const settings::RecordingScreenSettings &Settings);
     146    int initVideo(const settings::RecordingScreenSettings &screenSettings);
    147147    int unitVideo(void);
    148 
    149     int initAudio(const settings::RecordingScreenSettings &Settings);
    150148
    151149    bool isLimitReachedInternal(uint64_t msTimestamp) const;
    152150    int iterateInternal(uint64_t msTimestamp);
     151
     152    int codecWriteToWebM(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags);
    153153
    154154    void lock(void);
     
    171171
    172172    /** Recording context this stream is associated to. */
    173     RecordingContext       *pCtx;
     173    RecordingContext       *m_pCtx;
    174174    /** The current state. */
    175175    RECORDINGSTREAMSTATE    enmState;
     
    192192    /** Critical section to serialize access. */
    193193    RTCRITSECT          CritSect;
    194     /** Timestamp (in ms) of when recording has been start. */
     194    /** Timestamp (in ms) of when recording has been started. */
    195195    uint64_t            tsStartMs;
    196 
    197     /** Audio codec instance data to use. */
    198     RECORDINGCODEC                    CodecAudio;
     196#ifdef VBOX_WITH_AUDIO_RECORDING
     197    /** Pointer to audio codec instance data to use.
     198     *
     199     *  We multiplex audio data from the recording context to all streams,
     200     *  to avoid encoding the same audio data for each stream. We ASSUME that
     201     *  all audio data of a VM will be the same for each stream at a given
     202     *  point in time.
     203     *
     204     *  Might be NULL if not being used. */
     205    PRECORDINGCODEC     pCodecAudio;
     206#endif /* VBOX_WITH_AUDIO_RECORDING */
    199207    /** Video codec instance data to use. */
    200     RECORDINGCODEC                    CodecVideo;
     208    RECORDINGCODEC      CodecVideo;
    201209    /** Screen settings to use. */
    202     settings::RecordingScreenSettings ScreenSettings;
     210    settings::RecordingScreenSettings
     211                        ScreenSettings;
    203212    /** Common set of recording (data) blocks, needed for
    204213     *  multiplexing to all recording streams. */
    205     RecordingBlockSet                 Blocks;
     214    RecordingBlockSet   Blocks;
    206215};
    207216
  • trunk/src/VBox/Main/include/WebMWriter.h

    r96210 r96229  
    563563    int AddVideoTrack(PRECORDINGCODEC pCodec, uint16_t uWidth, uint16_t uHeight, uint32_t uFPS, uint8_t *puTrack);
    564564
    565     int WriteBlock(uint8_t uTrack, const void *pvData, size_t cbData);
     565    int WriteBlock(uint8_t uTrack, const void *pvData, size_t cbData, WebMTimecodeAbs tcAbsPTSMs, WebMBlockFlags uFlags);
    566566
    567567    const com::Utf8Str& GetFileName(void);
     
    594594    int writeSimpleBlockQueued(WebMTrack *a_pTrack, WebMSimpleBlock *a_pBlock);
    595595
    596 #ifdef VBOX_WITH_LIBVPX
    597     int writeSimpleBlockVP8(WebMTrack *a_pTrack, const vpx_codec_enc_cfg_t *a_pCfg, const vpx_codec_cx_pkt_t *a_pPkt);
    598 #endif
    599 
    600     int writeSimpleBlockAudio(WebMTrack *pTrack, const void *pvData, size_t cbData, WebMTimecodeAbs tcAbsPTSMs);
    601 
    602596    int processQueue(WebMQueue *pQueue, bool fForce);
    603597
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