2016-03-03 16:15:54 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2016 Centricular Ltd.
|
|
|
|
* Author: Arun Raghavan <arun@centricular.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2016-11-08 16:09:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-03-03 16:15:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-08-25 23:23:23 +00:00
|
|
|
#define GST_NET_API /* empty */
|
|
|
|
|
2016-03-03 16:15:54 +00:00
|
|
|
/* We need the internal netclock estimation function to (re)run the code on
|
|
|
|
* captured samples, plus its dependencies for the build to succeed. */
|
|
|
|
#include "../../libs/gst/net/gstntppacket.c"
|
2018-08-25 23:23:23 +00:00
|
|
|
#include "../../libs/gst/net/gstnettimepacket.c"
|
2016-03-03 16:15:54 +00:00
|
|
|
#include "../../libs/gst/net/gstnetclientclock.c"
|
2017-11-01 09:31:52 +00:00
|
|
|
#include "../../libs/gst/net/gstnetutils.c"
|
2016-03-03 16:15:54 +00:00
|
|
|
|
|
|
|
static gchar *input = NULL;
|
|
|
|
static gboolean debug = FALSE;
|
|
|
|
static gint rtt_limit = 0;
|
|
|
|
|
|
|
|
static GOptionEntry entries[] = {
|
|
|
|
{"input", 'i', 0, G_OPTION_ARG_FILENAME, &input,
|
|
|
|
"Clock reading file containing one local and remote time readings, one "
|
|
|
|
"per line",
|
|
|
|
"FILE"},
|
|
|
|
{"rtt-limit", 'r', 0, G_OPTION_ARG_INT64, &rtt_limit,
|
|
|
|
"Round trip time limit on packets (in ms)", "MSEC"},
|
|
|
|
{"debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Verbose debug output", NULL},
|
|
|
|
{NULL,}
|
|
|
|
};
|
|
|
|
|
Don't use glib format modifiers with sscanf or printf
We do not have a way to know the format modifiers to use with string
functions provided by the system. `G_GUINT64_FORMAT` and other string
modifiers only work for glib string formatting functions. We cannot
use them for string functions provided by the stdlib. See:
https://developer.gnome.org/glib/stable/glib-Basic-Types.html#glib-Basic-Types.description
F.ex.:
```
../tools/gst-stats.c:921:11: error: too many arguments for format [-Werror=format-extra-args]
printf ("Number of Buffers passed: %" G_GUINT64_FORMAT "\n", num_buffers);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tools/gst-stats.c:922:11: error: unknown conversion type character 'l' in format [-Werror=format=]
printf ("Number of Events sent: %" G_GUINT64_FORMAT "\n", num_events);
^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib/gtypes.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib/galloca.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib.h:30,
from ../gst/gst.h:27,
from ../tools/tools.h:28,
from ../tools/gst-stats.c:30:
/builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/lib/glib-2.0/include/glibconfig.h:69:28: note: format string is defined here
#define G_GUINT64_FORMAT "llu"
^
```
and
```
../tests/misc/netclock-replay.c: In function 'main':
../tests/misc/netclock-replay.c:98:23: error: unknown conversion type character 'l' in format [-Werror=format=]
if (sscanf (line, "%" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT " %"
^~~
In file included from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib/gtypes.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib/galloca.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib.h:30,
from ../tests/misc/../../libs/gst/net/gstntppacket.c:38,
from ../tests/misc/netclock-replay.c:31:
/builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/lib/glib-2.0/include/glibconfig.h:69:28: note: format string is defined here
#define G_GUINT64_FORMAT "llu"
^
```
This is needed for upgrading glib inside Cerbero which builds with
`-Werror` on Windows:
https://gitlab.freedesktop.org/gstreamer/cerbero/merge_requests/419
2020-02-25 13:43:59 +00:00
|
|
|
static gboolean
|
|
|
|
parse_time_values (const gchar * line, GstClockTime * local_1,
|
|
|
|
GstClockTime * remote_1, GstClockTime * remote_2, GstClockTime * local_2)
|
|
|
|
{
|
|
|
|
gchar **split;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (!line)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
split = g_strsplit (line, " ", -1);
|
|
|
|
|
|
|
|
if (g_strv_length (split) != 4)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_ascii_string_to_unsigned (split[0], 10, 0, G_MAXUINT64, local_1, NULL))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_ascii_string_to_unsigned (split[1], 10, 0, G_MAXUINT64, remote_1,
|
|
|
|
NULL))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_ascii_string_to_unsigned (split[2], 10, 0, G_MAXUINT64, remote_2,
|
|
|
|
NULL))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_ascii_string_to_unsigned (split[3], 10, 0, G_MAXUINT64, local_2, NULL))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
out:
|
|
|
|
g_strfreev (split);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:15:54 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GstNetClientInternalClock *clock;
|
|
|
|
GstBus *bus;
|
|
|
|
GIOChannel *channel;
|
|
|
|
GIOStatus status;
|
|
|
|
GError *error = NULL;
|
|
|
|
GOptionContext *context;
|
|
|
|
gchar *line;
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
context = g_option_context_new (NULL);
|
|
|
|
g_option_context_add_main_entries (context, entries, NULL);
|
|
|
|
g_option_context_add_group (context, gst_init_get_option_group ());
|
|
|
|
|
|
|
|
if (!g_option_context_parse (context, &argc, &argv, &error)) {
|
|
|
|
g_print ("Failed to parse options: %s\n\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input) {
|
|
|
|
if (!(channel = g_io_channel_new_file (input, "r", NULL))) {
|
|
|
|
g_print ("Could not read input file: %s\n", input);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(channel = g_io_channel_unix_new (0))) {
|
|
|
|
g_print ("Could not read stdin");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clock = g_object_new (GST_TYPE_NET_CLIENT_INTERNAL_CLOCK, NULL);
|
|
|
|
bus = gst_bus_new ();
|
|
|
|
|
|
|
|
/* FIXME: Find a way to do this without touching the structure internals */
|
|
|
|
if (rtt_limit)
|
|
|
|
clock->roundtrip_limit = rtt_limit * GST_MSECOND;
|
|
|
|
clock->busses = g_list_prepend (clock->busses, bus);
|
|
|
|
|
|
|
|
while ((status = g_io_channel_read_line (channel, &line, NULL, NULL,
|
|
|
|
&error)) == G_IO_STATUS_NORMAL) {
|
Don't use glib format modifiers with sscanf or printf
We do not have a way to know the format modifiers to use with string
functions provided by the system. `G_GUINT64_FORMAT` and other string
modifiers only work for glib string formatting functions. We cannot
use them for string functions provided by the stdlib. See:
https://developer.gnome.org/glib/stable/glib-Basic-Types.html#glib-Basic-Types.description
F.ex.:
```
../tools/gst-stats.c:921:11: error: too many arguments for format [-Werror=format-extra-args]
printf ("Number of Buffers passed: %" G_GUINT64_FORMAT "\n", num_buffers);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tools/gst-stats.c:922:11: error: unknown conversion type character 'l' in format [-Werror=format=]
printf ("Number of Events sent: %" G_GUINT64_FORMAT "\n", num_events);
^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib/gtypes.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib/galloca.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib.h:30,
from ../gst/gst.h:27,
from ../tools/tools.h:28,
from ../tools/gst-stats.c:30:
/builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/lib/glib-2.0/include/glibconfig.h:69:28: note: format string is defined here
#define G_GUINT64_FORMAT "llu"
^
```
and
```
../tests/misc/netclock-replay.c: In function 'main':
../tests/misc/netclock-replay.c:98:23: error: unknown conversion type character 'l' in format [-Werror=format=]
if (sscanf (line, "%" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT " %"
^~~
In file included from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib/gtypes.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib/galloca.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib.h:30,
from ../tests/misc/../../libs/gst/net/gstntppacket.c:38,
from ../tests/misc/netclock-replay.c:31:
/builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/lib/glib-2.0/include/glibconfig.h:69:28: note: format string is defined here
#define G_GUINT64_FORMAT "llu"
^
```
This is needed for upgrading glib inside Cerbero which builds with
`-Werror` on Windows:
https://gitlab.freedesktop.org/gstreamer/cerbero/merge_requests/419
2020-02-25 13:43:59 +00:00
|
|
|
GstClockTime local_1, remote_1, remote_2, local_2;
|
2016-03-03 16:15:54 +00:00
|
|
|
GstMessage *message;
|
|
|
|
|
Don't use glib format modifiers with sscanf or printf
We do not have a way to know the format modifiers to use with string
functions provided by the system. `G_GUINT64_FORMAT` and other string
modifiers only work for glib string formatting functions. We cannot
use them for string functions provided by the stdlib. See:
https://developer.gnome.org/glib/stable/glib-Basic-Types.html#glib-Basic-Types.description
F.ex.:
```
../tools/gst-stats.c:921:11: error: too many arguments for format [-Werror=format-extra-args]
printf ("Number of Buffers passed: %" G_GUINT64_FORMAT "\n", num_buffers);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tools/gst-stats.c:922:11: error: unknown conversion type character 'l' in format [-Werror=format=]
printf ("Number of Events sent: %" G_GUINT64_FORMAT "\n", num_events);
^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib/gtypes.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib/galloca.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/include/glib-2.0/glib.h:30,
from ../gst/gst.h:27,
from ../tools/tools.h:28,
from ../tools/gst-stats.c:30:
/builds/nirbheek/cerbero/cerbero-build/dist/windows_x86_64/lib/glib-2.0/include/glibconfig.h:69:28: note: format string is defined here
#define G_GUINT64_FORMAT "llu"
^
```
and
```
../tests/misc/netclock-replay.c: In function 'main':
../tests/misc/netclock-replay.c:98:23: error: unknown conversion type character 'l' in format [-Werror=format=]
if (sscanf (line, "%" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT " %"
^~~
In file included from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib/gtypes.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib/galloca.h:32,
from /builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/include/glib-2.0/glib.h:30,
from ../tests/misc/../../libs/gst/net/gstntppacket.c:38,
from ../tests/misc/netclock-replay.c:31:
/builds/nirbheek/cerbero/cerbero-build/dist/windows_x86/lib/glib-2.0/include/glibconfig.h:69:28: note: format string is defined here
#define G_GUINT64_FORMAT "llu"
^
```
This is needed for upgrading glib inside Cerbero which builds with
`-Werror` on Windows:
https://gitlab.freedesktop.org/gstreamer/cerbero/merge_requests/419
2020-02-25 13:43:59 +00:00
|
|
|
if (!parse_time_values (line, &local_1, &remote_1, &remote_2, &local_2)) {
|
2016-03-03 16:15:54 +00:00
|
|
|
g_print ("Failed to get local/remote time values from: %s\n", line);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
g_print ("%s", line);
|
|
|
|
|
|
|
|
gst_net_client_internal_clock_observe_times (clock, local_1, remote_1,
|
|
|
|
remote_2, local_2);
|
|
|
|
|
|
|
|
g_free (line);
|
|
|
|
|
|
|
|
if ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ELEMENT))) {
|
|
|
|
const GstStructure *st;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
st = gst_message_get_structure (message);
|
|
|
|
str = gst_structure_to_string (st);
|
|
|
|
|
|
|
|
g_print ("%s\n", str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
gst_message_unref (message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == G_IO_CHANNEL_ERROR) {
|
|
|
|
g_print ("Error reading file: %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_io_channel_unref (channel);
|
|
|
|
g_free (input);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|