Line data Source code
1 : /*
2 : * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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 :
11 : #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h"
12 :
13 : #include <assert.h>
14 : #include <string.h>
15 :
16 : #ifdef WIN32
17 : #include <winsock2.h>
18 : #else
19 : #include <arpa/inet.h>
20 : #endif
21 :
22 : #include <memory>
23 :
24 : #include "webrtc/base/checks.h"
25 : #include "webrtc/base/logging.h"
26 : #include "webrtc/base/trace_event.h"
27 : #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
28 : #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
29 : #include "webrtc/modules/rtp_rtcp/source/rtp_format.h"
30 : #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h"
31 : #include "webrtc/modules/rtp_rtcp/source/rtp_format_h264.h"
32 : #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
33 :
34 : namespace webrtc {
35 :
36 0 : RTPReceiverStrategy* RTPReceiverStrategy::CreateVideoStrategy(
37 : RtpData* data_callback) {
38 0 : return new RTPReceiverVideo(data_callback);
39 : }
40 :
41 0 : RTPReceiverVideo::RTPReceiverVideo(RtpData* data_callback)
42 0 : : RTPReceiverStrategy(data_callback) {
43 0 : }
44 :
45 0 : RTPReceiverVideo::~RTPReceiverVideo() {
46 0 : }
47 :
48 0 : bool RTPReceiverVideo::ShouldReportCsrcChanges(uint8_t payload_type) const {
49 : // Always do this for video packets.
50 0 : return true;
51 : }
52 :
53 0 : int32_t RTPReceiverVideo::OnNewPayloadTypeCreated(
54 : const CodecInst& audio_codec) {
55 0 : RTC_NOTREACHED();
56 0 : return 0;
57 : }
58 :
59 0 : int32_t RTPReceiverVideo::ParseRtpPacket(WebRtcRTPHeader* rtp_header,
60 : const PayloadUnion& specific_payload,
61 : bool is_red,
62 : const uint8_t* payload,
63 : size_t payload_length,
64 : int64_t timestamp_ms,
65 : bool is_first_packet) {
66 0 : TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "Video::ParseRtp",
67 : "seqnum", rtp_header->header.sequenceNumber, "timestamp",
68 : rtp_header->header.timestamp);
69 0 : rtp_header->type.Video.codec = specific_payload.Video.videoCodecType;
70 :
71 0 : RTC_DCHECK_GE(payload_length, rtp_header->header.paddingLength);
72 : const size_t payload_data_length =
73 0 : payload_length - rtp_header->header.paddingLength;
74 :
75 0 : if (payload == NULL || payload_data_length == 0) {
76 0 : return data_callback_->OnReceivedPayloadData(NULL, 0, rtp_header) == 0 ? 0
77 0 : : -1;
78 : }
79 :
80 0 : if (first_packet_received_()) {
81 0 : LOG(LS_INFO) << "Received first video RTP packet";
82 : }
83 :
84 : // We are not allowed to hold a critical section when calling below functions.
85 : std::unique_ptr<RtpDepacketizer> depacketizer(
86 0 : RtpDepacketizer::Create(rtp_header->type.Video.codec));
87 0 : if (depacketizer.get() == NULL) {
88 0 : LOG(LS_ERROR) << "Failed to create depacketizer.";
89 0 : return -1;
90 : }
91 :
92 0 : rtp_header->type.Video.is_first_packet_in_frame = is_first_packet;
93 : RtpDepacketizer::ParsedPayload parsed_payload;
94 0 : if (!depacketizer->Parse(&parsed_payload, payload, payload_data_length))
95 0 : return -1;
96 :
97 0 : rtp_header->frameType = parsed_payload.frame_type;
98 0 : rtp_header->type = parsed_payload.type;
99 0 : rtp_header->type.Video.rotation = kVideoRotation_0;
100 :
101 : // Retrieve the video rotation information.
102 0 : if (rtp_header->header.extension.hasVideoRotation) {
103 0 : rtp_header->type.Video.rotation =
104 0 : rtp_header->header.extension.videoRotation;
105 : }
106 :
107 0 : rtp_header->type.Video.playout_delay =
108 : rtp_header->header.extension.playout_delay;
109 :
110 0 : return data_callback_->OnReceivedPayloadData(parsed_payload.payload,
111 : parsed_payload.payload_length,
112 0 : rtp_header) == 0
113 0 : ? 0
114 0 : : -1;
115 : }
116 :
117 0 : RTPAliveType RTPReceiverVideo::ProcessDeadOrAlive(
118 : uint16_t last_payload_length) const {
119 0 : return kRtpDead;
120 : }
121 :
122 0 : int32_t RTPReceiverVideo::InvokeOnInitializeDecoder(
123 : RtpFeedback* callback,
124 : int8_t payload_type,
125 : const char payload_name[RTP_PAYLOAD_NAME_SIZE],
126 : const PayloadUnion& specific_payload) const {
127 : // TODO(pbos): Remove as soon as audio can handle a changing payload type
128 : // without this callback.
129 0 : return 0;
130 : }
131 :
132 : } // namespace webrtc
|