1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/encoder/EncodedFrameContainer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 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 EncodedFrameContainer_H_ 1.10 +#define EncodedFrameContainer_H_ 1.11 + 1.12 +#include "nsAutoPtr.h" 1.13 +#include "nsTArray.h" 1.14 + 1.15 +namespace mozilla { 1.16 + 1.17 +class EncodedFrame; 1.18 + 1.19 +/* 1.20 + * This container is used to carry video or audio encoded data from encoder to muxer. 1.21 + * The media data object is created by encoder and recycle by the destructor. 1.22 + * Only allow to store audio or video encoded data in EncodedData. 1.23 + */ 1.24 +class EncodedFrameContainer 1.25 +{ 1.26 +public: 1.27 + // Append encoded frame data 1.28 + void AppendEncodedFrame(EncodedFrame* aEncodedFrame) 1.29 + { 1.30 + mEncodedFrames.AppendElement(aEncodedFrame); 1.31 + } 1.32 + // Retrieve all of the encoded frames 1.33 + const nsTArray<nsRefPtr<EncodedFrame> >& GetEncodedFrames() const 1.34 + { 1.35 + return mEncodedFrames; 1.36 + } 1.37 +private: 1.38 + // This container is used to store the video or audio encoded packets. 1.39 + // Muxer should check mFrameType and get the encoded data type from mEncodedFrames. 1.40 + nsTArray<nsRefPtr<EncodedFrame> > mEncodedFrames; 1.41 +}; 1.42 + 1.43 +// Represent one encoded frame 1.44 +class EncodedFrame MOZ_FINAL 1.45 +{ 1.46 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodedFrame) 1.47 +public: 1.48 + EncodedFrame() : 1.49 + mTimeStamp(0), 1.50 + mDuration(0), 1.51 + mFrameType(UNKNOWN) 1.52 + {} 1.53 + enum FrameType { 1.54 + VP8_I_FRAME, // VP8 intraframe 1.55 + VP8_P_FRAME, // VP8 predicted frame 1.56 + OPUS_AUDIO_FRAME, // Opus audio frame 1.57 + VORBIS_AUDIO_FRAME, 1.58 + AVC_I_FRAME, 1.59 + AVC_P_FRAME, 1.60 + AVC_B_FRAME, 1.61 + AVC_CSD, // AVC codec specific data 1.62 + AAC_AUDIO_FRAME, 1.63 + AAC_CSD, // AAC codec specific data 1.64 + AMR_AUDIO_CSD, 1.65 + AMR_AUDIO_FRAME, 1.66 + UNKNOWN // FrameType not set 1.67 + }; 1.68 + nsresult SwapInFrameData(nsTArray<uint8_t>& aData) 1.69 + { 1.70 + mFrameData.SwapElements(aData); 1.71 + return NS_OK; 1.72 + } 1.73 + nsresult SwapOutFrameData(nsTArray<uint8_t>& aData) 1.74 + { 1.75 + if (mFrameType != UNKNOWN) { 1.76 + // Reset this frame type to UNKNOWN once the data is swapped out. 1.77 + mFrameData.SwapElements(aData); 1.78 + mFrameType = UNKNOWN; 1.79 + return NS_OK; 1.80 + } 1.81 + return NS_ERROR_FAILURE; 1.82 + } 1.83 + const nsTArray<uint8_t>& GetFrameData() const 1.84 + { 1.85 + return mFrameData; 1.86 + } 1.87 + uint64_t GetTimeStamp() const { return mTimeStamp; } 1.88 + void SetTimeStamp(uint64_t aTimeStamp) { mTimeStamp = aTimeStamp; } 1.89 + 1.90 + uint64_t GetDuration() const { return mDuration; } 1.91 + void SetDuration(uint64_t aDuration) { mDuration = aDuration; } 1.92 + 1.93 + FrameType GetFrameType() const { return mFrameType; } 1.94 + void SetFrameType(FrameType aFrameType) { mFrameType = aFrameType; } 1.95 +private: 1.96 + // Private destructor, to discourage deletion outside of Release(): 1.97 + ~EncodedFrame() 1.98 + { 1.99 + } 1.100 + 1.101 + // Encoded data 1.102 + nsTArray<uint8_t> mFrameData; 1.103 + uint64_t mTimeStamp; 1.104 + // The playback duration of this packet in number of samples 1.105 + uint64_t mDuration; 1.106 + // Represent what is in the FrameData 1.107 + FrameType mFrameType; 1.108 +}; 1.109 + 1.110 +} 1.111 +#endif