e_info_screen_recorder: set resolution of streamrecorder using size of wl_output. 32/227632/8
authorSeunghun Lee <shiin.lee@samsung.com>
Fri, 13 Mar 2020 08:01:27 +0000 (17:01 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Tue, 24 Mar 2020 04:02:09 +0000 (13:02 +0900)
NOTE: Streamrecorder may possibly not support the resolution size of
wl_output. Just let it fail in this case, because there is no way to
know which resolution is supported by streamrecorder for now.

Change-Id: I3c2b5e365af72929727068f5e5ffbf073b69a041

configure.ac
packaging/enlightenment.spec
src/bin/e_info_client_screen_recorder.c

index 07ff69ad5c65b495d41210a1b3fa869cdc2f155a..cd53a21278c048584e155c587cbf38e771433b29 100755 (executable)
@@ -293,6 +293,7 @@ PKG_CHECK_MODULES(E_INFO, [
   eldbus >= ${efl_version}
   xkbcommon
   capi-media-streamrecorder
+  wayland-client
 ])
 
 PKG_CHECK_EXISTS([xkeyboard-config],[
index 37ac686c7c78ca5e4f70308b5d58355eaf4a5adc..76d743add7e82f4bd1bf435b45f636c314fbae18 100644 (file)
@@ -57,6 +57,7 @@ BuildRequires:  pkgconfig(presentation-time-server)
 Requires:       libwayland-extension-server
 
 # for recording video in enlightenment_info
+BuildRequires:  pkgconfig(wayland-client)
 BuildRequires:  pkgconfig(capi-media-streamrecorder)
 
 %if "%{LIBGOMP}" == "use"
index 6bfdab2e622cd2694c686c481e67cc1a2b87436e..32b48e4fb164197affa8596074dcbd0d7d8f54c6 100644 (file)
@@ -1,8 +1,8 @@
 #include <unistd.h>
 #include <Eina.h>
 #include <Ecore.h>
-#include <Ecore_Input.h>
 #include <streamrecorder.h>
+#include <wayland-client.h>
 #include "e_info_client_screen_recorder.h"
 
 int _log_dom = -1;
@@ -13,20 +13,23 @@ int _log_dom = -1;
 #define INF(...)  EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
 #define DBG(...)  EINA_LOG_DOM_DBG(_log_dom, __VA_ARGS__)
 
+typedef struct
+{
+   int w, h;
+} Screen_Recorder_Size;
+
 typedef struct
 {
    char filename[PATH_MAX];
    int framerate;
-   struct
-     {
-        int w, h;
-     } resolution;
+   Screen_Recorder_Size resolution;
 } Screen_Recorder_Args;
 
 streamrecorder_h _stream_recorder;
 
 static Eina_Bool   _screen_recorder_efl_init(void);
 static void        _screen_recorder_efl_shutdown(void);
+static Eina_Bool   _screen_recorder_output_size_get(Screen_Recorder_Size *out);
 static Eina_Bool   _screen_recorder_parse_args(int argc, char **argv, Screen_Recorder_Args *args);
 static Eina_Bool   _stream_recorder_run(const char *filename, int framerate, int w, int h);
 
@@ -79,6 +82,12 @@ e_info_client_screen_recorder_run(int argc, char **argv)
         setenv("XDG_RUNTIME_DIR", "/run", 1);
      }
 
+   if (!_screen_recorder_output_size_get(&args.resolution))
+     {
+        WRN("failed to get output size, use default size (%dx%d)",
+            args.resolution.w, args.resolution.h);
+     }
+
    res = _screen_recorder_parse_args(argc, argv, &args);
    if (!res)
      {
@@ -367,3 +376,115 @@ fail:
 
    return EINA_FALSE;
 }
+
+static void
+_screen_recorder_cb_wl_registry_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version)
+{
+   struct wl_output **output;
+
+   if (strcmp(interface, "wl_output") != 0)
+     return;
+
+
+   output = (struct wl_output **)data;
+   *output = wl_registry_bind(registry, id, &wl_output_interface, version);
+}
+
+static void
+_screen_recorder_cb_wl_registry_global_remove(void *data EINA_UNUSED, struct wl_registry *registry EINA_UNUSED, uint32_t name EINA_UNUSED)
+{
+}
+
+static const struct wl_registry_listener _registry_listener =
+{
+   _screen_recorder_cb_wl_registry_global,
+   _screen_recorder_cb_wl_registry_global_remove,
+};
+
+static void
+_screen_recorder_cb_wl_output_geometry(void *data EINA_UNUSED, struct wl_output *output EINA_UNUSED, int32_t x EINA_UNUSED, int32_t y EINA_UNUSED, int32_t pw EINA_UNUSED, int32_t ph EINA_UNUSED, int32_t subpixel EINA_UNUSED, const char *make EINA_UNUSED, const char *model EINA_UNUSED, int32_t transform EINA_UNUSED)
+{
+}
+
+static void
+_screen_recorder_cb_wl_output_mode(void *data, struct wl_output *output EINA_UNUSED, unsigned int flags, int w, int h, int refresh EINA_UNUSED)
+{
+   Screen_Recorder_Size *size;
+
+   if (!(flags & WL_OUTPUT_MODE_CURRENT))
+     return;
+
+   INF("wl_output.mode: (%dx%d)", w, h);
+   size = data;
+   size->w = w;
+   size->h = h;
+}
+
+static void
+_screen_recorder_cb_wl_output_done(void *data EINA_UNUSED, struct wl_output *output EINA_UNUSED)
+{
+}
+
+static void
+_screen_recorder_cb_wl_output_scale(void *data EINA_UNUSED, struct wl_output *output EINA_UNUSED, int32_t factor EINA_UNUSED)
+{
+}
+
+static const struct wl_output_listener _output_listener =
+{
+   _screen_recorder_cb_wl_output_geometry,
+   _screen_recorder_cb_wl_output_mode,
+   _screen_recorder_cb_wl_output_done,
+   _screen_recorder_cb_wl_output_scale,
+};
+
+static Eina_Bool
+_screen_recorder_output_size_get(Screen_Recorder_Size *out)
+{
+   struct wl_display *display;
+   struct wl_registry *registry;
+   struct wl_output *output = NULL;
+   Screen_Recorder_Size size = {0, };
+   Eina_Bool ret = EINA_FALSE;
+
+   display = wl_display_connect(NULL);
+   if (!display)
+     {
+        ERR("failed to connect wl_display");
+        return ret;
+     }
+
+   registry = wl_display_get_registry(display);
+   if (!registry)
+     {
+        ERR("failed to get wl_registry");
+        goto err_reg;
+     }
+
+   wl_registry_add_listener(registry, &_registry_listener, &output);
+   wl_display_roundtrip(display);
+
+   if (!output)
+     {
+        ERR("failed to bind wl_output");
+        goto err_output;
+     }
+
+   wl_output_add_listener(output, &_output_listener, &size);
+   wl_display_roundtrip(display);
+
+   ret = (size.w != 0);
+   if (ret)
+     {
+        out->w = size.w;
+        out->h = size.h;
+     }
+
+   wl_output_destroy(output);
+err_output:
+   wl_registry_destroy(registry);
+err_reg:
+   wl_display_disconnect(display);
+
+   return ret;
+}