// 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,
}
// 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;
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:
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;
//#define CONFIG_VAAPI
//#define CONFIG_DXVA2
+#define SUPPORT_MEMORY_MONOPOLIZING
+//#define ENCODE_VIDEO_USE_MEMORY_MONOPOLIZING
+
#ifdef CONFIG_VAAPI
#include "dlfcn.h"
#endif
#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
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:
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);
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;
}