decoder/ffmpeg: copy_interleave_frame() returns ConstBuffer
This commit is contained in:
parent
190cdfc326
commit
5c3afd020a
@ -34,6 +34,7 @@
|
|||||||
#include "tag/MixRamp.hxx"
|
#include "tag/MixRamp.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "CheckAudioFormat.hxx"
|
#include "CheckAudioFormat.hxx"
|
||||||
|
#include "util/ConstBuffer.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "LogV.hxx"
|
#include "LogV.hxx"
|
||||||
@ -273,10 +274,9 @@ 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 size_t
|
static ConstBuffer<void>
|
||||||
copy_interleave_frame(const AVCodecContext &codec_context,
|
copy_interleave_frame(const AVCodecContext &codec_context,
|
||||||
const AVFrame &frame,
|
const AVFrame &frame,
|
||||||
uint8_t **output_buffer,
|
|
||||||
FfmpegBuffer &global_buffer,
|
FfmpegBuffer &global_buffer,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
@ -294,24 +294,26 @@ copy_interleave_frame(const AVCodecContext &codec_context,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *output_buffer;
|
||||||
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 */
|
||||||
error.SetErrno(ENOMEM);
|
error.SetErrno(ENOMEM);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_interleave_frame2(*output_buffer, frame.extended_data,
|
copy_interleave_frame2((uint8_t *)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 { output_buffer, (size_t)data_size };
|
||||||
}
|
}
|
||||||
|
|
||||||
static DecoderCommand
|
static DecoderCommand
|
||||||
@ -350,12 +352,10 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
|||||||
if (!got_frame || frame.nb_samples <= 0)
|
if (!got_frame || frame.nb_samples <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint8_t *output_buffer = nullptr;
|
auto output_buffer =
|
||||||
size_t audio_size =
|
|
||||||
copy_interleave_frame(codec_context, frame,
|
copy_interleave_frame(codec_context, frame,
|
||||||
&output_buffer,
|
|
||||||
buffer, error);
|
buffer, error);
|
||||||
if (audio_size == 0) {
|
if (output_buffer.IsNull()) {
|
||||||
/* this must be a serious error,
|
/* this must be a serious error,
|
||||||
e.g. OOM */
|
e.g. OOM */
|
||||||
LogError(error);
|
LogError(error);
|
||||||
@ -363,7 +363,7 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd = decoder_data(decoder, is,
|
cmd = decoder_data(decoder, is,
|
||||||
output_buffer, audio_size,
|
output_buffer.data, output_buffer.size,
|
||||||
codec_context.bit_rate / 1000);
|
codec_context.bit_rate / 1000);
|
||||||
}
|
}
|
||||||
return cmd;
|
return cmd;
|
||||||
|
Loading…
Reference in New Issue
Block a user