camera_test: Add preview callback setting before start preview 74/301274/1 accepted/tizen/unified/20231115.024844
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 10 Nov 2023 01:36:56 +0000 (10:36 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Mon, 13 Nov 2023 07:43:37 +0000 (16:43 +0900)
In case of encoded format, it can not be decoded without first buffer.
To get first buffer, the preview callback setting is added before start preview.

[Version] 0.4.115
[Issue Type] test

Change-Id: I569a283374944eb565373df7c23538e546ccf20b
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/capi-media-camera.spec
test/camera_test.c

index f19e85f..11e6b0a 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-camera
 Summary:    A Camera API
-Version:    0.4.114
+Version:    0.4.115
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 6744e56..43146df 100644 (file)
@@ -264,6 +264,15 @@ const char *facing_direction[] = {
        "FRONT",
 };
 
+enum {
+       PREVIEW_CB_TYPE_NORMAL = 0,
+       PREVIEW_CB_TYPE_MEDIA_PACKET,
+       PREVIEW_CB_TYPE_EXTRA
+};
+
+typedef void (*preview_cb)(void);
+typedef int (*set_preview_cb)(camera_h, void *, void *);
+
 
 /*---------------------------------------------------------------------------
   |    LOCAL FUNCTION PROTOTYPES:                                             |
@@ -637,6 +646,62 @@ _MEDIA_PACKET_PREVIEW_CB_OUT:
        media_packet_unref(pkt);
 }
 
+
+static int __set_preview_cb_common(int *preview_cb_dump, set_preview_cb set_cb, preview_cb callback)
+{
+       g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
+
+       if (scanf("%d", preview_cb_dump) <= 0)
+               g_print("\n\tscanf for preview_cb_dump failed[errno:%d]\n", errno);
+
+       flush_stdin();
+
+       return set_cb(hcamcorder->camera, callback, hcamcorder->camera);
+}
+
+
+static int _camera_set_preview_cb(int type)
+{
+       int set_cb = 0;
+
+       g_print("* Preview Callback[type:%d,0:NORMAL,1:MEDIAPACKET,2:EXTRA]\n", type);
+
+       g_print("\tUnset[0] / Set[Others] :");
+
+       if (scanf("%d", &set_cb) <= 0)
+               g_print("\n\tscanf failed[errno:%d]\n", errno);
+
+       flush_stdin();
+
+       switch (type) {
+       case PREVIEW_CB_TYPE_NORMAL:
+               if (set_cb == 0)
+                       return camera_unset_preview_cb(hcamcorder->camera);
+               else
+                       return __set_preview_cb_common(&g_camera_preview_cb_dump,
+                               (set_preview_cb)camera_set_preview_cb,
+                               (preview_cb)_camera_preview_cb);
+       case PREVIEW_CB_TYPE_MEDIA_PACKET:
+               if (set_cb == 0)
+                       return camera_unset_media_packet_preview_cb(hcamcorder->camera);
+               else
+                       return __set_preview_cb_common(&g_camera_mp_preview_cb_dump,
+                               (set_preview_cb)camera_set_media_packet_preview_cb,
+                               (preview_cb)_camera_media_packet_preview_cb);
+       case PREVIEW_CB_TYPE_EXTRA:
+               if (set_cb == 0)
+                       return camera_unset_extra_preview_cb(hcamcorder->camera);
+               else
+                       return __set_preview_cb_common(&g_camera_extra_preview_cb_dump,
+                               (set_preview_cb)camera_set_extra_preview_cb,
+                               (preview_cb)_camera_extra_preview_cb);
+       default:
+               g_print("\n\tUnknown type[%d]\n", type);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+}
+
+
 static bool _resolution_cb(int width, int height, void *user_data)
 {
        resolution_stack *data = (resolution_stack *)user_data;
@@ -910,7 +975,6 @@ static void main_menu(gchar buf)
        int err = 0;
        int interval = 0;
        int count = 0;
-       int set_cb = 0;
 
        switch (buf) {
        case '1': /* Capture */
@@ -957,48 +1021,15 @@ static void main_menu(gchar buf)
                camera_start_preview(hcamcorder->camera);
                break;
        case '5':
-               g_print("* Preview Callback\n");
-               g_print("\tUnset[0] / Set[Others] :");
-               err = scanf("%d", &set_cb);
-               flush_stdin();
-               if (set_cb) {
-                       g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
-                       err = scanf("%d", &g_camera_preview_cb_dump);
-                       flush_stdin();
-                       err = camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
-               } else {
-                       err = camera_unset_preview_cb(hcamcorder->camera);
-               }
+               err = _camera_set_preview_cb(PREVIEW_CB_TYPE_NORMAL);
                g_print("\tresult[0x%x]\n\n", err);
                break;
        case '6':
-               g_print("* Extra Preview Callback\n");
-               g_print("\tUnset[0] / Set[Others] :");
-               err = scanf("%d", &set_cb);
-               flush_stdin();
-               if (set_cb) {
-                       g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
-                       err = scanf("%d", &g_camera_extra_preview_cb_dump);
-                       flush_stdin();
-                       err = camera_set_extra_preview_cb(hcamcorder->camera, _camera_extra_preview_cb, hcamcorder->camera);
-               } else {
-                       err = camera_unset_extra_preview_cb(hcamcorder->camera);
-               }
+               err = _camera_set_preview_cb(PREVIEW_CB_TYPE_EXTRA);
                g_print("\tresult[0x%x]\n\n", err);
                break;
        case '7':
-               g_print("* Media Packet Preview Callback\n");
-               g_print("\tUnset[0] / Set[Others] :");
-               err = scanf("%d", &set_cb);
-               flush_stdin();
-               if (set_cb) {
-                       g_print("\n\tDump media packet preview data to file - NO[0], YES[Others] : ");
-                       err = scanf("%d", &g_camera_mp_preview_cb_dump);
-                       flush_stdin();
-                       err = camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
-               } else {
-                       err = camera_unset_media_packet_preview_cb(hcamcorder->camera);
-               }
+               err = _camera_set_preview_cb(PREVIEW_CB_TYPE_MEDIA_PACKET);
                g_print("\tresult[0x%x]\n\n", err);
                break;
        case 'b': /* back */
@@ -2002,6 +2033,9 @@ static gboolean mode_change(gchar buf)
        /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
        /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
 
+       if (_camera_set_preview_cb(PREVIEW_CB_TYPE_NORMAL) != CAMERA_ERROR_NONE)
+               g_print("\n\tpreview cb failed\n");
+
        if (camera_is_supported_extra_preview(hcamcorder->camera)) {
                g_print("\n\tEnable extra preview callback - NO[0], YES[Others] : ");
                err = scanf("%d", (int *)&enable_extra_preview);