Add reference count to media packet 15/251115/2 accepted/tizen/unified/20210118.141117 submit/tizen/20210113.021956
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 8 Jan 2021 07:52:57 +0000 (16:52 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Fri, 8 Jan 2021 07:56:43 +0000 (16:56 +0900)
[Version] 0.1.31
[Issue Type] New feature

Change-Id: Ib83dd9b883832fe78722d1e609c409ff90cb546d
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/media_packet_private.h
packaging/capi-media-tool.spec
src/media_packet.c

index aab463a53760915f2580268ce35c81a3820085ee..d3f54e727ae605e017f5dab970c10dfa85b49ec4 100644 (file)
@@ -120,7 +120,6 @@ typedef enum {
 } media_buffer_type_e;
 
 typedef struct _media_packet_s {
-
        uint64_t pts;
        uint64_t dts;
        uint64_t duration;
@@ -140,6 +139,7 @@ typedef struct _media_packet_s {
        media_buffer_flags_e flags;
        media_packet_rotate_method_e method;
 
+       int ref_count;
 } media_packet_s;
 
 #ifdef __cplusplus
index d8e32670c495cfdce1dfde3936491f36523aa7f1..641bd963f4702dad113ccfeb242cb57b6ee6411a 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-tool
 Summary:    A Core API media tool library in Tizen Native API
-Version:    0.1.30
+Version:    0.1.31
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 24dd93cba6bf5530261f28f59c45c43b7b2db9be..e14cbe721f047629271a36a24374d001e8294b41 100644 (file)
@@ -62,11 +62,11 @@ static int __pkt_init(media_buffer_type_e type, media_format_h fmt,
                return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
        }
 
+       g_atomic_int_set(&new_handle->ref_count, 1);
        new_handle->type = type;
        new_handle->format = MEDIA_FORMAT_CAST(fmt);
        new_handle->finalizecb_func = fcb;
        new_handle->userdata = fcb_data;
-
        media_format_ref((media_format_h)new_handle->format);
 
        *handle = new_handle;
@@ -1143,6 +1143,11 @@ int media_packet_destroy(media_packet_h packet)
 
        handle = (media_packet_s *)packet;
 
+       if (!g_atomic_int_dec_and_test(&handle->ref_count)) {
+               LOGD("ref count %d", g_atomic_int_get(&handle->ref_count));
+               return MEDIA_PACKET_ERROR_NONE;
+       }
+
        /* finalize callback */
        if (handle->finalizecb_func) {
                int finalize_cb_ret;
@@ -1151,6 +1156,7 @@ int media_packet_destroy(media_packet_h packet)
                /* creator do not want to destroy media packet handle */
                if (finalize_cb_ret == MEDIA_PACKET_REUSE) {
                        LOGI("the media packet handle will be reused.");        //LCOV_EXCL_LINE
+                       g_atomic_int_set(&handle->ref_count, 1);
                        return MEDIA_PACKET_ERROR_NONE;
                }
        }