OLD | NEW |
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 remote_ssrc_(0), | 161 remote_ssrc_(0), |
162 sequence_number_forced_(false), | 162 sequence_number_forced_(false), |
163 ssrc_forced_(false), | 163 ssrc_forced_(false), |
164 timestamp_(0), | 164 timestamp_(0), |
165 capture_time_ms_(0), | 165 capture_time_ms_(0), |
166 last_timestamp_time_ms_(0), | 166 last_timestamp_time_ms_(0), |
167 media_has_been_sent_(false), | 167 media_has_been_sent_(false), |
168 last_packet_marker_bit_(false), | 168 last_packet_marker_bit_(false), |
169 csrcs_(), | 169 csrcs_(), |
170 rtx_(kRtxOff), | 170 rtx_(kRtxOff), |
171 rtx_payload_type_(-1), | |
172 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 171 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
173 target_bitrate_(0) { | 172 target_bitrate_(0) { |
174 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); | 173 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); |
175 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); | 174 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); |
176 // We need to seed the random generator for BuildPaddingPacket() below. | 175 // We need to seed the random generator for BuildPaddingPacket() below. |
177 // TODO(holmer,tommi): Note that TimeInMilliseconds might return 0 on Mac | 176 // TODO(holmer,tommi): Note that TimeInMilliseconds might return 0 on Mac |
178 // early on in the process. | 177 // early on in the process. |
179 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); | 178 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); |
180 ssrc_ = ssrc_db_->CreateSSRC(); | 179 ssrc_ = ssrc_db_->CreateSSRC(); |
181 RTC_DCHECK(ssrc_ != 0); | 180 RTC_DCHECK(ssrc_ != 0); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 int associated_payload_type) { | 432 int associated_payload_type) { |
434 rtc::CritScope lock(&send_critsect_); | 433 rtc::CritScope lock(&send_critsect_); |
435 RTC_DCHECK_LE(payload_type, 127); | 434 RTC_DCHECK_LE(payload_type, 127); |
436 RTC_DCHECK_LE(associated_payload_type, 127); | 435 RTC_DCHECK_LE(associated_payload_type, 127); |
437 if (payload_type < 0) { | 436 if (payload_type < 0) { |
438 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; | 437 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; |
439 return; | 438 return; |
440 } | 439 } |
441 | 440 |
442 rtx_payload_type_map_[associated_payload_type] = payload_type; | 441 rtx_payload_type_map_[associated_payload_type] = payload_type; |
443 rtx_payload_type_ = payload_type; | |
444 } | |
445 | |
446 std::pair<int, int> RTPSender::RtxPayloadType() const { | |
447 rtc::CritScope lock(&send_critsect_); | |
448 for (const auto& kv : rtx_payload_type_map_) { | |
449 if (kv.second == rtx_payload_type_) { | |
450 return std::make_pair(rtx_payload_type_, kv.first); | |
451 } | |
452 } | |
453 return std::make_pair(-1, -1); | |
454 } | 442 } |
455 | 443 |
456 int32_t RTPSender::CheckPayloadType(int8_t payload_type, | 444 int32_t RTPSender::CheckPayloadType(int8_t payload_type, |
457 RtpVideoCodecTypes* video_type) { | 445 RtpVideoCodecTypes* video_type) { |
458 rtc::CritScope lock(&send_critsect_); | 446 rtc::CritScope lock(&send_critsect_); |
459 | 447 |
460 if (payload_type < 0) { | 448 if (payload_type < 0) { |
461 LOG(LS_ERROR) << "Invalid payload_type " << payload_type; | 449 LOG(LS_ERROR) << "Invalid payload_type " << payload_type; |
462 return -1; | 450 return -1; |
463 } | 451 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 // frame (and therefore the same timestamp). | 647 // frame (and therefore the same timestamp). |
660 if (last_timestamp_time_ms_ > 0) { | 648 if (last_timestamp_time_ms_ > 0) { |
661 timestamp += | 649 timestamp += |
662 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90; | 650 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90; |
663 capture_time_ms += | 651 capture_time_ms += |
664 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_); | 652 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_); |
665 } | 653 } |
666 ssrc = ssrc_rtx_; | 654 ssrc = ssrc_rtx_; |
667 sequence_number = sequence_number_rtx_; | 655 sequence_number = sequence_number_rtx_; |
668 ++sequence_number_rtx_; | 656 ++sequence_number_rtx_; |
669 payload_type = rtx_payload_type_; | 657 payload_type = rtx_payload_type_map_.begin()->second; |
670 over_rtx = true; | 658 over_rtx = true; |
671 } | 659 } |
672 } | 660 } |
673 | 661 |
674 uint8_t padding_packet[IP_PACKET_SIZE]; | 662 uint8_t padding_packet[IP_PACKET_SIZE]; |
675 size_t header_length = | 663 size_t header_length = |
676 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, | 664 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, |
677 sequence_number, std::vector<uint32_t>()); | 665 sequence_number, std::vector<uint32_t>()); |
678 BuildPaddingPacket(padding_packet, header_length, padding_bytes_in_packet); | 666 BuildPaddingPacket(padding_packet, header_length, padding_bytes_in_packet); |
679 size_t length = padding_bytes_in_packet + header_length; | 667 size_t length = padding_bytes_in_packet + header_length; |
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 RtpUtility::RtpHeaderParser rtp_parser( | 1835 RtpUtility::RtpHeaderParser rtp_parser( |
1848 reinterpret_cast<const uint8_t*>(buffer), *length); | 1836 reinterpret_cast<const uint8_t*>(buffer), *length); |
1849 | 1837 |
1850 RTPHeader rtp_header; | 1838 RTPHeader rtp_header; |
1851 rtp_parser.Parse(&rtp_header); | 1839 rtp_parser.Parse(&rtp_header); |
1852 | 1840 |
1853 // Add original RTP header. | 1841 // Add original RTP header. |
1854 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength); | 1842 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength); |
1855 | 1843 |
1856 // Replace payload type, if a specific type is set for RTX. | 1844 // Replace payload type, if a specific type is set for RTX. |
1857 if (rtx_payload_type_ != -1) { | 1845 auto kv = rtx_payload_type_map_.find(rtp_header.payloadType); |
1858 data_buffer_rtx[1] = static_cast<uint8_t>(rtx_payload_type_); | 1846 // Use rtx mapping associated with media codec if we can't find one, assuming |
1859 if (rtp_header.markerBit) | 1847 // it's red. |
1860 data_buffer_rtx[1] |= kRtpMarkerBitMask; | 1848 // TODO(holmer): Remove once old Chrome versions don't rely on this. |
1861 } | 1849 if (kv == rtx_payload_type_map_.end()) |
| 1850 kv = rtx_payload_type_map_.find(payload_type_); |
| 1851 if (kv != rtx_payload_type_map_.end()) |
| 1852 data_buffer_rtx[1] = kv->second; |
| 1853 if (rtp_header.markerBit) |
| 1854 data_buffer_rtx[1] |= kRtpMarkerBitMask; |
1862 | 1855 |
1863 // Replace sequence number. | 1856 // Replace sequence number. |
1864 uint8_t* ptr = data_buffer_rtx + 2; | 1857 uint8_t* ptr = data_buffer_rtx + 2; |
1865 ByteWriter<uint16_t>::WriteBigEndian(ptr, sequence_number_rtx_++); | 1858 ByteWriter<uint16_t>::WriteBigEndian(ptr, sequence_number_rtx_++); |
1866 | 1859 |
1867 // Replace SSRC. | 1860 // Replace SSRC. |
1868 ptr += 6; | 1861 ptr += 6; |
1869 ByteWriter<uint32_t>::WriteBigEndian(ptr, ssrc_rtx_); | 1862 ByteWriter<uint32_t>::WriteBigEndian(ptr, ssrc_rtx_); |
1870 | 1863 |
1871 // Add OSN (original sequence number). | 1864 // Add OSN (original sequence number). |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 rtc::CritScope lock(&send_critsect_); | 1920 rtc::CritScope lock(&send_critsect_); |
1928 | 1921 |
1929 RtpState state; | 1922 RtpState state; |
1930 state.sequence_number = sequence_number_rtx_; | 1923 state.sequence_number = sequence_number_rtx_; |
1931 state.start_timestamp = start_timestamp_; | 1924 state.start_timestamp = start_timestamp_; |
1932 | 1925 |
1933 return state; | 1926 return state; |
1934 } | 1927 } |
1935 | 1928 |
1936 } // namespace webrtc | 1929 } // namespace webrtc |
OLD | NEW |