Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp9/vp9_impl.h

Issue 1328113004: Work on flexible mode and screen sharing. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Use alt_fb_idx for keyframes, fully initialize structure. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 * 9 *
10 */ 10 */
11 11
12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ 12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ 13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_
14 14
15 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" 15 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
16 #include "webrtc/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h" 16 #include "webrtc/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h"
17 17
18 #include "vpx/svc_context.h" 18 #include "vpx/svc_context.h"
19 #include "vpx/vpx_decoder.h" 19 #include "vpx/vpx_decoder.h"
20 #include "vpx/vpx_encoder.h" 20 #include "vpx/vpx_encoder.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 23
24 class ScreenshareLayersVP9;
25
24 class VP9EncoderImpl : public VP9Encoder { 26 class VP9EncoderImpl : public VP9Encoder {
25 public: 27 public:
26 VP9EncoderImpl(); 28 VP9EncoderImpl();
27 29
28 virtual ~VP9EncoderImpl(); 30 virtual ~VP9EncoderImpl();
29 31
30 int Release() override; 32 int Release() override;
31 33
32 int InitEncode(const VideoCodec* codec_settings, 34 int InitEncode(const VideoCodec* codec_settings,
33 int number_of_cores, 35 int number_of_cores,
34 size_t max_payload_size) override; 36 size_t max_payload_size) override;
35 37
36 int Encode(const VideoFrame& input_image, 38 int Encode(const VideoFrame& input_image,
37 const CodecSpecificInfo* codec_specific_info, 39 const CodecSpecificInfo* codec_specific_info,
38 const std::vector<FrameType>* frame_types) override; 40 const std::vector<FrameType>* frame_types) override;
39 41
40 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; 42 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
41 43
42 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; 44 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
43 45
44 int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override; 46 int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override;
45 47
46 void OnDroppedFrame() override {} 48 void OnDroppedFrame() override {}
47 49
50 struct LayerFrameRefSettings {
51 int8_t upd_buf = -1; // -1 - no update, 0..7 - update buffer 0..7
52 int8_t ref_buf1 = -1; // -1 - no reference, 0..7 - reference buffer 0..7
53 int8_t ref_buf2 = -1; // -1 - no reference, 0..7 - reference buffer 0..7
54 int8_t ref_buf3 = -1; // -1 - no reference, 0..7 - reference buffer 0..7
55 };
56
57 struct SuperFrameRefSettings {
58 LayerFrameRefSettings layer[kMaxVp9NumberOfSpatialLayers];
59 uint8_t start_layer = 0; // the first spatial layer to be encoded.
60 uint8_t stop_layer = 0; // the last spatial layer to be encoded.
61 bool is_keyframe = false;
62 };
63
48 private: 64 private:
49 // Determine number of encoder threads to use. 65 // Determine number of encoder threads to use.
50 int NumberOfThreads(int width, int height, int number_of_cores); 66 int NumberOfThreads(int width, int height, int number_of_cores);
51 67
52 // Call encoder initialize function and set control settings. 68 // Call encoder initialize function and set control settings.
53 int InitAndSetControlSettings(const VideoCodec* inst); 69 int InitAndSetControlSettings(const VideoCodec* inst);
54 70
55 void PopulateCodecSpecific(CodecSpecificInfo* codec_specific, 71 void PopulateCodecSpecific(CodecSpecificInfo* codec_specific,
56 const vpx_codec_cx_pkt& pkt, 72 const vpx_codec_cx_pkt& pkt,
57 uint32_t timestamp); 73 uint32_t timestamp);
58 74
59 bool ExplicitlyConfiguredSpatialLayers() const; 75 bool ExplicitlyConfiguredSpatialLayers() const;
60 bool SetSvcRates(); 76 bool SetSvcRates();
61 77
78 // Used for flexible mode to set the flags and buffer references used
79 // by the encoder. Also calculates the references used by the RTP
80 // packetizer.
81 //
82 // Has to be called for every frame (keyframes included) to update the
83 // state used to calculate references.
84 vpx_svc_ref_frame_config GenerateRefsAndFlags(
85 const SuperFrameRefSettings& settings);
86
62 virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt); 87 virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt);
63 88
64 // Callback function for outputting packets per spatial layer. 89 // Callback function for outputting packets per spatial layer.
65 static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt, 90 static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt,
66 void* user_data); 91 void* user_data);
67 92
68 // Determine maximum target for Intra frames 93 // Determine maximum target for Intra frames
69 // 94 //
70 // Input: 95 // Input:
71 // - optimal_buffer_size : Optimal buffer size 96 // - optimal_buffer_size : Optimal buffer size
(...skipping 10 matching lines...) Expand all
82 int cpu_speed_; 107 int cpu_speed_;
83 uint32_t rc_max_intra_target_; 108 uint32_t rc_max_intra_target_;
84 vpx_codec_ctx_t* encoder_; 109 vpx_codec_ctx_t* encoder_;
85 vpx_codec_enc_cfg_t* config_; 110 vpx_codec_enc_cfg_t* config_;
86 vpx_image_t* raw_; 111 vpx_image_t* raw_;
87 SvcInternal_t svc_internal_; 112 SvcInternal_t svc_internal_;
88 const VideoFrame* input_image_; 113 const VideoFrame* input_image_;
89 GofInfoVP9 gof_; // Contains each frame's temporal information for 114 GofInfoVP9 gof_; // Contains each frame's temporal information for
90 // non-flexible mode. 115 // non-flexible mode.
91 uint8_t tl0_pic_idx_; // Only used in non-flexible mode. 116 uint8_t tl0_pic_idx_; // Only used in non-flexible mode.
92 size_t gof_idx_; // Only used in non-flexible mode. 117 size_t frames_since_kf_;
93 uint8_t num_temporal_layers_; 118 uint8_t num_temporal_layers_;
94 uint8_t num_spatial_layers_; 119 uint8_t num_spatial_layers_;
120
121 // Used for flexible mode.
122 bool is_flexible_mode_;
123 int64_t buffer_updated_at_frame_[kNumVp9Buffers];
124 int64_t frames_encoded_;
125 uint8_t num_ref_pics_[kMaxVp9NumberOfSpatialLayers];
126 uint16_t p_diff_[kMaxVp9NumberOfSpatialLayers][kMaxVp9RefPics];
127 rtc::scoped_ptr<ScreenshareLayersVP9> spatial_layer_;
95 }; 128 };
96 129
97 130
98 class VP9DecoderImpl : public VP9Decoder { 131 class VP9DecoderImpl : public VP9Decoder {
99 public: 132 public:
100 VP9DecoderImpl(); 133 VP9DecoderImpl();
101 134
102 virtual ~VP9DecoderImpl(); 135 virtual ~VP9DecoderImpl();
103 136
104 int InitDecode(const VideoCodec* inst, int number_of_cores) override; 137 int InitDecode(const VideoCodec* inst, int number_of_cores) override;
(...skipping 17 matching lines...) Expand all
122 Vp9FrameBufferPool frame_buffer_pool_; 155 Vp9FrameBufferPool frame_buffer_pool_;
123 DecodedImageCallback* decode_complete_callback_; 156 DecodedImageCallback* decode_complete_callback_;
124 bool inited_; 157 bool inited_;
125 vpx_codec_ctx_t* decoder_; 158 vpx_codec_ctx_t* decoder_;
126 VideoCodec codec_; 159 VideoCodec codec_;
127 bool key_frame_required_; 160 bool key_frame_required_;
128 }; 161 };
129 } // namespace webrtc 162 } // namespace webrtc
130 163
131 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ 164 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698