-From 3ff09fecbe55d2f84f9a83f8965dffb913c00db7 Mon Sep 17 00:00:00 2001
-From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
-Date: Thu, 27 Apr 2017 16:47:00 +0900
-Subject: [PATCH 2/3] Add gst-recorder for h264 output streaming
+From c953d91f8d7e4bca5dd68246c763fd4c4e354287 Mon Sep 17 00:00:00 2001
+From: Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>
+Date: Thu, 10 Aug 2017 15:49:14 +0900
+Subject: [PATCH 2/4] Add gst-recorder for h264 output streaming
-Following patch ported to Weston 1.11 with minor updates
---------
-To use gst-recorder run weston with arg --gst-record. Add
-recorder=true property to output section of one of the outputs
-(real or virtual). Use properties ip, port to set host of RTP
-stream. Use property bitrate to set desirable maximum h264 bitrate.
+This patch is ported to weston 2.0.0.
--------
+Author: Damian Hobson-Garcia <dhobsong@igel.co.jp>
+Date: Thu Apr 27 16:47:00 2017 +0900
+
+ Following patch ported to Weston 1.11 with minor updates
+ --------
+ To use gst-recorder run weston with arg --gst-record. Add
+ recorder=true property to output section of one of the outputs
+ (real or virtual). Use properties ip, port to set host of RTP
+ stream. Use property bitrate to set desirable maximum h264 bitrate.
+ --------
---
- Makefile.am | 17 +
- configure.ac | 12 +
- src/compositor-drm.c | 199 ++++++-
- src/compositor-drm.h | 3 +
- src/gst-recorder.c | 1213 +++++++++++++++++++++++++++++++++++++++++
- src/gst-recorder.h | 58 ++
- src/main.c | 4 +-
- src/media-ctl/libmediactl.c | 955 ++++++++++++++++++++++++++++++++
- src/media-ctl/libv4l2subdev.c | 759 ++++++++++++++++++++++++++
- src/media-ctl/mediactl-priv.h | 64 +++
- src/media-ctl/mediactl.h | 423 ++++++++++++++
- src/media-ctl/tools.h | 32 ++
- src/media-ctl/v4l2subdev.h | 258 +++++++++
- 13 files changed, 3995 insertions(+), 2 deletions(-)
- create mode 100644 src/gst-recorder.c
- create mode 100644 src/gst-recorder.h
- create mode 100644 src/media-ctl/libmediactl.c
- create mode 100644 src/media-ctl/libv4l2subdev.c
- create mode 100644 src/media-ctl/mediactl-priv.h
- create mode 100644 src/media-ctl/mediactl.h
- create mode 100644 src/media-ctl/tools.h
- create mode 100644 src/media-ctl/v4l2subdev.h
+ Makefile.am | 17 +
+ compositor/main.c | 4 +-
+ configure.ac | 13 +
+ libweston/compositor-drm.c | 203 +++++-
+ libweston/compositor-drm.h | 3 +
+ libweston/gst-recorder.c | 1213 +++++++++++++++++++++++++++++++++++
+ libweston/gst-recorder.h | 58 ++
+ libweston/media-ctl/libmediactl.c | 955 +++++++++++++++++++++++++++
+ libweston/media-ctl/libv4l2subdev.c | 759 ++++++++++++++++++++++
+ libweston/media-ctl/mediactl-priv.h | 64 ++
+ libweston/media-ctl/mediactl.h | 423 ++++++++++++
+ libweston/media-ctl/tools.h | 32 +
+ libweston/media-ctl/v4l2subdev.h | 258 ++++++++
+ 13 files changed, 4000 insertions(+), 2 deletions(-)
+ create mode 100644 libweston/gst-recorder.c
+ create mode 100644 libweston/gst-recorder.h
+ create mode 100644 libweston/media-ctl/libmediactl.c
+ create mode 100644 libweston/media-ctl/libv4l2subdev.c
+ create mode 100644 libweston/media-ctl/mediactl-priv.h
+ create mode 100644 libweston/media-ctl/mediactl.h
+ create mode 100644 libweston/media-ctl/tools.h
+ create mode 100644 libweston/media-ctl/v4l2subdev.h
diff --git a/Makefile.am b/Makefile.am
-index 98cd683..301c444 100644
+index cdf82ab..9fb9ba0 100644
--- a/Makefile.am
+++ b/Makefile.am
-@@ -328,6 +328,23 @@ drm_backend_la_SOURCES += src/vaapi-recorder.c src/vaapi-recorder.h
- drm_backend_la_LIBADD += $(LIBVA_LIBS)
+@@ -386,6 +386,23 @@ drm_backend_la_LIBADD += $(LIBVA_LIBS)
+ drm_backend_la_LDFLAGS += -pthread
drm_backend_la_CFLAGS += $(LIBVA_CFLAGS)
endif
+
+if ENABLE_GST_RECORDER
+drm_backend_la_SOURCES += \
-+ src/gst-recorder.c \
-+ src/gst-recorder.h \
-+ src/v4l2-device.h \
-+ src/media-ctl/libmediactl.c \
-+ src/media-ctl/libv4l2subdev.c \
-+ src/media-ctl/mediactl-priv.h \
-+ src/media-ctl/mediactl.h \
-+ src/media-ctl/tools.h \
-+ src/media-ctl/v4l2subdev.h
++ libweston/gst-recorder.c \
++ libweston/gst-recorder.h \
++ libweston/v4l2-device.h \
++ libweston/media-ctl/libmediactl.c \
++ libweston/media-ctl/libv4l2subdev.c \
++ libweston/media-ctl/mediactl-priv.h \
++ libweston/media-ctl/mediactl.h \
++ libweston/media-ctl/tools.h \
++ libweston/media-ctl/v4l2subdev.h
+drm_backend_la_LIBADD += $(LIBVA_LIBS) \
+ -lgstallocators-1.0 \
+ -lgstvideo-1.0
endif
if ENABLE_WAYLAND_COMPOSITOR
+diff --git a/compositor/main.c b/compositor/main.c
+index 72c3cd1..6a8ca7f 100644
+--- a/compositor/main.c
++++ b/compositor/main.c
+@@ -566,7 +566,8 @@ usage(int error_code)
+ " --seat=SEAT\t\tThe seat that weston should run on\n"
+ " --tty=TTY\t\tThe tty to use\n"
+ " --use-pixman\t\tUse the pixman (CPU) renderer\n"
+- " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
++ " --current-mode\tPrefer current KMS mode over EDID preferred mode\n"
++ " --gst-record\t\tEnable GStreamer recording\n\n");
+ #endif
+
+ #if defined(BUILD_FBDEV_COMPOSITOR)
+@@ -1227,6 +1228,7 @@ load_drm_backend(struct weston_compositor *c,
+ { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
+ { WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
+ { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
++ { WESTON_OPTION_BOOLEAN, "gst-record", 0, &config.enable_recorder },
+ };
+
+ parse_options(options, ARRAY_LENGTH(options), argc, argv);
diff --git a/configure.ac b/configure.ac
-index 1d11864..c0717b3 100644
+index a36a516..3cc7501 100644
--- a/configure.ac
+++ b/configure.ac
-@@ -249,6 +249,17 @@ if test "x$enable_rpi_compositor" = "xyes"; then
+@@ -242,6 +242,18 @@ if test x$enable_headless_compositor = xyes; then
fi
- AM_CONDITIONAL(INSTALL_RPI_COMPOSITOR, test "x$have_bcm_host" = "xyes")
+
+AC_ARG_ENABLE(gst-recorder, [ --enable-gst-recorder],,
+ enable_gst_recorder=yes)
+fi
+AM_CONDITIONAL(ENABLE_GST_RECORDER, test "x$enable_gst_recorder" != xno)
+
-
++
AC_ARG_ENABLE([fbdev-compositor], [ --enable-fbdev-compositor],,
enable_fbdev_compositor=yes)
-@@ -734,4 +745,5 @@ AC_MSG_RESULT([
+ AM_CONDITIONAL([ENABLE_FBDEV_COMPOSITOR],
+@@ -724,4 +736,5 @@ AC_MSG_RESULT([
libwebp Support ${have_webp}
libunwind Support ${have_libunwind}
VA H.264 encoding Support ${have_libva}
+ GStreamer H.264 enc. Support ${enable_gst_recorder}
])
-diff --git a/src/compositor-drm.c b/src/compositor-drm.c
-index fc5a2ff..8b65637 100644
---- a/src/compositor-drm.c
-+++ b/src/compositor-drm.c
-@@ -57,6 +57,7 @@
- #include "v4l2-renderer.h"
+diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
+index d0f07e9..0b9643f 100644
+--- a/libweston/compositor-drm.c
++++ b/libweston/compositor-drm.c
+@@ -58,9 +58,11 @@
+ #include "libinput-seat.h"
#include "launcher-util.h"
#include "vaapi-recorder.h"
+#include "gst-recorder.h"
#include "presentation-time-server-protocol.h"
#include "linux-dmabuf.h"
+ #include "linux-dmabuf-unstable-v1-server-protocol.h"
++#include "compositor/weston.h"
-@@ -117,6 +118,8 @@ struct drm_backend {
+ #ifndef DRM_CAP_TIMESTAMP_MONOTONIC
+ #define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
+@@ -113,6 +115,8 @@ struct drm_backend {
- int use_v4l2;
+ int use_pixman;
+ int enable_recorder;
+
- uint32_t prev_state;
-
struct udev_input input;
-@@ -197,7 +200,12 @@ struct drm_output {
+
+ int32_t cursor_width;
+@@ -180,7 +184,12 @@ struct drm_output {
int current_image;
pixman_region32_t previous_damage;
struct wl_listener recorder_frame_listener;
/* not real output device */
-@@ -2350,6 +2358,23 @@ parse_modeline(const char *s, drmModeModeInfo *mode)
+@@ -239,6 +248,9 @@ drm_output_set_cursor(struct drm_output *output);
+ static void
+ drm_output_update_msc(struct drm_output *output, unsigned int seq);
+
++static void
++recorders_enable(struct drm_backend *b);
++
+ static int
+ drm_sprite_crtc_supported(struct drm_output *output, struct drm_sprite *sprite)
+ {
+@@ -2197,6 +2209,23 @@ parse_modeline(const char *s, drmModeModeInfo *mode)
return 0;
}
static void
setup_output_seat_constraint(struct drm_backend *b,
struct weston_output *output,
-@@ -3478,7 +3503,171 @@ recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
+@@ -3457,7 +3486,173 @@ recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
recorder_destroy(output);
}
}
+
+#ifdef BUILD_GST_RECORDER
+static void
-+recorder_destroy(struct drm_backend *c, struct drm_output *output)
++recorder_destroy(struct drm_output *output)
+{
+ wl_list_remove(&output->recorder_frame_listener.link);
+
+{
+ int ret = 0;
+ struct drm_output *output;
-+ struct drm_backend *c;
++ struct drm_backend *b;
+ int fd;
+
+ output = container_of(listener, struct drm_output,
+ recorder_frame_listener);
-+ c = (struct drm_backend *) output->base.compositor->backend;
++ b = to_drm_backend(output->base.compositor);
+
+ if (!output->recorder) {
+ weston_log("%s: output have no recorder enabled\n",
+ return;
+ }
+
-+ ret = drmPrimeHandleToFD(c->drm.fd, output->current->handle, DRM_CLOEXEC, &fd);
++ ret = drmPrimeHandleToFD(b->drm.fd, output->current->handle,
++ DRM_CLOEXEC, &fd);
+ if (!ret) {
+ ret = gst_recorder_frame_dmafd(output->recorder, fd,
+ output->current->stride);
+
+ if (ret < 0) {
+ weston_log("[gst recorder] aborted: %m\n");
-+ recorder_destroy(c, output);
++ recorder_destroy(output);
+ }
+}
+
+static int
-+recorder_enable(struct drm_backend *c, struct drm_output *output)
++recorder_enable(struct drm_backend *b, struct drm_output *output)
+{
+ int enable_recorder = 0;
+ struct gst_recorder_settings *settings;
+ struct weston_config_section *section;
++ struct weston_config *config = wet_get_config(b->compositor);
+ char* s;
+ struct v4l2_rect crop = { .width = output->base.current_mode->width,
+ .height = output->base.current_mode->height,
+ if (output->recorder)
+ return -1;
+
-+ section = weston_config_get_section(c->compositor->config, "output", "name",
++ section = weston_config_get_section(config, "output", "name",
+ output->base.name);
+
+ weston_config_section_get_bool(section, "recorder", &enable_recorder, 0);
+}
+
+static void
-+recorders_enable(struct drm_backend *c)
++recorders_enable(struct drm_backend *b)
+{
+ struct drm_output *output;
+
-+ wl_list_for_each(output, &c->compositor->output_list, base.link) {
-+ recorder_enable(c, output);
++ wl_list_for_each(output, &b->compositor->output_list, base.link) {
++ recorder_enable(b, output);
+ }
+}
+
+recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
+ void *data)
+{
-+ struct drm_backend *c = data;
++ struct drm_backend *b = data;
+ struct drm_output *output;
+
+ /* fix this */
-+ wl_list_for_each(output, &c->compositor->output_list, base.link) {
++ wl_list_for_each(output, &b->compositor->output_list, base.link) {
+ if (!output->recorder)
-+ recorder_enable(c, output);
++ recorder_enable(b, output);
+ else
-+ recorder_destroy(c, output);
++ recorder_destroy(output);
+ }
+}
+#endif
static void
recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
void *data)
-@@ -3571,6 +3760,7 @@ drm_backend_create(struct weston_compositor *compositor,
+@@ -3562,6 +3757,7 @@ drm_backend_create(struct weston_compositor *compositor,
+ b->sprites_are_broken = 1;
b->compositor = compositor;
b->use_pixman = config->use_pixman;
- b->use_v4l2 = config->use_v4l2;
+ b->enable_recorder = config->enable_recorder;
- b->configure_output = config->configure_output;
- b->use_current_mode = config->use_current_mode;
-@@ -3627,6 +3817,10 @@ drm_backend_create(struct weston_compositor *compositor,
+ if (parse_gbm_format(config->gbm_format, GBM_FORMAT_XRGB8888, &b->gbm_format) < 0)
+ goto err_compositor;
+@@ -3611,6 +3807,11 @@ drm_backend_create(struct weston_compositor *compositor,
}
}
+#ifdef BUILD_GST_RECORDER
-+ gst_recorder_init();
++ if (b->enable_recorder)
++ gst_recorder_init();
+#endif
+
b->base.destroy = drm_destroy;
b->base.restore = drm_restore;
-@@ -3688,6 +3882,9 @@ drm_backend_create(struct weston_compositor *compositor,
- recorder_binding, b);
- weston_compositor_add_debug_binding(compositor, KEY_W,
- renderer_switch_binding, b);
-+ /* enable GST recording-streaming */
-+ if (b->enable_recorder)
-+ recorders_enable(b);
-
- if (compositor->renderer->import_dmabuf) {
- if (linux_dmabuf_setup(compositor) < 0)
-diff --git a/src/compositor-drm.h b/src/compositor-drm.h
-index d3d15af..65305d9 100644
---- a/src/compositor-drm.h
-+++ b/src/compositor-drm.h
-@@ -90,6 +90,9 @@ struct weston_drm_backend_config {
- /** Whether to use the v4l2 renderer insted of the OpenGL ES renderer. */
- bool use_v4l2;
+diff --git a/libweston/compositor-drm.h b/libweston/compositor-drm.h
+index 00171c8..4eb6097 100644
+--- a/libweston/compositor-drm.h
++++ b/libweston/compositor-drm.h
+@@ -111,6 +111,9 @@ struct weston_drm_backend_config {
+ /** Whether to use the pixman renderer instead of the OpenGL ES renderer. */
+ bool use_pixman;
+ /** Whether to use the v4l2 renderer insted of the OpenGL ES renderer. */
+ bool enable_recorder;
/** The seat to be used for input and output.
*
* If NULL the default "seat0" will be used. The backend will
-diff --git a/src/gst-recorder.c b/src/gst-recorder.c
+diff --git a/libweston/gst-recorder.c b/libweston/gst-recorder.c
new file mode 100644
-index 0000000..2e3b359
+index 0000000..d46d4f0
--- /dev/null
-+++ b/src/gst-recorder.c
++++ b/libweston/gst-recorder.c
@@ -0,0 +1,1213 @@
+/*
+ * Copyright © 2016 Cogent Embedded Inc
+#include "compositor.h"
+#include "gst-recorder.h"
+
-+/* VSP includes */
-+#include <media-ctl/mediactl.h>
-+#include <media-ctl/v4l2subdev.h>
-+
+/* Gstreamer includes */
+#include <gst/gst.h>
+#include <gst/app/gstappsrc.h>
+ /* bus */
+ GstBus *bus;
+ /* timestamp */
++ GstClock *clock;
+ GstClockTime timestamp;
-+ uint32_t ts_last_frame;
++ GstClockTime ts_last_frame;
+ /* to be removed */
+ guint callback_tag;
+
+ guint64 dropped;
+
+ gst_message_parse_qos_stats (message, &format, &processed, &dropped);
-+ weston_log("gst_pipeline: qos from: %s processed %lld, dropped %lld\n",
++ weston_log("gst_pipeline: qos from: %s processed %lud, dropped %lud\n",
+ GST_OBJECT_NAME (message->src),
+ processed, dropped);
+ }
+ goto err_gst_stop;
+ }
+
++ /* set clock time */
++ r->clock = gst_element_get_clock (GST_ELEMENT_CAST (r->appsrc));
++
+ weston_log("gst_recorder_create done\n");
+
+ return r;
+static int
+gst_recorder_set_timestamp(struct gst_recorder *r, GstBuffer *buffer)
+{
-+ uint32_t cur_time = weston_compositor_get_time();
++ GstClockTime cur_time = gst_clock_get_time(r->clock);
+
+ if (r->timestamp == 0) {
+ /* first frame assume around DEFAULT_FPS FPS */
+ GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale_int(1, GST_SECOND, DEFAULT_FPS);
+ } else {
-+ uint32_t delta = cur_time - r->ts_last_frame;
-+ /* delta in mS */
-+ GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale_int(delta, GST_SECOND, 1000);
++ GstClockTime delta = cur_time - r->ts_last_frame;
++ /* delta in nS */
++ GST_BUFFER_DURATION(buffer) = delta;
+ }
+
+ r->timestamp += GST_BUFFER_DURATION(buffer);
+
+ return 0;
+}
-diff --git a/src/gst-recorder.h b/src/gst-recorder.h
+diff --git a/libweston/gst-recorder.h b/libweston/gst-recorder.h
new file mode 100644
-index 0000000..e1c53ff
+index 0000000..78290c1
--- /dev/null
-+++ b/src/gst-recorder.h
++++ b/libweston/gst-recorder.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2016 Cogent Embedded Inc
+gst_recorder_frame_dmafd(struct gst_recorder *r, int fd, int stride);
+
+#endif /* _GST_RECORDER_H_ */
-diff --git a/src/main.c b/src/main.c
-index c2168eb..e287a88 100644
---- a/src/main.c
-+++ b/src/main.c
-@@ -278,7 +278,8 @@ usage(int error_code)
- " --tty=TTY\t\tThe tty to use\n"
- " --use-pixman\t\tUse the pixman (CPU) renderer\n"
- " --use-v4l2\t\tUse the v4l2 renderer\n"
-- " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
-+ " --current-mode\tPrefer current KMS mode over EDID preferred mode\n"
-+ " --gst-record\t\tEnable GStreamer recording\n\n");
- #endif
-
- #if defined(BUILD_FBDEV_COMPOSITOR)
-@@ -752,6 +753,7 @@ load_drm_backend(struct weston_compositor *c, const char *backend,
- { WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode },
- { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
- { WESTON_OPTION_BOOLEAN, "use-v4l2", 0, &config.use_v4l2 },
-+ { WESTON_OPTION_BOOLEAN, "gst-record", 0, &config.enable_recorder },
- };
-
- parse_options(options, ARRAY_LENGTH(options), argc, argv);
-diff --git a/src/media-ctl/libmediactl.c b/src/media-ctl/libmediactl.c
+diff --git a/libweston/media-ctl/libmediactl.c b/libweston/media-ctl/libmediactl.c
new file mode 100644
index 0000000..f15b1a3
--- /dev/null
-+++ b/src/media-ctl/libmediactl.c
++++ b/libweston/media-ctl/libmediactl.c
@@ -0,0 +1,955 @@
+/*
+ * Media controller interface library
+
+ return *end ? -EINVAL : 0;
+}
-diff --git a/src/media-ctl/libv4l2subdev.c b/src/media-ctl/libv4l2subdev.c
+diff --git a/libweston/media-ctl/libv4l2subdev.c b/libweston/media-ctl/libv4l2subdev.c
new file mode 100644
index 0000000..4ede4fa
--- /dev/null
-+++ b/src/media-ctl/libv4l2subdev.c
++++ b/libweston/media-ctl/libv4l2subdev.c
@@ -0,0 +1,759 @@
+/*
+ * V4L2 subdev interface library
+
+ return mbus_formats[i].code;
+}
-diff --git a/src/media-ctl/mediactl-priv.h b/src/media-ctl/mediactl-priv.h
+diff --git a/libweston/media-ctl/mediactl-priv.h b/libweston/media-ctl/mediactl-priv.h
new file mode 100644
index 0000000..a0d3a55
--- /dev/null
-+++ b/src/media-ctl/mediactl-priv.h
++++ b/libweston/media-ctl/mediactl-priv.h
@@ -0,0 +1,64 @@
+/*
+ * Media controller interface library
+ (media)->debug_handler((media)->debug_priv, __VA_ARGS__)
+
+#endif /* __MEDIA_PRIV_H__ */
-diff --git a/src/media-ctl/mediactl.h b/src/media-ctl/mediactl.h
+diff --git a/libweston/media-ctl/mediactl.h b/libweston/media-ctl/mediactl.h
new file mode 100644
index 0000000..77ac182
--- /dev/null
-+++ b/src/media-ctl/mediactl.h
++++ b/libweston/media-ctl/mediactl.h
@@ -0,0 +1,423 @@
+/*
+ * Media controller interface library
+int media_parse_setup_links(struct media_device *media, const char *p);
+
+#endif
-diff --git a/src/media-ctl/tools.h b/src/media-ctl/tools.h
+diff --git a/libweston/media-ctl/tools.h b/libweston/media-ctl/tools.h
new file mode 100644
index 0000000..815534c
--- /dev/null
-+++ b/src/media-ctl/tools.h
++++ b/libweston/media-ctl/tools.h
@@ -0,0 +1,32 @@
+/*
+ * Media controller test application
+
+#endif /* __TOOLS_H__ */
+
-diff --git a/src/media-ctl/v4l2subdev.h b/src/media-ctl/v4l2subdev.h
+diff --git a/libweston/media-ctl/v4l2subdev.h b/libweston/media-ctl/v4l2subdev.h
new file mode 100644
index 0000000..1cb53ff
--- /dev/null
-+++ b/src/media-ctl/v4l2subdev.h
++++ b/libweston/media-ctl/v4l2subdev.h
@@ -0,0 +1,258 @@
+/*
+ * V4L2 subdev interface library
+ unsigned int length);
+#endif
--
-1.9.1
+2.9.2