brillcodec: introduce new feature MEMORY_MONOPOLIZING 88/27488/6
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Sun, 14 Sep 2014 09:59:29 +0000 (18:59 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 16 Sep 2014 01:58:15 +0000 (10:58 +0900)
Change-Id: Ia420a289a2ea98fd2d61899390ca9d779c8459ad
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/hw/pci/maru_brillcodec.c
tizen/src/hw/pci/maru_brillcodec.h
tizen/src/hw/pci/maru_brillcodec_device.c

index 07a7cf1..18caf4e 100644 (file)
@@ -58,18 +58,6 @@ MULTI_DEBUG_CHANNEL(qemu, brillcodec);
 // COMMON
 //
 
-enum codec_api_type {
-    INIT = 0,
-    DECODE_VIDEO,
-    ENCODE_VIDEO,
-    DECODE_AUDIO,
-    ENCODE_AUDIO,
-    PICTURE_COPY,
-    DEINIT,
-    FLUSH_BUFFERS,
-    DECODE_VIDEO_AND_PICTURE_COPY,
- };
-
 enum codec_type {
     CODEC_TYPE_UNKNOWN = -1,
     CODEC_TYPE_DECODE,
@@ -150,30 +138,32 @@ static void default_get_data(void *dst, void *src, size_t size)
 }
 
 // queue
-static void *brillcodec_store_inbuf(uint8_t *mem_base,
-                                        CodecParam *ioparam)
+static void *brillcodec_store_inbuf(MaruBrillCodecState *s,
+                        uint8_t *mem_base, CodecParam *ioparam)
 {
     DeviceMemEntry *elem = NULL;
-    int readbuf_size, size = 0;
+    uint32_t readbuf_size = 0;
+    size_t size = sizeof(uint32_t);
     uint8_t *readbuf = NULL;
     uint8_t *device_mem = mem_base + ioparam->mem_offset;
 
     elem = g_malloc0(sizeof(DeviceMemEntry));
-
-    memcpy(&readbuf_size, device_mem, sizeof(readbuf_size));
-    size = sizeof(readbuf_size);
-
-    TRACE("readbuf size: %d\n", readbuf_size);
-    if (readbuf_size <= 0) {
-        TRACE("inbuf size is 0. api_id %d, ctx_id %d, mem_offset %x\n",
-            ioparam->api_index, ioparam->ctx_index, ioparam->mem_offset);
+    if (s->memory_monopolizing & (1 << ioparam->api_index)) {
+        readbuf = device_mem + size;
     } else {
-        readbuf = g_malloc0(readbuf_size);
-        TRACE("copy input buffer from guest. ctx_id: %d, mem_offset: %x\n",
-                ioparam->ctx_index, ioparam->mem_offset);
-        memcpy(readbuf, device_mem + size, readbuf_size);
+        memcpy(&readbuf_size, device_mem, sizeof(readbuf_size));
+
+        TRACE("readbuf size: %d\n", readbuf_size);
+        if (readbuf_size == 0) {
+            TRACE("inbuf size is 0. api_id %d, ctx_id %d, mem_offset %x\n",
+                    ioparam->api_index, ioparam->ctx_index, ioparam->mem_offset);
+        } else {
+            readbuf = g_malloc0(readbuf_size);
+            TRACE("copy input buffer from guest. ctx_id: %d, mem_offset: %x\n",
+                    ioparam->ctx_index, ioparam->mem_offset);
+            memcpy(readbuf, device_mem + size, readbuf_size);
+        }
     }
-    // memset(device_mem, 0x00, sizeof(readbuf_size));
 
     elem->opaque = readbuf;
     elem->data_size = readbuf_size;
@@ -199,7 +189,7 @@ static void brillcodec_push_readqueue(MaruBrillCodecState *s,
     case DECODE_AUDIO:
     case ENCODE_AUDIO:
     case DECODE_VIDEO_AND_PICTURE_COPY:
-        data_buf = brillcodec_store_inbuf((uint8_t *)s->vaddr, ioparam);
+        data_buf = brillcodec_store_inbuf(s, (uint8_t *)s->vaddr, ioparam);
         break;
     case PICTURE_COPY:
     case DEINIT:
@@ -399,7 +389,8 @@ void *brillcodec_threads(void *opaque)
         elem->param_buf = NULL;
 
         if (elem->data_buf) {
-            if (elem->data_buf->opaque) {
+            if (elem->data_buf->opaque &&
+                        !(s->memory_monopolizing & (1 << api_id))) {
                 TRACE("release inbuf\n");
                 g_free(elem->data_buf->opaque);
                 elem->data_buf->opaque = NULL;
index d2f7885..1304447 100644 (file)
@@ -98,9 +98,22 @@ struct MaruBrillCodecState {
     CodecContext        context[CODEC_CONTEXT_MAX];
     CodecParam          ioparam;
 
+    uint16_t             memory_monopolizing;
     CodecPlugin         *hwaccel_plugin;
 };
 
+enum codec_api_type {
+    INIT = 0,
+    DECODE_VIDEO,
+    ENCODE_VIDEO,
+    DECODE_AUDIO,
+    ENCODE_AUDIO,
+    PICTURE_COPY,
+    DEINIT,
+    FLUSH_BUFFERS,
+    DECODE_VIDEO_AND_PICTURE_COPY,
+ };
+
 typedef struct DeviceMemEntry {
     void *opaque;
     uint32_t data_size;
index 428525f..db2e5de 100644 (file)
@@ -32,6 +32,9 @@
 //#define CONFIG_VAAPI
 //#define CONFIG_DXVA2
 
+#define SUPPORT_MEMORY_MONOPOLIZING
+//#define ENCODE_VIDEO_USE_MEMORY_MONOPOLIZING
+
 #ifdef CONFIG_VAAPI
 #include "dlfcn.h"
 #endif
@@ -49,7 +52,10 @@ MULTI_DEBUG_CHANNEL(qemu, brillcodec);
 
 #define CODEC_DEVICE_NAME   "codec-pci"
 #define CODEC_DEVICE_THREAD "codec-workthread"
-#define CODEC_VERSION               3
+
+#define CODEC_MAJOR_VERSION         3
+#define CODEC_MINOR_VERSION         0
+
 #define CODEC_REG_SIZE              (256)
 #define DEFAULT_WORKER_THREAD_CNT   8
 
@@ -179,9 +185,11 @@ static uint64_t brillcodec_read(void *opaque,
         break;
 
     case DEVICE_CMD_GET_DEVICE_INFO:
-        // we have only version information for now...
-        ret = CODEC_VERSION;
-        TRACE("codec version: %d\n", ret);
+        ret |= CODEC_MAJOR_VERSION << 8;
+        ret |= CODEC_MINOR_VERSION;
+        TRACE("codec version: %d.%d.%d\n", CODEC_MAJOR_VERSION, CODEC_MINOR_VERSION, 0);
+
+        ret |= s->memory_monopolizing << 16;
         break;
 
     case DEVICE_CMD_GET_ELEMENT:
@@ -294,6 +302,8 @@ static int brillcodec_initfn(PCIDevice *dev)
     uint8_t *pci_conf = s->dev.config;
 
     INFO("device initialization.\n");
+    INFO("version: %d.%d.%d\n", CODEC_MAJOR_VERSION, CODEC_MINOR_VERSION, 0);
+
     pci_config_set_interrupt_pin(pci_conf, 1);
 
     memory_region_init_ram(&s->vram, OBJECT(s), "maru_brill_codec.vram", CODEC_MEM_SIZE);
@@ -320,6 +330,15 @@ static int brillcodec_initfn(PCIDevice *dev)
         INFO("VA-API extension is enabled.\n");
     }
 
+    // configurations
+    s->memory_monopolizing = 0;
+#ifdef SUPPORT_MEMORY_MONOPOLIZING
+# ifdef ENCODE_VIDEO_USE_MEMORY_MONOPOLIZING
+    s->memory_monopolizing |= 1 << ENCODE_VIDEO;
+    INFO("API [%d] use memory monopolizing.\n", ENCODE_VIDEO);
+# endif
+#endif
+
     return 0;
 }