blob: 65d1831e8d23264c9116210de407474b730a947b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/rtp_rtcp/source/rtp_receiver_video.h"
pwestin@webrtc.org741da942011-09-20 13:52:04 +000012
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000013#include <assert.h>
14#include <string.h>
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +000015
kwiberg84be5112016-04-27 01:19:58 -070016#include <memory>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#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.com470e71d2011-07-07 08:21:25 +000026
27namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000028
wu@webrtc.org822fbd82013-08-15 23:38:54 +000029RTPReceiverStrategy* RTPReceiverStrategy::CreateVideoStrategy(
andresp@webrtc.orgdc80bae2014-04-08 11:06:12 +000030 RtpData* data_callback) {
31 return new RTPReceiverVideo(data_callback);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000032}
33
andresp@webrtc.orgdc80bae2014-04-08 11:06:12 +000034RTPReceiverVideo::RTPReceiverVideo(RtpData* data_callback)
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000035 : RTPReceiverStrategy(data_callback) {
36}
niklase@google.com470e71d2011-07-07 08:21:25 +000037
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +000038RTPReceiverVideo::~RTPReceiverVideo() {
niklase@google.com470e71d2011-07-07 08:21:25 +000039}
40
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000041bool RTPReceiverVideo::ShouldReportCsrcChanges(uint8_t payload_type) const {
phoglund@webrtc.org5accd372013-01-22 12:31:01 +000042 // Always do this for video packets.
43 return true;
44}
45
pbos@webrtc.org2f446732013-04-08 11:08:41 +000046int32_t RTPReceiverVideo::OnNewPayloadTypeCreated(
Karl Wibergc62f6c72017-10-04 12:38:53 +020047 int payload_type,
48 const SdpAudioFormat& audio_format) {
magjed56124bd2016-11-24 09:34:46 -080049 RTC_NOTREACHED();
phoglund@webrtc.org244251a2013-02-04 13:23:07 +000050 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000051}
52
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000053int32_t RTPReceiverVideo::ParseRtpPacket(WebRtcRTPHeader* rtp_header,
54 const PayloadUnion& specific_payload,
55 bool is_red,
56 const uint8_t* payload,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000057 size_t payload_length,
Niels Möllerbbf389c2017-09-26 14:05:05 +020058 int64_t timestamp_ms) {
sprang@webrtc.org0200f702015-02-16 12:06:00 +000059 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "Video::ParseRtp",
60 "seqnum", rtp_header->header.sequenceNumber, "timestamp",
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000061 rtp_header->header.timestamp);
Karl Wibergc856dc22017-09-28 20:13:59 +020062 rtp_header->type.Video.codec =
63 specific_payload.video_payload().videoCodecType;
pbos@webrtc.org30e055c2013-09-08 11:15:00 +000064
henrikg91d6ede2015-09-17 00:24:34 -070065 RTC_DCHECK_GE(payload_length, rtp_header->header.paddingLength);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000066 const size_t payload_data_length =
pbos@webrtc.org30e055c2013-09-08 11:15:00 +000067 payload_length - rtp_header->header.paddingLength;
68
pbos@webrtc.org730d2702014-09-29 08:00:22 +000069 if (payload == NULL || payload_data_length == 0) {
pbos@webrtc.org30e055c2013-09-08 11:15:00 +000070 return data_callback_->OnReceivedPayloadData(NULL, 0, rtp_header) == 0 ? 0
71 : -1;
pbos@webrtc.org730d2702014-09-29 08:00:22 +000072 }
pbos@webrtc.org30e055c2013-09-08 11:15:00 +000073
skvlad98bb6642016-04-07 15:36:45 -070074 if (first_packet_received_()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010075 RTC_LOG(LS_INFO) << "Received first video RTP packet";
skvlad98bb6642016-04-07 15:36:45 -070076 }
77
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000078 // We are not allowed to hold a critical section when calling below functions.
kwiberg84be5112016-04-27 01:19:58 -070079 std::unique_ptr<RtpDepacketizer> depacketizer(
pbos@webrtc.org730d2702014-09-29 08:00:22 +000080 RtpDepacketizer::Create(rtp_header->type.Video.codec));
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000081 if (depacketizer.get() == NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010082 RTC_LOG(LS_ERROR) << "Failed to create depacketizer.";
pbos@webrtc.orgb5e6bfc2014-09-12 11:05:55 +000083 return -1;
84 }
85
pbos@webrtc.orgd42a3ad2014-11-07 11:02:12 +000086 RtpDepacketizer::ParsedPayload parsed_payload;
pbos@webrtc.org730d2702014-09-29 08:00:22 +000087 if (!depacketizer->Parse(&parsed_payload, payload, payload_data_length))
88 return -1;
89
pbos@webrtc.orgd42a3ad2014-11-07 11:02:12 +000090 rtp_header->frameType = parsed_payload.frame_type;
91 rtp_header->type = parsed_payload.type;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -070092 rtp_header->type.Video.rotation = kVideoRotation_0;
ilnik00d802b2017-04-11 10:34:31 -070093 rtp_header->type.Video.content_type = VideoContentType::UNSPECIFIED;
sprangba050a62017-08-18 02:51:12 -070094 rtp_header->type.Video.video_timing.flags = TimingFrameFlags::kInvalid;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -070095
96 // Retrieve the video rotation information.
97 if (rtp_header->header.extension.hasVideoRotation) {
magjed71eb61c2016-09-08 03:24:58 -070098 rtp_header->type.Video.rotation =
99 rtp_header->header.extension.videoRotation;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -0700100 }
101
ilnik00d802b2017-04-11 10:34:31 -0700102 if (rtp_header->header.extension.hasVideoContentType) {
103 rtp_header->type.Video.content_type =
104 rtp_header->header.extension.videoContentType;
105 }
106
ilnik04f4d122017-06-19 07:18:55 -0700107 if (rtp_header->header.extension.has_video_timing) {
108 rtp_header->type.Video.video_timing =
109 rtp_header->header.extension.video_timing;
ilnik04f4d122017-06-19 07:18:55 -0700110 }
111
isheriff6b4b5f32016-06-08 00:24:21 -0700112 rtp_header->type.Video.playout_delay =
113 rtp_header->header.extension.playout_delay;
114
pbos@webrtc.org730d2702014-09-29 08:00:22 +0000115 return data_callback_->OnReceivedPayloadData(parsed_payload.payload,
116 parsed_payload.payload_length,
pbos@webrtc.orgd42a3ad2014-11-07 11:02:12 +0000117 rtp_header) == 0
pbos@webrtc.org730d2702014-09-29 08:00:22 +0000118 ? 0
119 : -1;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +0000120}
121
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +0000122RTPAliveType RTPReceiverVideo::ProcessDeadOrAlive(
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000123 uint16_t last_payload_length) const {
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +0000124 return kRtpDead;
125}
126
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000127int32_t RTPReceiverVideo::InvokeOnInitializeDecoder(
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +0000128 RtpFeedback* callback,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000129 int8_t payload_type,
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +0000130 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000131 const PayloadUnion& specific_payload) const {
Peter Boströmed3277b2016-02-02 15:40:04 +0100132 // TODO(pbos): Remove as soon as audio can handle a changing payload type
133 // without this callback.
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +0000134 return 0;
135}
136
phoglund@webrtc.orga7303bd2013-02-05 15:12:39 +0000137} // namespace webrtc