gboolean gst_maruenc_register (GstPlugin *plugin, GList *element);
static GList *codec_element = NULL;
+static gboolean codec_element_init = FALSE;
+static GStaticMutex gst_maru_mutex = G_STATIC_MUTEX_INIT;
static gboolean
gst_maru_codec_element_init ()
void *buffer = NULL;
CodecElement *elem = NULL;
+ CODEC_LOG (DEBUG, "enter: %s\n", __func__);
+
+ codec_element_init = TRUE;
+
fd = open (CODEC_DEV, O_RDWR);
if (fd < 0) {
perror ("[gst-maru] failed to open codec device");
}
CODEC_LOG (DEBUG, "request a device to get codec element.\n");
- if (ioctl(fd, CODEC_CMD_GET_ELEMENT, NULL) < 0) {
+ if (ioctl(fd, CODEC_CMD_GET_ELEMENT, &data_length) < 0) {
perror ("[gst-maru] failed to get codec elements");
munmap (buffer, 4096);
close (fd);
return FALSE;
}
- memcpy(&data_length, (uint8_t *)buffer, sizeof(data_length));
- size += sizeof(data_length);
-
+ CODEC_LOG (DEBUG, "sizeof codec elements. %d\n", data_length);
elem = g_malloc0 (data_length);
if (!elem) {
CODEC_LOG (ERR, "Failed to allocate memory.\n");
return FALSE;
}
- memcpy (elem, (uint8_t *)buffer + size, data_length);
+ if (ioctl(fd, CODEC_CMD_GET_ELEMENT_DATA, elem) < 0) {
+ CODEC_LOG (ERR, "failed to get codec elements\n");
+ munmap (buffer, 4096);
+ close (fd);
+ return FALSE;
+ }
elem_cnt = data_length / sizeof(CodecElement);
for (i = 0; i < elem_cnt; i++) {
munmap (buffer, 4096);
close (fd);
+ CODEC_LOG (DEBUG, "leave: %s\n", __func__);
+
return TRUE;
}
gst_maru_init_pix_fmt_info ();
- if (!gst_maru_codec_element_init ()) {
- GST_ERROR ("failed to get codec elements from QEMU");
- return FALSE;
+ g_static_mutex_lock (&gst_maru_mutex);
+ if (!codec_element_init) {
+ if (!gst_maru_codec_element_init ()) {
+ g_static_mutex_unlock (&gst_maru_mutex);
+
+ GST_ERROR ("failed to get codec elements from QEMU");
+ return FALSE;
+ }
}
+ g_static_mutex_unlock (&gst_maru_mutex);
if (!gst_marudec_register (plugin, codec_element)) {
GST_ERROR ("failed to register decoder elements");
CODEC_LOG (DEBUG,
"init. ctx: %d meta_offset = 0x%x\n", ctx->index, meta_offset);
-// size = _codec_header (CODEC_INIT, 0, mmapbuf + meta_offset);
size = 8;
_codec_init_meta_to (ctx, codec, mmapbuf + meta_offset + size);
CODEC_LOG (DEBUG,
"init. ctx: %d meta_offset = 0x%x, size: %d\n", ctx->index, meta_offset, size);
-#if 0
- if (codec->media_type == AVMEDIA_TYPE_AUDIO) {
- CODEC_LOG (DEBUG,
- "opened: %d, audio_sample_fmt: %d\n",
- *(int *)(mmapbuf + meta_offset + size),
- *(int *)(mmapbuf + meta_offset + size + 4));
- }
-#endif
-
opened =
_codec_init_meta_from (ctx, codec->media_type, mmapbuf + meta_offset + size);
ctx->codec= codec;
ret = ioctl (fd, CODEC_CMD_SECURE_SMALL_BUFFER, &mem_offset);
if (ret < 0) {
CODEC_LOG (ERR,
- "decode_audio. failed to get available memory to write inbuf\n");
+ "decode_video. failed to get available memory to write inbuf\n");
return -1;
}
CODEC_LOG (DEBUG, "decode_video. mem_offset = 0x%x\n", mem_offset);
meta_offset = (ctx->index - 1) * CODEC_META_DATA_SIZE;
CODEC_LOG (DEBUG, "decode_video. meta_offset = 0x%x\n", meta_offset);
-// size = _codec_header (CODEC_DECODE_VIDEO, mem_offset, mmapbuf + meta_offset);
size = 8;
_codec_decode_video_meta_to (in_size, idx, in_offset, mmapbuf + meta_offset + size);
_codec_decode_video_inbuf (in_buf, in_size, mmapbuf + mem_offset);
"decode_audio. failed to get available memory to write inbuf\n");
return -1;
}
- CODEC_LOG (DEBUG, "decode audio. mem_offset = 0x%x\n", mem_offset);
+// CODEC_LOG (DEBUG, "decode audio. mem_offset = 0x%x\n", mem_offset);
+ CODEC_LOG (DEBUG, "decode_audio. ctx_id: %d mem_offset = 0x%x\n", ctx->index, mem_offset);
meta_offset = (ctx->index - 1) * CODEC_META_DATA_SIZE;
- CODEC_LOG (DEBUG, "decode_audio. meta_offset = 0x%x\n", meta_offset);
+ CODEC_LOG (DEBUG, "decode_audio. ctx_id: %d meta_offset = 0x%x\n", ctx->index, meta_offset);
-// size = _codec_header (CODEC_DECODE_AUDIO, mem_offset, mmapbuf + meta_offset);
size = 8;
_codec_decode_audio_meta_to (in_size, mmapbuf + meta_offset + size);
_codec_decode_audio_inbuf (in_buf, in_size, mmapbuf + mem_offset);
if (ret < 0) {
return -1;
}
+ CODEC_LOG (DEBUG, "after decode_audio. ctx_id: %d mem_offset = 0x%x\n", ctx->index, mem_offset);
len =
_codec_decode_audio_meta_from (&ctx->audio, have_data, mmapbuf + meta_offset + size);
if (len > 0) {
_codec_decode_audio_outbuf (*have_data, samples, mmapbuf + mem_offset);
+ } else {
+ CODEC_LOG (DEBUG, "decode_audio failure. ctx_id: %d\n", ctx->index);
}
+
memset(mmapbuf + mem_offset, 0x00, sizeof(len));
ret = ioctl(fd, CODEC_CMD_RELEASE_BUFFER, &mem_offset);
meta_offset = (ctx->index - 1) * CODEC_META_DATA_SIZE;
CODEC_LOG (DEBUG, "encode_video. meta_offset = 0x%x\n", meta_offset);
-// size =
-// _codec_header (CODEC_ENCODE_VIDEO, mem_offset, mmapbuf + meta_offset);
size = 8;
meta_offset += size;
_codec_encode_video_meta_to (in_size, in_timestamp, mmapbuf + meta_offset);