X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fgstmaru.c;h=81f472ed310b2dbdbb62635c753d99731da2d468;hb=refs%2Fchanges%2F17%2F12017%2F4;hp=19b88a83423f071bd2599654e443389cb6c53bc1;hpb=4b9e3b6ab217999a2c7557f34f2a9b3983a1e2b8;p=platform%2Fadaptation%2Femulator%2Fgst-plugins-emulator.git diff --git a/src/gstmaru.c b/src/gstmaru.c index 19b88a8..81f472e 100644 --- a/src/gstmaru.c +++ b/src/gstmaru.c @@ -55,17 +55,23 @@ gboolean gst_marudec_register (GstPlugin *plugin, GList *element); gboolean gst_maruenc_register (GstPlugin *plugin, GList *element); static GList *codec_element = NULL; +static gboolean codec_element_init = FALSE; +static GMutex gst_maru_mutex; static gboolean gst_maru_codec_element_init () { - int fd = 0, size = 0; + int fd = 0; int version = 0; - int data_length = 0; int i, elem_cnt = 0; + uint32_t data_length = 0; 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"); @@ -88,16 +94,14 @@ gst_maru_codec_element_init () } 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"); @@ -106,7 +110,12 @@ gst_maru_codec_element_init () 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++) { @@ -116,6 +125,8 @@ gst_maru_codec_element_init () munmap (buffer, 4096); close (fd); + CODEC_LOG (DEBUG, "leave: %s\n", __func__); + return TRUE; } @@ -127,10 +138,16 @@ plugin_init (GstPlugin *plugin) gst_maru_init_pix_fmt_info (); - if (!gst_maru_codec_element_init ()) { - GST_ERROR ("failed to get codec elements from QEMU"); - return FALSE; + g_mutex_lock (&gst_maru_mutex); + if (!codec_element_init) { + if (!gst_maru_codec_element_init ()) { + g_mutex_unlock (&gst_maru_mutex); + + GST_ERROR ("failed to get codec elements from QEMU"); + return FALSE; + } } + g_mutex_unlock (&gst_maru_mutex); if (!gst_marudec_register (plugin, codec_element)) { GST_ERROR ("failed to register decoder elements"); @@ -151,7 +168,7 @@ plugin_init (GstPlugin *plugin) } #ifndef PACKAGE -#define PACKAGE "gst-plugins-maruator" +#define PACKAGE "gst-plugins-emulator" #endif GST_PLUGIN_DEFINE ( @@ -160,7 +177,7 @@ GST_PLUGIN_DEFINE ( "tizen-emul", "Codecs for Tizen Emulator", plugin_init, - "0.1.1", + "0.1.2", "LGPL", "gst-plugins-emulator", "http://tizen.org"