VirtualBox

Ignore:
Timestamp:
Jan 13, 2017 1:21:12 PM (8 years ago)
Author:
vboxsync
Message:

VideoRec: Opus encoding header fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/EbmlWriter.cpp

    r65263 r65281  
    11/* $Id$ */
    22/** @file
    3  * EbmlWriter.cpp - EBML writer + WebM container
     3 * EbmlWriter.cpp - EBML writer + WebM container handling.
    44 */
    55
     
    316316    struct OpusPrivData
    317317    {
     318        OpusPrivData(uint32_t a_u32SampleRate, uint8_t a_u8Channels)
     319            : u8Channels(a_u8Channels)
     320            , u32SampleRate(a_u32SampleRate) { }
     321
     322        /** "OpusHead". */
    318323        uint8_t  au8Head[8]      = { 0x4f, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64 };
     324        /** Must set to 1. */
    319325        uint8_t  u8Version       = 1;
    320         uint8_t  c8Channels      = 0;
     326        uint8_t  u8Channels      = 0;
    321327        uint16_t u16PreSkip      = 0;
     328        /** Sample rate *before* encoding to Opus.
     329         *  Note: This rate has nothing to do with the playback rate later! */
    322330        uint32_t u32SampleRate   = 0;
    323331        uint16_t u16Gain         = 0;
     332        /** Must stay 0 -- otherwise a mapping table must be appended
     333         *  right after this header. */
    324334        uint8_t  u8MappingFamily = 0;
    325335    };
     
    385395        , m_offSegClusterStart(0) {}
    386396
    387     int AddAudioTrack(float fSamplingHz, float fOutputHz, uint8_t cChannels, uint8_t cBitDepth)
     397    int AddAudioTrack(uint16_t uHz, uint8_t cChannels, uint8_t cBits)
    388398    {
    389399#ifdef VBOX_WITH_LIBOPUS
     
    395405        m_lstTracks.push_back(TrackAudio);
    396406
     407        if (uHz >= 44100)
     408            uHz = 48000;
     409
    397410        /** @todo Resolve codec type. */
    398         OpusPrivData opusPrivData;
     411        OpusPrivData opusPrivData(uHz, cChannels);
    399412
    400413        m_Ebml.serializeUnsignedInteger(TrackUID, TrackAudio.uID, 4)
     
    402415              .serializeString(CodecID, "A_OPUS")
    403416              .serializeData(CodecPrivate, &opusPrivData, sizeof(opusPrivData))
     417              .serializeUnsignedInteger(CodecDelay, 0)
     418              .serializeUnsignedInteger(SeekPreRoll, 80000000)
    404419              .subStart(Audio)
    405               .serializeFloat(SamplingFrequency, fSamplingHz)
    406               .serializeFloat(OutputSamplingFrequency, fOutputHz)
    407               .serializeUnsignedInteger(Channels, cChannels)
    408               .serializeUnsignedInteger(BitDepth, cBitDepth)
     420                  .serializeFloat(SamplingFrequency,       (float)uHz)
     421                  .serializeUnsignedInteger(Channels,      cChannels)
     422                  .serializeUnsignedInteger(BitDepth,      cBits)
    409423              .subEnd(Audio)
    410424              .subEnd(TrackEntry);
     
    412426        return VINF_SUCCESS;
    413427#else
    414         RT_NOREF(fSamplingHz, fOutputHz, cChannels, cBitDepth);
     428        RT_NOREF(uHz, cChannels, cBits);
    415429        return VERR_NOT_SUPPORTED;
    416430#endif
     
    563577static uint16_t s_uTimecode = 0;
    564578
     579        if (!m_fClusterOpen)
     580        {
     581            m_Ebml.subStart(Cluster)
     582                  .serializeUnsignedInteger(Timecode, 0);
     583            m_fClusterOpen = true;
     584        }
     585
    565586        return writeSimpleBlockInternal(0 /** @todo FIX! */, s_uTimecode++, pvData, cbData, 0 /* Flags */);
    566587    }
     
    759780}
    760781
    761 int WebMWriter::AddAudioTrack(float fSamplingHz, float fOutputHz, uint8_t cChannels, uint8_t cBitDepth)
    762 {
    763     return m_pImpl->AddAudioTrack(fSamplingHz, fOutputHz, cChannels, cBitDepth);
     782int WebMWriter::AddAudioTrack(uint16_t uHz, uint8_t cChannels, uint8_t cBitDepth)
     783{
     784    return m_pImpl->AddAudioTrack(uHz, cChannels, cBitDepth);
    764785}
    765786
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