OggWriter.h (1758B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef OggWriter_h_ 7 #define OggWriter_h_ 8 9 #include <ogg/ogg.h> 10 11 #include "ContainerWriter.h" 12 #include "OpusTrackEncoder.h" 13 14 namespace mozilla { 15 /** 16 * WriteEncodedTrack inserts raw packets into Ogg stream (ogg_stream_state), and 17 * GetContainerData outputs an ogg_page when enough packets have been written 18 * to the Ogg stream. 19 * For more details, please reference: 20 * http://www.xiph.org/ogg/doc/libogg/encoding.html 21 */ 22 class OggWriter : public ContainerWriter { 23 public: 24 OggWriter(); 25 ~OggWriter(); 26 27 // Write frames into the ogg container. aFlags should be set to END_OF_STREAM 28 // for the final set of frames. 29 nsresult WriteEncodedTrack(const nsTArray<RefPtr<EncodedFrame>>& aData, 30 uint32_t aFlags = 0) override; 31 32 nsresult GetContainerData(nsTArray<nsTArray<uint8_t>>* aOutputBufs, 33 uint32_t aFlags = 0) override; 34 35 // Check metadata type integrity and reject unacceptable track encoder. 36 nsresult SetMetadata( 37 const nsTArray<RefPtr<TrackMetadataBase>>& aMetadata) override; 38 39 private: 40 nsresult Init(); 41 42 nsresult WriteEncodedData(const nsTArray<uint8_t>& aBuffer, int aDuration, 43 uint32_t aFlags = 0); 44 45 void ProduceOggPage(nsTArray<nsTArray<uint8_t>>* aOutputBufs); 46 // Store the Medatata from track encoder 47 RefPtr<OpusMetadata> mMetadata; 48 49 ogg_stream_state mOggStreamState; 50 ogg_page mOggPage; 51 ogg_packet mPacket; 52 }; 53 54 } // namespace mozilla 55 56 #endif