Line data Source code
1 : /*
2 : * Copyright (c) 2011 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/video_coding/packet.h"
12 :
13 : #include <assert.h>
14 :
15 : #include "webrtc/modules/include/module_common_types.h"
16 : #include "webrtc/modules/rtp_rtcp/source/rtp_format_h264.h"
17 :
18 : namespace webrtc {
19 :
20 0 : VCMPacket::VCMPacket()
21 : : payloadType(0),
22 : timestamp(0),
23 : ntp_time_ms_(0),
24 : seqNum(0),
25 : dataPtr(NULL),
26 : sizeBytes(0),
27 : markerBit(false),
28 : timesNacked(-1),
29 : frameType(kEmptyFrame),
30 : codec(kVideoCodecUnknown),
31 : is_first_packet_in_frame(false),
32 : completeNALU(kNaluUnset),
33 : insertStartCode(false),
34 : width(0),
35 : height(0),
36 0 : video_header() {
37 0 : video_header.playout_delay = {-1, -1};
38 0 : }
39 :
40 0 : VCMPacket::VCMPacket(const uint8_t* ptr,
41 : const size_t size,
42 0 : const WebRtcRTPHeader& rtpHeader)
43 0 : : payloadType(rtpHeader.header.payloadType),
44 0 : timestamp(rtpHeader.header.timestamp),
45 0 : ntp_time_ms_(rtpHeader.ntp_time_ms),
46 0 : seqNum(rtpHeader.header.sequenceNumber),
47 : dataPtr(ptr),
48 : sizeBytes(size),
49 0 : markerBit(rtpHeader.header.markerBit),
50 : timesNacked(-1),
51 0 : frameType(rtpHeader.frameType),
52 : codec(kVideoCodecUnknown),
53 0 : is_first_packet_in_frame(rtpHeader.type.Video.is_first_packet_in_frame),
54 : completeNALU(kNaluComplete),
55 : insertStartCode(false),
56 0 : width(rtpHeader.type.Video.width),
57 0 : height(rtpHeader.type.Video.height),
58 0 : video_header(rtpHeader.type.Video) {
59 0 : CopyCodecSpecifics(rtpHeader.type.Video);
60 :
61 0 : if (markerBit) {
62 0 : video_header.rotation = rtpHeader.type.Video.rotation;
63 : }
64 : // Playout decisions are made entirely based on first packet in a frame.
65 0 : if (is_first_packet_in_frame) {
66 0 : video_header.playout_delay = rtpHeader.type.Video.playout_delay;
67 : } else {
68 0 : video_header.playout_delay = {-1, -1};
69 : }
70 0 : }
71 :
72 0 : void VCMPacket::Reset() {
73 0 : payloadType = 0;
74 0 : timestamp = 0;
75 0 : ntp_time_ms_ = 0;
76 0 : seqNum = 0;
77 0 : dataPtr = NULL;
78 0 : sizeBytes = 0;
79 0 : markerBit = false;
80 0 : timesNacked = -1;
81 0 : frameType = kEmptyFrame;
82 0 : codec = kVideoCodecUnknown;
83 0 : is_first_packet_in_frame = false;
84 0 : completeNALU = kNaluUnset;
85 0 : insertStartCode = false;
86 0 : width = 0;
87 0 : height = 0;
88 0 : memset(&video_header, 0, sizeof(RTPVideoHeader));
89 0 : }
90 :
91 0 : void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader) {
92 0 : switch (videoHeader.codec) {
93 : case kRtpVideoVp8:
94 : // Handle all packets within a frame as depending on the previous packet
95 : // TODO(holmer): This should be changed to make fragments independent
96 : // when the VP8 RTP receiver supports fragments.
97 0 : if (is_first_packet_in_frame && markerBit)
98 0 : completeNALU = kNaluComplete;
99 0 : else if (is_first_packet_in_frame)
100 0 : completeNALU = kNaluStart;
101 0 : else if (markerBit)
102 0 : completeNALU = kNaluEnd;
103 : else
104 0 : completeNALU = kNaluIncomplete;
105 :
106 0 : codec = kVideoCodecVP8;
107 0 : return;
108 : case kRtpVideoVp9:
109 0 : if (is_first_packet_in_frame && markerBit)
110 0 : completeNALU = kNaluComplete;
111 0 : else if (is_first_packet_in_frame)
112 0 : completeNALU = kNaluStart;
113 0 : else if (markerBit)
114 0 : completeNALU = kNaluEnd;
115 : else
116 0 : completeNALU = kNaluIncomplete;
117 :
118 0 : codec = kVideoCodecVP9;
119 0 : return;
120 : case kRtpVideoH264:
121 0 : is_first_packet_in_frame = videoHeader.is_first_packet_in_frame;
122 0 : if (is_first_packet_in_frame)
123 0 : insertStartCode = true;
124 :
125 0 : if (is_first_packet_in_frame && markerBit) {
126 0 : completeNALU = kNaluComplete;
127 0 : } else if (is_first_packet_in_frame) {
128 0 : completeNALU = kNaluStart;
129 0 : } else if (markerBit) {
130 0 : completeNALU = kNaluEnd;
131 : } else {
132 0 : completeNALU = kNaluIncomplete;
133 : }
134 0 : codec = kVideoCodecH264;
135 0 : return;
136 : case kRtpVideoGeneric:
137 : case kRtpVideoNone:
138 0 : if (isFirstPacket && markerBit)
139 0 : completeNALU = kNaluComplete;
140 0 : else if (isFirstPacket)
141 0 : completeNALU = kNaluStart;
142 0 : else if (markerBit)
143 0 : completeNALU = kNaluEnd;
144 : else
145 0 : completeNALU = kNaluIncomplete;
146 0 : codec = kVideoCodecUnknown;
147 0 : return;
148 : }
149 : }
150 :
151 : } // namespace webrtc
|