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

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

Issue 1905583002: Reland of Deprecate VCMPacketizationCallback::SendData and use EncodedImageCallback instead. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 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) 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
11 #include "webrtc/modules/video_coding/generic_encoder.h" 11 #include "webrtc/modules/video_coding/generic_encoder.h"
12 12
13 #include <vector> 13 #include <vector>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
17 #include "webrtc/base/trace_event.h" 17 #include "webrtc/base/trace_event.h"
18 #include "webrtc/engine_configurations.h" 18 #include "webrtc/engine_configurations.h"
19 #include "webrtc/modules/video_coding/encoded_frame.h" 19 #include "webrtc/modules/video_coding/encoded_frame.h"
20 #include "webrtc/modules/video_coding/media_optimization.h" 20 #include "webrtc/modules/video_coding/media_optimization.h"
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
22 22
23 namespace webrtc { 23 namespace webrtc {
24 namespace {
25 // Map information from info into rtp. If no relevant information is found
26 // in info, rtp is set to NULL.
27 void CopyCodecSpecific(const CodecSpecificInfo* info, RTPVideoHeader* rtp) {
28 RTC_DCHECK(info);
29 switch (info->codecType) {
30 case kVideoCodecVP8: {
31 rtp->codec = kRtpVideoVp8;
32 rtp->codecHeader.VP8.InitRTPVideoHeaderVP8();
33 rtp->codecHeader.VP8.pictureId = info->codecSpecific.VP8.pictureId;
34 rtp->codecHeader.VP8.nonReference = info->codecSpecific.VP8.nonReference;
35 rtp->codecHeader.VP8.temporalIdx = info->codecSpecific.VP8.temporalIdx;
36 rtp->codecHeader.VP8.layerSync = info->codecSpecific.VP8.layerSync;
37 rtp->codecHeader.VP8.tl0PicIdx = info->codecSpecific.VP8.tl0PicIdx;
38 rtp->codecHeader.VP8.keyIdx = info->codecSpecific.VP8.keyIdx;
39 rtp->simulcastIdx = info->codecSpecific.VP8.simulcastIdx;
40 return;
41 }
42 case kVideoCodecVP9: {
43 rtp->codec = kRtpVideoVp9;
44 rtp->codecHeader.VP9.InitRTPVideoHeaderVP9();
45 rtp->codecHeader.VP9.inter_pic_predicted =
46 info->codecSpecific.VP9.inter_pic_predicted;
47 rtp->codecHeader.VP9.flexible_mode =
48 info->codecSpecific.VP9.flexible_mode;
49 rtp->codecHeader.VP9.ss_data_available =
50 info->codecSpecific.VP9.ss_data_available;
51 rtp->codecHeader.VP9.picture_id = info->codecSpecific.VP9.picture_id;
52 rtp->codecHeader.VP9.tl0_pic_idx = info->codecSpecific.VP9.tl0_pic_idx;
53 rtp->codecHeader.VP9.temporal_idx = info->codecSpecific.VP9.temporal_idx;
54 rtp->codecHeader.VP9.spatial_idx = info->codecSpecific.VP9.spatial_idx;
55 rtp->codecHeader.VP9.temporal_up_switch =
56 info->codecSpecific.VP9.temporal_up_switch;
57 rtp->codecHeader.VP9.inter_layer_predicted =
58 info->codecSpecific.VP9.inter_layer_predicted;
59 rtp->codecHeader.VP9.gof_idx = info->codecSpecific.VP9.gof_idx;
60 rtp->codecHeader.VP9.num_spatial_layers =
61 info->codecSpecific.VP9.num_spatial_layers;
62
63 if (info->codecSpecific.VP9.ss_data_available) {
64 rtp->codecHeader.VP9.spatial_layer_resolution_present =
65 info->codecSpecific.VP9.spatial_layer_resolution_present;
66 if (info->codecSpecific.VP9.spatial_layer_resolution_present) {
67 for (size_t i = 0; i < info->codecSpecific.VP9.num_spatial_layers;
68 ++i) {
69 rtp->codecHeader.VP9.width[i] = info->codecSpecific.VP9.width[i];
70 rtp->codecHeader.VP9.height[i] = info->codecSpecific.VP9.height[i];
71 }
72 }
73 rtp->codecHeader.VP9.gof.CopyGofInfoVP9(info->codecSpecific.VP9.gof);
74 }
75
76 rtp->codecHeader.VP9.num_ref_pics = info->codecSpecific.VP9.num_ref_pics;
77 for (int i = 0; i < info->codecSpecific.VP9.num_ref_pics; ++i)
78 rtp->codecHeader.VP9.pid_diff[i] = info->codecSpecific.VP9.p_diff[i];
79 return;
80 }
81 case kVideoCodecH264:
82 rtp->codec = kRtpVideoH264;
83 return;
84 case kVideoCodecGeneric:
85 rtp->codec = kRtpVideoGeneric;
86 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx;
87 return;
88 default:
89 return;
90 }
91 }
92 } // namespace
93
94 VCMGenericEncoder::VCMGenericEncoder( 24 VCMGenericEncoder::VCMGenericEncoder(
95 VideoEncoder* encoder, 25 VideoEncoder* encoder,
96 VideoEncoderRateObserver* rate_observer, 26 VideoEncoderRateObserver* rate_observer,
97 VCMEncodedFrameCallback* encoded_frame_callback, 27 VCMEncodedFrameCallback* encoded_frame_callback,
98 bool internal_source) 28 bool internal_source)
99 : encoder_(encoder), 29 : encoder_(encoder),
100 rate_observer_(rate_observer), 30 rate_observer_(rate_observer),
101 vcm_encoded_frame_callback_(encoded_frame_callback), 31 vcm_encoded_frame_callback_(encoded_frame_callback),
102 internal_source_(internal_source), 32 internal_source_(internal_source),
103 encoder_params_({0, 0, 0, 0}), 33 encoder_params_({0, 0, 0, 0}),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 139 }
210 140
211 int VCMGenericEncoder::GetTargetFramerate() { 141 int VCMGenericEncoder::GetTargetFramerate() {
212 return encoder_->GetTargetFramerate(); 142 return encoder_->GetTargetFramerate();
213 } 143 }
214 144
215 VCMEncodedFrameCallback::VCMEncodedFrameCallback( 145 VCMEncodedFrameCallback::VCMEncodedFrameCallback(
216 EncodedImageCallback* post_encode_callback) 146 EncodedImageCallback* post_encode_callback)
217 : send_callback_(), 147 : send_callback_(),
218 media_opt_(nullptr), 148 media_opt_(nullptr),
219 payload_type_(0),
220 internal_source_(false), 149 internal_source_(false),
221 post_encode_callback_(post_encode_callback) {} 150 post_encode_callback_(post_encode_callback) {}
222 151
223 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() {} 152 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() {}
224 153
225 int32_t VCMEncodedFrameCallback::SetTransportCallback( 154 int32_t VCMEncodedFrameCallback::SetTransportCallback(
226 VCMPacketizationCallback* transport) { 155 VCMPacketizationCallback* transport) {
227 send_callback_ = transport; 156 send_callback_ = transport;
228 return VCM_OK; 157 return VCM_OK;
229 } 158 }
230 159
231 int32_t VCMEncodedFrameCallback::Encoded( 160 int32_t VCMEncodedFrameCallback::Encoded(
232 const EncodedImage& encoded_image, 161 const EncodedImage& encoded_image,
233 const CodecSpecificInfo* codec_specific, 162 const CodecSpecificInfo* codec_specific,
234 const RTPFragmentationHeader* fragmentation_header) { 163 const RTPFragmentationHeader* fragmentation_header) {
235 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", 164 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded",
236 "timestamp", encoded_image._timeStamp); 165 "timestamp", encoded_image._timeStamp);
237 post_encode_callback_->Encoded(encoded_image, nullptr, nullptr); 166 int ret_val = post_encode_callback_->Encoded(encoded_image, codec_specific,
238 167 fragmentation_header);
239 if (send_callback_ == nullptr)
240 return VCM_UNINITIALIZED;
241
242 RTPVideoHeader rtp_video_header;
243 memset(&rtp_video_header, 0, sizeof(RTPVideoHeader));
244 if (codec_specific)
245 CopyCodecSpecific(codec_specific, &rtp_video_header);
246 rtp_video_header.rotation = encoded_image.rotation_;
247
248 int32_t ret_val = send_callback_->SendData(
249 payload_type_, encoded_image, fragmentation_header, &rtp_video_header);
250 if (ret_val < 0) 168 if (ret_val < 0)
251 return ret_val; 169 return ret_val;
252 170
253 if (media_opt_) { 171 if (media_opt_) {
254 media_opt_->UpdateWithEncodedData(encoded_image); 172 media_opt_->UpdateWithEncodedData(encoded_image);
255 if (internal_source_) 173 if (internal_source_)
256 return media_opt_->DropFrame(); // Signal to encoder to drop next frame. 174 return media_opt_->DropFrame(); // Signal to encoder to drop next frame.
257 } 175 }
258 return VCM_OK; 176 return VCM_OK;
259 } 177 }
260 178
261 void VCMEncodedFrameCallback::SetMediaOpt( 179 void VCMEncodedFrameCallback::SetMediaOpt(
262 media_optimization::MediaOptimization* mediaOpt) { 180 media_optimization::MediaOptimization* mediaOpt) {
263 media_opt_ = mediaOpt; 181 media_opt_ = mediaOpt;
264 } 182 }
265 183
266 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( 184 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed(
267 const char* implementation_name) { 185 const char* implementation_name) {
268 if (send_callback_) 186 if (send_callback_)
269 send_callback_->OnEncoderImplementationName(implementation_name); 187 send_callback_->OnEncoderImplementationName(implementation_name);
270 } 188 }
271 } // namespace webrtc 189 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/generic_encoder.h ('k') | webrtc/modules/video_coding/include/video_coding_defines.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698