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

Side by Side Diff: webrtc/video/payload_router.cc

Issue 1897233002: 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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/video/payload_router.h" 11 #include "webrtc/video/payload_router.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
16 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
16 17
17 namespace webrtc { 18 namespace webrtc {
18 19
19 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules) 20 namespace {
20 : active_(false), num_sending_modules_(1), rtp_modules_(rtp_modules) { 21 // Map information from info into rtp.
22 void CopyCodecSpecific(const CodecSpecificInfo* info, RTPVideoHeader* rtp) {
23 RTC_DCHECK(info);
24 switch (info->codecType) {
25 case kVideoCodecVP8: {
26 rtp->codec = kRtpVideoVp8;
27 rtp->codecHeader.VP8.InitRTPVideoHeaderVP8();
28 rtp->codecHeader.VP8.pictureId = info->codecSpecific.VP8.pictureId;
29 rtp->codecHeader.VP8.nonReference = info->codecSpecific.VP8.nonReference;
30 rtp->codecHeader.VP8.temporalIdx = info->codecSpecific.VP8.temporalIdx;
31 rtp->codecHeader.VP8.layerSync = info->codecSpecific.VP8.layerSync;
32 rtp->codecHeader.VP8.tl0PicIdx = info->codecSpecific.VP8.tl0PicIdx;
33 rtp->codecHeader.VP8.keyIdx = info->codecSpecific.VP8.keyIdx;
34 rtp->simulcastIdx = info->codecSpecific.VP8.simulcastIdx;
35 return;
36 }
37 case kVideoCodecVP9: {
38 rtp->codec = kRtpVideoVp9;
39 rtp->codecHeader.VP9.InitRTPVideoHeaderVP9();
40 rtp->codecHeader.VP9.inter_pic_predicted =
41 info->codecSpecific.VP9.inter_pic_predicted;
42 rtp->codecHeader.VP9.flexible_mode =
43 info->codecSpecific.VP9.flexible_mode;
44 rtp->codecHeader.VP9.ss_data_available =
45 info->codecSpecific.VP9.ss_data_available;
46 rtp->codecHeader.VP9.picture_id = info->codecSpecific.VP9.picture_id;
47 rtp->codecHeader.VP9.tl0_pic_idx = info->codecSpecific.VP9.tl0_pic_idx;
48 rtp->codecHeader.VP9.temporal_idx = info->codecSpecific.VP9.temporal_idx;
49 rtp->codecHeader.VP9.spatial_idx = info->codecSpecific.VP9.spatial_idx;
50 rtp->codecHeader.VP9.temporal_up_switch =
51 info->codecSpecific.VP9.temporal_up_switch;
52 rtp->codecHeader.VP9.inter_layer_predicted =
53 info->codecSpecific.VP9.inter_layer_predicted;
54 rtp->codecHeader.VP9.gof_idx = info->codecSpecific.VP9.gof_idx;
55 rtp->codecHeader.VP9.num_spatial_layers =
56 info->codecSpecific.VP9.num_spatial_layers;
57
58 if (info->codecSpecific.VP9.ss_data_available) {
59 rtp->codecHeader.VP9.spatial_layer_resolution_present =
60 info->codecSpecific.VP9.spatial_layer_resolution_present;
61 if (info->codecSpecific.VP9.spatial_layer_resolution_present) {
62 for (size_t i = 0; i < info->codecSpecific.VP9.num_spatial_layers;
63 ++i) {
64 rtp->codecHeader.VP9.width[i] = info->codecSpecific.VP9.width[i];
65 rtp->codecHeader.VP9.height[i] = info->codecSpecific.VP9.height[i];
66 }
67 }
68 rtp->codecHeader.VP9.gof.CopyGofInfoVP9(info->codecSpecific.VP9.gof);
69 }
70
71 rtp->codecHeader.VP9.num_ref_pics = info->codecSpecific.VP9.num_ref_pics;
72 for (int i = 0; i < info->codecSpecific.VP9.num_ref_pics; ++i)
73 rtp->codecHeader.VP9.pid_diff[i] = info->codecSpecific.VP9.p_diff[i];
74 return;
75 }
76 case kVideoCodecH264:
77 rtp->codec = kRtpVideoH264;
78 return;
79 case kVideoCodecGeneric:
80 rtp->codec = kRtpVideoGeneric;
81 return;
82 default:
83 return;
84 }
85 }
86 } // namespace
87
88 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
89 int payload_type)
90 : active_(false),
91 num_sending_modules_(1),
92 rtp_modules_(rtp_modules),
93 payload_type_(payload_type) {
21 UpdateModuleSendingState(); 94 UpdateModuleSendingState();
22 } 95 }
23 96
24 PayloadRouter::~PayloadRouter() {} 97 PayloadRouter::~PayloadRouter() {}
25 98
26 size_t PayloadRouter::DefaultMaxPayloadLength() { 99 size_t PayloadRouter::DefaultMaxPayloadLength() {
27 const size_t kIpUdpSrtpLength = 44; 100 const size_t kIpUdpSrtpLength = 44;
28 return IP_PACKET_SIZE - kIpUdpSrtpLength; 101 return IP_PACKET_SIZE - kIpUdpSrtpLength;
29 } 102 }
30 103
(...skipping 22 matching lines...) Expand all
53 rtp_modules_[i]->SetSendingStatus(active_); 126 rtp_modules_[i]->SetSendingStatus(active_);
54 rtp_modules_[i]->SetSendingMediaStatus(active_); 127 rtp_modules_[i]->SetSendingMediaStatus(active_);
55 } 128 }
56 // Disable inactive modules. 129 // Disable inactive modules.
57 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) { 130 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) {
58 rtp_modules_[i]->SetSendingStatus(false); 131 rtp_modules_[i]->SetSendingStatus(false);
59 rtp_modules_[i]->SetSendingMediaStatus(false); 132 rtp_modules_[i]->SetSendingMediaStatus(false);
60 } 133 }
61 } 134 }
62 135
63 bool PayloadRouter::RoutePayload(FrameType frame_type, 136 int32_t PayloadRouter::Encoded(const EncodedImage& encoded_image,
64 int8_t payload_type, 137 const CodecSpecificInfo* codec_specific_info,
65 uint32_t time_stamp, 138 const RTPFragmentationHeader* fragmentation) {
66 int64_t capture_time_ms,
67 const uint8_t* payload_data,
68 size_t payload_length,
69 const RTPFragmentationHeader* fragmentation,
70 const RTPVideoHeader* rtp_video_hdr) {
71 rtc::CritScope lock(&crit_); 139 rtc::CritScope lock(&crit_);
72 RTC_DCHECK(!rtp_modules_.empty()); 140 RTC_DCHECK(!rtp_modules_.empty());
73 if (!active_ || num_sending_modules_ == 0) 141 if (!active_ || num_sending_modules_ == 0)
74 return false; 142 return -1;
75 143
76 int stream_idx = 0; 144 int stream_idx = 0;
77 if (rtp_video_hdr) { 145
78 RTC_DCHECK_LT(rtp_video_hdr->simulcastIdx, rtp_modules_.size()); 146 RTPVideoHeader rtp_video_header;
79 // The simulcast index might actually be larger than the number of modules 147 memset(&rtp_video_header, 0, sizeof(RTPVideoHeader));
80 // in case the encoder was processing a frame during a codec reconfig. 148 if (codec_specific_info)
81 if (rtp_video_hdr->simulcastIdx >= num_sending_modules_) 149 CopyCodecSpecific(codec_specific_info, &rtp_video_header);
82 return false; 150
83 stream_idx = rtp_video_hdr->simulcastIdx; 151 RTC_DCHECK_LT(rtp_video_header.simulcastIdx, rtp_modules_.size());
84 } 152 // The simulcast index might actually be larger than the number of modules
153 // in case the encoder was processing a frame during a codec reconfig.
154 if (rtp_video_header.simulcastIdx >= num_sending_modules_)
155 return -1;
156 stream_idx = rtp_video_header.simulcastIdx;
157
85 return rtp_modules_[stream_idx]->SendOutgoingData( 158 return rtp_modules_[stream_idx]->SendOutgoingData(
86 frame_type, payload_type, time_stamp, capture_time_ms, payload_data, 159 encoded_image._frameType, payload_type_, encoded_image._timeStamp,
87 payload_length, fragmentation, rtp_video_hdr) == 0 ? true : false; 160 encoded_image.capture_time_ms_, encoded_image._buffer,
161 encoded_image._length, fragmentation, &rtp_video_header);
88 } 162 }
89 163
90 void PayloadRouter::SetTargetSendBitrates( 164 void PayloadRouter::SetTargetSendBitrates(
91 const std::vector<uint32_t>& stream_bitrates) { 165 const std::vector<uint32_t>& stream_bitrates) {
92 rtc::CritScope lock(&crit_); 166 rtc::CritScope lock(&crit_);
93 RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size()); 167 RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size());
94 for (size_t i = 0; i < stream_bitrates.size(); ++i) { 168 for (size_t i = 0; i < stream_bitrates.size(); ++i) {
95 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]); 169 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]);
96 } 170 }
97 } 171 }
98 172
99 size_t PayloadRouter::MaxPayloadLength() const { 173 size_t PayloadRouter::MaxPayloadLength() const {
100 size_t min_payload_length = DefaultMaxPayloadLength(); 174 size_t min_payload_length = DefaultMaxPayloadLength();
101 rtc::CritScope lock(&crit_); 175 rtc::CritScope lock(&crit_);
102 for (size_t i = 0; i < num_sending_modules_; ++i) { 176 for (size_t i = 0; i < num_sending_modules_; ++i) {
103 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength(); 177 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength();
104 if (module_payload_length < min_payload_length) 178 if (module_payload_length < min_payload_length)
105 min_payload_length = module_payload_length; 179 min_payload_length = module_payload_length;
106 } 180 }
107 return min_payload_length; 181 return min_payload_length;
108 } 182 }
109 183
110 } // namespace webrtc 184 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698