History

avcodec/encode: Redo checks for small last audio frame

In particular, check that there is only one small last frame in case the encoder has the AV_CODEC_CAP_SMALL_LAST_FRAME set.

Andreas Rheinhardt committed 4 years ago

Commit dc7b6641 parent e6bfb142 files · +11 −14Browse files

Unified · Split

2 files
  1. libavcodec/encode.c +9 −12
  2. libavcodec/internal.h +2 −2
libavcodec/encode.c+9−12
@@ -157,6 +157,7 @@ static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src) · 156 unmodified lines
157157
158158 fail:
159159 av_frame_unref(frame);
160+ s->internal->last_audio_frame = 0;
160161 return ret;
161162 }
162163
@@ -392,28 +393,24 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src) · 229 unmodified lines
392393 avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
393394
394395 /* check for valid frame size */
395− if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
396− if (src->nb_samples > avctx->frame_size) {
397− av_log(avctx, AV_LOG_ERROR, "more samples than frame size\n");
398− return AVERROR(EINVAL);
399− }
400− } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
396+ if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
401397 /* if we already got an undersized frame, that must have been the last */
402398 if (avctx->internal->last_audio_frame) {
403399 av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame\n", avctx->frame_size);
404400 return AVERROR(EINVAL);
405401 }
406−
402+ if (src->nb_samples > avctx->frame_size) {
403+ av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) > frame_size (%d)\n", src->nb_samples, avctx->frame_size);
404+ return AVERROR(EINVAL);
405+ }
407406 if (src->nb_samples < avctx->frame_size) {
407+ avctx->internal->last_audio_frame = 1;
408+ if (!(avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)) {
408409 ret = pad_last_frame(avctx, dst, src);
409410 if (ret < 0)
410411 return ret;
411−
412− avctx->internal->last_audio_frame = 1;
413412 goto finish;
414− } else if (src->nb_samples > avctx->frame_size) {
415− av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d)\n", src->nb_samples, avctx->frame_size);
416− return AVERROR(EINVAL);
413+ }
417414 }
418415 }
419416 }
libavcodec/internal.h+2−2
@@ -57,8 +57,8 @@ typedef struct AVCodecInternal { · 56 unmodified lines
5757 int is_copy;
5858
5959 /**
60− * An audio frame with less than required samples has been submitted and
61− * padded with silence. Reject all subsequent frames.
60+ * An audio frame with less than required samples has been submitted (and
61+ * potentially padded with silence). Reject all subsequent frames.
6262 */
6363 int last_audio_frame;
6464

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t