summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.com>2020-02-06 09:57:48 +0530
committerGuillaume Desmottes <guillaume.desmottes@collabora.com>2020-02-27 04:05:48 +0000
commite616094a53b4fc1da7fce3ea5dfd319ed80cf516 (patch)
tree4a90be7de872c52b28f6ad9c0343f432fca06264
parentf14f5d9f70e97b359b52bca2d272af517268fc1b (diff)
downloadgst-omx-e616094a53b4fc1da7fce3ea5dfd319ed80cf516.tar.gz
omxvideo(enc): use GST_VIDEO_INFO_FIELD_RATE_N()
Does not change anything for now but will be needed when we'll support interlace-mode=alternate as the field rate will be twice the frame rate. Made the code safe from division by 0 while I was on it.
-rw-r--r--omx/gstomxvideo.c8
-rw-r--r--omx/gstomxvideoenc.c15
2 files changed, 16 insertions, 7 deletions
diff --git a/omx/gstomxvideo.c b/omx/gstomxvideo.c
index 8bbee9e..28d7bd1 100644
--- a/omx/gstomxvideo.c
+++ b/omx/gstomxvideo.c
@@ -238,7 +238,13 @@ gst_omx_video_calculate_framerate_q16 (GstVideoInfo * info)
{
g_assert (info);
- return gst_util_uint64_scale_int (1 << 16, info->fps_n, info->fps_d);
+ if (!info->fps_d)
+ return 0;
+
+ /* OMX API expects frame rate to actually be the field rate, so twice
+ * the frame rate in interlace mode. */
+ return gst_util_uint64_scale_int (1 << 16, GST_VIDEO_INFO_FIELD_RATE_N (info),
+ info->fps_d);
}
gboolean
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c
index 99f5952..03a006e 100644
--- a/omx/gstomxvideoenc.c
+++ b/omx/gstomxvideoenc.c
@@ -2349,10 +2349,12 @@ gst_omx_video_enc_framerate_changed (GstOMXVideoEnc * self,
GST_OMX_INIT_STRUCT (&config);
config.nPortIndex = self->enc_in_port->index;
- if (klass->cdata.hacks & GST_OMX_HACK_VIDEO_FRAMERATE_INTEGER)
- config.xEncodeFramerate = info->fps_n ? (info->fps_n) / (info->fps_d) : 0;
- else
+ if (klass->cdata.hacks & GST_OMX_HACK_VIDEO_FRAMERATE_INTEGER) {
+ config.xEncodeFramerate =
+ info->fps_d ? GST_VIDEO_INFO_FIELD_RATE_N (info) / (info->fps_d) : 0;
+ } else {
config.xEncodeFramerate = gst_omx_video_calculate_framerate_q16 (info);
+ }
err = gst_omx_component_set_config (self->enc,
OMX_IndexConfigVideoFramerate, &config);
@@ -2456,12 +2458,13 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
port_def.format.video.nFrameWidth = info->width;
port_def.format.video.nFrameHeight = GST_VIDEO_INFO_FIELD_HEIGHT (info);
- if (G_UNLIKELY (klass->cdata.hacks & GST_OMX_HACK_VIDEO_FRAMERATE_INTEGER))
+ if (G_UNLIKELY (klass->cdata.hacks & GST_OMX_HACK_VIDEO_FRAMERATE_INTEGER)) {
port_def.format.video.xFramerate =
- info->fps_n ? (info->fps_n) / (info->fps_d) : 0;
- else
+ info->fps_d ? GST_VIDEO_INFO_FIELD_RATE_N (info) / (info->fps_d) : 0;
+ } else {
port_def.format.video.xFramerate =
gst_omx_video_calculate_framerate_q16 (info);
+ }
GST_DEBUG_OBJECT (self, "Setting inport port definition");
if (gst_omx_port_update_port_definition (self->enc_in_port,