brillcodec: apply struct base access for codec elements 99/27399/3
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 12 Sep 2014 08:32:07 +0000 (17:32 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 12 Sep 2014 09:56:32 +0000 (18:56 +0900)
Change-Id: I6544e718b9f0d3c3372cc88527b61c30fe55b5f3
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/hw/pci/maru_brillcodec.c

index b3364d572b3e2c30defe54efe5b30346d716a1cd..8e695b6f20c28166d485b9abce1cb4f5b7600447 100644 (file)
@@ -67,7 +67,7 @@ enum codec_api_type {
     CODEC_PICTURE_COPY,
     CODEC_DEINIT,
     CODEC_FLUSH_BUFFERS,
-    CODEC_DECODE_VIDEO2,
+    CODEC_DECODE_VIDEO_AND_PICTURE_COPY,
  };
 
 enum codec_type {
@@ -114,7 +114,7 @@ static bool codec_decode_audio(MaruBrillCodecState *, int, void *);
 static bool codec_encode_audio(MaruBrillCodecState *, int, void *);
 static bool codec_picture_copy(MaruBrillCodecState *, int, void *);
 static bool codec_flush_buffers(MaruBrillCodecState *, int, void *);
-static bool codec_decode_video2(MaruBrillCodecState *, int, void *);
+static bool codec_decode_video_and_picture_copy(MaruBrillCodecState *, int, void *);
 
 typedef bool (*CodecFuncEntry)(MaruBrillCodecState *, int, void *);
 static CodecFuncEntry codec_func_handler[] = {
@@ -126,7 +126,7 @@ static CodecFuncEntry codec_func_handler[] = {
     codec_picture_copy,
     codec_deinit,
     codec_flush_buffers,
-    codec_decode_video2,
+    codec_decode_video_and_picture_copy,
 };
 
 // default data handler
@@ -194,10 +194,10 @@ static void brillcodec_push_readqueue(MaruBrillCodecState *s,
     case CODEC_ENCODE_VIDEO:
     case CODEC_DECODE_AUDIO:
     case CODEC_ENCODE_AUDIO:
-    case CODEC_PICTURE_COPY:
-    case CODEC_DECODE_VIDEO2:
+    case CODEC_DECODE_VIDEO_AND_PICTURE_COPY:
         data_buf = brillcodec_store_inbuf((uint8_t *)s->vaddr, ioparam);
         break;
+    case CODEC_PICTURE_COPY:
     default:
         TRACE("no buffer from guest\n");
         break;
@@ -497,13 +497,20 @@ void brillcodec_release_context(MaruBrillCodecState *s, int32_t ctx_id)
     TRACE("leave: %s\n", __func__);
 }
 
+struct codec_element {
+  int32_t codec_type;
+  int32_t media_type;
+  gchar name[32];
+  gchar long_name[64];
+  union {
+    int32_t pix_fmts[4];
+    int32_t sample_fmts[4];
+  };
+} __attribute__((packed));
+
 int brillcodec_query_list (MaruBrillCodecState *s)
 {
     AVCodec *codec = NULL;
-    uint32_t size = 0, mem_size = 0;
-    uint32_t data_len = 0, length = 0;
-    int32_t codec_type, media_type;
-    int32_t codec_fmts[4], i;
 
     /* register avcodec */
     TRACE("register avcodec\n");
@@ -516,52 +523,42 @@ int brillcodec_query_list (MaruBrillCodecState *s)
     }
 
     // a region to store the number of codecs.
-    length = 32 + 64 + 6 * sizeof(int32_t);
-    mem_size = size = sizeof(uint32_t);
-
+    struct codec_element *element = (struct codec_element *)(s->vaddr + sizeof(uint32_t));
     while (codec) {
-        codec_type =
-            codec->decode ? CODEC_TYPE_DECODE : CODEC_TYPE_ENCODE;
-        media_type = codec->type;
+        int32_t codec_fmts[4], i;
 
         memset(codec_fmts, -1, sizeof(codec_fmts));
-        if (media_type == AVMEDIA_TYPE_VIDEO) {
+        if (codec->type == AVMEDIA_TYPE_VIDEO) {
             if (codec->pix_fmts) {
                 for (i = 0; codec->pix_fmts[i] != -1 && i < 4; i++) {
                     codec_fmts[i] = codec->pix_fmts[i];
                 }
             }
-        } else if (media_type == AVMEDIA_TYPE_AUDIO) {
+        } else if (codec->type == AVMEDIA_TYPE_AUDIO) {
             if (codec->sample_fmts) {
-                for (i = 0; codec->sample_fmts[i] != -1; i++) {
+                for (i = 0; codec->sample_fmts[i] != -1 && i < 4; i++) {
                     codec_fmts[i] = codec->sample_fmts[i];
                 }
             }
         } else {
-            ERR("unknown media type: %d\n", media_type);
+            ERR("unknown media type: %d\n", codec->type);
         }
 
-        memset(s->vaddr + mem_size, 0x00, length);
-        mem_size += length;
+        memset(element, 0x00, sizeof(struct codec_element));
+        element->codec_type = codec->decode ? CODEC_TYPE_DECODE : CODEC_TYPE_ENCODE;
+        element->media_type = codec->type;
+        g_strlcpy(element->name, codec->name, sizeof(element->name));
+        g_strlcpy(element->long_name, codec->long_name, sizeof(element->long_name));
+        memcpy(element->pix_fmts, codec_fmts, sizeof(codec_fmts));
 
-        data_len += length;
-        memcpy(s->vaddr, &data_len, sizeof(data_len));
+        TRACE("register %s %s\n", codec->name, codec->decode ? "decoder" : "encoder");
 
-        memcpy(s->vaddr + size, &codec_type, sizeof(codec_type));
-        size += sizeof(codec_type);
-        memcpy(s->vaddr + size, &media_type, sizeof(media_type));
-        size += sizeof(media_type);
-        memcpy(s->vaddr + size, codec->name, strlen(codec->name));
-        size += 32;
-        memcpy(s->vaddr + size,
-           codec->long_name, strlen(codec->long_name));
-        size += 64;
-        memcpy(s->vaddr + size, codec_fmts, sizeof(codec_fmts));
-        size += sizeof(codec_fmts);
+        ++element;
 
-        TRACE("register %s %s\n", codec->name, codec->decode ? "decoder" : "encoder");
         codec = av_codec_next(codec);
     }
+    uint32_t size = (intptr_t)element - ((intptr_t)s->vaddr + sizeof(uint32_t));
+    memcpy(s->vaddr, &size, sizeof(uint32_t));
 
     return 0;
 }
@@ -669,7 +666,7 @@ struct video_decode_input {
 struct video_decode_output {
     int32_t len;
     int32_t got_picture;
-    uint8_t data;          // for pointing data address
+    uint8_t data;           // for pointing data address
 } __attribute__((packed));
 
 struct video_encode_input {
@@ -682,7 +679,7 @@ struct video_encode_output {
     int32_t len;
     int32_t coded_frame;
     int32_t key_frame;
-    uint8_t data;          // for pointing data address
+    uint8_t data;           // for pointing data address
 } __attribute__((packed));
 
 static void fill_video_data(const AVCodecContext *avctx,
@@ -926,7 +923,7 @@ static bool codec_decode_video(MaruBrillCodecState *s, int ctx_id, void *data_bu
     return codec_decode_video_common(s, ctx_id, data_buf, false);
 }
 
-static bool codec_decode_video2(MaruBrillCodecState *s, int ctx_id, void *data_buf)
+static bool codec_decode_video_and_picture_copy(MaruBrillCodecState *s, int ctx_id, void *data_buf)
 {
     return codec_decode_video_common(s, ctx_id, data_buf, true);
 }