weston: Fix gst-record uses MONOTONIC time for IVI-Cluster system
[AGL/meta-agl-demo.git] / recipes-graphics / wayland / weston / 0005-gst-record-switch-to-gettime-function-to-CLOCK_MONOT.patch
1 From 725eeebe45149c1340d68a24da50b301955146fc Mon Sep 17 00:00:00 2001
2 From: Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>
3 Date: Sat, 10 Jun 2017 11:23:02 +0900
4 Subject: [PATCH] gst-record: switch to gettime function to CLOCK_MONOTONIC
5
6 When system time is changed (e.g. from NTP) and buffer duration
7 is bigger, the gst-record stops. It should use the CLOCK_MONOTONIC time.
8
9 This patch is updated from
10 https://gerrit.automotivelinux.org/gerrit/#/c/9417/
11
12 Signed-off-by: Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>
13 ---
14  src/gst-recorder.c | 14 +++++++++-----
15  1 file changed, 9 insertions(+), 5 deletions(-)
16
17 diff --git a/src/gst-recorder.c b/src/gst-recorder.c
18 index 441e294..ed1526d 100644
19 --- a/src/gst-recorder.c
20 +++ b/src/gst-recorder.c
21 @@ -102,8 +102,9 @@ struct gst_recorder {
22         /* bus */
23         GstBus *bus;
24         /* timestamp */
25 +       GstClock   *clock;
26         GstClockTime timestamp;
27 -       uint32_t ts_last_frame;
28 +       GstClockTime ts_last_frame;
29         /* to be removed */
30         guint callback_tag;
31  
32 @@ -1036,6 +1037,9 @@ gst_recorder_create(struct gst_recorder_settings *settings)
33                 goto err_gst_stop;
34         }
35  
36 +       /* set clock time */
37 +       r->clock = gst_element_get_clock (GST_ELEMENT_CAST (r->appsrc));
38 +
39         weston_log("gst_recorder_create done\n");
40  
41         return r;
42 @@ -1071,15 +1075,15 @@ gst_recorder_destroy(struct gst_recorder *r)
43  static int
44  gst_recorder_set_timestamp(struct gst_recorder *r, GstBuffer *buffer)
45  {
46 -       uint32_t cur_time = weston_compositor_get_time();
47 +       GstClockTime cur_time = gst_clock_get_time(r->clock);
48  
49         if (r->timestamp == 0) {
50                 /* first frame assume around DEFAULT_FPS FPS */
51                 GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale_int(1, GST_SECOND, DEFAULT_FPS);
52         } else {
53 -               uint32_t delta = cur_time - r->ts_last_frame;
54 -               /* delta in mS */
55 -               GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale_int(delta, GST_SECOND, 1000);
56 +               GstClockTime delta = cur_time - r->ts_last_frame;
57 +               /* delta in nS */
58 +               GST_BUFFER_DURATION(buffer) = delta;
59         }
60  
61         r->timestamp += GST_BUFFER_DURATION(buffer);
62 -- 
63 2.9.2
64