OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FILTERS_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_ | 5 #ifndef MEDIA_FILTERS_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_ |
6 #define MEDIA_FILTERS_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_ | 6 #define MEDIA_FILTERS_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/basictypes.h" | 12 #include "base/macros.h" |
11 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
12 | 14 |
13 namespace media { | 15 namespace media { |
14 | 16 |
15 namespace mp4 { | 17 namespace mp4 { |
16 struct AVCDecoderConfigurationRecord; | 18 struct AVCDecoderConfigurationRecord; |
17 } | 19 } |
18 | 20 |
19 // H264ToAnnexBBitstreamConverter is a class to convert H.264 bitstream from | 21 // H264ToAnnexBBitstreamConverter is a class to convert H.264 bitstream from |
20 // MP4 format (as specified in ISO/IEC 14496-15) into H.264 bytestream | 22 // MP4 format (as specified in ISO/IEC 14496-15) into H.264 bytestream |
(...skipping 12 matching lines...) Expand all Loading... |
33 // Pointer to buffer containing AVCDecoderConfigurationRecord. | 35 // Pointer to buffer containing AVCDecoderConfigurationRecord. |
34 // configuration_record_size | 36 // configuration_record_size |
35 // Size of the buffer in bytes. | 37 // Size of the buffer in bytes. |
36 // avc_config | 38 // avc_config |
37 // Pointer to place the parsed AVCDecoderConfigurationRecord data into. | 39 // Pointer to place the parsed AVCDecoderConfigurationRecord data into. |
38 // | 40 // |
39 // Returns | 41 // Returns |
40 // Returns true if |configuration_record| was successfully parsed. False | 42 // Returns true if |configuration_record| was successfully parsed. False |
41 // is returned if a parsing error occurred. | 43 // is returned if a parsing error occurred. |
42 // |avc_config| only contains valid data when true is returned. | 44 // |avc_config| only contains valid data when true is returned. |
43 bool ParseConfiguration( | 45 bool ParseConfiguration(const uint8_t* configuration_record, |
44 const uint8* configuration_record, | 46 int configuration_record_size, |
45 int configuration_record_size, | 47 mp4::AVCDecoderConfigurationRecord* avc_config); |
46 mp4::AVCDecoderConfigurationRecord* avc_config); | |
47 | 48 |
48 // Returns the buffer size needed to store the parameter sets in |avc_config| | 49 // Returns the buffer size needed to store the parameter sets in |avc_config| |
49 // in Annex B form. | 50 // in Annex B form. |
50 uint32 GetConfigSize( | 51 uint32_t GetConfigSize( |
51 const mp4::AVCDecoderConfigurationRecord& avc_config) const; | 52 const mp4::AVCDecoderConfigurationRecord& avc_config) const; |
52 | 53 |
53 // Calculates needed buffer size for the bitstream converted into bytestream. | 54 // Calculates needed buffer size for the bitstream converted into bytestream. |
54 // Lightweight implementation that does not do the actual conversion. | 55 // Lightweight implementation that does not do the actual conversion. |
55 // | 56 // |
56 // Parameters | 57 // Parameters |
57 // input | 58 // input |
58 // Pointer to buffer containing NAL units in MP4 format. | 59 // Pointer to buffer containing NAL units in MP4 format. |
59 // input_size | 60 // input_size |
60 // Size of the buffer in bytes. | 61 // Size of the buffer in bytes. |
61 // avc_config | 62 // avc_config |
62 // The AVCDecoderConfigurationRecord that contains the parameter sets that | 63 // The AVCDecoderConfigurationRecord that contains the parameter sets that |
63 // will be inserted into the output. NULL if no parameter sets need to be | 64 // will be inserted into the output. NULL if no parameter sets need to be |
64 // inserted. | 65 // inserted. |
65 // | 66 // |
66 // Returns | 67 // Returns |
67 // Required buffer size for the output NAL unit buffer when converted | 68 // Required buffer size for the output NAL unit buffer when converted |
68 // to bytestream format, or 0 if could not determine the size of | 69 // to bytestream format, or 0 if could not determine the size of |
69 // the output buffer from the data in |input| and |avc_config|. | 70 // the output buffer from the data in |input| and |avc_config|. |
70 uint32 CalculateNeededOutputBufferSize( | 71 uint32_t CalculateNeededOutputBufferSize( |
71 const uint8* input, | 72 const uint8_t* input, |
72 uint32 input_size, | 73 uint32_t input_size, |
73 const mp4::AVCDecoderConfigurationRecord* avc_config) const; | 74 const mp4::AVCDecoderConfigurationRecord* avc_config) const; |
74 | 75 |
75 // ConvertAVCDecoderConfigToByteStream converts the | 76 // ConvertAVCDecoderConfigToByteStream converts the |
76 // AVCDecoderConfigurationRecord from the MP4 headers to bytestream format. | 77 // AVCDecoderConfigurationRecord from the MP4 headers to bytestream format. |
77 // Client is responsible for making sure the output buffer is large enough | 78 // Client is responsible for making sure the output buffer is large enough |
78 // to hold the output data. Client can precalculate the needed output buffer | 79 // to hold the output data. Client can precalculate the needed output buffer |
79 // size by using GetConfigSize(). | 80 // size by using GetConfigSize(). |
80 // | 81 // |
81 // Parameters | 82 // Parameters |
82 // avc_config | 83 // avc_config |
83 // The AVCDecoderConfigurationRecord that contains the parameter sets that | 84 // The AVCDecoderConfigurationRecord that contains the parameter sets that |
84 // will be written to |output|. | 85 // will be written to |output|. |
85 // output | 86 // output |
86 // Pointer to buffer where the output should be written to. | 87 // Pointer to buffer where the output should be written to. |
87 // output_size (i/o) | 88 // output_size (i/o) |
88 // Pointer to the size of the output buffer. Will contain the number of | 89 // Pointer to the size of the output buffer. Will contain the number of |
89 // bytes written to output after successful call. | 90 // bytes written to output after successful call. |
90 // | 91 // |
91 // Returns | 92 // Returns |
92 // true if successful conversion| | 93 // true if successful conversion| |
93 // false if conversion not successful (|output_size| will hold the amount | 94 // false if conversion not successful (|output_size| will hold the amount |
94 // of converted data) | 95 // of converted data) |
95 bool ConvertAVCDecoderConfigToByteStream( | 96 bool ConvertAVCDecoderConfigToByteStream( |
96 const mp4::AVCDecoderConfigurationRecord& avc_config, | 97 const mp4::AVCDecoderConfigurationRecord& avc_config, |
97 uint8* output, | 98 uint8_t* output, |
98 uint32* output_size); | 99 uint32_t* output_size); |
99 | 100 |
100 // ConvertNalUnitStreamToByteStream converts the NAL unit from MP4 format | 101 // ConvertNalUnitStreamToByteStream converts the NAL unit from MP4 format |
101 // to bytestream format. Client is responsible for making sure the output | 102 // to bytestream format. Client is responsible for making sure the output |
102 // buffer is large enough to hold the output data. Client can precalculate the | 103 // buffer is large enough to hold the output data. Client can precalculate the |
103 // needed output buffer size by using CalculateNeededOutputBufferSize. | 104 // needed output buffer size by using CalculateNeededOutputBufferSize. |
104 // | 105 // |
105 // Parameters | 106 // Parameters |
106 // input | 107 // input |
107 // Pointer to buffer containing NAL units in MP4 format. | 108 // Pointer to buffer containing NAL units in MP4 format. |
108 // input_size | 109 // input_size |
109 // Size of the buffer in bytes. | 110 // Size of the buffer in bytes. |
110 // avc_config | 111 // avc_config |
111 // The AVCDecoderConfigurationRecord that contains the parameter sets to | 112 // The AVCDecoderConfigurationRecord that contains the parameter sets to |
112 // insert into the output. NULL if no parameter sets need to be inserted. | 113 // insert into the output. NULL if no parameter sets need to be inserted. |
113 // output | 114 // output |
114 // Pointer to buffer where the output should be written to. | 115 // Pointer to buffer where the output should be written to. |
115 // output_size (i/o) | 116 // output_size (i/o) |
116 // Pointer to the size of the output buffer. Will contain the number of | 117 // Pointer to the size of the output buffer. Will contain the number of |
117 // bytes written to output after successful call. | 118 // bytes written to output after successful call. |
118 // | 119 // |
119 // Returns | 120 // Returns |
120 // true if successful conversion | 121 // true if successful conversion |
121 // false if conversion not successful (output_size will hold the amount | 122 // false if conversion not successful (output_size will hold the amount |
122 // of converted data) | 123 // of converted data) |
123 bool ConvertNalUnitStreamToByteStream( | 124 bool ConvertNalUnitStreamToByteStream( |
124 const uint8* input, | 125 const uint8_t* input, |
125 uint32 input_size, | 126 uint32_t input_size, |
126 const mp4::AVCDecoderConfigurationRecord* avc_config, | 127 const mp4::AVCDecoderConfigurationRecord* avc_config, |
127 uint8* output, | 128 uint8_t* output, |
128 uint32* output_size); | 129 uint32_t* output_size); |
129 | 130 |
130 private: | 131 private: |
131 // Writes Annex B start code and |param_set| to |*out|. | 132 // Writes Annex B start code and |param_set| to |*out|. |
132 // |*out| - Is the memory location to write the parameter set. | 133 // |*out| - Is the memory location to write the parameter set. |
133 // |*out_size| - Number of bytes available for the parameter set. | 134 // |*out_size| - Number of bytes available for the parameter set. |
134 // Returns true if the start code and param set were successfully | 135 // Returns true if the start code and param set were successfully |
135 // written. On a successful write, |*out| is updated to point to the first | 136 // written. On a successful write, |*out| is updated to point to the first |
136 // byte after the data that was written. |*out_size| is updated to reflect | 137 // byte after the data that was written. |*out_size| is updated to reflect |
137 // the new number of bytes left in |*out|. | 138 // the new number of bytes left in |*out|. |
138 bool WriteParamSet(const std::vector<uint8>& param_set, | 139 bool WriteParamSet(const std::vector<uint8_t>& param_set, |
139 uint8** out, | 140 uint8_t** out, |
140 uint32* out_size) const; | 141 uint32_t* out_size) const; |
141 | 142 |
142 // Flag for indicating whether global parameter sets have been processed. | 143 // Flag for indicating whether global parameter sets have been processed. |
143 bool configuration_processed_; | 144 bool configuration_processed_; |
144 // Flag for indicating whether next NAL unit starts new access unit. | 145 // Flag for indicating whether next NAL unit starts new access unit. |
145 bool first_nal_unit_in_access_unit_; | 146 bool first_nal_unit_in_access_unit_; |
146 // Variable to hold interleaving field's length in bytes. | 147 // Variable to hold interleaving field's length in bytes. |
147 uint8 nal_unit_length_field_width_; | 148 uint8_t nal_unit_length_field_width_; |
148 | 149 |
149 DISALLOW_COPY_AND_ASSIGN(H264ToAnnexBBitstreamConverter); | 150 DISALLOW_COPY_AND_ASSIGN(H264ToAnnexBBitstreamConverter); |
150 }; | 151 }; |
151 | 152 |
152 } // namespace media | 153 } // namespace media |
153 | 154 |
154 #endif // MEDIA_FILTERS_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_ | 155 #endif // MEDIA_FILTERS_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_ |
OLD | NEW |