webrtc_display: Add support for YV12 format 25/277625/5
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 11 Jul 2022 01:03:06 +0000 (10:03 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 12 Jul 2022 03:46:36 +0000 (03:46 +0000)
[Version] 0.3.149
[Issue Type] Improvement

Change-Id: I9f1c31c1ce3189998709e8a1288c25f2a19ef6c1
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_display.c

index 49b207ddd534aa4afa127bde81aa14322195d367..cf4d17583b638225afe8665af3549d18322c9ba7 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.148
+Version:    0.3.149
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index b7c0ee81a7b400a684cb3a4487e3e4a95ef1628b..953e352d184fabc319d1f249062ab213201b0bf6 100644 (file)
@@ -306,30 +306,33 @@ static bool __swcodec_set_stride_elevation(video_decoded_data_info_s *info)
 {
        RET_VAL_IF(info == NULL, false, "info is NULL");
 
-       if (info->format == MM_PIXEL_FORMAT_I420) {
+       switch (info->format) {
+       case MM_PIXEL_FORMAT_I420:
+       case MM_PIXEL_FORMAT_YV12: {
                int ret = TBM_SURFACE_ERROR_NONE;
                tbm_surface_h ts;
                tbm_surface_info_s ts_info;
                unsigned int i;
 
-               ts = tbm_surface_create(info->width, info->height, TBM_FORMAT_YUV420);
+               ts = tbm_surface_create(info->width, info->height, info->format == MM_PIXEL_FORMAT_I420 ? TBM_FORMAT_YUV420 : TBM_FORMAT_YVU420);
+               RET_VAL_IF(ts == NULL, false, "failed to tbm_surface_create()");
                ret = tbm_surface_get_info(ts, &ts_info);
                tbm_surface_destroy(ts);
-               if (ret != TBM_SURFACE_ERROR_NONE)
-                       return false;
+               RET_VAL_IF(ret != TBM_SURFACE_ERROR_NONE, false, "failed to tbm_surface_get_info()");
 
                for (i = 0; i < ts_info.num_planes; i++) {
                        info->stride[i] = ts_info.planes[i].stride;
                        info->elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
                }
                info->bo_size = ts_info.size;
-
-       } else if (info->format == MM_PIXEL_FORMAT_RGBA) {
+               break;
+       }
+       case MM_PIXEL_FORMAT_RGBA:
                info->stride[0] = info->width * 4;
                info->elevation[0] = info->height;
                info->bo_size = info->stride[0] * info->height;
-
-       } else {
+               break;
+       default:
                LOGE("not supported format(%d)", info->format);
                return false;
        }
@@ -362,8 +365,10 @@ static bool __swcodec_set_bo(webrtc_display_s *display, video_decoded_data_info_
                goto ERROR;
        }
 
-       if (display->tbm->bo_list == NULL)
+       if (display->tbm->bo_list == NULL) {
+               LOG_DEBUG("MMPixelFormatType[%d]", info->format);
                _create_tbm_bo_list(display->tbm, info->bo_size, 10); /* FIXME: use ini file to get list length */
+       }
 
        info->bo[0] = _get_unused_tbm_bo(display->tbm, 10); /* FIXME: use ini file to get timeout sec */
        if (info->bo[0] == NULL) {
@@ -377,17 +382,22 @@ static bool __swcodec_set_bo(webrtc_display_s *display, video_decoded_data_info_
                goto ERROR;
        }
 
-       if (info->format == MM_PIXEL_FORMAT_I420) {
+       switch (info->format) {
+       case MM_PIXEL_FORMAT_I420:
+       case MM_PIXEL_FORMAT_YV12: {
+               int u_plane_idx = info->format == MM_PIXEL_FORMAT_I420 ? 1 : 2;
+               int v_plane_idx = info->format == MM_PIXEL_FORMAT_I420 ? 2 : 1;
+
                src_stride[0] = GST_ROUND_UP_4(info->width);
                src_stride[1] = src_stride[2] = GST_ROUND_UP_4(info->width >> 1);
-               src_offset[1] = src_stride[0] * GST_ROUND_UP_2(info->height);
-               src_offset[2] = src_offset[1] + (src_stride[1] * (GST_ROUND_UP_2(info->height) >> 1));
+               src_offset[u_plane_idx] = src_stride[0] * GST_ROUND_UP_2(info->height);
+               src_offset[v_plane_idx] = src_offset[u_plane_idx] + (src_stride[1] * (GST_ROUND_UP_2(info->height) >> 1));
 
                dest_offset[0] = 0;
                dest_offset[1] = info->stride[0] * info->elevation[0];
                dest_offset[2] = dest_offset[1] + info->stride[1] * info->elevation[1];
 
-               for (i = 0; i < 3; i++) {
+               for (i = 0; i < info->plane_num; i++) {
                        src = mapinfo.data + src_offset[i];
                        dest = thandle.ptr + dest_offset[i];
 
@@ -395,16 +405,17 @@ static bool __swcodec_set_bo(webrtc_display_s *display, video_decoded_data_info_
                                k = 1;
 
                        for (j = 0; j < info->height >> k; j++) {
-                               memcpy(dest, src, info->width>>k);
+                               memcpy(dest, src, info->width >> k);
                                src += src_stride[i];
                                dest += info->stride[i];
                        }
                }
-
-       } else if (info->format == MM_PIXEL_FORMAT_RGBA) {
+               break;
+       }
+       case MM_PIXEL_FORMAT_RGBA:
                memcpy(thandle.ptr, mapinfo.data, info->bo_size);
-
-       } else {
+               break;
+       default:
                LOG_ERROR("not support format %d", info->format);
                goto ERROR;
        }