mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-06 23:48:53 +00:00
videotimecode: Init from GDateTime
Add a function to init the time code from a GDateTime https://bugzilla.gnome.org/show_bug.cgi?id=778702
This commit is contained in:
parent
0c2c82ad69
commit
b3df5786a9
5 changed files with 155 additions and 0 deletions
|
@ -2775,6 +2775,7 @@ gst_video_time_code_new_empty
|
||||||
gst_video_time_code_free
|
gst_video_time_code_free
|
||||||
gst_video_time_code_copy
|
gst_video_time_code_copy
|
||||||
gst_video_time_code_init
|
gst_video_time_code_init
|
||||||
|
gst_video_time_code_init_from_date_time
|
||||||
gst_video_time_code_clear
|
gst_video_time_code_clear
|
||||||
gst_video_time_code_is_valid
|
gst_video_time_code_is_valid
|
||||||
gst_video_time_code_compare
|
gst_video_time_code_compare
|
||||||
|
@ -2786,6 +2787,7 @@ gst_video_time_code_to_date_time
|
||||||
gst_video_time_code_to_string
|
gst_video_time_code_to_string
|
||||||
gst_video_time_code_add_interval
|
gst_video_time_code_add_interval
|
||||||
gst_video_time_code_new_from_string
|
gst_video_time_code_new_from_string
|
||||||
|
gst_video_time_code_new_from_date_time
|
||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
GstVideoTimeCodeInterval
|
GstVideoTimeCodeInterval
|
||||||
|
|
|
@ -190,6 +190,55 @@ gst_video_time_code_to_date_time (const GstVideoTimeCode * tc)
|
||||||
return ret2;
|
return ret2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_video_time_code_init_from_date_time:
|
||||||
|
* @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.
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
GDateTime *jam;
|
||||||
|
guint64 frames;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Note: This might be inaccurate for 1 frame
|
||||||
|
* in case we have a drop frame timecode */
|
||||||
|
frames =
|
||||||
|
gst_util_uint64_scale_round (g_date_time_get_microsecond (dt) *
|
||||||
|
G_GINT64_CONSTANT (1000), fps_n, fps_d * GST_SECOND);
|
||||||
|
|
||||||
|
gst_video_time_code_init (tc, fps_n, fps_d, jam, flags,
|
||||||
|
g_date_time_get_hour (dt), g_date_time_get_minute (dt),
|
||||||
|
g_date_time_get_second (dt), frames, field_count);
|
||||||
|
|
||||||
|
if (tc->config.flags & GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME) {
|
||||||
|
guint df = (tc->config.fps_n + (tc->config.fps_d >> 1)) /
|
||||||
|
(15 * tc->config.fps_d);
|
||||||
|
if (tc->minutes % 10 && tc->seconds == 0 && tc->frames < df) {
|
||||||
|
tc->frames = df;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_date_time_unref (jam);
|
||||||
|
|
||||||
|
g_return_if_fail (gst_video_time_code_is_valid (tc));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_video_time_code_nsec_since_daily_jam:
|
* gst_video_time_code_nsec_since_daily_jam:
|
||||||
* @tc: a #GstVideoTimeCode
|
* @tc: a #GstVideoTimeCode
|
||||||
|
@ -618,6 +667,31 @@ gst_video_time_code_new_from_string (const gchar * tc_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_video_time_code_new_from_date_time:
|
||||||
|
* @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 #GVideoTimeCode representation of @dt.
|
||||||
|
*
|
||||||
|
* Since: 1.12
|
||||||
|
*/
|
||||||
|
GstVideoTimeCode *
|
||||||
|
gst_video_time_code_new_from_date_time (guint fps_n, guint fps_d,
|
||||||
|
GDateTime * dt, GstVideoTimeCodeFlags flags, guint field_count)
|
||||||
|
{
|
||||||
|
GstVideoTimeCode *tc;
|
||||||
|
tc = gst_video_time_code_new_empty ();
|
||||||
|
gst_video_time_code_init_from_date_time (tc, fps_n, fps_d, dt, flags,
|
||||||
|
field_count);
|
||||||
|
return tc;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_video_time_code_init:
|
* gst_video_time_code_init:
|
||||||
|
|
|
@ -135,6 +135,11 @@ GstVideoTimeCode * gst_video_time_code_new (guint fp
|
||||||
guint field_count);
|
guint field_count);
|
||||||
GstVideoTimeCode * gst_video_time_code_new_empty (void);
|
GstVideoTimeCode * gst_video_time_code_new_empty (void);
|
||||||
GstVideoTimeCode * gst_video_time_code_new_from_string (const gchar * tc_str);
|
GstVideoTimeCode * gst_video_time_code_new_from_string (const gchar * tc_str);
|
||||||
|
GstVideoTimeCode * gst_video_time_code_new_from_date_time (guint fps_n,
|
||||||
|
guint fps_d,
|
||||||
|
GDateTime * dt,
|
||||||
|
GstVideoTimeCodeFlags flags,
|
||||||
|
guint field_count);
|
||||||
void gst_video_time_code_free (GstVideoTimeCode * tc);
|
void gst_video_time_code_free (GstVideoTimeCode * tc);
|
||||||
|
|
||||||
GstVideoTimeCode * gst_video_time_code_copy (const GstVideoTimeCode * tc);
|
GstVideoTimeCode * gst_video_time_code_copy (const GstVideoTimeCode * tc);
|
||||||
|
@ -149,6 +154,12 @@ void gst_video_time_code_init (GstVideoTimeCode * tc
|
||||||
guint seconds,
|
guint seconds,
|
||||||
guint frames,
|
guint frames,
|
||||||
guint field_count);
|
guint field_count);
|
||||||
|
void gst_video_time_code_init_from_date_time (GstVideoTimeCode * tc,
|
||||||
|
guint fps_n,
|
||||||
|
guint fps_d,
|
||||||
|
GDateTime * dt,
|
||||||
|
GstVideoTimeCodeFlags flags,
|
||||||
|
guint field_count);
|
||||||
void gst_video_time_code_clear (GstVideoTimeCode * tc);
|
void gst_video_time_code_clear (GstVideoTimeCode * tc);
|
||||||
|
|
||||||
gboolean gst_video_time_code_is_valid (const GstVideoTimeCode * tc);
|
gboolean gst_video_time_code_is_valid (const GstVideoTimeCode * tc);
|
||||||
|
|
|
@ -584,6 +584,68 @@ GST_START_TEST (videotimecode_interval)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (videotimecode_from_date_time_1s)
|
||||||
|
{
|
||||||
|
GstVideoTimeCode *tc;
|
||||||
|
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,
|
||||||
|
GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME, 0);
|
||||||
|
|
||||||
|
fail_unless_equals_int (tc->hours, 0);
|
||||||
|
fail_unless_equals_int (tc->minutes, 0);
|
||||||
|
fail_unless_equals_int (tc->seconds, 1);
|
||||||
|
fail_unless_equals_int (tc->frames, 0);
|
||||||
|
|
||||||
|
gst_video_time_code_free (tc);
|
||||||
|
g_date_time_unref (dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (videotimecode_from_date_time_halfsecond)
|
||||||
|
{
|
||||||
|
GstVideoTimeCode *tc;
|
||||||
|
GDateTime *dt, *dt2;
|
||||||
|
|
||||||
|
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,
|
||||||
|
GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME, 0);
|
||||||
|
|
||||||
|
fail_unless_equals_int (tc->hours, 14);
|
||||||
|
fail_unless_equals_int (tc->minutes, 13);
|
||||||
|
fail_unless_equals_int (tc->seconds, 0);
|
||||||
|
fail_unless_equals_int (tc->frames, 15);
|
||||||
|
|
||||||
|
gst_video_time_code_free (tc);
|
||||||
|
g_date_time_unref (dt2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (videotimecode_from_date_time)
|
||||||
|
{
|
||||||
|
GstVideoTimeCode *tc;
|
||||||
|
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,
|
||||||
|
GST_VIDEO_TIME_CODE_FLAGS_DROP_FRAME, 0);
|
||||||
|
|
||||||
|
fail_unless_equals_int (tc->hours, 14);
|
||||||
|
fail_unless_equals_int (tc->minutes, 13);
|
||||||
|
fail_unless_equals_int (tc->seconds, 30);
|
||||||
|
fail_unless_equals_int (tc->frames, 0);
|
||||||
|
|
||||||
|
gst_video_time_code_free (tc);
|
||||||
|
g_date_time_unref (dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
static Suite *
|
static Suite *
|
||||||
gst_videotimecode_suite (void)
|
gst_videotimecode_suite (void)
|
||||||
{
|
{
|
||||||
|
@ -617,6 +679,10 @@ gst_videotimecode_suite (void)
|
||||||
tcase_add_test (tc, videotimecode_dailyjam_distance);
|
tcase_add_test (tc, videotimecode_dailyjam_distance);
|
||||||
tcase_add_test (tc, videotimecode_serialize_deserialize);
|
tcase_add_test (tc, videotimecode_serialize_deserialize);
|
||||||
tcase_add_test (tc, videotimecode_interval);
|
tcase_add_test (tc, videotimecode_interval);
|
||||||
|
|
||||||
|
tcase_add_test (tc, videotimecode_from_date_time_1s);
|
||||||
|
tcase_add_test (tc, videotimecode_from_date_time_halfsecond);
|
||||||
|
tcase_add_test (tc, videotimecode_from_date_time);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,6 +301,7 @@ EXPORTS
|
||||||
gst_video_time_code_get_type
|
gst_video_time_code_get_type
|
||||||
gst_video_time_code_increment_frame
|
gst_video_time_code_increment_frame
|
||||||
gst_video_time_code_init
|
gst_video_time_code_init
|
||||||
|
gst_video_time_code_init_from_date_time
|
||||||
gst_video_time_code_interval_clear
|
gst_video_time_code_interval_clear
|
||||||
gst_video_time_code_interval_copy
|
gst_video_time_code_interval_copy
|
||||||
gst_video_time_code_interval_free
|
gst_video_time_code_interval_free
|
||||||
|
@ -313,6 +314,7 @@ EXPORTS
|
||||||
gst_video_time_code_meta_get_info
|
gst_video_time_code_meta_get_info
|
||||||
gst_video_time_code_new
|
gst_video_time_code_new
|
||||||
gst_video_time_code_new_empty
|
gst_video_time_code_new_empty
|
||||||
|
gst_video_time_code_new_from_date_time
|
||||||
gst_video_time_code_new_from_string
|
gst_video_time_code_new_from_string
|
||||||
gst_video_time_code_nsec_since_daily_jam
|
gst_video_time_code_nsec_since_daily_jam
|
||||||
gst_video_time_code_to_date_time
|
gst_video_time_code_to_date_time
|
||||||
|
|
Loading…
Reference in a new issue