Index: media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.cc |
diff --git a/media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.cc b/media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.cc |
index 31f03f5646d43fd7ca6c0cf5ab7245ffbc3ab68e..e957b4e521ce8c4599351c00e62da059c117e203 100644 |
--- a/media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.cc |
+++ b/media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.cc |
@@ -6,6 +6,7 @@ |
#include "base/logging.h" |
#include "media/ffmpeg/ffmpeg_common.h" |
+#include "media/formats/mp4/box_definitions.h" |
namespace media { |
@@ -22,40 +23,38 @@ bool FFmpegH264ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) { |
uint32 output_packet_size = 0; |
uint32 configuration_size = 0; |
uint32 io_size = 0; |
- if (packet == NULL) { |
+ scoped_ptr<mp4::AVCDecoderConfigurationRecord> avc_config; |
+ |
+ if (packet == NULL || !packet->data) |
return false; |
- } |
// Calculate the needed output buffer size. |
if (!configuration_processed_) { |
- // FFmpeg's AVCodecContext's extradata field contains the Decoder |
- // Specific Information from MP4 headers that contain the H.264 SPS and |
- // PPS members. See ISO/IEC 14496-15 Chapter 5.2.4 |
- // AVCDecoderConfigurationRecord for exact specification. |
- // Extradata must be at least 7 bytes long. |
- if (stream_context_->extradata == NULL || |
- stream_context_->extradata_size <= 7) { |
- return false; // Can't go on with conversion without configuration. |
- } |
- configuration_size += converter_.ParseConfigurationAndCalculateSize( |
+ if (!stream_context_->extradata || stream_context_->extradata_size <= 0) |
+ return false; |
+ |
+ avc_config.reset(new mp4::AVCDecoderConfigurationRecord()); |
+ |
+ configuration_size = converter_.ParseConfigurationAndCalculateSize( |
stream_context_->extradata, |
- stream_context_->extradata_size); |
- if (configuration_size == 0) { |
+ stream_context_->extradata_size, |
+ avc_config.get()); |
+ if (configuration_size == 0) |
return false; // Not possible to parse the configuration. |
- } |
} |
+ |
uint32 output_nal_size = |
converter_.CalculateNeededOutputBufferSize(packet->data, packet->size); |
- if (output_nal_size == 0) { |
+ if (output_nal_size == 0) |
return false; // Invalid input packet. |
- } |
+ |
output_packet_size = configuration_size + output_nal_size; |
// Allocate new packet for the output. |
AVPacket dest_packet; |
- if (av_new_packet(&dest_packet, output_packet_size) != 0) { |
+ if (av_new_packet(&dest_packet, output_packet_size) != 0) |
return false; // Memory allocation failure. |
- } |
+ |
// This is a bit tricky: since the interface does not allow us to replace |
// the pointer of the old packet with a new one, we will initially copy the |
// metadata from old packet to new bigger packet. |
@@ -70,7 +69,7 @@ bool FFmpegH264ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) { |
// Process the configuration if not done earlier. |
if (!configuration_processed_) { |
if (!converter_.ConvertAVCDecoderConfigToByteStream( |
- stream_context_->extradata, stream_context_->extradata_size, |
+ *avc_config, |
dest_packet.data, &configuration_size)) { |
return false; // Failed to convert the buffer. |
} |
@@ -94,4 +93,3 @@ bool FFmpegH264ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) { |
} |
} // namespace media |
- |