diff options
author | Christian König <christian.koenig@amd.com> | 2013-09-05 02:23:39 -0600 |
---|---|---|
committer | Josep Torra <n770galaxy@gmail.com> | 2014-03-05 10:49:16 +0100 |
commit | daf78a7717a38a85d98b306858e99ef2873d72ab (patch) | |
tree | 0fa85f4182955733552196a5f0056cdf591cf73f | |
parent | 0197170e5b6e5bd2ed0caf93b65baa630c78ce8d (diff) |
omxvideodec: simplify _find_nearest_frame
No need to make it more complicated and error prone than
necessary. Also give the function a gst_omx_video_dec prefix
to distinct it from the encoder function.
https://bugzilla.gnome.org/show_bug.cgi?id=724236
-rw-r--r-- | omx/gstomxvideodec.c | 57 |
1 files changed, 13 insertions, 44 deletions
diff --git a/omx/gstomxvideodec.c b/omx/gstomxvideodec.c index 7283fc6..4397a28 100644 --- a/omx/gstomxvideodec.c +++ b/omx/gstomxvideodec.c @@ -36,18 +36,6 @@ GST_DEBUG_CATEGORY_STATIC (gst_omx_video_dec_debug_category); #define N_EGL_IMAGES 4 -typedef struct _BufferIdentification BufferIdentification; -struct _BufferIdentification -{ - guint64 timestamp; -}; - -static void -buffer_identification_free (BufferIdentification * id) -{ - g_slice_free (BufferIdentification, id); -} - /* prototypes */ static void gst_omx_video_dec_finalize (GObject * object); static void gst_omx_video_dec_set_property (GObject * object, @@ -460,40 +448,29 @@ gst_omx_video_dec_change_state (GstElement * element, GstStateChange transition) } static GstVideoCodecFrame * -_find_nearest_frame (GstOMXVideoDec * self, GstOMXBuffer * buf) +gst_omx_video_dec_find_nearest_frame (GstOMXVideoDec * self, GstOMXBuffer * buf) { GstVideoCodecFrame *best = NULL; - guint64 best_diff = G_MAXUINT64; + GstClockTimeDiff best_diff = G_MAXINT64; + GstClockTime timestamp; GList *frames; GList *l; + timestamp = + gst_util_uint64_scale (buf->omx_buf->nTimeStamp, GST_SECOND, + OMX_TICKS_PER_SECOND); + frames = gst_video_decoder_get_frames (GST_VIDEO_DECODER (self)); for (l = frames; l; l = l->next) { GstVideoCodecFrame *tmp = l->data; - BufferIdentification *id = gst_video_codec_frame_get_user_data (tmp); - guint64 timestamp, diff; + GstClockTimeDiff diff = ABS (GST_CLOCK_DIFF (timestamp, tmp->pts)); - /* This happens for frames that were just added but - * which were not passed to the component yet. Ignore - * them here! - */ - if (!id) - continue; - - timestamp = id->timestamp; - - if (timestamp > buf->omx_buf->nTimeStamp) - diff = timestamp - buf->omx_buf->nTimeStamp; - else - diff = buf->omx_buf->nTimeStamp - timestamp; - - if (best == NULL || diff < best_diff) { + if (diff < best_diff) { best = tmp; best_diff = diff; - /* For frames without timestamp we simply take the first frame */ - if ((buf->omx_buf->nTimeStamp == 0 && timestamp == 0) || diff == 0) + if (diff == 0) break; } } @@ -1281,7 +1258,7 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self) (guint) buf->omx_buf->nFlags, (guint64) buf->omx_buf->nTimeStamp); GST_VIDEO_DECODER_STREAM_LOCK (self); - frame = _find_nearest_frame (self, buf); + frame = gst_omx_video_dec_find_nearest_frame (self, buf); if (frame && (deadline = gst_video_decoder_get_max_decode_time @@ -2308,16 +2285,8 @@ gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder, buf->omx_buf->nTickCount = 0; } - if (offset == 0) { - BufferIdentification *id = g_slice_new0 (BufferIdentification); - - if (GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) - buf->omx_buf->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; - - id->timestamp = buf->omx_buf->nTimeStamp; - gst_video_codec_frame_set_user_data (frame, id, - (GDestroyNotify) buffer_identification_free); - } + if (offset == 0 && GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) + buf->omx_buf->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; /* TODO: Set flags * - OMX_BUFFERFLAG_DECODEONLY for buffers that are outside |