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

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: feedback 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),
99 internal_source_(internalSource),
97 encoder_params_({0, 0, 0, 0}), 100 encoder_params_({0, 0, 0, 0}),
98 internal_source_(internalSource),
99 rotation_(kVideoRotation_0), 101 rotation_(kVideoRotation_0),
100 is_screenshare_(false) {} 102 is_screenshare_(false) {}
101 103
102 VCMGenericEncoder::~VCMGenericEncoder() 104 VCMGenericEncoder::~VCMGenericEncoder() {}
103 { 105
106 int32_t VCMGenericEncoder::Release() {
107 return encoder_->Release();
104 } 108 }
105 109
106 int32_t VCMGenericEncoder::Release() 110 int32_t VCMGenericEncoder::InitEncode(const VideoCodec* settings,
107 { 111 int32_t numberOfCores,
108 { 112 size_t maxPayloadSize) {
109 rtc::CritScope lock(&params_lock_); 113 {
110 encoder_params_ = {0, 0, 0, 0}; 114 rtc::CritScope lock(&params_lock_);
111 vcm_encoded_frame_callback_ = nullptr; 115 encoder_params_.target_bitrate = settings->startBitrate * 1000;
112 } 116 encoder_params_.input_frame_rate = settings->maxFramerate;
117 }
113 118
114 return encoder_->Release(); 119 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing;
115 } 120 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) {
116 121 LOG(LS_ERROR) << "Failed to initialize the encoder associated with "
117 int32_t 122 "payload name: "
118 VCMGenericEncoder::InitEncode(const VideoCodec* settings, 123 << settings->plName;
119 int32_t numberOfCores, 124 return -1;
120 size_t maxPayloadSize) 125 }
121 { 126 encoder_->RegisterEncodeCompleteCallback(vcm_encoded_frame_callback_);
122 { 127 return 0;
123 rtc::CritScope lock(&params_lock_);
124 encoder_params_.target_bitrate = settings->startBitrate * 1000;
125 encoder_params_.input_frame_rate = settings->maxFramerate;
126 }
127
128 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing;
129 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) {
130 LOG(LS_ERROR) << "Failed to initialize the encoder associated with "
131 "payload name: " << settings->plName;
132 return -1;
133 }
134 return 0;
135 } 128 }
136 129
137 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, 130 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame,
138 const CodecSpecificInfo* codecSpecificInfo, 131 const CodecSpecificInfo* codecSpecificInfo,
139 const std::vector<FrameType>& frameTypes) { 132 const std::vector<FrameType>& frameTypes) {
140 for (FrameType frame_type : frameTypes) 133 for (FrameType frame_type : frameTypes)
141 RTC_DCHECK(frame_type == kVideoFrameKey || frame_type == kVideoFrameDelta); 134 RTC_DCHECK(frame_type == kVideoFrameKey || frame_type == kVideoFrameDelta);
142 135
143 rotation_ = inputFrame.rotation(); 136 rotation_ = inputFrame.rotation();
144 137
145 if (vcm_encoded_frame_callback_) { 138 // Keep track of the current frame rotation and apply to the output of the
146 // Keep track of the current frame rotation and apply to the output of the 139 // encoder. There might not be exact as the encoder could have one frame delay
147 // encoder. There might not be exact as the encoder could have one frame 140 // but it should be close enough.
148 // delay but it should be close enough. 141 // TODO(pbos): Map from timestamp, this is racy (even if rotation_ is locked
149 vcm_encoded_frame_callback_->SetRotation(rotation_); 142 // properly, which it isn't). More than one frame may be in the pipeline.
150 } 143 vcm_encoded_frame_callback_->SetRotation(rotation_);
151 144
152 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); 145 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes);
153 if (is_screenshare_ && 146 if (is_screenshare_ &&
154 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { 147 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) {
155 // Target bitrate exceeded, encoder state has been reset - try again. 148 // Target bitrate exceeded, encoder state has been reset - try again.
156 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); 149 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes);
157 } 150 }
158 151
159 return result; 152 return result;
160 } 153 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 { 187 {
195 return encoder_->SetPeriodicKeyFrames(enable); 188 return encoder_->SetPeriodicKeyFrames(enable);
196 } 189 }
197 190
198 int32_t VCMGenericEncoder::RequestFrame( 191 int32_t VCMGenericEncoder::RequestFrame(
199 const std::vector<FrameType>& frame_types) { 192 const std::vector<FrameType>& frame_types) {
200 VideoFrame image; 193 VideoFrame image;
201 return encoder_->Encode(image, NULL, &frame_types); 194 return encoder_->Encode(image, NULL, &frame_types);
202 } 195 }
203 196
204 int32_t
205 VCMGenericEncoder::RegisterEncodeCallback(VCMEncodedFrameCallback* VCMencodedFra meCallback)
206 {
207 VCMencodedFrameCallback->SetInternalSource(internal_source_);
208 vcm_encoded_frame_callback_ = VCMencodedFrameCallback;
209 return encoder_->RegisterEncodeCompleteCallback(VCMencodedFrameCallback);
210 }
211
212 bool 197 bool
213 VCMGenericEncoder::InternalSource() const 198 VCMGenericEncoder::InternalSource() const
214 { 199 {
215 return internal_source_; 200 return internal_source_;
216 } 201 }
217 202
218 void VCMGenericEncoder::OnDroppedFrame() { 203 void VCMGenericEncoder::OnDroppedFrame() {
219 encoder_->OnDroppedFrame(); 204 encoder_->OnDroppedFrame();
220 } 205 }
221 206
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 289 }
305 290
306 void 291 void
307 VCMEncodedFrameCallback::SetMediaOpt( 292 VCMEncodedFrameCallback::SetMediaOpt(
308 media_optimization::MediaOptimization *mediaOpt) 293 media_optimization::MediaOptimization *mediaOpt)
309 { 294 {
310 _mediaOpt = mediaOpt; 295 _mediaOpt = mediaOpt;
311 } 296 }
312 297
313 } // namespace webrtc 298 } // 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