mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
videotimecode: Add API for initializing from a GDateTime with validation
The old API would only assert or return an invalid timecode, the new API returns a boolean or NULL. We can't change the existing API unfortunately but can at least deprecate it.
This commit is contained in:
parent
ac6ae25b53
commit
c02d3b03c2
4 changed files with 96 additions and 12 deletions
|
@ -3075,6 +3075,7 @@ gst_video_time_code_free
|
|||
gst_video_time_code_copy
|
||||
gst_video_time_code_init
|
||||
gst_video_time_code_init_from_date_time
|
||||
gst_video_time_code_init_from_date_time_full
|
||||
GST_VIDEO_TIME_CODE_INIT
|
||||
gst_video_time_code_clear
|
||||
gst_video_time_code_is_valid
|
||||
|
@ -3088,6 +3089,7 @@ gst_video_time_code_to_string
|
|||
gst_video_time_code_add_interval
|
||||
gst_video_time_code_new_from_string
|
||||
gst_video_time_code_new_from_date_time
|
||||
gst_video_time_code_new_from_date_time_full
|
||||
|
||||
<SUBSECTION>
|
||||
GstVideoTimeCodeInterval
|
||||
|
|
|
@ -230,18 +230,52 @@ gst_video_time_code_to_date_time (const GstVideoTimeCode * tc)
|
|||
* The resulting config->latest_daily_jam is set to
|
||||
* midnight, and timecode is set to the given time.
|
||||
*
|
||||
* Will assert on invalid parameters, use gst_video_time_code_init_from_date_time_full()
|
||||
* for being able to handle invalid parameters.
|
||||
*
|
||||
* Since: 1.12
|
||||
*/
|
||||
|
||||
void
|
||||
gst_video_time_code_init_from_date_time (GstVideoTimeCode * tc,
|
||||
guint fps_n, guint fps_d,
|
||||
GDateTime * dt, GstVideoTimeCodeFlags flags, guint field_count)
|
||||
{
|
||||
if (!gst_video_time_code_init_from_date_time_full (tc, fps_n, fps_d, dt,
|
||||
flags, field_count))
|
||||
g_return_if_fail (gst_video_time_code_is_valid (tc));
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_time_code_init_from_date_time_full:
|
||||
* @tc: a #GstVideoTimeCode
|
||||
* @fps_n: Numerator of the frame rate
|
||||
* @fps_d: Denominator of the frame rate
|
||||
* @dt: #GDateTime to convert
|
||||
* @flags: #GstVideoTimeCodeFlags
|
||||
* @field_count: Interlaced video field count
|
||||
*
|
||||
* The resulting config->latest_daily_jam is set to
|
||||
* midnight, and timecode is set to the given time.
|
||||
*
|
||||
* Returns: %TRUE if @tc could be correctly initialized to a valid timecode
|
||||
*
|
||||
* Since: 1.16
|
||||
*/
|
||||
gboolean
|
||||
gst_video_time_code_init_from_date_time_full (GstVideoTimeCode * tc,
|
||||
guint fps_n, guint fps_d,
|
||||
GDateTime * dt, GstVideoTimeCodeFlags flags, guint field_count)
|
||||
{
|
||||
GDateTime *jam;
|
||||
guint64 frames;
|
||||
gboolean add_a_frame = FALSE;
|
||||
|
||||
g_return_val_if_fail (tc != NULL, FALSE);
|
||||
g_return_val_if_fail (dt != NULL, FALSE);
|
||||
g_return_val_if_fail (fps_d != 0, FALSE);
|
||||
|
||||
gst_video_time_code_clear (tc);
|
||||
|
||||
jam = g_date_time_new_local (g_date_time_get_year (dt),
|
||||
g_date_time_get_month (dt), g_date_time_get_day_of_month (dt), 0, 0, 0.0);
|
||||
|
||||
|
@ -273,7 +307,7 @@ gst_video_time_code_init_from_date_time (GstVideoTimeCode * tc,
|
|||
|
||||
g_date_time_unref (jam);
|
||||
|
||||
g_return_if_fail (gst_video_time_code_is_valid (tc));
|
||||
return gst_video_time_code_is_valid (tc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -710,6 +744,10 @@ gst_video_time_code_new_from_string (const gchar * tc_str)
|
|||
* The resulting config->latest_daily_jam is set to
|
||||
* midnight, and timecode is set to the given time.
|
||||
*
|
||||
* This might return a completely invalid timecode, use
|
||||
* gst_video_time_code_new_from_date_time_full() to ensure
|
||||
* that you would get %NULL instead in that case.
|
||||
*
|
||||
* Returns: the #GstVideoTimeCode representation of @dt.
|
||||
*
|
||||
* Since: 1.12
|
||||
|
@ -720,11 +758,41 @@ gst_video_time_code_new_from_date_time (guint fps_n, guint fps_d,
|
|||
{
|
||||
GstVideoTimeCode *tc;
|
||||
tc = gst_video_time_code_new_empty ();
|
||||
gst_video_time_code_init_from_date_time (tc, fps_n, fps_d, dt, flags,
|
||||
gst_video_time_code_init_from_date_time_full (tc, fps_n, fps_d, dt, flags,
|
||||
field_count);
|
||||
return tc;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_time_code_new_from_date_time_full:
|
||||
* @fps_n: Numerator of the frame rate
|
||||
* @fps_d: Denominator of the frame rate
|
||||
* @dt: #GDateTime to convert
|
||||
* @flags: #GstVideoTimeCodeFlags
|
||||
* @field_count: Interlaced video field count
|
||||
*
|
||||
* The resulting config->latest_daily_jam is set to
|
||||
* midnight, and timecode is set to the given time.
|
||||
*
|
||||
* Returns: the #GstVideoTimeCode representation of @dt, or %NULL if
|
||||
* no valid timecode could be created.
|
||||
*
|
||||
* Since: 1.16
|
||||
*/
|
||||
GstVideoTimeCode *
|
||||
gst_video_time_code_new_from_date_time_full (guint fps_n, guint fps_d,
|
||||
GDateTime * dt, GstVideoTimeCodeFlags flags, guint field_count)
|
||||
{
|
||||
GstVideoTimeCode *tc;
|
||||
tc = gst_video_time_code_new_empty ();
|
||||
if (!gst_video_time_code_init_from_date_time_full (tc, fps_n, fps_d, dt,
|
||||
flags, field_count)) {
|
||||
gst_video_time_code_free (tc);
|
||||
return NULL;
|
||||
}
|
||||
return tc;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_video_time_code_init:
|
||||
* @tc: a #GstVideoTimeCode
|
||||
|
|
|
@ -144,13 +144,20 @@ GstVideoTimeCode * gst_video_time_code_new_empty (void);
|
|||
GST_VIDEO_API
|
||||
GstVideoTimeCode * gst_video_time_code_new_from_string (const gchar * tc_str);
|
||||
|
||||
GST_VIDEO_API
|
||||
GST_VIDEO_DEPRECATED_FOR(gst_video_time_code_new_from_date_time_full)
|
||||
GstVideoTimeCode * gst_video_time_code_new_from_date_time (guint fps_n,
|
||||
guint fps_d,
|
||||
GDateTime * dt,
|
||||
GstVideoTimeCodeFlags flags,
|
||||
guint field_count);
|
||||
|
||||
GST_VIDEO_API
|
||||
GstVideoTimeCode * gst_video_time_code_new_from_date_time_full (guint fps_n,
|
||||
guint fps_d,
|
||||
GDateTime * dt,
|
||||
GstVideoTimeCodeFlags flags,
|
||||
guint field_count);
|
||||
|
||||
GST_VIDEO_API
|
||||
void gst_video_time_code_free (GstVideoTimeCode * tc);
|
||||
|
||||
|
@ -169,13 +176,20 @@ void gst_video_time_code_init (GstVideoTimeCode * tc
|
|||
guint frames,
|
||||
guint field_count);
|
||||
|
||||
GST_VIDEO_API
|
||||
GST_VIDEO_DEPRECATED_FOR(gst_video_time_code_init_from_date_time_full)
|
||||
void gst_video_time_code_init_from_date_time (GstVideoTimeCode * tc,
|
||||
guint fps_n,
|
||||
guint fps_d,
|
||||
GDateTime * dt,
|
||||
GstVideoTimeCodeFlags flags,
|
||||
guint field_count);
|
||||
GST_VIDEO_API
|
||||
gboolean gst_video_time_code_init_from_date_time_full (GstVideoTimeCode * tc,
|
||||
guint fps_n,
|
||||
guint fps_d,
|
||||
GDateTime * dt,
|
||||
GstVideoTimeCodeFlags flags,
|
||||
guint field_count);
|
||||
|
||||
GST_VIDEO_API
|
||||
void gst_video_time_code_clear (GstVideoTimeCode * tc);
|
||||
|
|
|
@ -614,7 +614,7 @@ GST_START_TEST (videotimecode_from_date_time_1s)
|
|||
GDateTime *dt;
|
||||
|
||||
dt = g_date_time_new_local (2017, 2, 16, 0, 0, 1);
|
||||
tc = gst_video_time_code_new_from_date_time (30000, 1001, dt,
|
||||
tc = gst_video_time_code_new_from_date_time_full (30000, 1001, dt,
|
||||
GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME, 0);
|
||||
|
||||
fail_unless_equals_int (tc->hours, 0);
|
||||
|
@ -636,7 +636,7 @@ GST_START_TEST (videotimecode_from_date_time_halfsecond)
|
|||
dt = g_date_time_new_local (2017, 2, 17, 14, 13, 0);
|
||||
dt2 = g_date_time_add (dt, 500000);
|
||||
g_date_time_unref (dt);
|
||||
tc = gst_video_time_code_new_from_date_time (30000, 1001, dt2,
|
||||
tc = gst_video_time_code_new_from_date_time_full (30000, 1001, dt2,
|
||||
GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME, 0);
|
||||
|
||||
fail_unless_equals_int (tc->hours, 14);
|
||||
|
@ -656,7 +656,7 @@ GST_START_TEST (videotimecode_from_date_time)
|
|||
GDateTime *dt;
|
||||
|
||||
dt = g_date_time_new_local (2017, 2, 17, 14, 13, 30);
|
||||
tc = gst_video_time_code_new_from_date_time (30000, 1001, dt,
|
||||
tc = gst_video_time_code_new_from_date_time_full (30000, 1001, dt,
|
||||
GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME, 0);
|
||||
|
||||
fail_unless_equals_int (tc->hours, 14);
|
||||
|
|
Loading…
Reference in a new issue