tee: Check for the removed pad flag also in the slow pushing path
[platform/upstream/gstreamer.git] / tests / misc / netclock-replay.c
1 /* GStreamer
2  * Copyright (C) 2016 Centricular Ltd.
3  * Author: Arun Raghavan <arun@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <stdio.h>
26
27 #define GST_NET_API             /* empty */
28
29 /* We need the internal netclock estimation function to (re)run the code on
30  * captured samples, plus its dependencies for the build to succeed. */
31 #include "../../libs/gst/net/gstntppacket.c"
32 #include "../../libs/gst/net/gstnettimepacket.c"
33 #include "../../libs/gst/net/gstnetclientclock.c"
34 #include "../../libs/gst/net/gstnetutils.c"
35
36 static gchar *input = NULL;
37 static gboolean debug = FALSE;
38 static gint rtt_limit = 0;
39
40 static GOptionEntry entries[] = {
41   {"input", 'i', 0, G_OPTION_ARG_FILENAME, &input,
42         "Clock reading file containing one local and remote time readings, one "
43         "per line",
44       "FILE"},
45   {"rtt-limit", 'r', 0, G_OPTION_ARG_INT64, &rtt_limit,
46       "Round trip time limit on packets (in ms)", "MSEC"},
47   {"debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Verbose debug output", NULL},
48   {NULL,}
49 };
50
51 int
52 main (int argc, char *argv[])
53 {
54   GstNetClientInternalClock *clock;
55   GstBus *bus;
56   GIOChannel *channel;
57   GIOStatus status;
58   GError *error = NULL;
59   GOptionContext *context;
60   gchar *line;
61   int ret = 1;
62
63   context = g_option_context_new (NULL);
64   g_option_context_add_main_entries (context, entries, NULL);
65   g_option_context_add_group (context, gst_init_get_option_group ());
66
67   if (!g_option_context_parse (context, &argc, &argv, &error)) {
68     g_print ("Failed to parse options: %s\n\n", error->message);
69     g_error_free (error);
70     return 1;
71   }
72
73   if (input) {
74     if (!(channel = g_io_channel_new_file (input, "r", NULL))) {
75       g_print ("Could not read input file: %s\n", input);
76       return 1;
77     }
78   } else {
79     if (!(channel = g_io_channel_unix_new (0))) {
80       g_print ("Could not read stdin");
81       return 1;
82     }
83   }
84
85   clock = g_object_new (GST_TYPE_NET_CLIENT_INTERNAL_CLOCK, NULL);
86   bus = gst_bus_new ();
87
88   /* FIXME: Find a way to do this without touching the structure internals */
89   if (rtt_limit)
90     clock->roundtrip_limit = rtt_limit * GST_MSECOND;
91   clock->busses = g_list_prepend (clock->busses, bus);
92
93   while ((status = g_io_channel_read_line (channel, &line, NULL, NULL,
94               &error)) == G_IO_STATUS_NORMAL) {
95     GstClockTime local_1, local_2, remote_1, remote_2;
96     GstMessage *message;
97
98     if (sscanf (line, "%" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT " %"
99             G_GUINT64_FORMAT " %" G_GUINT64_FORMAT, &local_1, &remote_1,
100             &remote_2, &local_2) != 4) {
101       g_print ("Failed to get local/remote time values from: %s\n", line);
102       goto done;
103     }
104
105     if (debug)
106       g_print ("%s", line);
107
108     gst_net_client_internal_clock_observe_times (clock, local_1, remote_1,
109         remote_2, local_2);
110
111     g_free (line);
112
113     if ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ELEMENT))) {
114       const GstStructure *st;
115       gchar *str;
116
117       st = gst_message_get_structure (message);
118       str = gst_structure_to_string (st);
119
120       g_print ("%s\n", str);
121
122       g_free (str);
123       gst_message_unref (message);
124     }
125   }
126
127   if (status == G_IO_CHANNEL_ERROR) {
128     g_print ("Error reading file: %s\n", error->message);
129     g_error_free (error);
130     goto done;
131   }
132
133   g_io_channel_unref (channel);
134   g_free (input);
135   gst_object_unref (bus);
136
137   ret = 0;
138
139 done:
140   return ret;
141 }