| 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 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" | 5 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/ffmpeg/ffmpeg_common.h" | 10 #include "media/ffmpeg/ffmpeg_common.h" |
| 11 #include "media/formats/mp4/box_definitions.h" | 11 #include "media/formats/mp4/box_definitions.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 FFmpegH264ToAnnexBBitstreamConverter::FFmpegH264ToAnnexBBitstreamConverter( | 15 FFmpegH264ToAnnexBBitstreamConverter::FFmpegH264ToAnnexBBitstreamConverter( |
| 16 AVCodecContext* stream_codec_context) | 16 AVCodecParameters* stream_codec_parameters) |
| 17 : configuration_processed_(false), | 17 : configuration_processed_(false), |
| 18 stream_codec_context_(stream_codec_context) { | 18 stream_codec_parameters_(stream_codec_parameters) { |
| 19 CHECK(stream_codec_context_); | 19 CHECK(stream_codec_parameters_); |
| 20 } | 20 } |
| 21 | 21 |
| 22 FFmpegH264ToAnnexBBitstreamConverter::~FFmpegH264ToAnnexBBitstreamConverter() {} | 22 FFmpegH264ToAnnexBBitstreamConverter::~FFmpegH264ToAnnexBBitstreamConverter() {} |
| 23 | 23 |
| 24 bool FFmpegH264ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) { | 24 bool FFmpegH264ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) { |
| 25 std::unique_ptr<mp4::AVCDecoderConfigurationRecord> avc_config; | 25 std::unique_ptr<mp4::AVCDecoderConfigurationRecord> avc_config; |
| 26 | 26 |
| 27 if (packet == NULL || !packet->data) | 27 if (packet == NULL || !packet->data) |
| 28 return false; | 28 return false; |
| 29 | 29 |
| 30 // Calculate the needed output buffer size. | 30 // Calculate the needed output buffer size. |
| 31 if (!configuration_processed_) { | 31 if (!configuration_processed_) { |
| 32 if (!stream_codec_context_->extradata || | 32 if (!stream_codec_parameters_->extradata || |
| 33 stream_codec_context_->extradata_size <= 0) | 33 stream_codec_parameters_->extradata_size <= 0) |
| 34 return false; | 34 return false; |
| 35 | 35 |
| 36 avc_config.reset(new mp4::AVCDecoderConfigurationRecord()); | 36 avc_config.reset(new mp4::AVCDecoderConfigurationRecord()); |
| 37 | 37 |
| 38 if (!converter_.ParseConfiguration( | 38 if (!converter_.ParseConfiguration(stream_codec_parameters_->extradata, |
| 39 stream_codec_context_->extradata, | 39 stream_codec_parameters_->extradata_size, |
| 40 stream_codec_context_->extradata_size, | 40 avc_config.get())) { |
| 41 avc_config.get())) { | |
| 42 return false; | 41 return false; |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | 44 |
| 46 uint32_t output_packet_size = converter_.CalculateNeededOutputBufferSize( | 45 uint32_t output_packet_size = converter_.CalculateNeededOutputBufferSize( |
| 47 packet->data, packet->size, avc_config.get()); | 46 packet->data, packet->size, avc_config.get()); |
| 48 | 47 |
| 49 if (output_packet_size == 0) | 48 if (output_packet_size == 0) |
| 50 return false; // Invalid input packet. | 49 return false; // Invalid input packet. |
| 51 | 50 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 73 configuration_processed_ = true; | 72 configuration_processed_ = true; |
| 74 | 73 |
| 75 // At the end we must destroy the old packet. | 74 // At the end we must destroy the old packet. |
| 76 av_packet_unref(packet); | 75 av_packet_unref(packet); |
| 77 *packet = dest_packet; // Finally, replace the values in the input packet. | 76 *packet = dest_packet; // Finally, replace the values in the input packet. |
| 78 | 77 |
| 79 return true; | 78 return true; |
| 80 } | 79 } |
| 81 | 80 |
| 82 } // namespace media | 81 } // namespace media |
| OLD | NEW |