• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_
13 
14 #include <queue>
15 #include <string>
16 
17 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h"
18 
19 namespace webrtc {
20 
21 class RtpPacketizerH264 : public RtpPacketizer {
22  public:
23   // Initialize with payload from encoder.
24   // The payload_data must be exactly one encoded H264 frame.
25   RtpPacketizerH264(FrameType frame_type, size_t max_payload_len);
26 
27   virtual ~RtpPacketizerH264();
28 
29   void SetPayloadData(const uint8_t* payload_data,
30                       size_t payload_size,
31                       const RTPFragmentationHeader* fragmentation) override;
32 
33   // Get the next payload with H264 payload header.
34   // buffer is a pointer to where the output will be written.
35   // bytes_to_send is an output variable that will contain number of bytes
36   // written to buffer. The parameter last_packet is true for the last packet of
37   // the frame, false otherwise (i.e., call the function again to get the
38   // next packet).
39   // Returns true on success or false if there was no payload to packetize.
40   bool NextPacket(uint8_t* buffer,
41                   size_t* bytes_to_send,
42                   bool* last_packet) override;
43 
44   ProtectionType GetProtectionType() override;
45 
46   StorageType GetStorageType(uint32_t retransmission_settings) override;
47 
48   std::string ToString() override;
49 
50  private:
51   struct Packet {
PacketPacket52     Packet(size_t offset,
53            size_t size,
54            bool first_fragment,
55            bool last_fragment,
56            bool aggregated,
57            uint8_t header)
58         : offset(offset),
59           size(size),
60           first_fragment(first_fragment),
61           last_fragment(last_fragment),
62           aggregated(aggregated),
63           header(header) {}
64 
65     size_t offset;
66     size_t size;
67     bool first_fragment;
68     bool last_fragment;
69     bool aggregated;
70     uint8_t header;
71   };
72   typedef std::queue<Packet> PacketQueue;
73 
74   void GeneratePackets();
75   void PacketizeFuA(size_t fragment_offset, size_t fragment_length);
76   int PacketizeStapA(size_t fragment_index,
77                      size_t fragment_offset,
78                      size_t fragment_length);
79   void NextAggregatePacket(uint8_t* buffer, size_t* bytes_to_send);
80   void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send);
81 
82   const uint8_t* payload_data_;
83   size_t payload_size_;
84   const size_t max_payload_len_;
85   RTPFragmentationHeader fragmentation_;
86   PacketQueue packets_;
87 
88   RTC_DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264);
89 };
90 
91 // Depacketizer for H264.
92 class RtpDepacketizerH264 : public RtpDepacketizer {
93  public:
~RtpDepacketizerH264()94   virtual ~RtpDepacketizerH264() {}
95 
96   bool Parse(ParsedPayload* parsed_payload,
97              const uint8_t* payload_data,
98              size_t payload_data_length) override;
99 };
100 }  // namespace webrtc
101 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_
102