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