content/media/encoder/EncodedFrameContainer.h

branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
equal deleted inserted replaced
-1:000000000000 0:2e7d38198f76
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 EncodedFrameContainer_H_
7 #define EncodedFrameContainer_H_
8
9 #include "nsAutoPtr.h"
10 #include "nsTArray.h"
11
12 namespace mozilla {
13
14 class EncodedFrame;
15
16 /*
17 * This container is used to carry video or audio encoded data from encoder to muxer.
18 * The media data object is created by encoder and recycle by the destructor.
19 * Only allow to store audio or video encoded data in EncodedData.
20 */
21 class EncodedFrameContainer
22 {
23 public:
24 // Append encoded frame data
25 void AppendEncodedFrame(EncodedFrame* aEncodedFrame)
26 {
27 mEncodedFrames.AppendElement(aEncodedFrame);
28 }
29 // Retrieve all of the encoded frames
30 const nsTArray<nsRefPtr<EncodedFrame> >& GetEncodedFrames() const
31 {
32 return mEncodedFrames;
33 }
34 private:
35 // This container is used to store the video or audio encoded packets.
36 // Muxer should check mFrameType and get the encoded data type from mEncodedFrames.
37 nsTArray<nsRefPtr<EncodedFrame> > mEncodedFrames;
38 };
39
40 // Represent one encoded frame
41 class EncodedFrame MOZ_FINAL
42 {
43 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodedFrame)
44 public:
45 EncodedFrame() :
46 mTimeStamp(0),
47 mDuration(0),
48 mFrameType(UNKNOWN)
49 {}
50 enum FrameType {
51 VP8_I_FRAME, // VP8 intraframe
52 VP8_P_FRAME, // VP8 predicted frame
53 OPUS_AUDIO_FRAME, // Opus audio frame
54 VORBIS_AUDIO_FRAME,
55 AVC_I_FRAME,
56 AVC_P_FRAME,
57 AVC_B_FRAME,
58 AVC_CSD, // AVC codec specific data
59 AAC_AUDIO_FRAME,
60 AAC_CSD, // AAC codec specific data
61 AMR_AUDIO_CSD,
62 AMR_AUDIO_FRAME,
63 UNKNOWN // FrameType not set
64 };
65 nsresult SwapInFrameData(nsTArray<uint8_t>& aData)
66 {
67 mFrameData.SwapElements(aData);
68 return NS_OK;
69 }
70 nsresult SwapOutFrameData(nsTArray<uint8_t>& aData)
71 {
72 if (mFrameType != UNKNOWN) {
73 // Reset this frame type to UNKNOWN once the data is swapped out.
74 mFrameData.SwapElements(aData);
75 mFrameType = UNKNOWN;
76 return NS_OK;
77 }
78 return NS_ERROR_FAILURE;
79 }
80 const nsTArray<uint8_t>& GetFrameData() const
81 {
82 return mFrameData;
83 }
84 uint64_t GetTimeStamp() const { return mTimeStamp; }
85 void SetTimeStamp(uint64_t aTimeStamp) { mTimeStamp = aTimeStamp; }
86
87 uint64_t GetDuration() const { return mDuration; }
88 void SetDuration(uint64_t aDuration) { mDuration = aDuration; }
89
90 FrameType GetFrameType() const { return mFrameType; }
91 void SetFrameType(FrameType aFrameType) { mFrameType = aFrameType; }
92 private:
93 // Private destructor, to discourage deletion outside of Release():
94 ~EncodedFrame()
95 {
96 }
97
98 // Encoded data
99 nsTArray<uint8_t> mFrameData;
100 uint64_t mTimeStamp;
101 // The playback duration of this packet in number of samples
102 uint64_t mDuration;
103 // Represent what is in the FrameData
104 FrameType mFrameType;
105 };
106
107 }
108 #endif

mercurial