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

Side by Side Diff: webrtc/modules/video_coding/main/source/generic_encoder.cc

Issue 1424843002: Make VCMEncodedFrameCallback const. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; 81 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx;
82 return; 82 return;
83 default: 83 default:
84 return; 84 return;
85 } 85 }
86 } 86 }
87 } // namespace 87 } // namespace
88 88
89 //#define DEBUG_ENCODER_BIT_STREAM 89 //#define DEBUG_ENCODER_BIT_STREAM
90 90
91 VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder, 91 VCMGenericEncoder::VCMGenericEncoder(
92 VideoEncoderRateObserver* rate_observer, 92 VideoEncoder* encoder,
93 bool internalSource) 93 VideoEncoderRateObserver* rate_observer,
94 VCMEncodedFrameCallback* encoded_frame_callback,
95 bool internalSource)
94 : encoder_(encoder), 96 : encoder_(encoder),
95 rate_observer_(rate_observer), 97 rate_observer_(rate_observer),
96 vcm_encoded_frame_callback_(nullptr), 98 vcm_encoded_frame_callback_(encoded_frame_callback),
97 bit_rate_(0), 99 bit_rate_(0),
98 frame_rate_(0), 100 frame_rate_(0),
99 internal_source_(internalSource), 101 internal_source_(internalSource),
100 rotation_(kVideoRotation_0), 102 rotation_(kVideoRotation_0),
101 is_screenshare_(false) { 103 is_screenshare_(false) {}
102 }
103 104
104 VCMGenericEncoder::~VCMGenericEncoder() 105 VCMGenericEncoder::~VCMGenericEncoder()
105 { 106 {
106 } 107 }
107 108
108 int32_t VCMGenericEncoder::Release() 109 int32_t VCMGenericEncoder::Release() {
109 { 110 {
110 { 111 rtc::CritScope lock(&rates_lock_);
111 rtc::CritScope lock(&rates_lock_); 112 bit_rate_ = 0;
112 bit_rate_ = 0; 113 frame_rate_ = 0;
113 frame_rate_ = 0; 114 }
stefan-webrtc 2015/10/29 07:28:06 Do we have to set these in Release(), given that w
pbos-webrtc 2015/10/29 15:51:10 Executive decision says no.
114 vcm_encoded_frame_callback_ = nullptr;
115 }
116 115
117 return encoder_->Release(); 116 return encoder_->Release();
118 } 117 }
119 118
120 int32_t 119 int32_t VCMGenericEncoder::InitEncode(const VideoCodec* settings,
121 VCMGenericEncoder::InitEncode(const VideoCodec* settings, 120 int32_t numberOfCores,
122 int32_t numberOfCores, 121 size_t maxPayloadSize) {
123 size_t maxPayloadSize) 122 {
124 { 123 rtc::CritScope lock(&rates_lock_);
125 { 124 bit_rate_ = settings->startBitrate * 1000;
126 rtc::CritScope lock(&rates_lock_); 125 frame_rate_ = settings->maxFramerate;
127 bit_rate_ = settings->startBitrate * 1000; 126 }
128 frame_rate_ = settings->maxFramerate;
129 }
130 127
131 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing; 128 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing;
132 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { 129 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) {
133 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " 130 LOG(LS_ERROR) << "Failed to initialize the encoder associated with "
134 "payload name: " << settings->plName; 131 "payload name: "
135 return -1; 132 << settings->plName;
136 } 133 return -1;
137 return 0; 134 }
135 encoder_->RegisterEncodeCompleteCallback(vcm_encoded_frame_callback_);
136 return 0;
138 } 137 }
139 138
140 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, 139 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame,
141 const CodecSpecificInfo* codecSpecificInfo, 140 const CodecSpecificInfo* codecSpecificInfo,
142 const std::vector<FrameType>& frameTypes) { 141 const std::vector<FrameType>& frameTypes) {
143 for (FrameType frame_type : frameTypes) 142 for (FrameType frame_type : frameTypes)
144 RTC_DCHECK(frame_type == kVideoFrameKey || frame_type == kVideoFrameDelta); 143 RTC_DCHECK(frame_type == kVideoFrameKey || frame_type == kVideoFrameDelta);
145 144
146 rotation_ = inputFrame.rotation(); 145 rotation_ = inputFrame.rotation();
147 146
148 if (vcm_encoded_frame_callback_) { 147 // Keep track of the current frame rotation and apply to the output of the
149 // Keep track of the current frame rotation and apply to the output of the 148 // encoder. There might not be exact as the encoder could have one frame delay
150 // encoder. There might not be exact as the encoder could have one frame 149 // but it should be close enough.
151 // delay but it should be close enough. 150 vcm_encoded_frame_callback_->SetRotation(rotation_);
stefan-webrtc 2015/10/29 07:28:06 I don't like this... I think we should use a map f
pbos-webrtc 2015/10/29 15:51:10 Agreed, eew. Done.
152 vcm_encoded_frame_callback_->SetRotation(rotation_);
153 }
154 151
155 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); 152 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes);
156 if (is_screenshare_ && 153 if (is_screenshare_ &&
157 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { 154 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) {
158 // Target bitrate exceeded, encoder state has been reset - try again. 155 // Target bitrate exceeded, encoder state has been reset - try again.
159 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); 156 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes);
160 } 157 }
161 158
162 return result; 159 return result;
163 } 160 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 { 214 {
218 return encoder_->SetPeriodicKeyFrames(enable); 215 return encoder_->SetPeriodicKeyFrames(enable);
219 } 216 }
220 217
221 int32_t VCMGenericEncoder::RequestFrame( 218 int32_t VCMGenericEncoder::RequestFrame(
222 const std::vector<FrameType>& frame_types) { 219 const std::vector<FrameType>& frame_types) {
223 VideoFrame image; 220 VideoFrame image;
224 return encoder_->Encode(image, NULL, &frame_types); 221 return encoder_->Encode(image, NULL, &frame_types);
225 } 222 }
226 223
227 int32_t
228 VCMGenericEncoder::RegisterEncodeCallback(VCMEncodedFrameCallback* VCMencodedFra meCallback)
229 {
230 VCMencodedFrameCallback->SetInternalSource(internal_source_);
231 vcm_encoded_frame_callback_ = VCMencodedFrameCallback;
232 return encoder_->RegisterEncodeCompleteCallback(VCMencodedFrameCallback);
233 }
234
235 bool 224 bool
236 VCMGenericEncoder::InternalSource() const 225 VCMGenericEncoder::InternalSource() const
237 { 226 {
238 return internal_source_; 227 return internal_source_;
239 } 228 }
240 229
241 void VCMGenericEncoder::OnDroppedFrame() { 230 void VCMGenericEncoder::OnDroppedFrame() {
242 encoder_->OnDroppedFrame(); 231 encoder_->OnDroppedFrame();
243 } 232 }
244 233
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 316 }
328 317
329 void 318 void
330 VCMEncodedFrameCallback::SetMediaOpt( 319 VCMEncodedFrameCallback::SetMediaOpt(
331 media_optimization::MediaOptimization *mediaOpt) 320 media_optimization::MediaOptimization *mediaOpt)
332 { 321 {
333 _mediaOpt = mediaOpt; 322 _mediaOpt = mediaOpt;
334 } 323 }
335 324
336 } // namespace webrtc 325 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/main/source/generic_encoder.h ('k') | webrtc/modules/video_coding/main/source/video_receiver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698