This source file includes following definitions.
- stream_context_
- ConvertPacket
#include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h"
#include "base/logging.h"
#include "media/ffmpeg/ffmpeg_common.h"
namespace media {
FFmpegH264ToAnnexBBitstreamConverter::FFmpegH264ToAnnexBBitstreamConverter(
AVCodecContext* stream_context)
: configuration_processed_(false),
stream_context_(stream_context) {
CHECK(stream_context_);
}
FFmpegH264ToAnnexBBitstreamConverter::~FFmpegH264ToAnnexBBitstreamConverter() {}
bool FFmpegH264ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) {
uint32 output_packet_size = 0;
uint32 configuration_size = 0;
uint32 io_size = 0;
if (packet == NULL) {
return false;
}
if (!configuration_processed_) {
if (stream_context_->extradata == NULL ||
stream_context_->extradata_size <= 7) {
return false;
}
configuration_size += converter_.ParseConfigurationAndCalculateSize(
stream_context_->extradata,
stream_context_->extradata_size);
if (configuration_size == 0) {
return false;
}
}
uint32 output_nal_size =
converter_.CalculateNeededOutputBufferSize(packet->data, packet->size);
if (output_nal_size == 0) {
return false;
}
output_packet_size = configuration_size + output_nal_size;
AVPacket dest_packet;
if (av_new_packet(&dest_packet, output_packet_size) != 0) {
return false;
}
dest_packet.pts = packet->pts;
dest_packet.dts = packet->dts;
dest_packet.pos = packet->pos;
dest_packet.duration = packet->duration;
dest_packet.convergence_duration = packet->convergence_duration;
dest_packet.flags = packet->flags;
dest_packet.stream_index = packet->stream_index;
if (!configuration_processed_) {
if (!converter_.ConvertAVCDecoderConfigToByteStream(
stream_context_->extradata, stream_context_->extradata_size,
dest_packet.data, &configuration_size)) {
return false;
}
configuration_processed_ = true;
}
io_size = dest_packet.size - configuration_size;
if (!converter_.ConvertNalUnitStreamToByteStream(
packet->data, packet->size,
dest_packet.data + configuration_size, &io_size)) {
return false;
}
av_free_packet(packet);
*packet = dest_packet;
return true;
}
}