michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ContainerWriter_h_ michael@0: #define ContainerWriter_h_ michael@0: michael@0: #include "nsTArray.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "EncodedFrameContainer.h" michael@0: #include "TrackMetadataBase.h" michael@0: michael@0: namespace mozilla { michael@0: /** michael@0: * ContainerWriter packs encoded track data into a specific media container. michael@0: */ michael@0: class ContainerWriter { michael@0: public: michael@0: ContainerWriter() michael@0: : mInitialized(false) michael@0: , mIsWritingComplete(false) michael@0: {} michael@0: virtual ~ContainerWriter() {} michael@0: // Mapping to DOMLocalMediaStream::TrackTypeHints michael@0: enum { michael@0: CREATE_AUDIO_TRACK = 1 << 0, michael@0: CREATE_VIDEO_TRACK = 1 << 1, michael@0: }; michael@0: enum { michael@0: END_OF_STREAM = 1 << 0 michael@0: }; michael@0: michael@0: /** michael@0: * Writes encoded track data from aBuffer to a packet, and insert this packet michael@0: * into the internal stream of container writer. aDuration is the playback michael@0: * duration of this packet in number of samples. aFlags is true with michael@0: * END_OF_STREAM if this is the last packet of track. michael@0: * Currently, WriteEncodedTrack doesn't support multiple tracks. michael@0: */ michael@0: virtual nsresult WriteEncodedTrack(const EncodedFrameContainer& aData, michael@0: uint32_t aFlags = 0) = 0; michael@0: michael@0: /** michael@0: * Set the meta data pointer into muxer michael@0: * This function will check the integrity of aMetadata. michael@0: * If the meta data isn't well format, this function will return NS_ERROR_FAILURE to caller, michael@0: * else save the pointer to mMetadata and return NS_OK. michael@0: */ michael@0: virtual nsresult SetMetadata(TrackMetadataBase* aMetadata) = 0; michael@0: michael@0: /** michael@0: * Indicate if the writer has finished to output data michael@0: */ michael@0: virtual bool IsWritingComplete() { return mIsWritingComplete; } michael@0: michael@0: enum { michael@0: FLUSH_NEEDED = 1 << 0, michael@0: GET_HEADER = 1 << 1 michael@0: }; michael@0: michael@0: /** michael@0: * Copies the final container data to a buffer if it has accumulated enough michael@0: * packets from WriteEncodedTrack. This buffer of data is appended to michael@0: * aOutputBufs, and existing elements of aOutputBufs should not be modified. michael@0: * aFlags is true with FLUSH_NEEDED will force OggWriter to flush an ogg page michael@0: * even it is not full, and copy these container data to a buffer for michael@0: * aOutputBufs to append. michael@0: */ michael@0: virtual nsresult GetContainerData(nsTArray >* aOutputBufs, michael@0: uint32_t aFlags = 0) = 0; michael@0: protected: michael@0: bool mInitialized; michael@0: bool mIsWritingComplete; michael@0: }; michael@0: } michael@0: #endif