libav: Port AVCodecContext.ticks_per_frame to AV_CODEC_PROP_FIELDS

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5186>
This commit is contained in:
L. E. Segovia 2024-01-14 15:46:17 -03:00 committed by Edward Hervey
parent 4dc955e94a
commit 09de59477a
7 changed files with 1442 additions and 7 deletions

24
.clang-format Normal file
View file

@ -0,0 +1,24 @@
BasedOnStyle: GNU
ColumnLimit: 80
IndentPPDirectives: AfterHash
PointerAlignment: Right
UseTab: Never
# BreakBeforeBraces: Linux
BreakBeforeBraces: Custom
BraceWrapping:
AfterEnum: true
AfterFunction: true
AfterStruct: true
SplitEmptyFunction: false
IndentCaseBlocks: true
IndentCaseLabels: true
TabWidth: 8
AlignAfterOpenBracket: DontAlign
ContinuationIndentWidth: 4
AlignEscapedNewlines: DontAlign
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllArgumentsOnNextLine: false
BinPackParameters: true
BinPackArguments: true
PackConstructorInitializers: NextLine
DerivePointerAlignment: true

1373
list.txt Normal file

File diff suppressed because it is too large Load diff

3
native-file.txt Normal file
View file

@ -0,0 +1,3 @@
[binaries]
pkg-config = 'false'

View file

@ -256,7 +256,9 @@ gst_ffmpegaudenc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
if (!ffmpegaudenc->context->time_base.den) {
ffmpegaudenc->context->time_base.den = GST_AUDIO_INFO_RATE (info);
ffmpegaudenc->context->time_base.num = 1;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 100)
ffmpegaudenc->context->ticks_per_frame = 1;
#endif
}
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
if (ffmpegaudenc->context->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {

View file

@ -2872,7 +2872,9 @@ gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
/* they're fine, this is because it does period=1/frequency */
context->time_base.den = gst_value_get_fraction_numerator (fps);
context->time_base.num = gst_value_get_fraction_denominator (fps);
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 100)
context->ticks_per_frame = 1;
#endif
GST_DEBUG ("setting framerate %d/%d = %lf",
context->time_base.den, context->time_base.num,
@ -3159,8 +3161,9 @@ gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
context->bits_per_coded_sample = bpp;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 100)
context->ticks_per_frame = 1;
#endif
if (GST_VIDEO_INFO_FPS_N (info) == 0) {
GST_DEBUG ("Using 25/1 framerate");
context->time_base.den = 25;

View file

@ -677,10 +677,21 @@ update_state:
/* Use the framerate values stored in the decoder for calculating latency. The
* upstream framerate might not be set but we still want to report a latency
* if needed. */
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 31, 100)
if (ffmpegdec->context->time_base.den && ffmpegdec->context->codec_descriptor
&& ffmpegdec->context->codec_descriptor->props) {
#else
if (ffmpegdec->context->time_base.den && ffmpegdec->context->ticks_per_frame) {
gint fps_n = ffmpegdec->context->time_base.den;
gint fps_d =
ffmpegdec->context->time_base.num * ffmpegdec->context->ticks_per_frame;
#endif
const gint fps_n = ffmpegdec->context->time_base.den;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 31, 100)
const gint ticks_per_frame =
(ffmpegdec->context->
codec_descriptor->props & AV_CODEC_PROP_FIELDS) ? 2 : 1;
#else
const gint ticks_per_frame = ffmpegdec->context->ticks_per_frame;
#endif
const gint fps_d = ffmpegdec->context->time_base.num * ticks_per_frame;
if (fps_n) {
latency = gst_util_uint64_scale_ceil (
(ffmpegdec->context->has_b_frames) * GST_SECOND, fps_d, fps_n);
@ -1138,7 +1149,13 @@ picture_changed (GstFFMpegVidDec * ffmpegdec, AVFrame * picture,
static gboolean
context_changed (GstFFMpegVidDec * ffmpegdec, AVCodecContext * context)
{
return !(ffmpegdec->ctx_ticks == context->ticks_per_frame
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 31, 100)
const gint ticks_per_frame = (context->codec_descriptor
&& context->codec_descriptor->props & AV_CODEC_PROP_FIELDS) ? 2 : 1;
#else
const gint ticks_per_frame = context->ticks_per_frame;
#endif
return !(ffmpegdec->ctx_ticks == ticks_per_frame
&& ffmpegdec->ctx_time_n == context->time_base.num
&& ffmpegdec->ctx_time_d == context->time_base.den);
}
@ -1193,7 +1210,13 @@ update_video_context (GstFFMpegVidDec * ffmpegdec, AVCodecContext * context,
if (!ffmpegdec->pic_interlaced)
ffmpegdec->pic_field_order_changed = FALSE;
ffmpegdec->ctx_ticks = context->ticks_per_frame;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 31, 100)
const gint ticks_per_frame = (context->codec_descriptor
&& context->codec_descriptor->props & AV_CODEC_PROP_FIELDS) ? 2 : 1;
#else
const gint ticks_per_frame = context->ticks_per_frame;
#endif
ffmpegdec->ctx_ticks = ticks_per_frame;
ffmpegdec->ctx_time_n = context->time_base.num;
ffmpegdec->ctx_time_d = context->time_base.den;

View file

@ -631,9 +631,16 @@ gst_ffmpegvidenc_send_frame (GstFFMpegVidEnc * ffmpegenc,
GST_ERROR_OBJECT (ffmpegenc, "PTS is going backwards");
picture->pts = AV_NOPTS_VALUE;
} else {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 31, 100)
const gint ticks_per_frame = (ffmpegenc->context->codec_descriptor
&& ffmpegenc->context->
codec_descriptor->props & AV_CODEC_PROP_FIELDS) ? 2 : 1;
#else
const gint ticks_per_frame = ffmpegenc->context->ticks_per_frame;
#endif
picture->pts =
gst_ffmpeg_time_gst_to_ff ((frame->pts - ffmpegenc->pts_offset) /
ffmpegenc->context->ticks_per_frame, ffmpegenc->context->time_base);
ticks_per_frame, ffmpegenc->context->time_base);
}
send_frame: