[vlc-devel] [PATCH 15/28] modules: simplify some vlc_rational_t value copying
Steve Lhomme
robux4 at videolabs.io
Fri Mar 31 18:14:30 CEST 2017
---
modules/access/imem.c | 3 +--
modules/access/linsys/linsys_hdsdi.c | 3 +--
modules/access/linsys/linsys_sdi.c | 3 +--
modules/codec/avcodec/directx_va.c | 3 +--
modules/codec/avcodec/encoder.c | 9 +++------
modules/codec/avcodec/video.c | 6 ++----
modules/demux/image.c | 10 ++++------
modules/demux/mpeg/h26x.c | 3 +--
modules/hw/mmal/codec.c | 3 +--
modules/hw/mmal/deinterlace.c | 3 +--
modules/packetizer/mpegvideo.c | 3 +--
modules/stream_out/transcode/video.c | 12 ++++--------
modules/video_filter/fps.c | 11 +++--------
13 files changed, 24 insertions(+), 48 deletions(-)
diff --git a/modules/access/imem.c b/modules/access/imem.c
index 5116dac208..67e175ff27 100644
--- a/modules/access/imem.c
+++ b/modules/access/imem.c
@@ -438,8 +438,7 @@ static int OpenDemux(vlc_object_t *object)
}
}
if (!var_InheritURational(object, &rat, "imem-fps") && rat.num && rat.den) {
- fmt.video.frame_rate.num = rat.num;
- fmt.video.frame_rate.den = rat.den;
+ fmt.video.frame_rate = rat;
}
msg_Dbg(object, "Video %4.4s %dx%d SAR %d:%d frame rate %u/%u",
diff --git a/modules/access/linsys/linsys_hdsdi.c b/modules/access/linsys/linsys_hdsdi.c
index 2b4e31b0b0..bd3402c86d 100644
--- a/modules/access/linsys/linsys_hdsdi.c
+++ b/modules/access/linsys/linsys_hdsdi.c
@@ -508,8 +508,7 @@ static int InitVideo( demux_t *p_demux )
/* Video ES */
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC('I','4','2','0') );
fmt.i_id = p_sys->i_id_video;
- fmt.video.frame_rate.num = p_sys->frame_rate.num;
- fmt.video.frame_rate.den = p_sys->frame_rate.den;
+ fmt.video.frame_rate = p_sys->frame_rate;
fmt.video.i_width = fmt.video.i_visible_width = p_sys->i_width;
fmt.video.i_height = fmt.video.i_visible_height = p_sys->i_height;
fmt.video.i_sar_num = p_sys->i_aspect * fmt.video.i_height
diff --git a/modules/access/linsys/linsys_sdi.c b/modules/access/linsys/linsys_sdi.c
index 6a07b156ad..7b4ad4f60c 100644
--- a/modules/access/linsys/linsys_sdi.c
+++ b/modules/access/linsys/linsys_sdi.c
@@ -442,8 +442,7 @@ static int StartDecode( demux_t *p_demux )
/* Video ES */
es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_I420 );
fmt.i_id = p_sys->i_id_video;
- fmt.video.frame_rate.num = p_sys->frame_rate.num;
- fmt.video.frame_rate.den = p_sys->frame_rate.den;
+ fmt.video.frame_rate = p_sys->frame_rate;
fmt.video.i_width = p_sys->i_width;
fmt.video.i_height = p_sys->i_height;
int i_aspect = p_sys->i_forced_aspect ? p_sys->i_forced_aspect
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 47f9c03408..4135c3f53f 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -329,8 +329,7 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, AVCodecContext *avctx)
memset(&fmt, 0, sizeof(fmt));
fmt.i_width = dx_sys->width;
fmt.i_height = dx_sys->height;
- fmt.frame_rate.num = avctx->framerate.num;
- fmt.frame_rate.den = avctx->framerate.den;
+ fmt.frame_rate = FromAVRational(avctx->framerate);
if (dx_sys->pf_create_decoder_surfaces(va, dx_sys->codec_id, &fmt))
return VLC_EGENERIC;
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index ffd88bdba5..4504ec1c08 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -263,12 +263,9 @@ static void probe_video_frame_rate( encoder_t *p_enc, AVCodecContext *p_context,
/* If we have something reasonable on supported framerates, use that*/
if( p_context->time_base.den && p_context->time_base.den < CLOCK_FREQ )
{
- p_enc->fmt_out.video.frame_rate.den =
- p_enc->fmt_in.video.frame_rate.den =
- p_context->time_base.num;
- p_enc->fmt_out.video.frame_rate.num =
- p_enc->fmt_in.video.frame_rate.num =
- p_context->time_base.den;
+ p_enc->fmt_out.video.frame_rate =
+ p_enc->fmt_in.video.frame_rate =
+ FromAVRational(p_context->time_base);
}
}
msg_Dbg( p_enc, "Time base set to %d/%d", p_context->time_base.num, p_context->time_base.den );
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 715a86f530..5afab55875 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -176,13 +176,11 @@ static int lavc_GetVideoFormat(decoder_t *dec, video_format_t *restrict fmt,
if (dec->fmt_in.video.frame_rate.num > 0
&& dec->fmt_in.video.frame_rate.den > 0)
{
- fmt->frame_rate.num = dec->fmt_in.video.frame_rate.num;
- fmt->frame_rate.den = dec->fmt_in.video.frame_rate.den;
+ fmt->frame_rate = dec->fmt_in.video.frame_rate;
}
else if (ctx->framerate.num > 0 && ctx->framerate.den > 0)
{
- fmt->frame_rate.num = ctx->framerate.num;
- fmt->frame_rate.den = ctx->framerate.den;
+ fmt->frame_rate = FromAVRational(ctx->framerate);
# if LIBAVCODEC_VERSION_MICRO < 100
// for some reason libav don't thinkg framerate presents actually same thing as in ffmpeg
fmt->frame_rate.den *= __MAX(ctx->ticks_per_frame, 1);
diff --git a/modules/demux/image.c b/modules/demux/image.c
index d19a5f06f6..6959bae332 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -665,15 +665,13 @@ static int Open(vlc_object_t *object)
}
fmt.i_id = var_InheritInteger(demux, "image-id");
fmt.i_group = var_InheritInteger(demux, "image-group");
- vlc_rational_t fps;
- if (var_InheritURational(demux, &fps, "image-fps") || !fps.num || !fps.den)
+ if (var_InheritURational(demux, &fmt.video.frame_rate, "image-fps") ||
+ !fmt.video.frame_rate.num || !fmt.video.frame_rate.den)
{
msg_Err(demux, "Invalid frame rate, using 10/1 instead");
- fps.num = 10;
- fps.den = 1;
+ fmt.video.frame_rate.num = 10;
+ fmt.video.frame_rate.den = 1;
}
- fmt.video.frame_rate.num = fps.num;
- fmt.video.frame_rate.den = fps.den;
/* If loadind failed, we still continue to avoid mis-detection
* by other demuxers. */
diff --git a/modules/demux/mpeg/h26x.c b/modules/demux/mpeg/h26x.c
index 7abb8b184e..aae2cce380 100644
--- a/modules/demux/mpeg/h26x.c
+++ b/modules/demux/mpeg/h26x.c
@@ -454,8 +454,7 @@ static int Demux( demux_t *p_demux)
if( p_sys->p_packetizer->fmt_out.video.frame_rate.den &&
p_sys->p_packetizer->fmt_out.video.frame_rate.num )
{
- p_sys->frame_rate.num = p_sys->p_packetizer->fmt_out.video.frame_rate.num;
- p_sys->frame_rate.den = p_sys->p_packetizer->fmt_out.video.frame_rate.den;
+ p_sys->frame_rate = p_sys->p_packetizer->fmt_out.video.frame_rate;
}
else
{
diff --git a/modules/hw/mmal/codec.c b/modules/hw/mmal/codec.c
index b76eb47609..b4103832f1 100644
--- a/modules/hw/mmal/codec.c
+++ b/modules/hw/mmal/codec.c
@@ -394,8 +394,7 @@ apply_fmt:
dec->fmt_out.video.i_visible_height = sys->output->format->es->video.crop.height;
dec->fmt_out.video.i_sar_num = sys->output->format->es->video.par.num;
dec->fmt_out.video.i_sar_den = sys->output->format->es->video.par.den;
- dec->fmt_out.video.frame_rate.num = sys->output->format->es->video.frame_rate.num;
- dec->fmt_out.video.frame_rate.den = sys->output->format->es->video.frame_rate.den;
+ dec->fmt_out.video.frame_rate = sys->output->format->es->video.frame_rate;
/* Query interlaced type */
interlace_type.hdr.id = MMAL_PARAMETER_VIDEO_INTERLACE_TYPE;
diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index 74e2d84732..08854df79a 100644
--- a/modules/hw/mmal/deinterlace.c
+++ b/modules/hw/mmal/deinterlace.c
@@ -301,8 +301,7 @@ static int send_output_buffer(filter_t *filter)
ret = -1;
goto out;
}
- picture->format.frame_rate.num = filter->fmt_out.video.frame_rate.num;
- picture->format.frame_rate.den = filter->fmt_out.video.frame_rate.den;
+ picture->format.frame_rate = filter->fmt_out.video.frame_rate;
buffer = picture->p_sys->buffer;
buffer->user_data = picture;
diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c
index 074df99a16..1158365447 100644
--- a/modules/packetizer/mpegvideo.c
+++ b/modules/packetizer/mpegvideo.c
@@ -666,8 +666,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
date_Change( &p_sys->dts, 2 * p_sys->frame_rate.num, p_sys->frame_rate.den );
date_Change( &p_sys->prev_iframe_dts, 2 * p_sys->frame_rate.num, p_sys->frame_rate.den );
}
- p_dec->fmt_out.video.frame_rate.num = p_sys->frame_rate.num;
- p_dec->fmt_out.video.frame_rate.den = p_sys->frame_rate.den;
+ p_dec->fmt_out.video.frame_rate = p_sys->frame_rate;
p_sys->b_seq_progressive = true;
p_sys->b_low_delay = true;
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index d48cddb818..ce870153b3 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -410,10 +410,8 @@ static void transcode_video_framerate_init( sout_stream_t *p_stream,
if( p_fmt_out->video.frame_rate.num &&
p_fmt_out->video.frame_rate.den )
{
- id->p_encoder->fmt_out.video.frame_rate.num =
- p_fmt_out->video.frame_rate.num;
- id->p_encoder->fmt_out.video.frame_rate.den =
- p_fmt_out->video.frame_rate.den;
+ id->p_encoder->fmt_out.video.frame_rate =
+ p_fmt_out->video.frame_rate;
}
else
{
@@ -423,10 +421,8 @@ static void transcode_video_framerate_init( sout_stream_t *p_stream,
}
}
- id->p_encoder->fmt_in.video.frame_rate.num =
- id->p_encoder->fmt_out.video.frame_rate.num;
- id->p_encoder->fmt_in.video.frame_rate.den =
- id->p_encoder->fmt_out.video.frame_rate.den;
+ id->p_encoder->fmt_in.video.frame_rate =
+ id->p_encoder->fmt_out.video.frame_rate;
vlc_ureduce( &id->p_encoder->fmt_in.video.frame_rate.num,
&id->p_encoder->fmt_in.video.frame_rate.den,
diff --git a/modules/video_filter/fps.c b/modules/video_filter/fps.c
index 1a528ae424..feeba07667 100644
--- a/modules/video_filter/fps.c
+++ b/modules/video_filter/fps.c
@@ -80,8 +80,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_picture)
return NULL;
}
- p_picture->format.frame_rate.num = p_filter->fmt_out.video.frame_rate.num;
- p_picture->format.frame_rate.den = p_filter->fmt_out.video.frame_rate.den;
+ p_picture->format.frame_rate = p_filter->fmt_out.video.frame_rate;
/* First time we get some valid timestamp, we'll take it as base for output
later on we retake new timestamp if it has jumped too much */
@@ -137,7 +136,6 @@ static int Open( vlc_object_t *p_this)
{
filter_t *p_filter = (filter_t*)p_this;
filter_sys_t *p_sys;
- vlc_rational_t fps;
p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
@@ -151,13 +149,10 @@ static int Open( vlc_object_t *p_this)
video_format_Copy( &p_filter->fmt_out.video, &p_filter->fmt_in.video );
/* If we don't have fps option, use filter output values */
- if( var_InheritURational( p_filter, &fps, CFG_PREFIX "fps" ) )
+ if( var_InheritURational( p_filter, &p_filter->fmt_out.video.frame_rate, CFG_PREFIX "fps" ) )
{
- fps.num = p_filter->fmt_in.video.frame_rate.num;
- fps.den = p_filter->fmt_in.video.frame_rate.den;
+ p_filter->fmt_out.video.frame_rate = p_filter->fmt_in.video.frame_rate;
}
- p_filter->fmt_out.video.frame_rate.num = fps.num;
- p_filter->fmt_out.video.frame_rate.den = fps.den;
msg_Dbg( p_filter, "Converting fps from %d/%d -> %d/%d",
p_filter->fmt_in.video.frame_rate.num, p_filter->fmt_in.video.frame_rate.den,
--
2.11.1
More information about the vlc-devel
mailing list