Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_h264.h

Issue 1979443004: Add H264 bitstream rewriting to limit frame reordering marker in header (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rewriting on the receiver side as well Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
17 #include "webrtc/base/constructormagic.h" 18 #include "webrtc/base/constructormagic.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" 19 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h"
19 20
21 namespace rtc {
22 class ByteBufferWriter;
23 }
24
20 namespace webrtc { 25 namespace webrtc {
21 26
22 class RtpPacketizerH264 : public RtpPacketizer { 27 class RtpPacketizerH264 : public RtpPacketizer {
23 public: 28 public:
24 // Initialize with payload from encoder. 29 // Initialize with payload from encoder.
25 // The payload_data must be exactly one encoded H264 frame. 30 // The payload_data must be exactly one encoded H264 frame.
26 RtpPacketizerH264(FrameType frame_type, size_t max_payload_len); 31 RtpPacketizerH264(FrameType frame_type, size_t max_payload_len);
27 32
28 virtual ~RtpPacketizerH264(); 33 virtual ~RtpPacketizerH264();
29 34
(...skipping 12 matching lines...) Expand all
42 size_t* bytes_to_send, 47 size_t* bytes_to_send,
43 bool* last_packet) override; 48 bool* last_packet) override;
44 49
45 ProtectionType GetProtectionType() override; 50 ProtectionType GetProtectionType() override;
46 51
47 StorageType GetStorageType(uint32_t retransmission_settings) override; 52 StorageType GetStorageType(uint32_t retransmission_settings) override;
48 53
49 std::string ToString() override; 54 std::string ToString() override;
50 55
51 private: 56 private:
52 struct Packet { 57 // Input fragments (NAL units), with an optionally owned temporary buffer,
53 Packet(size_t offset, 58 // used in case the fragment gets modified.
54 size_t size, 59 struct Fragment {
55 bool first_fragment, 60 Fragment(const uint8_t* buffer, size_t length);
56 bool last_fragment, 61 explicit Fragment(std::unique_ptr<rtc::ByteBufferWriter> buffer);
57 bool aggregated, 62 explicit Fragment(const Fragment& fragment);
58 uint8_t header) 63 const uint8_t* buffer = nullptr;
59 : offset(offset), 64 size_t length = 0;
60 size(size), 65 std::unique_ptr<const uint8_t[]> tmp_buffer;
66 };
67
68 // A packet unit (H264 packet), to be put into an RTP packet:
69 // If a NAL unit is too large for an RTP packet, this packet unit will
70 // represent a FU-A packet of a single fragment of the NAL unit.
71 // If a NAL unit is small enough to fit within a single RTP packet, this
72 // packet unit will represent a single STAP-A packet, of which there may be
73 // multiple in a single RTP packet, if the NAL units are small enough.
74 struct PacketUnit {
75 PacketUnit(const Fragment& source_fragment,
76 bool first_fragment,
77 bool last_fragment,
78 bool aggregated,
79 uint8_t header)
80 : source_fragment(source_fragment),
61 first_fragment(first_fragment), 81 first_fragment(first_fragment),
62 last_fragment(last_fragment), 82 last_fragment(last_fragment),
63 aggregated(aggregated), 83 aggregated(aggregated),
64 header(header) {} 84 header(header) {}
65 85
66 size_t offset; 86 const Fragment source_fragment;
67 size_t size;
68 bool first_fragment; 87 bool first_fragment;
69 bool last_fragment; 88 bool last_fragment;
70 bool aggregated; 89 bool aggregated;
71 uint8_t header; 90 uint8_t header;
72 }; 91 };
73 typedef std::queue<Packet> PacketQueue;
74 92
75 void GeneratePackets(); 93 void GeneratePackets();
76 void PacketizeFuA(size_t fragment_offset, size_t fragment_length); 94 void PacketizeFuA(size_t fragment_index);
77 int PacketizeStapA(size_t fragment_index, 95 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); 96 void NextAggregatePacket(uint8_t* buffer, size_t* bytes_to_send);
81 void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send); 97 void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send);
82 98
83 const uint8_t* payload_data_;
84 size_t payload_size_;
85 const size_t max_payload_len_; 99 const size_t max_payload_len_;
86 RTPFragmentationHeader fragmentation_; 100 std::deque<Fragment> input_fragments_;
87 PacketQueue packets_; 101 std::queue<PacketUnit> packets_;
88 102
89 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264); 103 RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264);
90 }; 104 };
91 105
92 // Depacketizer for H264. 106 // Depacketizer for H264.
93 class RtpDepacketizerH264 : public RtpDepacketizer { 107 class RtpDepacketizerH264 : public RtpDepacketizer {
94 public: 108 public:
95 virtual ~RtpDepacketizerH264() {} 109 RtpDepacketizerH264();
110 virtual ~RtpDepacketizerH264();
96 111
97 bool Parse(ParsedPayload* parsed_payload, 112 bool Parse(ParsedPayload* parsed_payload,
98 const uint8_t* payload_data, 113 const uint8_t* payload_data,
99 size_t payload_data_length) override; 114 size_t payload_data_length) override;
115
116 private:
117 bool ParseFuaNalu(RtpDepacketizer::ParsedPayload* parsed_payload,
118 const uint8_t* payload_data);
119 bool ParseSingleNalu(RtpDepacketizer::ParsedPayload* parsed_payload,
120 const uint8_t* payload_data);
121
122 size_t offset_;
123 size_t length_;
124 std::unique_ptr<uint8_t[]> modified_buffer_;
100 }; 125 };
101 } // namespace webrtc 126 } // namespace webrtc
102 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_ 127 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698