content/media/encoder/VP8TrackEncoder.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 VP8TrackEncoder_h_
michael@0 7 #define VP8TrackEncoder_h_
michael@0 8
michael@0 9 #include "TrackEncoder.h"
michael@0 10 #include "vpx/vpx_codec.h"
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13
michael@0 14 typedef struct vpx_codec_ctx vpx_codec_ctx_t;
michael@0 15 typedef struct vpx_codec_enc_cfg vpx_codec_enc_cfg_t;
michael@0 16 typedef struct vpx_image vpx_image_t;
michael@0 17
michael@0 18 /**
michael@0 19 * VP8TrackEncoder implements VideoTrackEncoder by using libvpx library.
michael@0 20 * We implement a realtime and fixed FPS encoder. In order to achieve that,
michael@0 21 * there is a pick target frame and drop frame encoding policy implemented in
michael@0 22 * GetEncodedTrack.
michael@0 23 */
michael@0 24 class VP8TrackEncoder : public VideoTrackEncoder
michael@0 25 {
michael@0 26 enum EncodeOperation {
michael@0 27 ENCODE_NORMAL_FRAME, // VP8 track encoder works normally.
michael@0 28 ENCODE_I_FRAME, // The next frame will be encoded as I-Frame.
michael@0 29 SKIP_FRAME, // Skip the next frame.
michael@0 30 };
michael@0 31 public:
michael@0 32 VP8TrackEncoder();
michael@0 33 virtual ~VP8TrackEncoder();
michael@0 34
michael@0 35 already_AddRefed<TrackMetadataBase> GetMetadata() MOZ_FINAL MOZ_OVERRIDE;
michael@0 36
michael@0 37 nsresult GetEncodedTrack(EncodedFrameContainer& aData) MOZ_FINAL MOZ_OVERRIDE;
michael@0 38
michael@0 39 protected:
michael@0 40 nsresult Init(int32_t aWidth, int32_t aHeight,
michael@0 41 int32_t aDisplayWidth, int32_t aDisplayHeight,
michael@0 42 TrackRate aTrackRate) MOZ_FINAL MOZ_OVERRIDE;
michael@0 43
michael@0 44 private:
michael@0 45 // Calculate the target frame's encoded duration.
michael@0 46 TrackTicks CalculateEncodedDuration(TrackTicks aDurationCopied);
michael@0 47
michael@0 48 // Calculate the mRemainingTicks for next target frame.
michael@0 49 TrackTicks CalculateRemainingTicks(TrackTicks aDurationCopied,
michael@0 50 TrackTicks aEncodedDuration);
michael@0 51
michael@0 52 // Get the EncodeOperation for next target frame.
michael@0 53 EncodeOperation GetNextEncodeOperation(TimeDuration aTimeElapsed,
michael@0 54 TrackTicks aProcessedDuration);
michael@0 55
michael@0 56 // Get the encoded data from encoder to aData.
michael@0 57 nsresult GetEncodedPartitions(EncodedFrameContainer& aData);
michael@0 58
michael@0 59 // Prepare the input data to the mVPXImageWrapper for encoding.
michael@0 60 nsresult PrepareRawFrame(VideoChunk &aChunk);
michael@0 61
michael@0 62 // Prepare the muted frame data to the mVPXImageWrapper for encoding.
michael@0 63 void PrepareMutedFrame();
michael@0 64
michael@0 65 // Output frame rate.
michael@0 66 uint32_t mEncodedFrameRate;
michael@0 67 // Duration for the output frame, reciprocal to mEncodedFrameRate.
michael@0 68 TrackTicks mEncodedFrameDuration;
michael@0 69 // Encoded timestamp.
michael@0 70 TrackTicks mEncodedTimestamp;
michael@0 71 // Duration to the next encode frame.
michael@0 72 TrackTicks mRemainingTicks;
michael@0 73
michael@0 74 // Muted frame, we only create it once.
michael@0 75 nsTArray<uint8_t> mMuteFrame;
michael@0 76
michael@0 77 // I420 frame, convert the 4:4:4, 4:2:2 to I420.
michael@0 78 nsTArray<uint8_t> mI420Frame;
michael@0 79
michael@0 80 /**
michael@0 81 * A local segment queue which takes the raw data out from mRawSegment in the
michael@0 82 * call of GetEncodedTrack(). Since we implement the fixed FPS encoding
michael@0 83 * policy, it needs to be global in order to store the leftover segments
michael@0 84 * taken from mRawSegment.
michael@0 85 */
michael@0 86 VideoSegment mSourceSegment;
michael@0 87
michael@0 88 // VP8 relative members.
michael@0 89 // Codec context structure.
michael@0 90 nsAutoPtr<vpx_codec_ctx_t> mVPXContext;
michael@0 91 // Image Descriptor.
michael@0 92 nsAutoPtr<vpx_image_t> mVPXImageWrapper;
michael@0 93 };
michael@0 94
michael@0 95 } // namespace mozilla
michael@0 96
michael@0 97 #endif

mercurial