MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_send_frame_internal

Function encode_send_frame_internal

libavcodec/encode.c:428–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426#endif
427
428static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
429{
430 AVCodecInternal *avci = avctx->internal;
431 EncodeContext *ec = encode_ctx(avci);
432 AVFrame *dst = avci->buffer_frame;
433 int ret;
434
435 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
436 /* extract audio service type metadata */
437 AVFrameSideData *sd = av_frame_get_side_data(src, AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
438 if (sd && sd->size >= sizeof(enum AVAudioServiceType))
439 avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
440
441 /* check for valid frame size */
442 if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
443 /* if we already got an undersized frame, that must have been the last */
444 if (ec->last_audio_frame) {
445 av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame\n", avctx->frame_size);
446 return AVERROR(EINVAL);
447 }
448 if (src->nb_samples > avctx->frame_size) {
449 av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) > frame_size (%d)\n", src->nb_samples, avctx->frame_size);
450 return AVERROR(EINVAL);
451 }
452 if (src->nb_samples < avctx->frame_size) {
453 ec->last_audio_frame = 1;
454 if (!(avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)) {
455 int pad_samples = avci->pad_samples ? avci->pad_samples : avctx->frame_size;
456 int out_samples = (src->nb_samples + pad_samples - 1) / pad_samples * pad_samples;
457
458 if (out_samples != src->nb_samples) {
459 ret = pad_last_frame(avctx, dst, src, out_samples);
460 if (ret < 0)
461 return ret;
462 goto finish;
463 }
464 }
465 }
466 }
467 }
468
469 ret = av_frame_ref(dst, src);
470 if (ret < 0)
471 return ret;
472
473finish:
474
475 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
476 ret = encode_generate_icc_profile(avctx, dst);
477 if (ret < 0)
478 return ret;
479 }
480
481 // unset frame duration unless AV_CODEC_FLAG_FRAME_DURATION is set,
482 // since otherwise we cannot be sure that whatever value it has is in the
483 // right timebase, so we would produce an incorrect value, which is worse
484 // than none at all
485 if (!(avctx->flags & AV_CODEC_FLAG_FRAME_DURATION))

Callers 1

avcodec_send_frameFunction · 0.85

Calls 6

encode_ctxFunction · 0.85
av_frame_get_side_dataFunction · 0.85
av_logFunction · 0.85
pad_last_frameFunction · 0.85
av_frame_refFunction · 0.85

Tested by

no test coverage detected