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

Side by Side Diff: media/filters/ffmpeg_aac_bitstream_converter.cc

Issue 2497603003: Roll src/third_party/ffmpeg/ 3c7a09882..cdf4accee (3188 commits). (Closed)
Patch Set: Updated DEPS to ffmpeg origin/master 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "media/filters/ffmpeg_aac_bitstream_converter.h" 5 #include "media/filters/ffmpeg_aac_bitstream_converter.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/ffmpeg/ffmpeg_common.h" 8 #include "media/ffmpeg/ffmpeg_common.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 hdr[6] |= (buffer_fullness & 0x3F) << 2; 151 hdr[6] |= (buffer_fullness & 0x3F) << 2;
152 152
153 hdr[6] |= number_of_frames_minus_one & 0x3; 153 hdr[6] |= number_of_frames_minus_one & 0x3;
154 154
155 return true; 155 return true;
156 } 156 }
157 157
158 } 158 }
159 159
160 FFmpegAACBitstreamConverter::FFmpegAACBitstreamConverter( 160 FFmpegAACBitstreamConverter::FFmpegAACBitstreamConverter(
161 AVCodecContext* stream_codec_context) 161 AVCodecParameters* stream_codec_parameters)
162 : stream_codec_context_(stream_codec_context), 162 : stream_codec_parameters_(stream_codec_parameters),
163 header_generated_(false), 163 header_generated_(false),
164 codec_(), 164 codec_(),
165 audio_profile_(), 165 audio_profile_(),
166 sample_rate_index_(), 166 sample_rate_index_(),
167 channel_configuration_(), 167 channel_configuration_(),
168 frame_length_() { 168 frame_length_() {
169 CHECK(stream_codec_context_); 169 CHECK(stream_codec_parameters_);
170 } 170 }
171 171
172 FFmpegAACBitstreamConverter::~FFmpegAACBitstreamConverter() { 172 FFmpegAACBitstreamConverter::~FFmpegAACBitstreamConverter() {
173 } 173 }
174 174
175 bool FFmpegAACBitstreamConverter::ConvertPacket(AVPacket* packet) { 175 bool FFmpegAACBitstreamConverter::ConvertPacket(AVPacket* packet) {
176 if (packet == NULL || !packet->data) { 176 if (packet == NULL || !packet->data) {
177 return false; 177 return false;
178 } 178 }
179 179
180 int header_plus_packet_size = 180 int header_plus_packet_size =
181 packet->size + kAdtsHeaderSize; 181 packet->size + kAdtsHeaderSize;
182 if (!stream_codec_context_->extradata) { 182 if (!stream_codec_parameters_->extradata) {
183 DLOG(ERROR) << "extradata is null"; 183 DLOG(ERROR) << "extradata is null";
184 return false; 184 return false;
185 } 185 }
186 if (stream_codec_context_->extradata_size < 2) { 186 if (stream_codec_parameters_->extradata_size < 2) {
187 DLOG(ERROR) << "extradata too small to contain MP4A header"; 187 DLOG(ERROR) << "extradata too small to contain MP4A header";
188 return false; 188 return false;
189 } 189 }
190 int sample_rate_index = 190 int sample_rate_index =
191 ((stream_codec_context_->extradata[0] & 0x07) << 1) | 191 ((stream_codec_parameters_->extradata[0] & 0x07) << 1) |
192 ((stream_codec_context_->extradata[1] & 0x80) >> 7); 192 ((stream_codec_parameters_->extradata[1] & 0x80) >> 7);
193 if (sample_rate_index > 12) { 193 if (sample_rate_index > 12) {
194 sample_rate_index = 4; 194 sample_rate_index = 4;
195 } 195 }
196 196
197 if (!header_generated_ || 197 if (!header_generated_ || codec_ != stream_codec_parameters_->codec_id ||
198 codec_ != stream_codec_context_->codec_id || 198 audio_profile_ != stream_codec_parameters_->profile ||
199 audio_profile_ != stream_codec_context_->profile ||
200 sample_rate_index_ != sample_rate_index || 199 sample_rate_index_ != sample_rate_index ||
201 channel_configuration_ != stream_codec_context_->channels || 200 channel_configuration_ != stream_codec_parameters_->channels ||
202 frame_length_ != header_plus_packet_size) { 201 frame_length_ != header_plus_packet_size) {
203 header_generated_ = GenerateAdtsHeader(stream_codec_context_->codec_id, 202 header_generated_ =
204 0, // layer 203 GenerateAdtsHeader(stream_codec_parameters_->codec_id,
205 stream_codec_context_->profile, 204 0, // layer
206 sample_rate_index, 205 stream_codec_parameters_->profile, sample_rate_index,
207 0, // private stream 206 0, // private stream
208 stream_codec_context_->channels, 207 stream_codec_parameters_->channels,
209 0, // originality 208 0, // originality
210 0, // home 209 0, // home
211 0, // copyrighted_stream 210 0, // copyrighted_stream
212 0, // copyright_ start 211 0, // copyright_ start
213 header_plus_packet_size, 212 header_plus_packet_size,
214 0x7FF, // buffer fullness 213 0x7FF, // buffer fullness
215 0, // one frame per packet 214 0, // one frame per packet
216 hdr_); 215 hdr_);
217 codec_ = stream_codec_context_->codec_id; 216 codec_ = stream_codec_parameters_->codec_id;
218 audio_profile_ = stream_codec_context_->profile; 217 audio_profile_ = stream_codec_parameters_->profile;
219 sample_rate_index_ = sample_rate_index; 218 sample_rate_index_ = sample_rate_index;
220 channel_configuration_ = stream_codec_context_->channels; 219 channel_configuration_ = stream_codec_parameters_->channels;
221 frame_length_ = header_plus_packet_size; 220 frame_length_ = header_plus_packet_size;
222 } 221 }
223 222
224 // Inform caller if the header generation failed. 223 // Inform caller if the header generation failed.
225 if (!header_generated_) 224 if (!header_generated_)
226 return false; 225 return false;
227 226
228 // Allocate new packet for the output. 227 // Allocate new packet for the output.
229 AVPacket dest_packet; 228 AVPacket dest_packet;
230 if (av_new_packet(&dest_packet, header_plus_packet_size) != 0) 229 if (av_new_packet(&dest_packet, header_plus_packet_size) != 0)
231 return false; // Memory allocation failure. 230 return false; // Memory allocation failure.
232 231
233 memcpy(dest_packet.data, hdr_, kAdtsHeaderSize); 232 memcpy(dest_packet.data, hdr_, kAdtsHeaderSize);
234 memcpy(reinterpret_cast<void*>(dest_packet.data + kAdtsHeaderSize), 233 memcpy(reinterpret_cast<void*>(dest_packet.data + kAdtsHeaderSize),
235 reinterpret_cast<void*>(packet->data), packet->size); 234 reinterpret_cast<void*>(packet->data), packet->size);
236 235
237 // This is a bit tricky: since the interface does not allow us to replace 236 // This is a bit tricky: since the interface does not allow us to replace
238 // the pointer of the old packet with a new one, we will initially copy the 237 // the pointer of the old packet with a new one, we will initially copy the
239 // metadata from old packet to new bigger packet. 238 // metadata from old packet to new bigger packet.
240 av_packet_copy_props(&dest_packet, packet); 239 av_packet_copy_props(&dest_packet, packet);
241 240
242 // Release the old packet. 241 // Release the old packet.
243 av_packet_unref(packet); 242 av_packet_unref(packet);
244 *packet = dest_packet; // Finally, replace the values in the input packet. 243 *packet = dest_packet; // Finally, replace the values in the input packet.
245 244
246 return true; 245 return true;
247 } 246 }
248 247
249 } // namespace media 248 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_aac_bitstream_converter.h ('k') | media/filters/ffmpeg_aac_bitstream_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698