Convert to the correct tbm format 39/298039/5
authorEunhye Choi <eunhae1.choi@samsung.com>
Wed, 30 Aug 2023 11:01:46 +0000 (20:01 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Thu, 31 Aug 2023 07:55:58 +0000 (16:55 +0900)
- the accurate tbm format is required
  to convert video frame to other format
  which is returned by GetDecodedPacket()

[Version] 0.0.32

Change-Id: If670d983b30b59ce25a75d84e240bce5dc91ef82

packaging/libtrackrenderer.spec
src/trackrenderer.cpp

index b63de23bc9c6c3664735f5c539e8854f4364a926..63a9126092b7db3dd4b6c30252dcd66af5d9a4de 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libtrackrenderer
 Summary:    new multimedia streaming player trackrenderer
-Version:    0.0.31
+Version:    0.0.32
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 611887655dfeb109fe94eb23fb13acc281630bc1..c7f7f90ef576b4393f233e43e72fd7ee0e8d24fd 100644 (file)
@@ -211,24 +211,23 @@ inline bool IsDisplayNeeded(DisplayType& type) {
 }
 
 uint32_t ConvertToTbmFormat(const gchar *data) {
-  uint32_t format = 0;
-
-  switch GST_MAKE_FOURCC(data[0], data[1], data[2], data[3]) {
-  case GST_MAKE_FOURCC('S', '4', '2', '0'):
-  case GST_MAKE_FOURCC('I', '4', '2', '0'):
-    format = TBM_FORMAT_YUV420;
-    break;
-  case GST_MAKE_FOURCC('B', 'G', 'R', 'A'):
-  case GST_MAKE_FOURCC('B', 'G', 'R', 'x'):
-  case GST_MAKE_FOURCC('S', 'R', '3', '2'):
-    format = TBM_FORMAT_ARGB8888;
-    break;
+  uint32_t fourcc = GST_STR_FOURCC(data);
+
+  switch (fourcc) {
+  case GST_STR_FOURCC("S420"):
+  case GST_STR_FOURCC("I420"):
+    return TBM_FORMAT_YUV420;
+  case GST_STR_FOURCC("BGRA"):
+    return TBM_FORMAT_BGRA8888;
+  case GST_STR_FOURCC("BGRx"):
+    return TBM_FORMAT_BGRX8888;
+  case GST_STR_FOURCC("SR32"):
+    return TBM_FORMAT_ARGB8888;
   default:
-    TRACKRENDERER_ERROR("Not supported type (%c%c%c%c)",
-    data[0], data[1], data[2], data[3]);
-    break;
+    TRACKRENDERER_ERROR("Not supported format %" GST_FOURCC_FORMAT,
+                  GST_FOURCC_ARGS(fourcc));
+    return 0;
   }
-  return format;
 }
 
 constexpr int kMaxPlane = 4;
@@ -315,7 +314,8 @@ tbm_surface_h CreateTbmSurfaceWithBuffer(GstMemory* mem, GstCaps* caps) {
 
   TRACKRENDERER_ERROR("width %d, height %d, bo_size %d", width, height, bo_size);
 
-  if (bo_format == TBM_FORMAT_YUV420) {
+  switch(bo_format) {
+  case TBM_FORMAT_YUV420:
     plane_stride[0] = info.planes[0].stride;
     plane_elevation[0] = info.planes[0].size / info.planes[0].stride;
     plane_stride[1] = info.planes[1].stride;
@@ -345,8 +345,16 @@ tbm_surface_h CreateTbmSurfaceWithBuffer(GstMemory* mem, GstCaps* caps) {
         dest += plane_stride[i];
       }
     }
-  } else if (bo_format == TBM_FORMAT_ARGB8888) { /* emulator */
+    break;
+  case TBM_FORMAT_BGRA8888:
+  case TBM_FORMAT_BGRX8888:
+  case TBM_FORMAT_ARGB8888:
     memcpy(thandle.ptr, mapinfo.data, bo_size);
+    break;
+  default:
+    TRACKRENDERER_ERROR("not supported format");
+    tbm_surface_destroy(tbm_surf);
+    return nullptr;
   }
 
   return tbm_surf;