1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/encoder/ContainerWriter.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef ContainerWriter_h_ 1.10 +#define ContainerWriter_h_ 1.11 + 1.12 +#include "nsTArray.h" 1.13 +#include "nsAutoPtr.h" 1.14 +#include "EncodedFrameContainer.h" 1.15 +#include "TrackMetadataBase.h" 1.16 + 1.17 +namespace mozilla { 1.18 +/** 1.19 + * ContainerWriter packs encoded track data into a specific media container. 1.20 + */ 1.21 +class ContainerWriter { 1.22 +public: 1.23 + ContainerWriter() 1.24 + : mInitialized(false) 1.25 + , mIsWritingComplete(false) 1.26 + {} 1.27 + virtual ~ContainerWriter() {} 1.28 + // Mapping to DOMLocalMediaStream::TrackTypeHints 1.29 + enum { 1.30 + CREATE_AUDIO_TRACK = 1 << 0, 1.31 + CREATE_VIDEO_TRACK = 1 << 1, 1.32 + }; 1.33 + enum { 1.34 + END_OF_STREAM = 1 << 0 1.35 + }; 1.36 + 1.37 + /** 1.38 + * Writes encoded track data from aBuffer to a packet, and insert this packet 1.39 + * into the internal stream of container writer. aDuration is the playback 1.40 + * duration of this packet in number of samples. aFlags is true with 1.41 + * END_OF_STREAM if this is the last packet of track. 1.42 + * Currently, WriteEncodedTrack doesn't support multiple tracks. 1.43 + */ 1.44 + virtual nsresult WriteEncodedTrack(const EncodedFrameContainer& aData, 1.45 + uint32_t aFlags = 0) = 0; 1.46 + 1.47 + /** 1.48 + * Set the meta data pointer into muxer 1.49 + * This function will check the integrity of aMetadata. 1.50 + * If the meta data isn't well format, this function will return NS_ERROR_FAILURE to caller, 1.51 + * else save the pointer to mMetadata and return NS_OK. 1.52 + */ 1.53 + virtual nsresult SetMetadata(TrackMetadataBase* aMetadata) = 0; 1.54 + 1.55 + /** 1.56 + * Indicate if the writer has finished to output data 1.57 + */ 1.58 + virtual bool IsWritingComplete() { return mIsWritingComplete; } 1.59 + 1.60 + enum { 1.61 + FLUSH_NEEDED = 1 << 0, 1.62 + GET_HEADER = 1 << 1 1.63 + }; 1.64 + 1.65 + /** 1.66 + * Copies the final container data to a buffer if it has accumulated enough 1.67 + * packets from WriteEncodedTrack. This buffer of data is appended to 1.68 + * aOutputBufs, and existing elements of aOutputBufs should not be modified. 1.69 + * aFlags is true with FLUSH_NEEDED will force OggWriter to flush an ogg page 1.70 + * even it is not full, and copy these container data to a buffer for 1.71 + * aOutputBufs to append. 1.72 + */ 1.73 + virtual nsresult GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs, 1.74 + uint32_t aFlags = 0) = 0; 1.75 +protected: 1.76 + bool mInitialized; 1.77 + bool mIsWritingComplete; 1.78 +}; 1.79 +} 1.80 +#endif