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