Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef ContainerWriter_h_ |
michael@0 | 7 | #define ContainerWriter_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsTArray.h" |
michael@0 | 10 | #include "nsAutoPtr.h" |
michael@0 | 11 | #include "EncodedFrameContainer.h" |
michael@0 | 12 | #include "TrackMetadataBase.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | /** |
michael@0 | 16 | * ContainerWriter packs encoded track data into a specific media container. |
michael@0 | 17 | */ |
michael@0 | 18 | class ContainerWriter { |
michael@0 | 19 | public: |
michael@0 | 20 | ContainerWriter() |
michael@0 | 21 | : mInitialized(false) |
michael@0 | 22 | , mIsWritingComplete(false) |
michael@0 | 23 | {} |
michael@0 | 24 | virtual ~ContainerWriter() {} |
michael@0 | 25 | // Mapping to DOMLocalMediaStream::TrackTypeHints |
michael@0 | 26 | enum { |
michael@0 | 27 | CREATE_AUDIO_TRACK = 1 << 0, |
michael@0 | 28 | CREATE_VIDEO_TRACK = 1 << 1, |
michael@0 | 29 | }; |
michael@0 | 30 | enum { |
michael@0 | 31 | END_OF_STREAM = 1 << 0 |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * Writes encoded track data from aBuffer to a packet, and insert this packet |
michael@0 | 36 | * into the internal stream of container writer. aDuration is the playback |
michael@0 | 37 | * duration of this packet in number of samples. aFlags is true with |
michael@0 | 38 | * END_OF_STREAM if this is the last packet of track. |
michael@0 | 39 | * Currently, WriteEncodedTrack doesn't support multiple tracks. |
michael@0 | 40 | */ |
michael@0 | 41 | virtual nsresult WriteEncodedTrack(const EncodedFrameContainer& aData, |
michael@0 | 42 | uint32_t aFlags = 0) = 0; |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Set the meta data pointer into muxer |
michael@0 | 46 | * This function will check the integrity of aMetadata. |
michael@0 | 47 | * If the meta data isn't well format, this function will return NS_ERROR_FAILURE to caller, |
michael@0 | 48 | * else save the pointer to mMetadata and return NS_OK. |
michael@0 | 49 | */ |
michael@0 | 50 | virtual nsresult SetMetadata(TrackMetadataBase* aMetadata) = 0; |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Indicate if the writer has finished to output data |
michael@0 | 54 | */ |
michael@0 | 55 | virtual bool IsWritingComplete() { return mIsWritingComplete; } |
michael@0 | 56 | |
michael@0 | 57 | enum { |
michael@0 | 58 | FLUSH_NEEDED = 1 << 0, |
michael@0 | 59 | GET_HEADER = 1 << 1 |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * Copies the final container data to a buffer if it has accumulated enough |
michael@0 | 64 | * packets from WriteEncodedTrack. This buffer of data is appended to |
michael@0 | 65 | * aOutputBufs, and existing elements of aOutputBufs should not be modified. |
michael@0 | 66 | * aFlags is true with FLUSH_NEEDED will force OggWriter to flush an ogg page |
michael@0 | 67 | * even it is not full, and copy these container data to a buffer for |
michael@0 | 68 | * aOutputBufs to append. |
michael@0 | 69 | */ |
michael@0 | 70 | virtual nsresult GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs, |
michael@0 | 71 | uint32_t aFlags = 0) = 0; |
michael@0 | 72 | protected: |
michael@0 | 73 | bool mInitialized; |
michael@0 | 74 | bool mIsWritingComplete; |
michael@0 | 75 | }; |
michael@0 | 76 | } |
michael@0 | 77 | #endif |