#include "qemu-thread.h"
#define MARU_CODEC_DEV_NAME "codec"
-#define MARU_CODEC_VERSION 13
+#define MARU_CODEC_VERSION 14
/* Needs 16M to support 1920x1080 video resolution.
* Output size for encoding has to be greater than (width * height * 6)
void qemu_reset_codec_info(SVCodecState *s, uint32_t value)
{
- int i;
- int ctx_index = 0, mem_index;
+ int ctx_idx;
TRACE("[%s] Enter\n", __func__);
qemu_mutex_lock(&s->thread_mutex);
- for (i = 0; i < CODEC_CONTEXT_MAX; i++) {
- if (s->codec_ctx[i].file_index == value) {
- TRACE("[%s] close %d context\n", __func__, i);
- s->codec_ctx[i].avctx_use = false;
+ for (ctx_idx = 0; ctx_idx < CODEC_CONTEXT_MAX; ctx_idx++) {
+ if (s->codec_ctx[ctx_idx].file_index == value) {
+ TRACE("reset %d context\n", ctx_idx);
+ qemu_mutex_unlock(&s->thread_mutex);
+ qemu_av_free(s, ctx_idx);
+ qemu_mutex_lock(&s->thread_mutex);
+ s->codec_ctx[ctx_idx].avctx_use = false;
break;
}
}
-
- mem_index = s->codec_ctx[i].mem_index;
- s->codec_offset[mem_index] = 0;
-
- qemu_parser_init(s, ctx_index);
+ qemu_parser_init(s, ctx_idx);
qemu_mutex_unlock(&s->thread_mutex);
TRACE("[%s] Leave\n", __func__);
ERR("[%s] failed to find codec of %d\n", __func__, codec_id);
}
+ if (codec->type == AVMEDIA_TYPE_AUDIO) {
+ s->codec_ctx[ctx_index].mem_index = s->codec_param.mem_index;
+ TRACE("set mem_index: %d into ctx_index: %d.\n",
+ s->codec_ctx[ctx_index].mem_index, ctx_index);
+ }
+
#if 0
avctx->get_buffer = qemu_avcodec_get_buffer;
avctx->release_buffer = qemu_avcodec_release_buffer;
ERR("[%s] avcodec_open failure, %d\n", __func__, ret);
}
- if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
- TRACE("[%s] sample_rate:%d, channels:%d\n", __func__,
- avctx->sample_rate, avctx->channels);
- }
-
memcpy((uint8_t *)s->vaddr + offset, &ctx_index, sizeof(int));
size = sizeof(int);
memcpy((uint8_t *)s->vaddr + offset + size, &avctx->pix_fmt, sizeof(int));
for (index = 0; index < CODEC_CONTEXT_MAX; index++) {
if (s->codec_ctx[index].avctx_use == false) {
TRACE("Succeeded to get %d of context.\n", index);
+ s->codec_ctx[index].avctx_use = true;
break;
}
TRACE("Failed to get context.\n");
s->codec_ctx[index].frame = avcodec_alloc_frame();
s->codec_ctx[index].file_index = s->codec_param.file_index;
- s->codec_ctx[index].mem_index = s->codec_param.mem_index;
- s->codec_ctx[index].avctx_use = true;
qemu_parser_init(s, index);
qemu_init_pix_fmt_info();
avctx->extradata = NULL;
}
+ if (avctx && avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+ int audio_idx = s->codec_ctx[ctx_index].mem_index;
+ TRACE("reset audio mem_idex: %d\n", __LINE__, audio_idx);
+ s->audio_codec_offset[audio_idx] = 0;
+ }
+
if (avctx) {
- TRACE("free codec context\n");
+ TRACE("free codec context of %d.\n", ctx_index);
av_free(avctx);
s->codec_ctx[ctx_index].avctx = NULL;
}
if (avframe) {
- TRACE("free codec frame\n");
+ TRACE("free codec frame of %d.\n", ctx_index);
av_free(avframe);
s->codec_ctx[ctx_index].frame = NULL;
}
memcpy(&buf_size, (uint8_t *)s->vaddr + offset, sizeof(int));
size = sizeof(int);
- memcpy(&avctx->channel_layout,
- (uint8_t *)s->vaddr + offset, sizeof(int64_t));
- size += sizeof(int64_t);
- memcpy(&avctx->request_channel_layout,
- (uint8_t *)s->vaddr + offset, sizeof(int64_t));
- size += sizeof(int64_t);
- TRACE("input buffer size : %d\n", buf_size);
-
if (parser_buf && parser_use) {
TRACE("[%s] use parser, buf:%p codec_id:%x\n",
__func__, parser_buf, avctx->codec_id);
size += sizeof(int);
memcpy((uint8_t *)s->vaddr + offset + size, &avctx->channels, sizeof(int));
size += sizeof(int);
+ memcpy((uint8_t *)s->vaddr + offset + size,
+ &avctx->channel_layout, sizeof(int64_t));
+ size += sizeof(int64_t);
memcpy((uint8_t *)s->vaddr + offset + size, &avctx->sub_id, sizeof(int));
size += sizeof(int);
memcpy((uint8_t *)s->vaddr + offset + size,
memcpy(inbuf, (uint8_t *)s->vaddr + offset + size, inbuf_size);
} else {
inbuf = NULL;
- INFO("[%s] input buffer size is zero.\n", __func__);
+ INFO("input buffer size for parser is zero.\n");
}
TRACE("[%s] inbuf:%p inbuf_size :%d\n", __func__, inbuf, inbuf_size);
int index = 0;
for (; index < AUDIO_CODEC_MEM_OFFSET_MAX; index++) {
- if (s->codec_offset[index] == 0) {
- s->codec_offset[index] = 1;
+ if (s->audio_codec_offset[index] == 0) {
+ s->audio_codec_offset[index] = 1;
break;
}
}
+ TRACE("return mmap offset: %d\n", index);
return index;
}