OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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_COMMON_VIDEO_H264_H264_COMMON_H_ |
| 12 #define WEBRTC_COMMON_VIDEO_H264_H264_COMMON_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <vector> |
| 16 |
| 17 #include "webrtc/base/common.h" |
| 18 #include "webrtc/base/buffer.h" |
| 19 |
| 20 namespace webrtc { |
| 21 |
| 22 namespace H264 { |
| 23 // The size of a full NALU start sequence {0 0 0 1}, used for the first NALU |
| 24 // of an access unit, and for SPS and PPS blocks. |
| 25 const size_t kNaluLongStartSequenceSize = 4; |
| 26 |
| 27 // The size of a shortened NALU start sequence {0 0 1}, that may be used if |
| 28 // not the first NALU of an access unit or an SPS or PPS block. |
| 29 const size_t kNaluShortStartSequenceSize = 3; |
| 30 |
| 31 // The size of the NALU type byte (1). |
| 32 const size_t kNaluTypeSize = 1; |
| 33 |
| 34 enum NaluType : uint8_t { |
| 35 kSlice = 1, |
| 36 kIdr = 5, |
| 37 kSei = 6, |
| 38 kSps = 7, |
| 39 kPps = 8, |
| 40 kAud = 9, |
| 41 kEndOfSequence = 10, |
| 42 kEndOfStream = 11, |
| 43 kFiller = 12, |
| 44 kStapA = 24, |
| 45 kFuA = 28 |
| 46 }; |
| 47 |
| 48 enum SliceType : uint8_t { kP = 0, kB = 1, kI = 2, kSp = 3, kSi = 4 }; |
| 49 |
| 50 struct NaluIndex { |
| 51 // Start index of NALU, including start sequence. |
| 52 size_t start_offset; |
| 53 // Start index of NALU payload, typically type header. |
| 54 size_t payload_start_offset; |
| 55 // Length of NALU payload, in bytes, counting from payload_start_offset. |
| 56 size_t payload_size; |
| 57 }; |
| 58 |
| 59 // Returns a vector of the NALU indices in the given buffer. |
| 60 std::vector<NaluIndex> FindNaluIndices(const uint8_t* buffer, |
| 61 size_t buffer_size); |
| 62 |
| 63 // Get the NAL type from the header byte immediately following start sequence. |
| 64 NaluType ParseNaluType(uint8_t data); |
| 65 |
| 66 // Methods for parsing and writing RBSP. See section 7.4.1 of the H264 spec. |
| 67 // |
| 68 // The following sequences are illegal, and need to be escaped when encoding: |
| 69 // 00 00 00 -> 00 00 03 00 |
| 70 // 00 00 01 -> 00 00 03 01 |
| 71 // 00 00 02 -> 00 00 03 02 |
| 72 // And things in the source that look like the emulation byte pattern (00 00 03) |
| 73 // need to have an extra emulation byte added, so it's removed when decoding: |
| 74 // 00 00 03 -> 00 00 03 03 |
| 75 // |
| 76 // Decoding is simply a matter of finding any 00 00 03 sequence and removing |
| 77 // the 03 emulation byte. |
| 78 |
| 79 // Parse the given data and remove any emulation byte escaping. |
| 80 std::unique_ptr<rtc::Buffer> ParseRbsp(const uint8_t* data, size_t length); |
| 81 |
| 82 // Write the given data to the destination buffer, inserting and emulation |
| 83 // bytes in order to escape any data the could be interpreted as a start |
| 84 // sequence. |
| 85 void WriteRbsp(const uint8_t* bytes, size_t length, rtc::Buffer* destination); |
| 86 } // namespace H264 |
| 87 } // namespace webrtc |
| 88 |
| 89 #endif // WEBRTC_COMMON_VIDEO_H264_H264_COMMON_H_ |
OLD | NEW |