fix audio encoder. 20/24420/1
authorKitae Kim <kt920.kim@samsung.com>
Mon, 14 Jul 2014 04:45:35 +0000 (13:45 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Mon, 14 Jul 2014 06:00:04 +0000 (15:00 +0900)
audio encoder has a problem because of some changes libav 9.8 on QEMU
 - encoding audio API on QEMU side.
 - audio sample format (INT/FLOAT to FLOAT PLANAR)

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

index 846889f..8b2ea2f 100644 (file)
@@ -1,5 +1,5 @@
 Name: gst-plugins-emulator
-Version: 0.2.7
+Version: 0.2.11
 Release: 0
 Summary: GStreamer Decoder and Encoder Plugins for Emulator
 Group: Multimedia/Libraries
index e12d2b7..e6a3ccf 100644 (file)
@@ -1,12 +1,6 @@
-/*
- * Emulator
- *
- * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * KiTae Kim <kt920.kim@samsung.com>
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * object definition and other useful things.
  */
 
-/*
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
+/* Modifications by Samsung Electronics Co., Ltd.
+ * 1. Get available Video/Audio Codecs from Qemu
  */
 
 #include "gstmaru.h"
@@ -73,14 +64,13 @@ gst_maru_codec_element_init ()
 
   fd = open (CODEC_DEV, O_RDWR);
   if (fd < 0) {
-    // perror ("[gst-maru] failed to open codec device");
+    perror ("[gst-maru] failed to open codec device");
     GST_ERROR ("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);
     GST_LOG ("version conflict between device: %d, plugin: %d", version, CODEC_VER);
     close (fd);
     return FALSE;
@@ -88,27 +78,24 @@ gst_maru_codec_element_init ()
 
   buffer = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
   if (buffer == MAP_FAILED) {
-    // perror ("[gst-maru] failure memory mapping.");
+    perror ("[gst-maru] memory mapping failure");
     GST_ERROR ("memory mapping failure");
     close (fd);
     return FALSE;
   }
 
-  // CODEC_LOG (DEBUG, "request a device to get codec element.\n");
   GST_DEBUG ("request a device to get codec element");
   if (ioctl(fd, CODEC_CMD_GET_ELEMENT, &data_length) < 0) {
-    // perror ("[gst-maru] failed to get codec elements");
+    perror ("[gst-maru] failed to get codec elements");
     GST_ERROR ("failed to get codec elements");
     munmap (buffer, 4096);
     close (fd);
     return FALSE;
   }
 
-  // CODEC_LOG (DEBUG, "sizeof codec elements. %d\n", data_length);
   GST_DEBUG ("total size of codec elements %d", data_length);
   elem = g_malloc0 (data_length);
   if (!elem) {
-    // CODEC_LOG (ERR, "Failed to allocate memory.\n");
     GST_ERROR ("failed to allocate memory for codec elements");
     munmap (buffer, 4096);
     close (fd);
@@ -116,7 +103,6 @@ gst_maru_codec_element_init ()
   }
 
   if (ioctl(fd, CODEC_CMD_GET_ELEMENT_DATA, elem) < 0) {
-    // CODEC_LOG (ERR, "failed to get codec elements\n");
     GST_ERROR ("failed to get codec elements");
     munmap (buffer, 4096);
     close (fd);
@@ -183,7 +169,7 @@ GST_PLUGIN_DEFINE (
   "tizen-emul",
   "Codecs for Tizen Emulator",
   plugin_init,
-  "0.2.8",
+  "0.2.11",
   "LGPL",
   "gst-plugins-emulator",
   "http://www.tizen.org"
index ba397ec..86fdb78 100644 (file)
@@ -1,12 +1,6 @@
-/*
- * GStreamer codec plugin for Tizen Emulator.
- *
- * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * KiTae Kim <kt920.kim@samsung.com>
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
  */
 
-// #include "gstmaru.h"
+/* Modifications by Samsung Electronics Co., Ltd.
+ * 1. Provide a hardware buffer in order to avoid additional memcpy operations.
+ */
+
 #include "gstmarudevice.h"
 #include "gstmaruutils.h"
 #include "gstmaruinterface.h"
-// #include "gstmarudevice.h"
 
 #define GST_MARUDEC_PARAMS_QDATA g_quark_from_static_string("marudec-params")
 
 /* indicate dts, pts, offset in the stream */
-
 #define GST_TS_INFO_NONE &ts_info_none
 static const GstTSInfo ts_info_none = { -1, -1, -1, -1 };
 
index f13884b..ca762b1 100644 (file)
@@ -1,12 +1,6 @@
-/*
- * GStreamer codec plugin for Tizen Emulator.
- *
- * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * KiTae Kim <kt920.kim@samsung.com>
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
  */
 
 #include "gstmarudevice.h"
@@ -417,7 +407,6 @@ gst_maruenc_getcaps (GstPad *pad)
     ctx->video.ticks_per_frame = 1;
     ctx->bit_rate = DEFAULT_VIDEO_BITRATE;
 
-//  ctx->strict_std_compliance = -1;
     ctx->video.pix_fmt = pixfmt;
 
     GST_DEBUG ("Attempting to open codec");
@@ -626,12 +615,10 @@ gst_maruenc_chain_video (GstPad *pad, GstBuffer *buffer)
   GstMaruEnc *maruenc = (GstMaruEnc *) (GST_PAD_PARENT (pad));
   GstBuffer *outbuf = NULL;
   gint ret_size = 0, frame_size = 0;
-  int ret = 0;
+  int coded_frame = 0, is_keyframe = 0;
   uint32_t mem_offset = 0;
   uint8_t *working_buf = NULL;
 
-  int coded_frame, is_keyframe;
-
   GST_DEBUG_OBJECT (maruenc,
       "Received buffer of time %" GST_TIME_FORMAT,
       GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
@@ -758,7 +745,7 @@ gst_maruenc_encode_audio (GstMaruEnc *maruenc, guint8 *audio_in,
   }
 
   res = codec_encode_audio (maruenc->context, audio_out, max_size,
-                                  audio_in, in_size, maruenc->dev);
+                            audio_in, in_size, timestamp, maruenc->dev);
 
   if (res < 0) {
     GST_ERROR_OBJECT (maruenc, "Failed to encode buffer: %d", res);
@@ -787,7 +774,7 @@ static GstFlowReturn
 gst_maruenc_chain_audio (GstPad *pad, GstBuffer *buffer)
 {
   GstMaruEnc *maruenc;
-//  GstMaruEncClass *oclass;
+  // GstMaruEncClass *oclass;
   GstClockTime timestamp, duration;
   guint in_size, frame_size;
   gint osize;
@@ -798,7 +785,7 @@ gst_maruenc_chain_audio (GstPad *pad, GstBuffer *buffer)
   CodecContext *ctx;
 
   maruenc = (GstMaruEnc *) (GST_OBJECT_PARENT (pad));
-//  oclass = (GstMaruEncClass *) G_OBJECT_GET_CLASS (maruenc);
+  // oclass = (GstMaruEncClass *) G_OBJECT_GET_CLASS (maruenc);
 
   ctx = maruenc->context;
 
index 27b4143..94ff2e3 100644 (file)
@@ -330,7 +330,7 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
     ctx->index, device_mem + opaque.buffer_size);
 
   len = codec_decode_audio_data_from (have_data, samples,
-                                   &ctx->audio, device_mem + opaque.buffer_size);
+    &ctx->audio, device_mem + opaque.buffer_size);
 
   GST_DEBUG ("decode_audio 3. ctx_id: %d len: %d", ctx->index, len);
 
@@ -387,9 +387,10 @@ codec_encode_video (CodecContext *ctx, uint8_t *out_buf,
 int
 codec_encode_audio (CodecContext *ctx, uint8_t *out_buf,
                     int max_size, uint8_t *in_buf,
-                    int in_size, CodecDevice *dev)
+                    int in_size, int64_t timestamp,
+                    CodecDevice *dev)
 {
-  int len = 0, ret = 0;
+  int ret = 0;
   gpointer buffer = NULL;
   CodecBufferId opaque;
 
@@ -400,7 +401,7 @@ codec_encode_audio (CodecContext *ctx, uint8_t *out_buf,
     return -1;
   }
 
-  codec_encode_audio_data_to (in_size, max_size, in_buf, buffer);
+  codec_encode_audio_data_to (in_size, max_size, in_buf, timestamp, buffer);
 
   dev->mem_info.offset = GET_OFFSET(buffer);
   _codec_invoke_qemu (ctx->index, CODEC_ENCODE_AUDIO, GET_OFFSET(buffer), dev->fd);
@@ -415,11 +416,11 @@ codec_encode_audio (CodecContext *ctx, uint8_t *out_buf,
 
   GST_DEBUG ("encode_audio. mem_offset = 0x%x", opaque.buffer_size);
 
-  len = codec_encode_audio_data_from (out_buf, device_mem + opaque.buffer_size);
+  ret = codec_encode_audio_data_from (out_buf, device_mem + opaque.buffer_size);
 
   release_device_mem(dev->fd, device_mem + opaque.buffer_size);
 
   CODEC_LOG (DEBUG, "leave: %s\n", __func__);
 
-  return len;
+  return ret;
 }
index 14b96f4..448fd66 100644 (file)
@@ -126,7 +126,8 @@ codec_encode_video (CodecContext *ctx, uint8_t*out_buf,
 int
 codec_encode_audio (CodecContext *ctx, uint8_t *out_buf,
                     int out_size, uint8_t *in_buf,
-                    int in_size, CodecDevice *dev);
+                    int in_size, int64_t timestamp,
+                    CodecDevice *dev);
 
 void
 codec_picture_copy (CodecContext *ctx, uint8_t *pict,
index 0e1e01a..70449fc 100644 (file)
@@ -204,9 +204,10 @@ codec_decode_audio_data_from (int *have_data, int16_t *samples,
     memcpy (&resample_size, buffer + size, sizeof(resample_size));
     size += sizeof(resample_size);
     memcpy (samples, buffer + size, resample_size);
+    size += resample_size;
   }
 
-//  return len;
+  // return len;
   return resample_size;
 }
 
@@ -254,15 +255,16 @@ codec_encode_video_data_from (uint8_t *out_buf, int *coded_frame, int *is_keyfra
 }
 
 void
-codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, gpointer buffer)
+codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, int64_t timestamp, gpointer buffer)
 {
   int size = 0;
 
   size = sizeof(size);
   memcpy (buffer + size, &in_size, sizeof(in_size));
   size += sizeof(in_size);
-  memcpy (buffer + size, &max_size, sizeof(max_size));
-  size += sizeof(max_size);
+
+  memcpy (buffer + size, &timestamp, sizeof(timestamp));
+  size += sizeof(timestamp);
 
   if (in_size > 0) {
     memcpy (buffer + size, in_buf, in_size);
@@ -276,15 +278,19 @@ codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, gpointer
 int
 codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer)
 {
-  int len = 0, size = 0;
+  int ret = 0, outbuf_size = 0, size = 0;
 
-  memcpy (&len, buffer, sizeof(len));
-  size = sizeof(len);
-  if (len > 0) {
-    memcpy (out_buf, buffer + size, len);
+  memcpy (&ret, buffer, sizeof(ret));
+  size = sizeof(ret);
+  if (ret == 0) {
+    memcpy (&outbuf_size, buffer + size, sizeof(outbuf_size));
+    size += sizeof(outbuf_size);
+    if (outbuf_size > 0) {
+      memcpy (out_buf, buffer + size, outbuf_size);
+    }
   }
 
-  GST_DEBUG ("encode_audio. outbuf size: %d", len);
+  GST_DEBUG ("encode_audio. ret: %d outbuf size: %d", ret, outbuf_size);
 
-  return len;
+  return outbuf_size;
 }
index 48993d2..e700598 100644 (file)
@@ -49,8 +49,8 @@ void codec_encode_video_data_to (int, int64_t, uint8_t *, gpointer);
 
 int codec_encode_video_data_from (uint8_t *, int *, int *, gpointer);
 
-void codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, gpointer buffer);
+void codec_encode_audio_data_to (int, int, uint8_t *, int64_t, gpointer);
 
-int codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer);
+int codec_encode_audio_data_from (uint8_t *, gpointer);
 
 #endif
index 787aaa7..8e6b435 100644 (file)
@@ -1,12 +1,6 @@
-/*
- * GStreamer codec plugin for Tizen Emulator.
- *
- * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * KiTae Kim <kt920.kim@samsung.com>
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
  */
 
 #include "gstmaruutils.h"
@@ -205,7 +195,7 @@ gst_maru_codectype_to_audio_caps (CodecContext *ctx, const char *name,
   GstCaps *caps = NULL;
 
   GST_DEBUG ("context: %p, codec: %s, encode: %d, codec: %p",
-      ctx, name, encode, codec);
+            ctx, name, encode, codec);
 
   if (ctx) {
     caps = gst_maru_smpfmt_to_caps (ctx->audio.sample_fmt, ctx, name);
@@ -215,8 +205,17 @@ gst_maru_codectype_to_audio_caps (CodecContext *ctx, const char *name,
 
     caps = gst_caps_new_empty ();
     for (i = 0; codec->sample_fmts[i] != -1; i++) {
+      int8_t sample_fmt = -1;
+
+      sample_fmt = codec->sample_fmts[i];
+      if (!strcmp(name, "aac") && encode) {
+        sample_fmt = SAMPLE_FMT_S16;
+        GST_DEBUG ("convert sample_fmt. codec %s, encode %d, sample_fmt %d",
+                  name, encode, sample_fmt);
+      }
+
       temp =
-          gst_maru_smpfmt_to_caps (codec->sample_fmts[i], ctx, name);
+          gst_maru_smpfmt_to_caps (sample_fmt, ctx, name);
       if (temp != NULL) {
         gst_caps_append (caps, temp);
       }
@@ -395,7 +394,6 @@ gst_maru_caps_to_smpfmt (const GstCaps *caps, CodecContext *ctx, gboolean raw)
   gst_structure_get_int (str, "channels", &ctx->audio.channels);
   gst_structure_get_int (str, "rate", &ctx->audio.sample_rate);
   gst_structure_get_int (str, "block_align", &ctx->audio.block_align);
-//  gst_structure_get_int (str, "bitrate", &ctx->audio.bit_rate);
   gst_structure_get_int (str, "bitrate", &ctx->bit_rate);
 
   if (!raw) {
@@ -1124,7 +1122,21 @@ gst_maru_codecname_to_caps (const char *name, CodecContext *ctx, gboolean encode
           G_TYPE_INT, version, "block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
           "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
   } else {
-    GST_ERROR("failed to new caps for %s.\n", name);
+    GST_ERROR("failed to new caps for %s", name);
+  }
+
+  if (caps != NULL) {
+    if (ctx && ctx->codecdata_size > 0) {
+      GstBuffer *data = gst_buffer_new_and_alloc (ctx->codecdata_size);
+
+      memcpy (GST_BUFFER_DATA(data), ctx->codecdata, ctx->codecdata_size);
+      gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
+
+      gst_buffer_unref (data);
+    }
+    GST_LOG ("caps for codec %s %" GST_PTR_FORMAT, name, caps);
+  } else {
+    GST_LOG ("No caps found for codec %s", name);
   }
 
   return caps;
index 2a7f6dd..3be8d25 100644 (file)
@@ -32,8 +32,6 @@
 #define __GST_MARU_UTIL_H__
 
 #include "gstmaru.h"
-
-// libav
 #include "audioconvert.h"
 
 /* Audio channel masks */