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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender.cc

Issue 1649493004: Support multiple rtx codecs. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove some more code. Created 4 years, 10 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
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 remote_ssrc_(0), 172 remote_ssrc_(0),
173 sequence_number_forced_(false), 173 sequence_number_forced_(false),
174 ssrc_forced_(false), 174 ssrc_forced_(false),
175 timestamp_(0), 175 timestamp_(0),
176 capture_time_ms_(0), 176 capture_time_ms_(0),
177 last_timestamp_time_ms_(0), 177 last_timestamp_time_ms_(0),
178 media_has_been_sent_(false), 178 media_has_been_sent_(false),
179 last_packet_marker_bit_(false), 179 last_packet_marker_bit_(false),
180 csrcs_(), 180 csrcs_(),
181 rtx_(kRtxOff), 181 rtx_(kRtxOff),
182 rtx_payload_type_(-1),
183 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()), 182 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
184 target_bitrate_(0) { 183 target_bitrate_(0) {
185 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); 184 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_));
186 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); 185 memset(nack_byte_count_, 0, sizeof(nack_byte_count_));
187 // We need to seed the random generator. 186 // We need to seed the random generator.
188 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); 187 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds()));
189 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. 188 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0.
190 ssrc_rtx_ = ssrc_db_.CreateSSRC(); // Can't be 0. 189 ssrc_rtx_ = ssrc_db_.CreateSSRC(); // Can't be 0.
191 bitrates_->set_ssrc(ssrc_); 190 bitrates_->set_ssrc(ssrc_);
192 // Random start, 16 bits. Can't be 0. 191 // Random start, 16 bits. Can't be 0.
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 int associated_payload_type) { 429 int associated_payload_type) {
431 CriticalSectionScoped cs(send_critsect_.get()); 430 CriticalSectionScoped cs(send_critsect_.get());
432 RTC_DCHECK_LE(payload_type, 127); 431 RTC_DCHECK_LE(payload_type, 127);
433 RTC_DCHECK_LE(associated_payload_type, 127); 432 RTC_DCHECK_LE(associated_payload_type, 127);
434 if (payload_type < 0) { 433 if (payload_type < 0) {
435 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; 434 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type;
436 return; 435 return;
437 } 436 }
438 437
439 rtx_payload_type_map_[associated_payload_type] = payload_type; 438 rtx_payload_type_map_[associated_payload_type] = payload_type;
440 rtx_payload_type_ = payload_type;
441 }
442
443 std::pair<int, int> RTPSender::RtxPayloadType() const {
444 CriticalSectionScoped cs(send_critsect_.get());
445 for (const auto& kv : rtx_payload_type_map_) {
446 if (kv.second == rtx_payload_type_) {
447 return std::make_pair(rtx_payload_type_, kv.first);
448 }
449 }
450 return std::make_pair(-1, -1);
451 } 439 }
452 440
453 int32_t RTPSender::CheckPayloadType(int8_t payload_type, 441 int32_t RTPSender::CheckPayloadType(int8_t payload_type,
454 RtpVideoCodecTypes* video_type) { 442 RtpVideoCodecTypes* video_type) {
455 CriticalSectionScoped cs(send_critsect_.get()); 443 CriticalSectionScoped cs(send_critsect_.get());
456 444
457 if (payload_type < 0) { 445 if (payload_type < 0) {
458 LOG(LS_ERROR) << "Invalid payload_type " << payload_type; 446 LOG(LS_ERROR) << "Invalid payload_type " << payload_type;
459 return -1; 447 return -1;
460 } 448 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 // frame (and therefore the same timestamp). 644 // frame (and therefore the same timestamp).
657 if (last_timestamp_time_ms_ > 0) { 645 if (last_timestamp_time_ms_ > 0) {
658 timestamp += 646 timestamp +=
659 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90; 647 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90;
660 capture_time_ms += 648 capture_time_ms +=
661 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_); 649 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_);
662 } 650 }
663 ssrc = ssrc_rtx_; 651 ssrc = ssrc_rtx_;
664 sequence_number = sequence_number_rtx_; 652 sequence_number = sequence_number_rtx_;
665 ++sequence_number_rtx_; 653 ++sequence_number_rtx_;
666 payload_type = rtx_payload_type_; 654 payload_type = rtx_payload_type_map_.begin()->second;
667 over_rtx = true; 655 over_rtx = true;
668 } 656 }
669 } 657 }
670 658
671 uint8_t padding_packet[IP_PACKET_SIZE]; 659 uint8_t padding_packet[IP_PACKET_SIZE];
672 size_t header_length = 660 size_t header_length =
673 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, 661 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp,
674 sequence_number, std::vector<uint32_t>()); 662 sequence_number, std::vector<uint32_t>());
675 BuildPaddingPacket(padding_packet, header_length, padding_bytes_in_packet); 663 BuildPaddingPacket(padding_packet, header_length, padding_bytes_in_packet);
676 size_t length = padding_bytes_in_packet + header_length; 664 size_t length = padding_bytes_in_packet + header_length;
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 RtpUtility::RtpHeaderParser rtp_parser( 1830 RtpUtility::RtpHeaderParser rtp_parser(
1843 reinterpret_cast<const uint8_t*>(buffer), *length); 1831 reinterpret_cast<const uint8_t*>(buffer), *length);
1844 1832
1845 RTPHeader rtp_header; 1833 RTPHeader rtp_header;
1846 rtp_parser.Parse(&rtp_header); 1834 rtp_parser.Parse(&rtp_header);
1847 1835
1848 // Add original RTP header. 1836 // Add original RTP header.
1849 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength); 1837 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength);
1850 1838
1851 // Replace payload type, if a specific type is set for RTX. 1839 // Replace payload type, if a specific type is set for RTX.
1852 if (rtx_payload_type_ != -1) { 1840 auto kv = rtx_payload_type_map_.find(rtp_header.payloadType);
1853 data_buffer_rtx[1] = static_cast<uint8_t>(rtx_payload_type_); 1841 // Use rtx mapping associated with media codec if we can't find one, assuming
1854 if (rtp_header.markerBit) 1842 // it's red.
1855 data_buffer_rtx[1] |= kRtpMarkerBitMask; 1843 // TODO(holmer): Remove once old Chrome versions don't rely on this.
pbos-webrtc 2016/02/01 14:32:19 Do you want to log a warning here?
stefan-webrtc 2016/02/01 15:26:08 I don't think so as that would spam warnings if a
1856 } 1844 if (kv == rtx_payload_type_map_.end())
1845 kv = rtx_payload_type_map_.find(payload_type_);
1846 if (kv != rtx_payload_type_map_.end())
1847 data_buffer_rtx[1] = kv->second;
1848 if (rtp_header.markerBit)
1849 data_buffer_rtx[1] |= kRtpMarkerBitMask;
1857 1850
1858 // Replace sequence number. 1851 // Replace sequence number.
1859 uint8_t* ptr = data_buffer_rtx + 2; 1852 uint8_t* ptr = data_buffer_rtx + 2;
1860 ByteWriter<uint16_t>::WriteBigEndian(ptr, sequence_number_rtx_++); 1853 ByteWriter<uint16_t>::WriteBigEndian(ptr, sequence_number_rtx_++);
1861 1854
1862 // Replace SSRC. 1855 // Replace SSRC.
1863 ptr += 6; 1856 ptr += 6;
1864 ByteWriter<uint32_t>::WriteBigEndian(ptr, ssrc_rtx_); 1857 ByteWriter<uint32_t>::WriteBigEndian(ptr, ssrc_rtx_);
1865 1858
1866 // Add OSN (original sequence number). 1859 // Add OSN (original sequence number).
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 CriticalSectionScoped lock(send_critsect_.get()); 1915 CriticalSectionScoped lock(send_critsect_.get());
1923 1916
1924 RtpState state; 1917 RtpState state;
1925 state.sequence_number = sequence_number_rtx_; 1918 state.sequence_number = sequence_number_rtx_;
1926 state.start_timestamp = start_timestamp_; 1919 state.start_timestamp = start_timestamp_;
1927 1920
1928 return state; 1921 return state;
1929 } 1922 }
1930 1923
1931 } // namespace webrtc 1924 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698