content/media/encoder/EncodedFrameContainer.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial