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

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: Implement general screenshare layer logic and unittests. Created 5 years, 3 months 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<VideoFrameType>* frame_types) override; 40 const std::vector<VideoFrameType>* 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;
60 uint8_t stop_layer = 0;
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 SetSvcRates(); 75 bool SetSvcRates();
60 76
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 */
85 vpx_svc_ref_frame_config GenerateRefsAndFlags(
86 const SuperFrameRefSettings& settings);
87
61 virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt); 88 virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt);
62 89
63 // Callback function for outputting packets per spatial layer. 90 // Callback function for outputting packets per spatial layer.
64 static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt, 91 static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt,
65 void* user_data); 92 void* user_data);
66 93
67 // Determine maximum target for Intra frames 94 // Determine maximum target for Intra frames
68 // 95 //
69 // Input: 96 // Input:
70 // - optimal_buffer_size : Optimal buffer size 97 // - optimal_buffer_size : Optimal buffer size
(...skipping 10 matching lines...) Expand all
81 int cpu_speed_; 108 int cpu_speed_;
82 uint32_t rc_max_intra_target_; 109 uint32_t rc_max_intra_target_;
83 vpx_codec_ctx_t* encoder_; 110 vpx_codec_ctx_t* encoder_;
84 vpx_codec_enc_cfg_t* config_; 111 vpx_codec_enc_cfg_t* config_;
85 vpx_image_t* raw_; 112 vpx_image_t* raw_;
86 SvcInternal_t svc_internal_; 113 SvcInternal_t svc_internal_;
87 const VideoFrame* input_image_; 114 const VideoFrame* input_image_;
88 GofInfoVP9 gof_; // Contains each frame's temporal information for 115 GofInfoVP9 gof_; // Contains each frame's temporal information for
89 // non-flexible mode. 116 // non-flexible mode.
90 uint8_t tl0_pic_idx_; // Only used in non-flexible mode. 117 uint8_t tl0_pic_idx_; // Only used in non-flexible mode.
91 size_t gof_idx_; // Only used in non-flexible mode. 118 size_t frames_since_kf_;
92 uint8_t num_temporal_layers_; 119 uint8_t num_temporal_layers_;
93 uint8_t num_spatial_layers_; 120 uint8_t num_spatial_layers_;
121
122 // Used for flexible mode.
123 bool is_flexible_mode_;
124 int64_t buf_upd_at_frame_[kNumVp9Buffers];
125 int64_t frames_encoded_;
126 uint8_t num_ref_pics_[kMaxVp9NumberOfSpatialLayers];
127 uint16_t p_diff_[kMaxVp9NumberOfSpatialLayers][kMaxVp9RefPics];
128 rtc::scoped_ptr<ScreenshareLayersVP9> spatial_layer_;
94 }; 129 };
95 130
96 131
97 class VP9DecoderImpl : public VP9Decoder { 132 class VP9DecoderImpl : public VP9Decoder {
98 public: 133 public:
99 VP9DecoderImpl(); 134 VP9DecoderImpl();
100 135
101 virtual ~VP9DecoderImpl(); 136 virtual ~VP9DecoderImpl();
102 137
103 int InitDecode(const VideoCodec* inst, int number_of_cores) override; 138 int InitDecode(const VideoCodec* inst, int number_of_cores) override;
(...skipping 17 matching lines...) Expand all
121 Vp9FrameBufferPool frame_buffer_pool_; 156 Vp9FrameBufferPool frame_buffer_pool_;
122 DecodedImageCallback* decode_complete_callback_; 157 DecodedImageCallback* decode_complete_callback_;
123 bool inited_; 158 bool inited_;
124 vpx_codec_ctx_t* decoder_; 159 vpx_codec_ctx_t* decoder_;
125 VideoCodec codec_; 160 VideoCodec codec_;
126 bool key_frame_required_; 161 bool key_frame_required_;
127 }; 162 };
128 } // namespace webrtc 163 } // namespace webrtc
129 164
130 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ 165 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698