video: Add ds_tizen_video_add_format() 52/283252/1
authorSeunghun Lee <shiin.lee@samsung.com>
Tue, 13 Sep 2022 09:37:10 +0000 (18:37 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Fri, 21 Oct 2022 02:27:55 +0000 (11:27 +0900)
This is to send supported formats to wayland clients as described by
tizen_video protocol.

Change-Id: Ibebdffdf637e6c1ae1d3b0b8aadaae37a2ac9946

include/libds-tizen/video.h
src/video/meson.build
src/video/video.c

index 36115c5..4e7943a 100644 (file)
@@ -11,6 +11,8 @@ struct ds_tizen_video;
 
 struct ds_tizen_video *ds_tizen_video_create(struct wl_display *display);
 
+void ds_tizen_video_add_format(struct ds_tizen_video *video, uint32_t format);
+
 void ds_tizen_video_add_destroy_listener(struct ds_tizen_video *video,
         struct wl_listener *listener);
 
index 7da8776..00aaea0 100644 (file)
@@ -3,6 +3,7 @@ libds_tizen_video_files = [
 ]
 
 libds_tizen_video_deps = [
+  dep_libshared,
   deps_libds_tizen,
   dependency('tizen-extension-server', required: true),
 ]
index b9a0557..b4f2796 100644 (file)
@@ -1,13 +1,18 @@
 #include <stdlib.h>
+#include <tbm_type.h>
 #include <wayland-server.h>
 #include <tizen-extension-server-protocol.h>
 #include <libds/log.h>
 
+#include "shared/pixel_format.h"
+
 #define TIZEN_VIDEO_VERSION 1
 
 struct ds_tizen_video
 {
     struct wl_global *global;
+    struct wl_list resources;
+    struct wl_array formats;
 
     struct wl_listener display_destroy;
 
@@ -20,6 +25,10 @@ static void video_handle_display_destroy(struct wl_listener *listener,
         void *data);
 static void video_bind(struct wl_client *client, void *data, uint32_t version,
         uint32_t id);
+static void video_send_format(struct ds_tizen_video *video,
+        tbm_format format);
+static void video_resource_send_formats(struct wl_resource *resource,
+        struct wl_array *formats);
 
 WL_EXPORT struct ds_tizen_video *
 ds_tizen_video_create(struct wl_display *display)
@@ -38,6 +47,9 @@ ds_tizen_video_create(struct wl_display *display)
         return NULL;
     }
 
+    wl_list_init(&video->resources);
+    wl_array_init(&video->formats);
+
     wl_signal_init(&video->events.destroy);
 
     video->display_destroy.notify = video_handle_display_destroy;
@@ -49,6 +61,22 @@ ds_tizen_video_create(struct wl_display *display)
 }
 
 WL_EXPORT void
+ds_tizen_video_add_format(struct ds_tizen_video *video, uint32_t format)
+{
+    tbm_format *p;
+
+    p = wl_array_add(&video->formats, sizeof *p);
+    if (!p) {
+        ds_err("Failed wl_array_add()");
+        return;
+    }
+
+    *p = convert_drm_format_to_tbm(format);
+
+    video_send_format(video, *p);
+}
+
+WL_EXPORT void
 ds_tizen_video_add_destroy_listener(struct ds_tizen_video *video,
         struct wl_listener *listener)
 {
@@ -66,6 +94,8 @@ video_handle_display_destroy(struct wl_listener *listener, void *data)
 
     wl_signal_emit(&video->events.destroy, video);
 
+    wl_array_release(&video->formats);
+
     wl_list_remove(&video->display_destroy.link);
     wl_global_destroy(video->global);
     free(video);
@@ -99,6 +129,12 @@ static const struct tizen_video_interface video_impl = {
 };
 
 static void
+video_handle_resource_destroy(struct wl_resource *resource)
+{
+    wl_list_remove(wl_resource_get_link(resource));
+}
+
+static void
 video_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
 {
     struct ds_tizen_video *video = data;
@@ -109,5 +145,29 @@ video_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
         wl_client_post_no_memory(client);
         return;
     }
-    wl_resource_set_implementation(resource, &video_impl, video, NULL);
+    wl_resource_set_implementation(resource, &video_impl, video,
+            video_handle_resource_destroy);
+
+    video_resource_send_formats(resource, &video->formats);
+
+    wl_list_insert(&video->resources, wl_resource_get_link(resource));
+}
+
+static void
+video_send_format(struct ds_tizen_video *video, tbm_format format)
+{
+    struct wl_resource *resource;
+
+    wl_resource_for_each(resource, &video->resources)
+        tizen_video_send_format(resource, format);
+}
+
+static void
+video_resource_send_formats(struct wl_resource *resource,
+        struct wl_array *formats)
+{
+    tbm_format *p;
+
+    wl_array_for_each(p, formats)
+        tizen_video_send_format(resource, *p);
 }