Commit ecb8f736 authored by Max Kellermann's avatar Max Kellermann

decoder/ffmpeg: copy_interleave_frame() throws exception on error

parent 17ccfec3
...@@ -150,12 +150,13 @@ start_time_fallback(const AVStream &stream) ...@@ -150,12 +150,13 @@ start_time_fallback(const AVStream &stream)
/** /**
* Copy PCM data from a non-empty AVFrame to an interleaved buffer. * Copy PCM data from a non-empty AVFrame to an interleaved buffer.
*
* Throws #std::exception on error.
*/ */
static ConstBuffer<void> static ConstBuffer<void>
copy_interleave_frame(const AVCodecContext &codec_context, copy_interleave_frame(const AVCodecContext &codec_context,
const AVFrame &frame, const AVFrame &frame,
FfmpegBuffer &global_buffer, FfmpegBuffer &global_buffer)
Error &error)
{ {
assert(frame.nb_samples > 0); assert(frame.nb_samples > 0);
...@@ -166,20 +167,16 @@ copy_interleave_frame(const AVCodecContext &codec_context, ...@@ -166,20 +167,16 @@ copy_interleave_frame(const AVCodecContext &codec_context,
frame.nb_samples, frame.nb_samples,
codec_context.sample_fmt, 1); codec_context.sample_fmt, 1);
assert(data_size != 0); assert(data_size != 0);
if (data_size < 0) { if (data_size < 0)
SetFfmpegError(error, data_size); throw MakeFfmpegError(data_size);
return 0;
}
void *output_buffer; 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); throw std::bad_alloc();
return 0;
}
PcmInterleave(output_buffer, PcmInterleave(output_buffer,
ConstBuffer<const void *>((const void *const*)frame.extended_data, ConstBuffer<const void *>((const void *const*)frame.extended_data,
...@@ -231,13 +228,14 @@ FfmpegSendFrame(Decoder &decoder, InputStream &is, ...@@ -231,13 +228,14 @@ FfmpegSendFrame(Decoder &decoder, InputStream &is,
size_t &skip_bytes, size_t &skip_bytes,
FfmpegBuffer &buffer) FfmpegBuffer &buffer)
{ {
Error error; ConstBuffer<void> output_buffer;
auto output_buffer =
copy_interleave_frame(codec_context, frame, try {
buffer, error); output_buffer = copy_interleave_frame(codec_context, frame,
if (output_buffer.IsNull()) { buffer);
} catch (const std::exception e) {
/* this must be a serious error, e.g. OOM */ /* this must be a serious error, e.g. OOM */
LogError(error); LogError(e);
return DecoderCommand::STOP; return DecoderCommand::STOP;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment