EncodedFrame.h (2206B)
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 EncodedFrame_h_ 7 #define EncodedFrame_h_ 8 9 #include "TimeUnits.h" 10 #include "VideoUtils.h" 11 #include "mozilla/media/MediaUtils.h" 12 #include "nsISupportsImpl.h" 13 14 namespace mozilla { 15 16 // Represent an encoded frame emitted by an encoder 17 class EncodedFrame final { 18 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodedFrame) 19 public: 20 enum FrameType { 21 VP8_I_FRAME, // VP8 intraframe 22 VP8_P_FRAME, // VP8 predicted frame 23 OPUS_AUDIO_FRAME, // Opus audio frame 24 UNKNOWN // FrameType not set 25 }; 26 using ConstFrameData = const media::Refcountable<nsTArray<uint8_t>>; 27 using FrameData = media::Refcountable<nsTArray<uint8_t>>; 28 EncodedFrame(const media::TimeUnit& aTime, uint64_t aDuration, 29 uint64_t aDurationBase, FrameType aFrameType, 30 RefPtr<ConstFrameData> aData) 31 : mTime(aTime), 32 mDuration(aDuration), 33 mDurationBase(aDurationBase), 34 mFrameType(aFrameType), 35 mFrameData(std::move(aData)) { 36 MOZ_ASSERT(mFrameData); 37 MOZ_ASSERT_IF(mFrameType == VP8_I_FRAME, mDurationBase == PR_USEC_PER_SEC); 38 MOZ_ASSERT_IF(mFrameType == VP8_P_FRAME, mDurationBase == PR_USEC_PER_SEC); 39 MOZ_ASSERT_IF(mFrameType == OPUS_AUDIO_FRAME, mDurationBase == 48000); 40 } 41 // Timestamp in microseconds 42 const media::TimeUnit mTime; 43 // The playback duration of this packet in mDurationBase. 44 const uint64_t mDuration; 45 // The time base of mDuration. 46 const uint64_t mDurationBase; 47 // Represent what is in the FrameData 48 const FrameType mFrameType; 49 // Encoded data 50 const RefPtr<ConstFrameData> mFrameData; 51 52 // The end time of the frame in microseconds. 53 media::TimeUnit GetEndTime() const { 54 return mTime + media::TimeUnit(mDuration, mDurationBase); 55 } 56 57 private: 58 // Private destructor, to discourage deletion outside of Release(): 59 ~EncodedFrame() = default; 60 }; 61 62 } // namespace mozilla 63 64 #endif // EncodedFrame_h_