static gboolean
gst_emul_codec_element_init ()
{
- int fd, size = 0;
+ int fd = 0, size = 0;
int version = 0;
int data_length = 0;
- int ret = TRUE;
int i, elem_cnt = 0;
void *buffer = NULL;
-// GList *element = NULL;
CodecElement *elem = NULL;
fd = open (CODEC_DEV, O_RDWR);
if (fd < 0) {
perror ("failed to open codec device");
+ return FALSE;
}
ioctl (fd, CODEC_CMD_GET_VERSION, &version);
if (version != CODEC_VER) {
CODEC_LOG (INFO, "version conflict between device: %d, plugin: %d\n",
version, CODEC_VER);
+ close (fd);
return FALSE;
}
buffer = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (!buffer) {
perror ("failure memory mapping.");
+ close (fd);
+ return FALSE;
}
-// CODEC_LOG (DEBUG, "request a device to get codec element.\n");
+ CODEC_LOG (DEBUG, "request a device to get codec element.\n");
ioctl(fd, CODEC_CMD_GET_ELEMENT, NULL);
memcpy(&data_length, (uint8_t *)buffer, sizeof(data_length));
size += sizeof(data_length);
-// printf("[gst-emul][%d] data_length = %d\n", __LINE__, data_length);
-
elem = g_malloc0 (data_length);
if (!elem) {
CODEC_LOG (ERR, "Failed to allocate memory.\n");
- ret = FALSE;
munmap (buffer, 4096);
close (fd);
- return ret;
+ return FALSE;
}
memcpy (elem, (uint8_t *)buffer + size, data_length);
elem_cnt = data_length / sizeof(CodecElement);
for (i = 0; i < elem_cnt; i++) {
-// element = g_list_append (element, &elem[i]);
codec_element = g_list_append (codec_element, &elem[i]);
}
-// codec_element = element;
munmap (buffer, 4096);
close (fd);
- return ret;
+ return TRUE;
}
static gboolean
if (codec->media_type == AVMEDIA_TYPE_VIDEO) {
CODEC_LOG (DEBUG, "before avcodec_open. pixel format: %d\n", ctx->video.pix_fmt);
-// memcpy (device_buf + size, &ctx->video, sizeof(ctx->video));
- *(VideoData *)(device_buf + size) = ctx->video;
+ memcpy (device_buf + size, &ctx->video, sizeof(ctx->video));
+// *(VideoData *)(device_buf + size) = ctx->video;
size += sizeof(ctx->video);
} else if (codec->media_type == AVMEDIA_TYPE_AUDIO) {
-// memcpy (device_buf + size, &ctx->audio, sizeof(ctx->audio));
- *(AudioData *)(device_buf + size) = ctx->audio;
+ memcpy (device_buf + size, &ctx->audio, sizeof(ctx->audio));
+// *(AudioData *)(device_buf + size) = ctx->audio;
size += sizeof(ctx->audio);
} else {
CODEC_LOG (ERR, "media type is unknown.\n");
return;
}
-// memcpy (device_buf + size,
-// &ctx->bit_rate, sizeof(ctx->bit_rate));
- *(int *)(device_buf + size) = ctx->bit_rate;
+ memcpy (device_buf + size,
+ &ctx->bit_rate, sizeof(ctx->bit_rate));
+// *(int *)(device_buf + size) = ctx->bit_rate;
size += sizeof(ctx->bit_rate);
-// memcpy (device_buf + size,
-// &ctx->codec_tag, sizeof(ctx->codec_tag));
- *(int *)(device_buf + size) = ctx->codec_tag;
+ memcpy (device_buf + size,
+ &ctx->codec_tag, sizeof(ctx->codec_tag));
+// *(int *)(device_buf + size) = ctx->codec_tag;
size += sizeof(ctx->codec_tag);
-// memcpy (device_buf + size,
-// &ctx->codecdata_size, sizeof(ctx->codecdata_size));
- *(int *)(device_buf + size) = ctx->codecdata_size;
+ memcpy (device_buf + size,
+ &ctx->codecdata_size, sizeof(ctx->codecdata_size));
+// *(int *)(device_buf + size) = ctx->codecdata_size;
size += sizeof(ctx->codecdata_size);
if (ctx->codecdata_size > 0) {
memcpy (device_buf + size, ctx->codecdata, ctx->codecdata_size);
size += ctx->codecdata_size;
}
size -= sizeof(size);
-// memcpy (device_buf, &size, sizeof(size));
- *(int *)device_buf = size;
+ memcpy (device_buf, &size, sizeof(size));
+// *(int *)device_buf = size;
CODEC_LOG (DEBUG, "[init] write data: %d\n", size);
}
int ret = 0, size = 0;
CODEC_LOG (DEBUG, "[init] read data from qemu.\n");
-// memcpy (&ret, (uint8_t *)device_buf, sizeof(ret));
- ret = *(int *)device_buf;
+ memcpy (&ret, (uint8_t *)device_buf, sizeof(ret));
+// ret = *(int *)device_buf;
size = sizeof(ret);
if (!ret) {
if (codec->media_type == AVMEDIA_TYPE_AUDIO) {
-// memcpy (&ctx->audio.sample_fmt,
-// (uint8_t *)device_buf + size, sizeof(ctx->audio.sample_fmt));
- ctx->audio.sample_fmt = *(int *)(device_buf + size);
+ memcpy (&ctx->audio.sample_fmt,
+ (uint8_t *)device_buf + size, sizeof(ctx->audio.sample_fmt));
+// ctx->audio.sample_fmt = *(int *)(device_buf + size);
size += sizeof(ctx->audio.sample_fmt);
-// memcpy (&ctx->audio.frame_size,
-// (uint8_t *)device_buf + size, sizeof(ctx->audio.frame_size));
- ctx->audio.frame_size = *(int *)(device_buf + size);
+ memcpy (&ctx->audio.frame_size,
+ (uint8_t *)device_buf + size, sizeof(ctx->audio.frame_size));
+// ctx->audio.frame_size = *(int *)(device_buf + size);
size += sizeof(ctx->audio.frame_size);
-// memcpy (&ctx->audio.bits_per_smp_fmt,
-// (uint8_t *)device_buf + size, sizeof(ctx->audio.bits_per_smp_fmt));
- ctx->audio.bits_per_smp_fmt = *(int *)(device_buf + size);
+ memcpy (&ctx->audio.bits_per_smp_fmt,
+ (uint8_t *)device_buf + size, sizeof(ctx->audio.bits_per_smp_fmt));
+// ctx->audio.bits_per_smp_fmt = *(int *)(device_buf + size);
size += sizeof(ctx->audio.bits_per_smp_fmt);
CODEC_LOG (DEBUG, "[init] sample_fmt %d\n", ctx->audio.sample_fmt);
}
-// memcpy (&ctx->index, (uint8_t *)device_buf + size, sizeof(ctx->index));
ctx->codec = codec;
} else {
CODEC_LOG (ERR, "failed to open codec context\n");
CODEC_LOG (DEBUG, "[decode_video] write data to qemu\n");
size = sizeof(size);
-// memcpy (device_buf + size, &in_size, sizeof(in_size));
- *(int *)(device_buf + size) = in_size;
+ memcpy (device_buf + size, &in_size, sizeof(in_size));
+// *(int *)(device_buf + size) = in_size;
size += sizeof(in_size);
-// memcpy (device_buf + size, &idx, sizeof(idx));
- *(int *)(device_buf + size) = idx;
+ memcpy (device_buf + size, &idx, sizeof(idx));
+// *(int *)(device_buf + size) = idx;
size += sizeof(idx);
-// memcpy (device_buf + size, &in_offset, sizeof(in_offset));
- *(int64_t *)(device_buf + size) = in_offset;
+ memcpy (device_buf + size, &in_offset, sizeof(in_offset));
+// *(int64_t *)(device_buf + size) = in_offset;
size += sizeof(in_offset);
if (in_size > 0) {
memcpy (device_buf + size, in_buf, in_size);
size -= sizeof(size);
CODEC_LOG (DEBUG, "[decode_video] total: %d, inbuf size: %d\n", size, in_size);
-// memcpy(device_buf, &size, sizeof(size));
- *(int *)device_buf = size;
+ memcpy(device_buf, &size, sizeof(size));
+// *(int *)device_buf = size;
CODEC_LOG (DEBUG, "[decode_video] leave\n");
}
int size = 0;
size = sizeof(size);
-// memcpy (device_buf + size, &in_size, sizeof(in_size));
- *(int *)(device_buf + size) = in_size;
+ memcpy (device_buf + size, &in_size, sizeof(in_size));
+// *(int *)(device_buf + size) = in_size;
size += sizeof(in_size);
if (in_size > 0) {
memcpy (device_buf + size, in_buf, in_size);
size -= sizeof(size);
memcpy (device_buf, &size, sizeof(size));
- *(int *)device_buf = size;
+// *(int *)device_buf = size;
CODEC_LOG (DEBUG, "[decode_audio] write size: %d, inbuf_size: %d\n", size, in_size);
}
size += sizeof(*frame_size_ptr);
CODEC_LOG (DEBUG, "[decode_audio] len: %d, frame_size: %d\n",
len, (*frame_size_ptr));
-#if 1
+#if 0
if (len > 0) {
memcpy (samples,
(uint8_t *)device_buf + size, FF_MAX_AUDIO_FRAME_SIZE);
GST_DEBUG_OBJECT (emulenc, "getting caps");
- if (oclass->codec->media_type == AVMEDIA_TYPE_AUDIO) {
+ if (oclass->codec && oclass->codec->media_type == AVMEDIA_TYPE_AUDIO) {
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
GST_DEBUG_OBJECT (emulenc, "audio caps, return template %" GST_PTR_FORMAT,
for (pixfmt = 0;; pixfmt++) {
GstCaps *tmpcaps;
- if (oclass->codec->pix_fmts) {
- if ((pixfmt = oclass->codec->pix_fmts[i++]) == PIX_FMT_NONE) {
- GST_DEBUG_OBJECT (emulenc,
- "At the end of official pixfmt for this codec, breaking out");
- break;
- }
- GST_DEBUG_OBJECT (emulenc,
- "Got an official pixfmt [%d], attempting to get caps", pixfmt);
- tmpcaps = gst_emul_pixfmt_to_caps (pixfmt, NULL, oclass->codec->name);
- if (tmpcaps) {
- GST_DEBUG_OBJECT (emulenc, "Got caps, breaking out");
- if (!caps) {
- caps = gst_caps_new_empty ();
- }
- gst_caps_append (caps, tmpcaps);
- continue;
- }
- GST_DEBUG_OBJECT (emulenc,
- "Couldn't figure out caps without context, trying again with a context");
- }
+// if (oclass->codec->pix_fmts) {
+ if ((pixfmt = oclass->codec->pix_fmts[i++]) == PIX_FMT_NONE) {
+ GST_DEBUG_OBJECT (emulenc,
+ "At the end of official pixfmt for this codec, breaking out");
+ break;
+ }
+ GST_DEBUG_OBJECT (emulenc,
+ "Got an official pixfmt [%d], attempting to get caps", pixfmt);
+ tmpcaps = gst_emul_pixfmt_to_caps (pixfmt, NULL, oclass->codec->name);
+ if (tmpcaps) {
+ GST_DEBUG_OBJECT (emulenc, "Got caps, breaking out");
+ if (!caps) {
+ caps = gst_caps_new_empty ();
+ }
+ gst_caps_append (caps, tmpcaps);
+ continue;
+ }
+ GST_DEBUG_OBJECT (emulenc,
+ "Couldn't figure out caps without context, trying again with a context");
+// }
GST_DEBUG_OBJECT (emulenc, "pixfmt: %d", pixfmt);
if (pixfmt >= PIX_FMT_NB) {
GType type;
gchar *type_name;
gint rank = GST_RANK_NONE;
- gboolean ret = TRUE;
GList *elem = element;
CodecElement *codec = NULL;
+ if (!elem) {
+ return FALSE;
+ }
+
/* register element */
-// while ((elem = g_list_next (elem))) {
do {
- codec = (CodecElement *)elem->data;
+ codec = (CodecElement *)(elem->data);
if (!codec) {
- ret = FALSE;
+ return FALSE;
break;
}
g_free (type_name);
} while ((elem = g_list_next (elem)));
- return ret;
+ return TRUE;
}