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(std::unique_ptr<rtc::Buffer> buffer); |
57 bool aggregated, | 59 explicit Fragment(const Fragment& fragment); |
58 uint8_t header) | 60 const uint8_t* buffer = nullptr; |
59 : offset(offset), | 61 size_t length = 0; |
60 size(size), | 62 std::unique_ptr<rtc::Buffer> tmp_buffer; |
63 }; | |
64 | |
65 // A packet unit (H264 packet), to be put into an RTP packet: | |
66 // If a NAL unit is too large for an RTP packet, this packet unit will | |
67 // represent a FU-A packet of a single fragment of the NAL unit. | |
68 // If a NAL unit is small enough to fit within a single RTP packet, this | |
69 // packet unit may represent a single NAL unit or a STAP-A packet, of which | |
70 // there may be multiple in a single RTP packet (if so, aggregated = true). | |
71 struct PacketUnit { | |
72 PacketUnit(const Fragment& source_fragment, | |
73 bool first_fragment, | |
74 bool last_fragment, | |
75 bool aggregated, | |
76 uint8_t header) | |
77 : source_fragment(source_fragment), | |
61 first_fragment(first_fragment), | 78 first_fragment(first_fragment), |
62 last_fragment(last_fragment), | 79 last_fragment(last_fragment), |
63 aggregated(aggregated), | 80 aggregated(aggregated), |
64 header(header) {} | 81 header(header) {} |
65 | 82 |
66 size_t offset; | 83 const Fragment source_fragment; |
67 size_t size; | |
68 bool first_fragment; | 84 bool first_fragment; |
69 bool last_fragment; | 85 bool last_fragment; |
70 bool aggregated; | 86 bool aggregated; |
71 uint8_t header; | 87 uint8_t header; |
72 }; | 88 }; |
73 typedef std::queue<Packet> PacketQueue; | |
74 | 89 |
75 void GeneratePackets(); | 90 void GeneratePackets(); |
76 void PacketizeFuA(size_t fragment_offset, size_t fragment_length); | 91 void PacketizeFuA(size_t fragment_index); |
77 int PacketizeStapA(size_t fragment_index, | 92 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); | 93 void NextAggregatePacket(uint8_t* buffer, size_t* bytes_to_send); |
81 void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send); | 94 void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send); |
82 | 95 |
83 const uint8_t* payload_data_; | |
84 size_t payload_size_; | |
85 const size_t max_payload_len_; | 96 const size_t max_payload_len_; |
86 RTPFragmentationHeader fragmentation_; | 97 std::deque<Fragment> input_fragments_; |
87 PacketQueue packets_; | 98 std::queue<PacketUnit> packets_; |
88 | 99 |
89 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264); | 100 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264); |
90 }; | 101 }; |
91 | 102 |
92 // Depacketizer for H264. | 103 // Depacketizer for H264. |
93 class RtpDepacketizerH264 : public RtpDepacketizer { | 104 class RtpDepacketizerH264 : public RtpDepacketizer { |
94 public: | 105 public: |
95 virtual ~RtpDepacketizerH264() {} | 106 RtpDepacketizerH264(); |
107 virtual ~RtpDepacketizerH264(); | |
96 | 108 |
97 bool Parse(ParsedPayload* parsed_payload, | 109 bool Parse(ParsedPayload* parsed_payload, |
98 const uint8_t* payload_data, | 110 const uint8_t* payload_data, |
99 size_t payload_data_length) override; | 111 size_t payload_data_length) override; |
112 | |
113 private: | |
114 bool ParseFuaNalu(RtpDepacketizer::ParsedPayload* parsed_payload, | |
115 const uint8_t* payload_data); | |
116 bool ParseSingleNalu(RtpDepacketizer::ParsedPayload* parsed_payload, | |
117 const uint8_t* payload_data); | |
118 | |
119 size_t offset_; | |
120 size_t length_; | |
121 std::unique_ptr<rtc::Buffer> modified_buffer_; | |
stefan-webrtc
2016/05/22 23:11:50
Did you consider propagating the copy on modify bu
sprang_webrtc
2016/05/25 09:06:03
Yes, but that turned out to be a bit more work tha
stefan-webrtc
2016/05/26 18:08:13
Acknowledged.
sprang_webrtc
2016/05/27 13:12:21
I've talked to Philip about this. We'll need a cop
stefan-webrtc
2016/05/27 20:56:59
Yes, a copy will be needed, at least for the near
sprang_webrtc
2016/05/30 08:57:23
The incoming packet goes out of scope when the Inc
stefan-webrtc
2016/05/30 11:00:55
I was thinking that ownership would be passed on t
sprang_webrtc
2016/05/30 12:39:30
Then I don't think CopyOnWriteBuffer is the way to
danilchap
2016/05/30 12:55:59
CopyOnWriteBuffer is actually a ref-counted rtc::B
| |
100 }; | 122 }; |
101 } // namespace webrtc | 123 } // namespace webrtc |
102 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ | 124 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ |
OLD | NEW |