|
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 ContainerWriter_h_ |
|
7 #define ContainerWriter_h_ |
|
8 |
|
9 #include "nsTArray.h" |
|
10 #include "nsAutoPtr.h" |
|
11 #include "EncodedFrameContainer.h" |
|
12 #include "TrackMetadataBase.h" |
|
13 |
|
14 namespace mozilla { |
|
15 /** |
|
16 * ContainerWriter packs encoded track data into a specific media container. |
|
17 */ |
|
18 class ContainerWriter { |
|
19 public: |
|
20 ContainerWriter() |
|
21 : mInitialized(false) |
|
22 , mIsWritingComplete(false) |
|
23 {} |
|
24 virtual ~ContainerWriter() {} |
|
25 // Mapping to DOMLocalMediaStream::TrackTypeHints |
|
26 enum { |
|
27 CREATE_AUDIO_TRACK = 1 << 0, |
|
28 CREATE_VIDEO_TRACK = 1 << 1, |
|
29 }; |
|
30 enum { |
|
31 END_OF_STREAM = 1 << 0 |
|
32 }; |
|
33 |
|
34 /** |
|
35 * Writes encoded track data from aBuffer to a packet, and insert this packet |
|
36 * into the internal stream of container writer. aDuration is the playback |
|
37 * duration of this packet in number of samples. aFlags is true with |
|
38 * END_OF_STREAM if this is the last packet of track. |
|
39 * Currently, WriteEncodedTrack doesn't support multiple tracks. |
|
40 */ |
|
41 virtual nsresult WriteEncodedTrack(const EncodedFrameContainer& aData, |
|
42 uint32_t aFlags = 0) = 0; |
|
43 |
|
44 /** |
|
45 * Set the meta data pointer into muxer |
|
46 * This function will check the integrity of aMetadata. |
|
47 * If the meta data isn't well format, this function will return NS_ERROR_FAILURE to caller, |
|
48 * else save the pointer to mMetadata and return NS_OK. |
|
49 */ |
|
50 virtual nsresult SetMetadata(TrackMetadataBase* aMetadata) = 0; |
|
51 |
|
52 /** |
|
53 * Indicate if the writer has finished to output data |
|
54 */ |
|
55 virtual bool IsWritingComplete() { return mIsWritingComplete; } |
|
56 |
|
57 enum { |
|
58 FLUSH_NEEDED = 1 << 0, |
|
59 GET_HEADER = 1 << 1 |
|
60 }; |
|
61 |
|
62 /** |
|
63 * Copies the final container data to a buffer if it has accumulated enough |
|
64 * packets from WriteEncodedTrack. This buffer of data is appended to |
|
65 * aOutputBufs, and existing elements of aOutputBufs should not be modified. |
|
66 * aFlags is true with FLUSH_NEEDED will force OggWriter to flush an ogg page |
|
67 * even it is not full, and copy these container data to a buffer for |
|
68 * aOutputBufs to append. |
|
69 */ |
|
70 virtual nsresult GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs, |
|
71 uint32_t aFlags = 0) = 0; |
|
72 protected: |
|
73 bool mInitialized; |
|
74 bool mIsWritingComplete; |
|
75 }; |
|
76 } |
|
77 #endif |