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

Side by Side Diff: webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h

Issue 2356793002: Add support for 3-byte headers in VideoToolbox NALU parser. (Closed)
Patch Set: rebase Created 4 years, 2 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 11
12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_ 12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_ 13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_
14 14
15 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" 15 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
16 16
17 #if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) 17 #if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
18 18
19 #include <CoreMedia/CoreMedia.h> 19 #include <CoreMedia/CoreMedia.h>
20 #include <vector>
20 21
21 #include "webrtc/base/buffer.h" 22 #include "webrtc/base/buffer.h"
23 #include "webrtc/common_video/h264/h264_common.h"
22 #include "webrtc/modules/include/module_common_types.h" 24 #include "webrtc/modules/include/module_common_types.h"
23 25
26 using webrtc::H264::NaluIndex;
27
24 namespace webrtc { 28 namespace webrtc {
25 29
26 // Converts a sample buffer emitted from the VideoToolbox encoder into a buffer 30 // Converts a sample buffer emitted from the VideoToolbox encoder into a buffer
27 // suitable for RTP. The sample buffer is in avcc format whereas the rtp buffer 31 // suitable for RTP. The sample buffer is in avcc format whereas the rtp buffer
28 // needs to be in Annex B format. Data is written directly to |annexb_buffer| 32 // needs to be in Annex B format. Data is written directly to |annexb_buffer|
29 // and a new RTPFragmentationHeader is returned in |out_header|. 33 // and a new RTPFragmentationHeader is returned in |out_header|.
30 bool H264CMSampleBufferToAnnexBBuffer( 34 bool H264CMSampleBufferToAnnexBBuffer(
31 CMSampleBufferRef avcc_sample_buffer, 35 CMSampleBufferRef avcc_sample_buffer,
32 bool is_keyframe, 36 bool is_keyframe,
33 rtc::Buffer* annexb_buffer, 37 rtc::Buffer* annexb_buffer,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // If the buffer has no remaining NALUs this will return zero. 76 // If the buffer has no remaining NALUs this will return zero.
73 size_t BytesRemaining() const; 77 size_t BytesRemaining() const;
74 78
75 private: 79 private:
76 // Returns the the next offset that contains NALU data. 80 // Returns the the next offset that contains NALU data.
77 size_t FindNextNaluHeader(const uint8_t* start, 81 size_t FindNextNaluHeader(const uint8_t* start,
78 size_t length, 82 size_t length,
79 size_t offset) const; 83 size_t offset) const;
80 84
81 const uint8_t* const start_; 85 const uint8_t* const start_;
82 size_t offset_; 86 std::vector<NaluIndex> offsets_;
83 size_t next_offset_; 87 std::vector<NaluIndex>::iterator offset_;
84 const size_t length_; 88 const size_t length_;
85 }; 89 };
86 90
87 // Helper class for writing NALUs using avcc format into a buffer. 91 // Helper class for writing NALUs using avcc format into a buffer.
88 class AvccBufferWriter final { 92 class AvccBufferWriter final {
89 public: 93 public:
90 AvccBufferWriter(uint8_t* const avcc_buffer, size_t length); 94 AvccBufferWriter(uint8_t* const avcc_buffer, size_t length);
91 ~AvccBufferWriter() {} 95 ~AvccBufferWriter() {}
92 AvccBufferWriter(const AvccBufferWriter& other) = delete; 96 AvccBufferWriter(const AvccBufferWriter& other) = delete;
93 void operator=(const AvccBufferWriter& other) = delete; 97 void operator=(const AvccBufferWriter& other) = delete;
94 98
95 // Writes the data slice into the buffer. Returns false if there isn't 99 // Writes the data slice into the buffer. Returns false if there isn't
96 // enough space left. 100 // enough space left.
97 bool WriteNalu(const uint8_t* data, size_t data_size); 101 bool WriteNalu(const uint8_t* data, size_t data_size);
98 102
99 // Returns the unused bytes in the buffer. 103 // Returns the unused bytes in the buffer.
100 size_t BytesRemaining() const; 104 size_t BytesRemaining() const;
101 105
102 private: 106 private:
103 uint8_t* const start_; 107 uint8_t* const start_;
104 size_t offset_; 108 size_t offset_;
105 const size_t length_; 109 const size_t length_;
106 }; 110 };
107 111
108 } // namespace webrtc 112 } // namespace webrtc
109 113
110 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) 114 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
111 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_ 115 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_
OLDNEW
« no previous file with comments | « webrtc/common_video/h264/h264_common.cc ('k') | webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698