decoder/ffmpeg: pass references instead of pointers
This commit is contained in:
parent
a142f93dca
commit
0f2a304d34
@ -196,10 +196,10 @@ ffmpeg_init(gcc_unused const config_param ¶m)
|
|||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static int
|
static int
|
||||||
ffmpeg_find_audio_stream(const AVFormatContext *format_context)
|
ffmpeg_find_audio_stream(const AVFormatContext &format_context)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < format_context->nb_streams; ++i)
|
for (unsigned i = 0; i < format_context.nb_streams; ++i)
|
||||||
if (format_context->streams[i]->codec->codec_type ==
|
if (format_context.streams[i]->codec->codec_type ==
|
||||||
AVMEDIA_TYPE_AUDIO)
|
AVMEDIA_TYPE_AUDIO)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
@ -273,33 +273,33 @@ copy_interleave_frame2(uint8_t *dest, uint8_t **src,
|
|||||||
* Copy PCM data from a AVFrame to an interleaved buffer.
|
* Copy PCM data from a AVFrame to an interleaved buffer.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
copy_interleave_frame(const AVCodecContext *codec_context,
|
copy_interleave_frame(const AVCodecContext &codec_context,
|
||||||
const AVFrame *frame,
|
const AVFrame &frame,
|
||||||
uint8_t **output_buffer,
|
uint8_t **output_buffer,
|
||||||
FfmpegBuffer &global_buffer)
|
FfmpegBuffer &global_buffer)
|
||||||
{
|
{
|
||||||
int plane_size;
|
int plane_size;
|
||||||
const int data_size =
|
const int data_size =
|
||||||
av_samples_get_buffer_size(&plane_size,
|
av_samples_get_buffer_size(&plane_size,
|
||||||
codec_context->channels,
|
codec_context.channels,
|
||||||
frame->nb_samples,
|
frame.nb_samples,
|
||||||
codec_context->sample_fmt, 1);
|
codec_context.sample_fmt, 1);
|
||||||
if (data_size <= 0)
|
if (data_size <= 0)
|
||||||
return data_size;
|
return data_size;
|
||||||
|
|
||||||
if (av_sample_fmt_is_planar(codec_context->sample_fmt) &&
|
if (av_sample_fmt_is_planar(codec_context.sample_fmt) &&
|
||||||
codec_context->channels > 1) {
|
codec_context.channels > 1) {
|
||||||
*output_buffer = global_buffer.GetT<uint8_t>(data_size);
|
*output_buffer = global_buffer.GetT<uint8_t>(data_size);
|
||||||
if (*output_buffer == nullptr)
|
if (*output_buffer == nullptr)
|
||||||
/* Not enough memory - shouldn't happen */
|
/* Not enough memory - shouldn't happen */
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
copy_interleave_frame2(*output_buffer, frame->extended_data,
|
copy_interleave_frame2(*output_buffer, frame.extended_data,
|
||||||
frame->nb_samples,
|
frame.nb_samples,
|
||||||
codec_context->channels,
|
codec_context.channels,
|
||||||
av_get_bytes_per_sample(codec_context->sample_fmt));
|
av_get_bytes_per_sample(codec_context.sample_fmt));
|
||||||
} else {
|
} else {
|
||||||
*output_buffer = frame->extended_data[0];
|
*output_buffer = frame.extended_data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return data_size;
|
return data_size;
|
||||||
@ -307,27 +307,27 @@ copy_interleave_frame(const AVCodecContext *codec_context,
|
|||||||
|
|
||||||
static DecoderCommand
|
static DecoderCommand
|
||||||
ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
||||||
const AVPacket *packet,
|
const AVPacket &packet,
|
||||||
AVCodecContext *codec_context,
|
AVCodecContext &codec_context,
|
||||||
const AVStream *stream,
|
const AVStream &stream,
|
||||||
AVFrame *frame,
|
AVFrame &frame,
|
||||||
FfmpegBuffer &buffer)
|
FfmpegBuffer &buffer)
|
||||||
{
|
{
|
||||||
if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE) {
|
if (packet.pts >= 0 && packet.pts != (int64_t)AV_NOPTS_VALUE) {
|
||||||
auto start = start_time_fallback(*stream);
|
auto start = start_time_fallback(stream);
|
||||||
if (packet->pts >= start)
|
if (packet.pts >= start)
|
||||||
decoder_timestamp(decoder,
|
decoder_timestamp(decoder,
|
||||||
time_from_ffmpeg(packet->pts - start,
|
time_from_ffmpeg(packet.pts - start,
|
||||||
stream->time_base));
|
stream.time_base));
|
||||||
}
|
}
|
||||||
|
|
||||||
AVPacket packet2 = *packet;
|
AVPacket packet2 = packet;
|
||||||
|
|
||||||
DecoderCommand cmd = DecoderCommand::NONE;
|
DecoderCommand cmd = DecoderCommand::NONE;
|
||||||
while (packet2.size > 0 && cmd == DecoderCommand::NONE) {
|
while (packet2.size > 0 && cmd == DecoderCommand::NONE) {
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
int len = avcodec_decode_audio4(codec_context,
|
int len = avcodec_decode_audio4(&codec_context,
|
||||||
frame, &got_frame,
|
&frame, &got_frame,
|
||||||
&packet2);
|
&packet2);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
/* if error, we skip the frame */
|
/* if error, we skip the frame */
|
||||||
@ -358,7 +358,7 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
|||||||
|
|
||||||
cmd = decoder_data(decoder, is,
|
cmd = decoder_data(decoder, is,
|
||||||
output_buffer, audio_size,
|
output_buffer, audio_size,
|
||||||
codec_context->bit_rate / 1000);
|
codec_context.bit_rate / 1000);
|
||||||
}
|
}
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
@ -578,7 +578,7 @@ ffmpeg_decode(Decoder &decoder, InputStream &input)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_stream = ffmpeg_find_audio_stream(format_context);
|
int audio_stream = ffmpeg_find_audio_stream(*format_context);
|
||||||
if (audio_stream == -1) {
|
if (audio_stream == -1) {
|
||||||
LogError(ffmpeg_domain, "No audio stream inside");
|
LogError(ffmpeg_domain, "No audio stream inside");
|
||||||
avformat_close_input(&format_context);
|
avformat_close_input(&format_context);
|
||||||
@ -677,9 +677,9 @@ ffmpeg_decode(Decoder &decoder, InputStream &input)
|
|||||||
|
|
||||||
if (packet.stream_index == audio_stream)
|
if (packet.stream_index == audio_stream)
|
||||||
cmd = ffmpeg_send_packet(decoder, input,
|
cmd = ffmpeg_send_packet(decoder, input,
|
||||||
&packet, codec_context,
|
packet, *codec_context,
|
||||||
av_stream,
|
*av_stream,
|
||||||
frame,
|
*frame,
|
||||||
interleaved_buffer);
|
interleaved_buffer);
|
||||||
else
|
else
|
||||||
cmd = decoder_get_command(decoder);
|
cmd = decoder_get_command(decoder);
|
||||||
@ -745,7 +745,7 @@ ffmpeg_scan_stream(InputStream &is,
|
|||||||
tag_handler_invoke_duration(handler, handler_ctx, duration);
|
tag_handler_invoke_duration(handler, handler_ctx, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = ffmpeg_find_audio_stream(f);
|
int idx = ffmpeg_find_audio_stream(*f);
|
||||||
FfmpegScanMetadata(*f, idx, *handler, handler_ctx);
|
FfmpegScanMetadata(*f, idx, *handler, handler_ctx);
|
||||||
|
|
||||||
avformat_close_input(&f);
|
avformat_close_input(&f);
|
||||||
|
Loading…
Reference in New Issue
Block a user