Changed a way to query codec element. 27/11827/1
authorKitae Kim <kt920.kim@samsung.com>
Thu, 24 Oct 2013 16:40:12 +0000 (01:40 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Wed, 6 Nov 2013 02:09:40 +0000 (11:09 +0900)
The query routine that copies some data from device is called when each element is used.
However, the codec information is static data and it does not
need to copy data from device everytime. So, the data is cached in the driver and
this module gets them from driver, not device.

Change-Id: I31ee17b508ed859297bfa25b09171858fdc37329
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
packaging/gst-plugins-emulator.changes
packaging/gst-plugins-emulator.spec
src/gstmaru.c
src/gstmaru.h
src/gstmaruinterface.c
src/gstmarumem.c

index ffd4dc2aa67ccb40cdb31d807b043874af874fc0..3df6198ca63e31be0d356be031665968b9757963 100644 (file)
@@ -1,3 +1,6 @@
+* Thu Oct 24 05:50:49 UTC 2013 Kitae Kim <kt920.kim@samsung.com>
+- A routine to query codec element is called once per a process when loading this plugin.
+
 * Fri Oct 18 02:41:49 UTC 2013 Kitae Kim <kt920.kim@samsung.com>
 - added flush_buffer routine in decoder.
 
index a8d88bedf561e9de6536b937701de2a6858e5fa7..a2b0fa64772d957cc810852c1ef2f3130b7c178f 100644 (file)
@@ -1,5 +1,5 @@
 Name: gst-plugins-emulator
-Version: 0.1.11
+Version: 0.1.12
 Release: 2 
 Summary: GStreamer Streaming-media framework plug-in for Tizen emulator.
 Group: TO_BE/FILLED_IN
index 19b88a83423f071bd2599654e443389cb6c53bc1..a442d573437a42f5bc503fcc67a07433f77341fb 100644 (file)
@@ -55,6 +55,8 @@ 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 GStaticMutex gst_maru_mutex = G_STATIC_MUTEX_INIT;
 
 static gboolean
 gst_maru_codec_element_init ()
@@ -66,6 +68,10 @@ 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");
@@ -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_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");
index 7075a6905dfc096351e7683013292c5ea0b4a85e..32a2b2d6c5fc7010ca87aec8a6b203358179c5ec 100644 (file)
@@ -151,6 +151,7 @@ enum CODEC_IO_CMD {
   CODEC_CMD_GET_VERSION = 20,
   CODEC_CMD_GET_ELEMENT,
   CODEC_CMD_GET_CONTEXT_INDEX,
+  CODEC_CMD_GET_ELEMENT_DATA,
   CODEC_CMD_USE_DEVICE_MEM = 40,
   CODEC_CMD_GET_DATA_FROM_SMALL_BUFFER,
   CODEC_CMD_GET_DATA_FROM_MEDIUM_BUFFER,
index a9cba6ce510ba889b256cf7392bd7ae0d9d30b9a..171e938f189ab69b90016193f43cde9d2f8eec6f 100644 (file)
@@ -219,7 +219,6 @@ codec_init (CodecContext *ctx, CodecElement *codec, CodecDevice *dev)
   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);
 
@@ -228,15 +227,6 @@ codec_init (CodecContext *ctx, CodecElement *codec, CodecDevice *dev)
   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;
@@ -327,7 +317,7 @@ codec_decode_video (CodecContext *ctx, uint8_t *in_buf, int in_size,
   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);
@@ -335,7 +325,6 @@ codec_decode_video (CodecContext *ctx, uint8_t *in_buf, int in_size,
   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);
@@ -458,12 +447,12 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
       "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);
@@ -475,12 +464,16 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
   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);
@@ -546,8 +539,6 @@ codec_encode_video (CodecContext *ctx, uint8_t *out_buf,
   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);
index a74a95b3c420715752d63358ba6993454624340b..9be306ccf5799deca6acb8ea09181de77f0ae9c4 100644 (file)
@@ -63,8 +63,8 @@ _codec_init_meta_to (CodecContext *ctx,
 
   size = _codec_info_data (codec, device_buf);
 
-  CODEC_LOG (INFO, "name: %s, media type: %s\n",
-    codec->name, codec->media_type ? "AUDIO" : "VIDEO");
+  CODEC_LOG (DEBUG, "context_id: %d, name: %s, media type: %s\n",
+    ctx->index, codec->name, codec->media_type ? "AUDIO" : "VIDEO");
 
   if (codec->media_type == AVMEDIA_TYPE_AUDIO) {
     CODEC_LOG (DEBUG,