OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 <string> | 11 #include <string> |
12 | 12 |
13 #include "webrtc/base/logging.h" | 13 #include "webrtc/base/logging.h" |
14 #include "webrtc/modules/include/module_common_types.h" | 14 #include "webrtc/modules/include/module_common_types.h" |
15 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" | 15 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
16 | 17 |
17 namespace webrtc { | 18 namespace webrtc { |
18 | 19 |
19 static const size_t kGenericHeaderLength = 1; | 20 static const size_t kGenericHeaderLength = 1; |
20 | 21 |
21 RtpPacketizerGeneric::RtpPacketizerGeneric(FrameType frame_type, | 22 RtpPacketizerGeneric::RtpPacketizerGeneric(FrameType frame_type, |
22 size_t max_payload_len) | 23 size_t max_payload_len) |
23 : payload_data_(NULL), | 24 : payload_data_(NULL), |
24 payload_size_(0), | 25 payload_size_(0), |
25 max_payload_len_(max_payload_len - kGenericHeaderLength), | 26 max_payload_len_(max_payload_len - kGenericHeaderLength), |
(...skipping 12 matching lines...) Expand all Loading... |
38 | 39 |
39 // Fragment packets more evenly by splitting the payload up evenly. | 40 // Fragment packets more evenly by splitting the payload up evenly. |
40 size_t num_packets = | 41 size_t num_packets = |
41 (payload_size_ + max_payload_len_ - 1) / max_payload_len_; | 42 (payload_size_ + max_payload_len_ - 1) / max_payload_len_; |
42 payload_length_ = (payload_size_ + num_packets - 1) / num_packets; | 43 payload_length_ = (payload_size_ + num_packets - 1) / num_packets; |
43 assert(payload_length_ <= max_payload_len_); | 44 assert(payload_length_ <= max_payload_len_); |
44 | 45 |
45 generic_header_ = RtpFormatVideoGeneric::kFirstPacketBit; | 46 generic_header_ = RtpFormatVideoGeneric::kFirstPacketBit; |
46 } | 47 } |
47 | 48 |
48 bool RtpPacketizerGeneric::NextPacket(uint8_t* buffer, | 49 bool RtpPacketizerGeneric::NextPacket(RtpPacketToSend* packet, |
49 size_t* bytes_to_send, | |
50 bool* last_packet) { | 50 bool* last_packet) { |
| 51 RTC_DCHECK(packet); |
| 52 RTC_DCHECK(last_packet); |
51 if (payload_size_ < payload_length_) { | 53 if (payload_size_ < payload_length_) { |
52 payload_length_ = payload_size_; | 54 payload_length_ = payload_size_; |
53 } | 55 } |
54 | 56 |
55 payload_size_ -= payload_length_; | 57 payload_size_ -= payload_length_; |
56 *bytes_to_send = payload_length_ + kGenericHeaderLength; | 58 RTC_DCHECK_LE(payload_length_, max_payload_len_); |
57 assert(payload_length_ <= max_payload_len_); | |
58 | 59 |
59 uint8_t* out_ptr = buffer; | 60 uint8_t* out_ptr = |
| 61 packet->AllocatePayload(kGenericHeaderLength + payload_length_); |
60 // Put generic header in packet | 62 // Put generic header in packet |
61 if (frame_type_ == kVideoFrameKey) { | 63 if (frame_type_ == kVideoFrameKey) { |
62 generic_header_ |= RtpFormatVideoGeneric::kKeyFrameBit; | 64 generic_header_ |= RtpFormatVideoGeneric::kKeyFrameBit; |
63 } | 65 } |
64 *out_ptr++ = generic_header_; | 66 out_ptr[0] = generic_header_; |
65 // Remove first-packet bit, following packets are intermediate | 67 // Remove first-packet bit, following packets are intermediate |
66 generic_header_ &= ~RtpFormatVideoGeneric::kFirstPacketBit; | 68 generic_header_ &= ~RtpFormatVideoGeneric::kFirstPacketBit; |
67 | 69 |
68 // Put payload in packet | 70 // Put payload in packet |
69 memcpy(out_ptr, payload_data_, payload_length_); | 71 memcpy(out_ptr + kGenericHeaderLength, payload_data_, payload_length_); |
70 payload_data_ += payload_length_; | 72 payload_data_ += payload_length_; |
71 | 73 |
72 *last_packet = payload_size_ <= 0; | 74 *last_packet = payload_size_ <= 0; |
73 | 75 packet->SetMarker(*last_packet); |
74 return true; | 76 return true; |
75 } | 77 } |
76 | 78 |
77 ProtectionType RtpPacketizerGeneric::GetProtectionType() { | 79 ProtectionType RtpPacketizerGeneric::GetProtectionType() { |
78 return kProtectedPacket; | 80 return kProtectedPacket; |
79 } | 81 } |
80 | 82 |
81 StorageType RtpPacketizerGeneric::GetStorageType( | 83 StorageType RtpPacketizerGeneric::GetStorageType( |
82 uint32_t retransmission_settings) { | 84 uint32_t retransmission_settings) { |
83 return kAllowRetransmission; | 85 return kAllowRetransmission; |
(...skipping 23 matching lines...) Expand all Loading... |
107 (generic_header & RtpFormatVideoGeneric::kFirstPacketBit) != 0; | 109 (generic_header & RtpFormatVideoGeneric::kFirstPacketBit) != 0; |
108 parsed_payload->type.Video.codec = kRtpVideoGeneric; | 110 parsed_payload->type.Video.codec = kRtpVideoGeneric; |
109 parsed_payload->type.Video.width = 0; | 111 parsed_payload->type.Video.width = 0; |
110 parsed_payload->type.Video.height = 0; | 112 parsed_payload->type.Video.height = 0; |
111 | 113 |
112 parsed_payload->payload = payload_data; | 114 parsed_payload->payload = payload_data; |
113 parsed_payload->payload_length = payload_data_length; | 115 parsed_payload->payload_length = payload_data_length; |
114 return true; | 116 return true; |
115 } | 117 } |
116 } // namespace webrtc | 118 } // namespace webrtc |
OLD | NEW |