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 EncodedFrameContainer_H_ michael@0: #define EncodedFrameContainer_H_ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsTArray.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class EncodedFrame; michael@0: michael@0: /* michael@0: * This container is used to carry video or audio encoded data from encoder to muxer. michael@0: * The media data object is created by encoder and recycle by the destructor. michael@0: * Only allow to store audio or video encoded data in EncodedData. michael@0: */ michael@0: class EncodedFrameContainer michael@0: { michael@0: public: michael@0: // Append encoded frame data michael@0: void AppendEncodedFrame(EncodedFrame* aEncodedFrame) michael@0: { michael@0: mEncodedFrames.AppendElement(aEncodedFrame); michael@0: } michael@0: // Retrieve all of the encoded frames michael@0: const nsTArray >& GetEncodedFrames() const michael@0: { michael@0: return mEncodedFrames; michael@0: } michael@0: private: michael@0: // This container is used to store the video or audio encoded packets. michael@0: // Muxer should check mFrameType and get the encoded data type from mEncodedFrames. michael@0: nsTArray > mEncodedFrames; michael@0: }; michael@0: michael@0: // Represent one encoded frame michael@0: class EncodedFrame MOZ_FINAL michael@0: { michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodedFrame) michael@0: public: michael@0: EncodedFrame() : michael@0: mTimeStamp(0), michael@0: mDuration(0), michael@0: mFrameType(UNKNOWN) michael@0: {} michael@0: enum FrameType { michael@0: VP8_I_FRAME, // VP8 intraframe michael@0: VP8_P_FRAME, // VP8 predicted frame michael@0: OPUS_AUDIO_FRAME, // Opus audio frame michael@0: VORBIS_AUDIO_FRAME, michael@0: AVC_I_FRAME, michael@0: AVC_P_FRAME, michael@0: AVC_B_FRAME, michael@0: AVC_CSD, // AVC codec specific data michael@0: AAC_AUDIO_FRAME, michael@0: AAC_CSD, // AAC codec specific data michael@0: AMR_AUDIO_CSD, michael@0: AMR_AUDIO_FRAME, michael@0: UNKNOWN // FrameType not set michael@0: }; michael@0: nsresult SwapInFrameData(nsTArray& aData) michael@0: { michael@0: mFrameData.SwapElements(aData); michael@0: return NS_OK; michael@0: } michael@0: nsresult SwapOutFrameData(nsTArray& aData) michael@0: { michael@0: if (mFrameType != UNKNOWN) { michael@0: // Reset this frame type to UNKNOWN once the data is swapped out. michael@0: mFrameData.SwapElements(aData); michael@0: mFrameType = UNKNOWN; michael@0: return NS_OK; michael@0: } michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: const nsTArray& GetFrameData() const michael@0: { michael@0: return mFrameData; michael@0: } michael@0: uint64_t GetTimeStamp() const { return mTimeStamp; } michael@0: void SetTimeStamp(uint64_t aTimeStamp) { mTimeStamp = aTimeStamp; } michael@0: michael@0: uint64_t GetDuration() const { return mDuration; } michael@0: void SetDuration(uint64_t aDuration) { mDuration = aDuration; } michael@0: michael@0: FrameType GetFrameType() const { return mFrameType; } michael@0: void SetFrameType(FrameType aFrameType) { mFrameType = aFrameType; } michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: ~EncodedFrame() michael@0: { michael@0: } michael@0: michael@0: // Encoded data michael@0: nsTArray mFrameData; michael@0: uint64_t mTimeStamp; michael@0: // The playback duration of this packet in number of samples michael@0: uint64_t mDuration; michael@0: // Represent what is in the FrameData michael@0: FrameType mFrameType; michael@0: }; michael@0: michael@0: } michael@0: #endif