CODEC_PICTURE_COPY,
CODEC_DEINIT,
CODEC_FLUSH_BUFFERS,
- CODEC_DECODE_VIDEO2,
+ CODEC_DECODE_VIDEO_AND_PICTURE_COPY,
};
enum codec_type {
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[] = {
codec_picture_copy,
codec_deinit,
codec_flush_buffers,
- codec_decode_video2,
+ codec_decode_video_and_picture_copy,
};
// default data handler
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;
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");
}
// 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;
}
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 {
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,
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);
}