niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/rtp_rtcp/source/rtp_receiver_video.h" |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 12 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | #include <string.h> |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 15 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/rtp_rtcp/include/rtp_cvo.h" |
| 19 | #include "modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 20 | #include "modules/rtp_rtcp/source/rtp_format.h" |
| 21 | #include "modules/rtp_rtcp/source/rtp_format_video_generic.h" |
| 22 | #include "modules/rtp_rtcp/source/rtp_utility.h" |
| 23 | #include "rtc_base/checks.h" |
| 24 | #include "rtc_base/logging.h" |
| 25 | #include "rtc_base/trace_event.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 29 | RTPReceiverStrategy* RTPReceiverStrategy::CreateVideoStrategy( |
andresp@webrtc.org | dc80bae | 2014-04-08 11:06:12 +0000 | [diff] [blame] | 30 | RtpData* data_callback) { |
| 31 | return new RTPReceiverVideo(data_callback); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 32 | } |
| 33 | |
andresp@webrtc.org | dc80bae | 2014-04-08 11:06:12 +0000 | [diff] [blame] | 34 | RTPReceiverVideo::RTPReceiverVideo(RtpData* data_callback) |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 35 | : RTPReceiverStrategy(data_callback) { |
| 36 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 38 | RTPReceiverVideo::~RTPReceiverVideo() { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | } |
| 40 | |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 41 | bool RTPReceiverVideo::ShouldReportCsrcChanges(uint8_t payload_type) const { |
phoglund@webrtc.org | 5accd37 | 2013-01-22 12:31:01 +0000 | [diff] [blame] | 42 | // Always do this for video packets. |
| 43 | return true; |
| 44 | } |
| 45 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 46 | int32_t RTPReceiverVideo::OnNewPayloadTypeCreated( |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 47 | int payload_type, |
| 48 | const SdpAudioFormat& audio_format) { |
magjed | 56124bd | 2016-11-24 09:34:46 -0800 | [diff] [blame] | 49 | RTC_NOTREACHED(); |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 50 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | } |
| 52 | |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 53 | int32_t RTPReceiverVideo::ParseRtpPacket(WebRtcRTPHeader* rtp_header, |
| 54 | const PayloadUnion& specific_payload, |
| 55 | bool is_red, |
| 56 | const uint8_t* payload, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 57 | size_t payload_length, |
Niels Möller | bbf389c | 2017-09-26 14:05:05 +0200 | [diff] [blame] | 58 | int64_t timestamp_ms) { |
sprang@webrtc.org | 0200f70 | 2015-02-16 12:06:00 +0000 | [diff] [blame] | 59 | TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "Video::ParseRtp", |
| 60 | "seqnum", rtp_header->header.sequenceNumber, "timestamp", |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 61 | rtp_header->header.timestamp); |
Karl Wiberg | c856dc2 | 2017-09-28 20:13:59 +0200 | [diff] [blame] | 62 | rtp_header->type.Video.codec = |
| 63 | specific_payload.video_payload().videoCodecType; |
pbos@webrtc.org | 30e055c | 2013-09-08 11:15:00 +0000 | [diff] [blame] | 64 | |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 65 | RTC_DCHECK_GE(payload_length, rtp_header->header.paddingLength); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 66 | const size_t payload_data_length = |
pbos@webrtc.org | 30e055c | 2013-09-08 11:15:00 +0000 | [diff] [blame] | 67 | payload_length - rtp_header->header.paddingLength; |
| 68 | |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 69 | if (payload == NULL || payload_data_length == 0) { |
pbos@webrtc.org | 30e055c | 2013-09-08 11:15:00 +0000 | [diff] [blame] | 70 | return data_callback_->OnReceivedPayloadData(NULL, 0, rtp_header) == 0 ? 0 |
| 71 | : -1; |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 72 | } |
pbos@webrtc.org | 30e055c | 2013-09-08 11:15:00 +0000 | [diff] [blame] | 73 | |
skvlad | 98bb664 | 2016-04-07 15:36:45 -0700 | [diff] [blame] | 74 | if (first_packet_received_()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 75 | RTC_LOG(LS_INFO) << "Received first video RTP packet"; |
skvlad | 98bb664 | 2016-04-07 15:36:45 -0700 | [diff] [blame] | 76 | } |
| 77 | |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 78 | // We are not allowed to hold a critical section when calling below functions. |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 79 | std::unique_ptr<RtpDepacketizer> depacketizer( |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 80 | RtpDepacketizer::Create(rtp_header->type.Video.codec)); |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 81 | if (depacketizer.get() == NULL) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 82 | RTC_LOG(LS_ERROR) << "Failed to create depacketizer."; |
pbos@webrtc.org | b5e6bfc | 2014-09-12 11:05:55 +0000 | [diff] [blame] | 83 | return -1; |
| 84 | } |
| 85 | |
pbos@webrtc.org | d42a3ad | 2014-11-07 11:02:12 +0000 | [diff] [blame] | 86 | RtpDepacketizer::ParsedPayload parsed_payload; |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 87 | if (!depacketizer->Parse(&parsed_payload, payload, payload_data_length)) |
| 88 | return -1; |
| 89 | |
pbos@webrtc.org | d42a3ad | 2014-11-07 11:02:12 +0000 | [diff] [blame] | 90 | rtp_header->frameType = parsed_payload.frame_type; |
| 91 | rtp_header->type = parsed_payload.type; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 92 | rtp_header->type.Video.rotation = kVideoRotation_0; |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 93 | rtp_header->type.Video.content_type = VideoContentType::UNSPECIFIED; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 94 | rtp_header->type.Video.video_timing.flags = TimingFrameFlags::kInvalid; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 95 | |
| 96 | // Retrieve the video rotation information. |
| 97 | if (rtp_header->header.extension.hasVideoRotation) { |
magjed | 71eb61c | 2016-09-08 03:24:58 -0700 | [diff] [blame] | 98 | rtp_header->type.Video.rotation = |
| 99 | rtp_header->header.extension.videoRotation; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 100 | } |
| 101 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 102 | if (rtp_header->header.extension.hasVideoContentType) { |
| 103 | rtp_header->type.Video.content_type = |
| 104 | rtp_header->header.extension.videoContentType; |
| 105 | } |
| 106 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 107 | if (rtp_header->header.extension.has_video_timing) { |
| 108 | rtp_header->type.Video.video_timing = |
| 109 | rtp_header->header.extension.video_timing; |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 110 | } |
| 111 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 112 | rtp_header->type.Video.playout_delay = |
| 113 | rtp_header->header.extension.playout_delay; |
| 114 | |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 115 | return data_callback_->OnReceivedPayloadData(parsed_payload.payload, |
| 116 | parsed_payload.payload_length, |
pbos@webrtc.org | d42a3ad | 2014-11-07 11:02:12 +0000 | [diff] [blame] | 117 | rtp_header) == 0 |
pbos@webrtc.org | 730d270 | 2014-09-29 08:00:22 +0000 | [diff] [blame] | 118 | ? 0 |
| 119 | : -1; |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 120 | } |
| 121 | |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 122 | RTPAliveType RTPReceiverVideo::ProcessDeadOrAlive( |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 123 | uint16_t last_payload_length) const { |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 124 | return kRtpDead; |
| 125 | } |
| 126 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 127 | int32_t RTPReceiverVideo::InvokeOnInitializeDecoder( |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 128 | RtpFeedback* callback, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 129 | int8_t payload_type, |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 130 | const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 131 | const PayloadUnion& specific_payload) const { |
Peter Boström | ed3277b | 2016-02-02 15:40:04 +0100 | [diff] [blame] | 132 | // TODO(pbos): Remove as soon as audio can handle a changing payload type |
| 133 | // without this callback. |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 137 | } // namespace webrtc |