Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / rtp_rtcp / source / rtp_format_h264.h
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   virtual void SetPayloadData(
30       const uint8_t* payload_data,
31       size_t payload_size,
32       const RTPFragmentationHeader* fragmentation) OVERRIDE;
33
34   // Get the next payload with H264 payload header.
35   // buffer is a pointer to where the output will be written.
36   // bytes_to_send is an output variable that will contain number of bytes
37   // written to buffer. The parameter last_packet is true for the last packet of
38   // the frame, false otherwise (i.e., call the function again to get the
39   // next packet).
40   // Returns true on success or false if there was no payload to packetize.
41   virtual bool NextPacket(uint8_t* buffer,
42                           size_t* bytes_to_send,
43                           bool* last_packet) OVERRIDE;
44
45   virtual ProtectionType GetProtectionType() OVERRIDE;
46
47   virtual StorageType GetStorageType(uint32_t retransmission_settings) OVERRIDE;
48
49   virtual std::string ToString() OVERRIDE;
50
51  private:
52   struct Packet {
53     Packet(size_t offset,
54            size_t size,
55            bool first_fragment,
56            bool last_fragment,
57            bool aggregated,
58            uint8_t header)
59         : offset(offset),
60           size(size),
61           first_fragment(first_fragment),
62           last_fragment(last_fragment),
63           aggregated(aggregated),
64           header(header) {}
65
66     size_t offset;
67     size_t size;
68     bool first_fragment;
69     bool last_fragment;
70     bool aggregated;
71     uint8_t header;
72   };
73   typedef std::queue<Packet> PacketQueue;
74
75   void GeneratePackets();
76   void PacketizeFuA(size_t fragment_offset, size_t fragment_length);
77   int 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);
81   void NextFragmentPacket(uint8_t* buffer, size_t* bytes_to_send);
82
83   const uint8_t* payload_data_;
84   size_t payload_size_;
85   const size_t max_payload_len_;
86   RTPFragmentationHeader fragmentation_;
87   PacketQueue packets_;
88   FrameType frame_type_;
89
90   DISALLOW_COPY_AND_ASSIGN(RtpPacketizerH264);
91 };
92
93 // Depacketizer for H264.
94 class RtpDepacketizerH264 : public RtpDepacketizer {
95  public:
96   virtual ~RtpDepacketizerH264() {}
97
98   virtual bool Parse(ParsedPayload* parsed_payload,
99                      const uint8_t* payload_data,
100                      size_t payload_data_length) OVERRIDE;
101 };
102 }  // namespace webrtc
103 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_H264_H_