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

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h

Issue 2484913003: Revert of Add a webrtc{en,de}coderfactory implementation for VideoToolbox (Closed)
Patch Set: Created 4 years, 1 month 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
(Empty)
1 /*
2 * Copyright (c) 2015 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
12 #ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_NALU_H_
13 #define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_NALU_H_
14
15 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
16
17 #include <CoreMedia/CoreMedia.h>
18
19 #include "webrtc/base/buffer.h"
20 #include "webrtc/modules/include/module_common_types.h"
21
22 namespace webrtc {
23
24 // Converts a sample buffer emitted from the VideoToolbox encoder into a buffer
25 // suitable for RTP. The sample buffer is in avcc format whereas the rtp buffer
26 // needs to be in Annex B format. Data is written directly to |annexb_buffer|
27 // and a new RTPFragmentationHeader is returned in |out_header|.
28 bool H264CMSampleBufferToAnnexBBuffer(
29 CMSampleBufferRef avcc_sample_buffer,
30 bool is_keyframe,
31 rtc::Buffer* annexb_buffer,
32 webrtc::RTPFragmentationHeader** out_header);
33
34 // Converts a buffer received from RTP into a sample buffer suitable for the
35 // VideoToolbox decoder. The RTP buffer is in annex b format whereas the sample
36 // buffer is in avcc format.
37 // If |is_keyframe| is true then |video_format| is ignored since the format will
38 // be read from the buffer. Otherwise |video_format| must be provided.
39 // Caller is responsible for releasing the created sample buffer.
40 bool H264AnnexBBufferToCMSampleBuffer(const uint8_t* annexb_buffer,
41 size_t annexb_buffer_size,
42 CMVideoFormatDescriptionRef video_format,
43 CMSampleBufferRef* out_sample_buffer);
44
45 // Returns true if the type of the first NALU in the supplied Annex B buffer is
46 // the SPS type.
47 bool H264AnnexBBufferHasVideoFormatDescription(const uint8_t* annexb_buffer,
48 size_t annexb_buffer_size);
49
50 // Returns a video format description created from the sps/pps information in
51 // the Annex B buffer. If there is no such information, nullptr is returned.
52 // The caller is responsible for releasing the description.
53 CMVideoFormatDescriptionRef CreateVideoFormatDescription(
54 const uint8_t* annexb_buffer,
55 size_t annexb_buffer_size);
56
57 // Helper class for reading NALUs from an RTP Annex B buffer.
58 class AnnexBBufferReader final {
59 public:
60 AnnexBBufferReader(const uint8_t* annexb_buffer, size_t length);
61 ~AnnexBBufferReader() {}
62 AnnexBBufferReader(const AnnexBBufferReader& other) = delete;
63 void operator=(const AnnexBBufferReader& other) = delete;
64
65 // Returns a pointer to the beginning of the next NALU slice without the
66 // header bytes and its length. Returns false if no more slices remain.
67 bool ReadNalu(const uint8_t** out_nalu, size_t* out_length);
68
69 // Returns the number of unread NALU bytes, including the size of the header.
70 // If the buffer has no remaining NALUs this will return zero.
71 size_t BytesRemaining() const;
72
73 private:
74 // Returns the the next offset that contains NALU data.
75 size_t FindNextNaluHeader(const uint8_t* start,
76 size_t length,
77 size_t offset) const;
78
79 const uint8_t* const start_;
80 size_t offset_;
81 size_t next_offset_;
82 const size_t length_;
83 };
84
85 // Helper class for writing NALUs using avcc format into a buffer.
86 class AvccBufferWriter final {
87 public:
88 AvccBufferWriter(uint8_t* const avcc_buffer, size_t length);
89 ~AvccBufferWriter() {}
90 AvccBufferWriter(const AvccBufferWriter& other) = delete;
91 void operator=(const AvccBufferWriter& other) = delete;
92
93 // Writes the data slice into the buffer. Returns false if there isn't
94 // enough space left.
95 bool WriteNalu(const uint8_t* data, size_t data_size);
96
97 // Returns the unused bytes in the buffer.
98 size_t BytesRemaining() const;
99
100 private:
101 uint8_t* const start_;
102 size_t offset_;
103 const size_t length_;
104 };
105
106 } // namespace webrtc
107
108 #endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_NALU_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698