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 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ |
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ |
13 | 13 |
| 14 #include <deque> |
14 #include <queue> | 15 #include <queue> |
15 #include <string> | 16 #include <string> |
16 | 17 |
| 18 #include "webrtc/base/buffer.h" |
17 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
18 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" |
19 | 21 |
20 namespace webrtc { | 22 namespace webrtc { |
21 | 23 |
22 class RtpPacketizerH264 : public RtpPacketizer { | 24 class RtpPacketizerH264 : public RtpPacketizer { |
23 public: | 25 public: |
24 // Initialize with payload from encoder. | 26 // Initialize with payload from encoder. |
25 // The payload_data must be exactly one encoded H264 frame. | 27 // The payload_data must be exactly one encoded H264 frame. |
26 RtpPacketizerH264(FrameType frame_type, size_t max_payload_len); | 28 RtpPacketizerH264(FrameType frame_type, size_t max_payload_len); |
(...skipping 15 matching lines...) Expand all Loading... |
42 size_t* bytes_to_send, | 44 size_t* bytes_to_send, |
43 bool* last_packet) override; | 45 bool* last_packet) override; |
44 | 46 |
45 ProtectionType GetProtectionType() override; | 47 ProtectionType GetProtectionType() override; |
46 | 48 |
47 StorageType GetStorageType(uint32_t retransmission_settings) override; | 49 StorageType GetStorageType(uint32_t retransmission_settings) override; |
48 | 50 |
49 std::string ToString() override; | 51 std::string ToString() override; |
50 | 52 |
51 private: | 53 private: |
52 struct Packet { | 54 // Input fragments (NAL units), with an optionally owned temporary buffer, |
53 Packet(size_t offset, | 55 // used in case the fragment gets modified. |
54 size_t size, | 56 struct Fragment { |
55 bool first_fragment, | 57 Fragment(const uint8_t* buffer, size_t length); |
56 bool last_fragment, | 58 explicit Fragment(const Fragment& fragment); |
57 bool aggregated, | 59 const uint8_t* buffer = nullptr; |
58 uint8_t header) | 60 size_t length = 0; |
59 : offset(offset), | 61 std::unique_ptr<rtc::Buffer> tmp_buffer; |
60 size(size), | 62 }; |
| 63 |
| 64 // A packet unit (H264 packet), to be put into an RTP packet: |
| 65 // If a NAL unit is too large for an RTP packet, this packet unit will |
| 66 // represent a FU-A packet of a single fragment of the NAL unit. |
| 67 // If a NAL unit is small enough to fit within a single RTP packet, this |
| 68 // packet unit may represent a single NAL unit or a STAP-A packet, of which |
| 69 // there may be multiple in a single RTP packet (if so, aggregated = true). |
| 70 struct PacketUnit { |
| 71 PacketUnit(const Fragment& source_fragment, |
| 72 bool first_fragment, |
| 73 bool last_fragment, |
| 74 bool aggregated, |
| 75 uint8_t header) |
| 76 : source_fragment(source_fragment), |
61 first_fragment(first_fragment), | 77 first_fragment(first_fragment), |
62 last_fragment(last_fragment), | 78 last_fragment(last_fragment), |
63 aggregated(aggregated), | 79 aggregated(aggregated), |
64 header(header) {} | 80 header(header) {} |
65 | 81 |
66 size_t offset; | 82 const Fragment source_fragment; |
67 size_t size; | |
68 bool first_fragment; | 83 bool first_fragment; |
69 bool last_fragment; | 84 bool last_fragment; |
70 bool aggregated; | 85 bool aggregated; |
71 uint8_t header; | 86 uint8_t header; |
72 }; | 87 }; |
73 typedef std::queue<Packet> PacketQueue; | |
74 | 88 |
75 void GeneratePackets(); | 89 void GeneratePackets(); |
76 void PacketizeFuA(size_t fragment_offset, size_t fragment_length); | 90 void PacketizeFuA(size_t fragment_index); |
77 int PacketizeStapA(size_t fragment_index, | 91 size_t PacketizeStapA(size_t fragment_index); |
78 size_t fragment_offset, | |
79 size_t fragment_length); | |
80 void NextAggregatePacket(uint8_t* buffer, size_t* bytes_to_send); | 92 void NextAggregatePacket(uint8_t* buffer, size_t* bytes_to_send); |
81 void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send); | 93 void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send); |
82 | 94 |
83 const uint8_t* payload_data_; | |
84 size_t payload_size_; | |
85 const size_t max_payload_len_; | 95 const size_t max_payload_len_; |
86 RTPFragmentationHeader fragmentation_; | 96 std::deque<Fragment> input_fragments_; |
87 PacketQueue packets_; | 97 std::queue<PacketUnit> packets_; |
88 | 98 |
89 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264); | 99 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264); |
90 }; | 100 }; |
91 | 101 |
92 // Depacketizer for H264. | 102 // Depacketizer for H264. |
93 class RtpDepacketizerH264 : public RtpDepacketizer { | 103 class RtpDepacketizerH264 : public RtpDepacketizer { |
94 public: | 104 public: |
95 virtual ~RtpDepacketizerH264() {} | 105 RtpDepacketizerH264(); |
| 106 virtual ~RtpDepacketizerH264(); |
96 | 107 |
97 bool Parse(ParsedPayload* parsed_payload, | 108 bool Parse(ParsedPayload* parsed_payload, |
98 const uint8_t* payload_data, | 109 const uint8_t* payload_data, |
99 size_t payload_data_length) override; | 110 size_t payload_data_length) override; |
| 111 |
| 112 private: |
| 113 bool ParseFuaNalu(RtpDepacketizer::ParsedPayload* parsed_payload, |
| 114 const uint8_t* payload_data); |
| 115 bool ProcessStapAOrSingleNalu(RtpDepacketizer::ParsedPayload* parsed_payload, |
| 116 const uint8_t* payload_data); |
| 117 |
| 118 size_t offset_; |
| 119 size_t length_; |
| 120 std::unique_ptr<rtc::Buffer> modified_buffer_; |
100 }; | 121 }; |
101 } // namespace webrtc | 122 } // namespace webrtc |
102 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ | 123 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ |
OLD | NEW |