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

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

Issue 2926253002: Rename class RtpStreamReceiver --> RtpVideoStreamReceiver. (Closed)
Patch Set: Created 3 years, 6 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/video/rtp_stream_receiver.h" 11 #include "webrtc/video/rtp_video_stream_receiver.h"
12 12
13 #include <vector> 13 #include <vector>
14 #include <utility> 14 #include <utility>
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/location.h" 17 #include "webrtc/base/location.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/common_types.h" 19 #include "webrtc/common_types.h"
20 #include "webrtc/config.h" 20 #include "webrtc/config.h"
21 #include "webrtc/media/base/mediaconstants.h" 21 #include "webrtc/media/base/mediaconstants.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 configuration.transport_feedback_callback = nullptr; 71 configuration.transport_feedback_callback = nullptr;
72 72
73 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration)); 73 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration));
74 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); 74 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound);
75 75
76 return rtp_rtcp; 76 return rtp_rtcp;
77 } 77 }
78 78
79 static const int kPacketLogIntervalMs = 10000; 79 static const int kPacketLogIntervalMs = 10000;
80 80
81 RtpStreamReceiver::RtpStreamReceiver( 81 RtpVideoStreamReceiver::RtpVideoStreamReceiver(
82 Transport* transport, 82 Transport* transport,
83 RtcpRttStats* rtt_stats, 83 RtcpRttStats* rtt_stats,
84 PacketRouter* packet_router, 84 PacketRouter* packet_router,
85 const VideoReceiveStream::Config* config, 85 const VideoReceiveStream::Config* config,
86 ReceiveStatisticsProxy* receive_stats_proxy, 86 ReceiveStatisticsProxy* receive_stats_proxy,
87 ProcessThread* process_thread, 87 ProcessThread* process_thread,
88 NackSender* nack_sender, 88 NackSender* nack_sender,
89 KeyFrameRequestSender* keyframe_request_sender, 89 KeyFrameRequestSender* keyframe_request_sender,
90 video_coding::OnCompleteFrameCallback* complete_frame_callback, 90 video_coding::OnCompleteFrameCallback* complete_frame_callback,
91 VCMTiming* timing) 91 VCMTiming* timing)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 nack_module_.reset( 182 nack_module_.reset(
183 new NackModule(clock_, nack_sender, keyframe_request_sender)); 183 new NackModule(clock_, nack_sender, keyframe_request_sender));
184 process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE); 184 process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE);
185 } 185 }
186 186
187 packet_buffer_ = video_coding::PacketBuffer::Create( 187 packet_buffer_ = video_coding::PacketBuffer::Create(
188 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this); 188 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this);
189 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this)); 189 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this));
190 } 190 }
191 191
192 RtpStreamReceiver::~RtpStreamReceiver() { 192 RtpVideoStreamReceiver::~RtpVideoStreamReceiver() {
193 if (nack_module_) { 193 if (nack_module_) {
194 process_thread_->DeRegisterModule(nack_module_.get()); 194 process_thread_->DeRegisterModule(nack_module_.get());
195 } 195 }
196 196
197 process_thread_->DeRegisterModule(rtp_rtcp_.get()); 197 process_thread_->DeRegisterModule(rtp_rtcp_.get());
198 198
199 packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get()); 199 packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get());
200 UpdateHistograms(); 200 UpdateHistograms();
201 } 201 }
202 202
203 bool RtpStreamReceiver::AddReceiveCodec( 203 bool RtpVideoStreamReceiver::AddReceiveCodec(
204 const VideoCodec& video_codec, 204 const VideoCodec& video_codec,
205 const std::map<std::string, std::string>& codec_params) { 205 const std::map<std::string, std::string>& codec_params) {
206 pt_codec_params_.insert(make_pair(video_codec.plType, codec_params)); 206 pt_codec_params_.insert(make_pair(video_codec.plType, codec_params));
207 return AddReceiveCodec(video_codec); 207 return AddReceiveCodec(video_codec);
208 } 208 }
209 209
210 bool RtpStreamReceiver::AddReceiveCodec(const VideoCodec& video_codec) { 210 bool RtpVideoStreamReceiver::AddReceiveCodec(const VideoCodec& video_codec) {
211 int8_t old_pltype = -1; 211 int8_t old_pltype = -1;
212 if (rtp_payload_registry_.ReceivePayloadType(video_codec, &old_pltype) != 212 if (rtp_payload_registry_.ReceivePayloadType(video_codec, &old_pltype) !=
213 -1) { 213 -1) {
214 rtp_payload_registry_.DeRegisterReceivePayload(old_pltype); 214 rtp_payload_registry_.DeRegisterReceivePayload(old_pltype);
215 } 215 }
216 return rtp_payload_registry_.RegisterReceivePayload(video_codec) == 0; 216 return rtp_payload_registry_.RegisterReceivePayload(video_codec) == 0;
217 } 217 }
218 218
219 uint32_t RtpStreamReceiver::GetRemoteSsrc() const { 219 uint32_t RtpVideoStreamReceiver::GetRemoteSsrc() const {
220 return rtp_receiver_->SSRC(); 220 return rtp_receiver_->SSRC();
221 } 221 }
222 222
223 int RtpStreamReceiver::GetCsrcs(uint32_t* csrcs) const { 223 int RtpVideoStreamReceiver::GetCsrcs(uint32_t* csrcs) const {
224 return rtp_receiver_->CSRCs(csrcs); 224 return rtp_receiver_->CSRCs(csrcs);
225 } 225 }
226 226
227 RtpReceiver* RtpStreamReceiver::GetRtpReceiver() const { 227 RtpReceiver* RtpVideoStreamReceiver::GetRtpReceiver() const {
228 return rtp_receiver_.get(); 228 return rtp_receiver_.get();
229 } 229 }
230 230
231 int32_t RtpStreamReceiver::OnReceivedPayloadData( 231 int32_t RtpVideoStreamReceiver::OnReceivedPayloadData(
232 const uint8_t* payload_data, 232 const uint8_t* payload_data,
233 size_t payload_size, 233 size_t payload_size,
234 const WebRtcRTPHeader* rtp_header) { 234 const WebRtcRTPHeader* rtp_header) {
235 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; 235 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
236 rtp_header_with_ntp.ntp_time_ms = 236 rtp_header_with_ntp.ntp_time_ms =
237 ntp_estimator_.Estimate(rtp_header->header.timestamp); 237 ntp_estimator_.Estimate(rtp_header->header.timestamp);
238 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); 238 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp);
239 packet.timesNacked = 239 packet.timesNacked =
240 nack_module_ ? nack_module_->OnReceivedPacket(packet) : -1; 240 nack_module_ ? nack_module_->OnReceivedPacket(packet) : -1;
241 241
(...skipping 30 matching lines...) Expand all
272 packet.dataPtr = data; 272 packet.dataPtr = data;
273 } 273 }
274 274
275 packet_buffer_->InsertPacket(&packet); 275 packet_buffer_->InsertPacket(&packet);
276 return 0; 276 return 0;
277 } 277 }
278 278
279 // TODO(nisse): Try to delete this method. Obstacles: It is used by 279 // TODO(nisse): Try to delete this method. Obstacles: It is used by
280 // ParseAndHandleEncapsulatingHeader, for handling Rtx packets, and 280 // ParseAndHandleEncapsulatingHeader, for handling Rtx packets, and
281 // for callbacks from |ulpfec_receiver_|. 281 // for callbacks from |ulpfec_receiver_|.
282 void RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, 282 void RtpVideoStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet,
283 size_t rtp_packet_length) { 283 size_t rtp_packet_length) {
284 RTPHeader header; 284 RTPHeader header;
285 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { 285 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
286 return; 286 return;
287 } 287 }
288 header.payload_type_frequency = kVideoPayloadTypeFrequency; 288 header.payload_type_frequency = kVideoPayloadTypeFrequency;
289 bool in_order = IsPacketInOrder(header); 289 bool in_order = IsPacketInOrder(header);
290 ReceivePacket(rtp_packet, rtp_packet_length, header, in_order); 290 ReceivePacket(rtp_packet, rtp_packet_length, header, in_order);
291 } 291 }
292 292
293 // TODO(pbos): Remove as soon as audio can handle a changing payload type 293 // TODO(pbos): Remove as soon as audio can handle a changing payload type
294 // without this callback. 294 // without this callback.
295 int32_t RtpStreamReceiver::OnInitializeDecoder( 295 int32_t RtpVideoStreamReceiver::OnInitializeDecoder(
296 const int8_t payload_type, 296 const int8_t payload_type,
297 const char payload_name[RTP_PAYLOAD_NAME_SIZE], 297 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
298 const int frequency, 298 const int frequency,
299 const size_t channels, 299 const size_t channels,
300 const uint32_t rate) { 300 const uint32_t rate) {
301 RTC_NOTREACHED(); 301 RTC_NOTREACHED();
302 return 0; 302 return 0;
303 } 303 }
304 304
305 void RtpStreamReceiver::OnIncomingSSRCChanged(const uint32_t ssrc) { 305 void RtpVideoStreamReceiver::OnIncomingSSRCChanged(const uint32_t ssrc) {
306 rtp_rtcp_->SetRemoteSSRC(ssrc); 306 rtp_rtcp_->SetRemoteSSRC(ssrc);
307 } 307 }
308 308
309 // This method handles both regular RTP packets and packets recovered 309 // This method handles both regular RTP packets and packets recovered
310 // via FlexFEC. 310 // via FlexFEC.
311 void RtpStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) { 311 void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) {
312 { 312 {
313 rtc::CritScope lock(&receive_cs_); 313 rtc::CritScope lock(&receive_cs_);
314 if (!receiving_) { 314 if (!receiving_) {
315 return; 315 return;
316 } 316 }
317 317
318 if (!packet.recovered()) { 318 if (!packet.recovered()) {
319 int64_t now_ms = clock_->TimeInMilliseconds(); 319 int64_t now_ms = clock_->TimeInMilliseconds();
320 320
321 // Periodically log the RTP header of incoming packets. 321 // Periodically log the RTP header of incoming packets.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // Receive statistics will be reset if the payload type changes (make sure 357 // Receive statistics will be reset if the payload type changes (make sure
358 // that the first packet is included in the stats). 358 // that the first packet is included in the stats).
359 if (!packet.recovered()) { 359 if (!packet.recovered()) {
360 // TODO(nisse): We should pass a recovered flag to stats, to aid 360 // TODO(nisse): We should pass a recovered flag to stats, to aid
361 // fixing bug bugs.webrtc.org/6339. 361 // fixing bug bugs.webrtc.org/6339.
362 rtp_receive_statistics_->IncomingPacket( 362 rtp_receive_statistics_->IncomingPacket(
363 header, packet.size(), IsPacketRetransmitted(header, in_order)); 363 header, packet.size(), IsPacketRetransmitted(header, in_order));
364 } 364 }
365 } 365 }
366 366
367 int32_t RtpStreamReceiver::RequestKeyFrame() { 367 int32_t RtpVideoStreamReceiver::RequestKeyFrame() {
368 return rtp_rtcp_->RequestKeyFrame(); 368 return rtp_rtcp_->RequestKeyFrame();
369 } 369 }
370 370
371 bool RtpStreamReceiver::IsUlpfecEnabled() const { 371 bool RtpVideoStreamReceiver::IsUlpfecEnabled() const {
372 return config_.rtp.ulpfec.ulpfec_payload_type != -1; 372 return config_.rtp.ulpfec.ulpfec_payload_type != -1;
373 } 373 }
374 374
375 bool RtpStreamReceiver::IsRedEnabled() const { 375 bool RtpVideoStreamReceiver::IsRedEnabled() const {
376 return config_.rtp.ulpfec.red_payload_type != -1; 376 return config_.rtp.ulpfec.red_payload_type != -1;
377 } 377 }
378 378
379 bool RtpStreamReceiver::IsRetransmissionsEnabled() const { 379 bool RtpVideoStreamReceiver::IsRetransmissionsEnabled() const {
380 return config_.rtp.nack.rtp_history_ms > 0; 380 return config_.rtp.nack.rtp_history_ms > 0;
381 } 381 }
382 382
383 void RtpStreamReceiver::RequestPacketRetransmit( 383 void RtpVideoStreamReceiver::RequestPacketRetransmit(
384 const std::vector<uint16_t>& sequence_numbers) { 384 const std::vector<uint16_t>& sequence_numbers) {
385 rtp_rtcp_->SendNack(sequence_numbers); 385 rtp_rtcp_->SendNack(sequence_numbers);
386 } 386 }
387 387
388 int32_t RtpStreamReceiver::ResendPackets(const uint16_t* sequence_numbers, 388 int32_t RtpVideoStreamReceiver::ResendPackets(const uint16_t* sequence_numbers,
389 uint16_t length) { 389 uint16_t length) {
390 return rtp_rtcp_->SendNACK(sequence_numbers, length); 390 return rtp_rtcp_->SendNACK(sequence_numbers, length);
391 } 391 }
392 392
393 void RtpStreamReceiver::OnReceivedFrame( 393 void RtpVideoStreamReceiver::OnReceivedFrame(
394 std::unique_ptr<video_coding::RtpFrameObject> frame) { 394 std::unique_ptr<video_coding::RtpFrameObject> frame) {
395
396 if (!has_received_frame_) { 395 if (!has_received_frame_) {
397 has_received_frame_ = true; 396 has_received_frame_ = true;
398 if (frame->FrameType() != kVideoFrameKey) 397 if (frame->FrameType() != kVideoFrameKey)
399 keyframe_request_sender_->RequestKeyFrame(); 398 keyframe_request_sender_->RequestKeyFrame();
400 } 399 }
401 400
402 if (!frame->delayed_by_retransmission()) 401 if (!frame->delayed_by_retransmission())
403 timing_->IncomingTimestamp(frame->timestamp, clock_->TimeInMilliseconds()); 402 timing_->IncomingTimestamp(frame->timestamp, clock_->TimeInMilliseconds());
404 reference_finder_->ManageFrame(std::move(frame)); 403 reference_finder_->ManageFrame(std::move(frame));
405 } 404 }
406 405
407 void RtpStreamReceiver::OnCompleteFrame( 406 void RtpVideoStreamReceiver::OnCompleteFrame(
408 std::unique_ptr<video_coding::FrameObject> frame) { 407 std::unique_ptr<video_coding::FrameObject> frame) {
409 { 408 {
410 rtc::CritScope lock(&last_seq_num_cs_); 409 rtc::CritScope lock(&last_seq_num_cs_);
411 video_coding::RtpFrameObject* rtp_frame = 410 video_coding::RtpFrameObject* rtp_frame =
412 static_cast<video_coding::RtpFrameObject*>(frame.get()); 411 static_cast<video_coding::RtpFrameObject*>(frame.get());
413 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); 412 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num();
414 } 413 }
415 complete_frame_callback_->OnCompleteFrame(std::move(frame)); 414 complete_frame_callback_->OnCompleteFrame(std::move(frame));
416 } 415 }
417 416
418 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 417 void RtpVideoStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms,
418 int64_t max_rtt_ms) {
419 if (nack_module_) 419 if (nack_module_)
420 nack_module_->UpdateRtt(max_rtt_ms); 420 nack_module_->UpdateRtt(max_rtt_ms);
421 } 421 }
422 422
423 rtc::Optional<int64_t> RtpStreamReceiver::LastReceivedPacketMs() const { 423 rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedPacketMs() const {
424 return packet_buffer_->LastReceivedPacketMs(); 424 return packet_buffer_->LastReceivedPacketMs();
425 } 425 }
426 426
427 rtc::Optional<int64_t> RtpStreamReceiver::LastReceivedKeyframePacketMs() const { 427 rtc::Optional<int64_t> RtpVideoStreamReceiver::LastReceivedKeyframePacketMs()
428 const {
428 return packet_buffer_->LastReceivedKeyframePacketMs(); 429 return packet_buffer_->LastReceivedKeyframePacketMs();
429 } 430 }
430 431
431 void RtpStreamReceiver::ReceivePacket(const uint8_t* packet, 432 void RtpVideoStreamReceiver::ReceivePacket(const uint8_t* packet,
432 size_t packet_length, 433 size_t packet_length,
433 const RTPHeader& header, 434 const RTPHeader& header,
434 bool in_order) { 435 bool in_order) {
435 if (rtp_payload_registry_.IsEncapsulated(header)) { 436 if (rtp_payload_registry_.IsEncapsulated(header)) {
436 ParseAndHandleEncapsulatingHeader(packet, packet_length, header); 437 ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
437 return; 438 return;
438 } 439 }
439 const uint8_t* payload = packet + header.headerLength; 440 const uint8_t* payload = packet + header.headerLength;
440 assert(packet_length >= header.headerLength); 441 assert(packet_length >= header.headerLength);
441 size_t payload_length = packet_length - header.headerLength; 442 size_t payload_length = packet_length - header.headerLength;
442 PayloadUnion payload_specific; 443 PayloadUnion payload_specific;
443 if (!rtp_payload_registry_.GetPayloadSpecifics(header.payloadType, 444 if (!rtp_payload_registry_.GetPayloadSpecifics(header.payloadType,
444 &payload_specific)) { 445 &payload_specific)) {
445 return; 446 return;
446 } 447 }
447 rtp_receiver_->IncomingRtpPacket(header, payload, payload_length, 448 rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
448 payload_specific, in_order); 449 payload_specific, in_order);
449 } 450 }
450 451
451 void RtpStreamReceiver::ParseAndHandleEncapsulatingHeader( 452 void RtpVideoStreamReceiver::ParseAndHandleEncapsulatingHeader(
452 const uint8_t* packet, size_t packet_length, const RTPHeader& header) { 453 const uint8_t* packet, size_t packet_length, const RTPHeader& header) {
453 if (rtp_payload_registry_.IsRed(header)) { 454 if (rtp_payload_registry_.IsRed(header)) {
454 int8_t ulpfec_pt = rtp_payload_registry_.ulpfec_payload_type(); 455 int8_t ulpfec_pt = rtp_payload_registry_.ulpfec_payload_type();
455 if (packet[header.headerLength] == ulpfec_pt) { 456 if (packet[header.headerLength] == ulpfec_pt) {
456 rtp_receive_statistics_->FecPacketReceived(header, packet_length); 457 rtp_receive_statistics_->FecPacketReceived(header, packet_length);
457 // Notify video_receiver about received FEC packets to avoid NACKing these 458 // Notify video_receiver about received FEC packets to avoid NACKing these
458 // packets. 459 // packets.
459 NotifyReceiverOfFecPacket(header); 460 NotifyReceiverOfFecPacket(header);
460 } 461 }
461 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length, 462 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length,
(...skipping 24 matching lines...) Expand all
486 << header.ssrc << " payload type: " 487 << header.ssrc << " payload type: "
487 << static_cast<int>(header.payloadType); 488 << static_cast<int>(header.payloadType);
488 return; 489 return;
489 } 490 }
490 restored_packet_in_use_ = true; 491 restored_packet_in_use_ = true;
491 OnRecoveredPacket(restored_packet_, packet_length); 492 OnRecoveredPacket(restored_packet_, packet_length);
492 restored_packet_in_use_ = false; 493 restored_packet_in_use_ = false;
493 } 494 }
494 } 495 }
495 496
496 void RtpStreamReceiver::NotifyReceiverOfFecPacket(const RTPHeader& header) { 497 void RtpVideoStreamReceiver::NotifyReceiverOfFecPacket(
498 const RTPHeader& header) {
497 int8_t last_media_payload_type = 499 int8_t last_media_payload_type =
498 rtp_payload_registry_.last_received_media_payload_type(); 500 rtp_payload_registry_.last_received_media_payload_type();
499 if (last_media_payload_type < 0) { 501 if (last_media_payload_type < 0) {
500 LOG(LS_WARNING) << "Failed to get last media payload type."; 502 LOG(LS_WARNING) << "Failed to get last media payload type.";
501 return; 503 return;
502 } 504 }
503 // Fake an empty media packet. 505 // Fake an empty media packet.
504 WebRtcRTPHeader rtp_header = {}; 506 WebRtcRTPHeader rtp_header = {};
505 rtp_header.header = header; 507 rtp_header.header = header;
506 rtp_header.header.payloadType = last_media_payload_type; 508 rtp_header.header.payloadType = last_media_payload_type;
(...skipping 11 matching lines...) Expand all
518 } 520 }
519 rtp_header.type.Video.content_type = VideoContentType::UNSPECIFIED; 521 rtp_header.type.Video.content_type = VideoContentType::UNSPECIFIED;
520 if (header.extension.hasVideoContentType) { 522 if (header.extension.hasVideoContentType) {
521 rtp_header.type.Video.content_type = header.extension.videoContentType; 523 rtp_header.type.Video.content_type = header.extension.videoContentType;
522 } 524 }
523 rtp_header.type.Video.playout_delay = header.extension.playout_delay; 525 rtp_header.type.Video.playout_delay = header.extension.playout_delay;
524 526
525 OnReceivedPayloadData(nullptr, 0, &rtp_header); 527 OnReceivedPayloadData(nullptr, 0, &rtp_header);
526 } 528 }
527 529
528 bool RtpStreamReceiver::DeliverRtcp(const uint8_t* rtcp_packet, 530 bool RtpVideoStreamReceiver::DeliverRtcp(const uint8_t* rtcp_packet,
529 size_t rtcp_packet_length) { 531 size_t rtcp_packet_length) {
530 { 532 {
531 rtc::CritScope lock(&receive_cs_); 533 rtc::CritScope lock(&receive_cs_);
532 if (!receiving_) { 534 if (!receiving_) {
533 return false; 535 return false;
534 } 536 }
535 } 537 }
536 538
537 rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length); 539 rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
538 540
539 int64_t rtt = 0; 541 int64_t rtt = 0;
540 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), &rtt, nullptr, nullptr, nullptr); 542 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), &rtt, nullptr, nullptr, nullptr);
541 if (rtt == 0) { 543 if (rtt == 0) {
542 // Waiting for valid rtt. 544 // Waiting for valid rtt.
543 return true; 545 return true;
544 } 546 }
545 uint32_t ntp_secs = 0; 547 uint32_t ntp_secs = 0;
546 uint32_t ntp_frac = 0; 548 uint32_t ntp_frac = 0;
547 uint32_t rtp_timestamp = 0; 549 uint32_t rtp_timestamp = 0;
548 if (rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, nullptr, nullptr, 550 if (rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, nullptr, nullptr,
549 &rtp_timestamp) != 0) { 551 &rtp_timestamp) != 0) {
550 // Waiting for RTCP. 552 // Waiting for RTCP.
551 return true; 553 return true;
552 } 554 }
553 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); 555 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
554 556
555 return true; 557 return true;
556 } 558 }
557 559
558 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { 560 void RtpVideoStreamReceiver::FrameContinuous(uint16_t picture_id) {
559 if (!nack_module_) 561 if (!nack_module_)
560 return; 562 return;
561 563
562 int seq_num = -1; 564 int seq_num = -1;
563 { 565 {
564 rtc::CritScope lock(&last_seq_num_cs_); 566 rtc::CritScope lock(&last_seq_num_cs_);
565 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); 567 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
566 if (seq_num_it != last_seq_num_for_pic_id_.end()) 568 if (seq_num_it != last_seq_num_for_pic_id_.end())
567 seq_num = seq_num_it->second; 569 seq_num = seq_num_it->second;
568 } 570 }
569 if (seq_num != -1) 571 if (seq_num != -1)
570 nack_module_->ClearUpTo(seq_num); 572 nack_module_->ClearUpTo(seq_num);
571 } 573 }
572 574
573 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { 575 void RtpVideoStreamReceiver::FrameDecoded(uint16_t picture_id) {
574 int seq_num = -1; 576 int seq_num = -1;
575 { 577 {
576 rtc::CritScope lock(&last_seq_num_cs_); 578 rtc::CritScope lock(&last_seq_num_cs_);
577 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); 579 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
578 if (seq_num_it != last_seq_num_for_pic_id_.end()) { 580 if (seq_num_it != last_seq_num_for_pic_id_.end()) {
579 seq_num = seq_num_it->second; 581 seq_num = seq_num_it->second;
580 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), 582 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(),
581 ++seq_num_it); 583 ++seq_num_it);
582 } 584 }
583 } 585 }
584 if (seq_num != -1) { 586 if (seq_num != -1) {
585 packet_buffer_->ClearTo(seq_num); 587 packet_buffer_->ClearTo(seq_num);
586 reference_finder_->ClearTo(seq_num); 588 reference_finder_->ClearTo(seq_num);
587 } 589 }
588 } 590 }
589 591
590 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { 592 void RtpVideoStreamReceiver::SignalNetworkState(NetworkState state) {
591 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode 593 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode
592 : RtcpMode::kOff); 594 : RtcpMode::kOff);
593 } 595 }
594 596
595 void RtpStreamReceiver::StartReceive() { 597 void RtpVideoStreamReceiver::StartReceive() {
596 rtc::CritScope lock(&receive_cs_); 598 rtc::CritScope lock(&receive_cs_);
597 receiving_ = true; 599 receiving_ = true;
598 } 600 }
599 601
600 void RtpStreamReceiver::StopReceive() { 602 void RtpVideoStreamReceiver::StopReceive() {
601 rtc::CritScope lock(&receive_cs_); 603 rtc::CritScope lock(&receive_cs_);
602 receiving_ = false; 604 receiving_ = false;
603 } 605 }
604 606
605 bool RtpStreamReceiver::IsPacketInOrder(const RTPHeader& header) const { 607 bool RtpVideoStreamReceiver::IsPacketInOrder(const RTPHeader& header) const {
606 StreamStatistician* statistician = 608 StreamStatistician* statistician =
607 rtp_receive_statistics_->GetStatistician(header.ssrc); 609 rtp_receive_statistics_->GetStatistician(header.ssrc);
608 if (!statistician) 610 if (!statistician)
609 return false; 611 return false;
610 return statistician->IsPacketInOrder(header.sequenceNumber); 612 return statistician->IsPacketInOrder(header.sequenceNumber);
611 } 613 }
612 614
613 bool RtpStreamReceiver::IsPacketRetransmitted(const RTPHeader& header, 615 bool RtpVideoStreamReceiver::IsPacketRetransmitted(const RTPHeader& header,
614 bool in_order) const { 616 bool in_order) const {
615 // Retransmissions are handled separately if RTX is enabled. 617 // Retransmissions are handled separately if RTX is enabled.
616 if (rtp_payload_registry_.RtxEnabled()) 618 if (rtp_payload_registry_.RtxEnabled())
617 return false; 619 return false;
618 StreamStatistician* statistician = 620 StreamStatistician* statistician =
619 rtp_receive_statistics_->GetStatistician(header.ssrc); 621 rtp_receive_statistics_->GetStatistician(header.ssrc);
620 if (!statistician) 622 if (!statistician)
621 return false; 623 return false;
622 // Check if this is a retransmission. 624 // Check if this is a retransmission.
623 int64_t min_rtt = 0; 625 int64_t min_rtt = 0;
624 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr); 626 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr);
625 return !in_order && 627 return !in_order &&
626 statistician->IsRetransmitOfOldPacket(header, min_rtt); 628 statistician->IsRetransmitOfOldPacket(header, min_rtt);
627 } 629 }
628 630
629 void RtpStreamReceiver::UpdateHistograms() { 631 void RtpVideoStreamReceiver::UpdateHistograms() {
630 FecPacketCounter counter = ulpfec_receiver_->GetPacketCounter(); 632 FecPacketCounter counter = ulpfec_receiver_->GetPacketCounter();
631 if (counter.first_packet_time_ms == -1) 633 if (counter.first_packet_time_ms == -1)
632 return; 634 return;
633 635
634 int64_t elapsed_sec = 636 int64_t elapsed_sec =
635 (clock_->TimeInMilliseconds() - counter.first_packet_time_ms) / 1000; 637 (clock_->TimeInMilliseconds() - counter.first_packet_time_ms) / 1000;
636 if (elapsed_sec < metrics::kMinRunTimeInSeconds) 638 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
637 return; 639 return;
638 640
639 if (counter.num_packets > 0) { 641 if (counter.num_packets > 0) {
640 RTC_HISTOGRAM_PERCENTAGE( 642 RTC_HISTOGRAM_PERCENTAGE(
641 "WebRTC.Video.ReceivedFecPacketsInPercent", 643 "WebRTC.Video.ReceivedFecPacketsInPercent",
642 static_cast<int>(counter.num_fec_packets * 100 / counter.num_packets)); 644 static_cast<int>(counter.num_fec_packets * 100 / counter.num_packets));
643 } 645 }
644 if (counter.num_fec_packets > 0) { 646 if (counter.num_fec_packets > 0) {
645 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.RecoveredMediaPacketsInPercentOfFec", 647 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.RecoveredMediaPacketsInPercentOfFec",
646 static_cast<int>(counter.num_recovered_packets * 648 static_cast<int>(counter.num_recovered_packets *
647 100 / counter.num_fec_packets)); 649 100 / counter.num_fec_packets));
648 } 650 }
649 } 651 }
650 652
651 void RtpStreamReceiver::EnableReceiveRtpHeaderExtension( 653 void RtpVideoStreamReceiver::EnableReceiveRtpHeaderExtension(
652 const std::string& extension, int id) { 654 const std::string& extension, int id) {
653 // One-byte-extension local identifiers are in the range 1-14 inclusive. 655 // One-byte-extension local identifiers are in the range 1-14 inclusive.
654 RTC_DCHECK_GE(id, 1); 656 RTC_DCHECK_GE(id, 1);
655 RTC_DCHECK_LE(id, 14); 657 RTC_DCHECK_LE(id, 14);
656 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); 658 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension));
657 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( 659 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension(
658 StringToRtpExtensionType(extension), id)); 660 StringToRtpExtensionType(extension), id));
659 } 661 }
660 662
661 void RtpStreamReceiver::InsertSpsPpsIntoTracker(uint8_t payload_type) { 663 void RtpVideoStreamReceiver::InsertSpsPpsIntoTracker(uint8_t payload_type) {
662 auto codec_params_it = pt_codec_params_.find(payload_type); 664 auto codec_params_it = pt_codec_params_.find(payload_type);
663 if (codec_params_it == pt_codec_params_.end()) 665 if (codec_params_it == pt_codec_params_.end())
664 return; 666 return;
665 667
666 LOG(LS_INFO) << "Found out of band supplied codec parameters for" 668 LOG(LS_INFO) << "Found out of band supplied codec parameters for"
667 << " payload type: " << static_cast<int>(payload_type); 669 << " payload type: " << static_cast<int>(payload_type);
668 670
669 H264SpropParameterSets sprop_decoder; 671 H264SpropParameterSets sprop_decoder;
670 auto sprop_base64_it = 672 auto sprop_base64_it =
671 codec_params_it->second.find(cricket::kH264FmtpSpropParameterSets); 673 codec_params_it->second.find(cricket::kH264FmtpSpropParameterSets);
672 674
673 if (sprop_base64_it == codec_params_it->second.end()) 675 if (sprop_base64_it == codec_params_it->second.end())
674 return; 676 return;
675 677
676 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) 678 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str()))
677 return; 679 return;
678 680
679 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), 681 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(),
680 sprop_decoder.pps_nalu()); 682 sprop_decoder.pps_nalu());
681 } 683 }
682 684
683 } // namespace webrtc 685 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/rtp_video_stream_receiver.h ('k') | webrtc/video/rtp_video_stream_receiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698