summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsungmin82.ha <sungmin82.ha@samsung.com>2013-07-30 15:15:20 +0900
committersungmin82.ha <sungmin82.ha@samsung.com>2013-07-30 15:15:20 +0900
commitecbf9267511c96c18721f9cdd14a30db49f94aaf (patch)
tree385230db760437196356ece74717c524ed359914 /ext
parent40473aba610cf4d2ff17334ff81b3712a189b453 (diff)
downloadgstreamer0.10-ffmpeg-emulator-tizen.tar.gz
gstreamer0.10-ffmpeg-emulator-tizen.tar.bz2
gstreamer0.10-ffmpeg-emulator-tizen.zip
sync with tizen_2.2HEADtizen
Change-Id: I51d8ca270d83720860046f6119eb145d4b0aa769 Signed-off-by: Sungmin Ha <sungmin82.ha@samsung.com>
Diffstat (limited to 'ext')
-rw-r--r--ext/ffmpeg/gstffmpeg.c5
-rw-r--r--ext/ffmpeg/gstffmpeg.h4
-rw-r--r--ext/ffmpeg/gstffmpegdec.c40
-rw-r--r--ext/ffmpeg/gstffmpegdef.c449
-rw-r--r--ext/ffmpeg/gstffmpegdef.h67
-rw-r--r--ext/ffmpeg/gstffmpegenc.c15
-rw-r--r--ext/ffmpeg/gstffmpegenc.h2
7 files changed, 193 insertions, 389 deletions
diff --git a/ext/ffmpeg/gstffmpeg.c b/ext/ffmpeg/gstffmpeg.c
index 8fc1a76..a782ff8 100644
--- a/ext/ffmpeg/gstffmpeg.c
+++ b/ext/ffmpeg/gstffmpeg.c
@@ -46,7 +46,7 @@ static uint32_t codec_debug_level = 1;
int
gst_ffmpeg_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
- CodecExtraInfo * codec_info)
+ CodecInfo * codec_info)
{
int ret;
@@ -60,7 +60,6 @@ gst_ffmpeg_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
#else
ret = emul_avcodec_init (avctx, codec, codec_info);
#endif
-
if (ret < 0) {
CODEC_LOG (1, "failed to open codec_id:%d. ret:%d\n", codec->id, ret);
}
@@ -71,7 +70,7 @@ gst_ffmpeg_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
}
int
-gst_ffmpeg_avcodec_close (AVCodecContext * avctx, CodecExtraInfo * codec_info)
+gst_ffmpeg_avcodec_close (AVCodecContext * avctx, CodecInfo * codec_info)
{
int ret;
diff --git a/ext/ffmpeg/gstffmpeg.h b/ext/ffmpeg/gstffmpeg.h
index be05e72..a131ba5 100644
--- a/ext/ffmpeg/gstffmpeg.h
+++ b/ext/ffmpeg/gstffmpeg.h
@@ -57,8 +57,8 @@ extern gboolean gst_ffmpegaudioresample_register (GstPlugin * plugin);
extern gboolean gst_ffmpegdeinterlace_register (GstPlugin * plugin);
#endif
-int gst_ffmpeg_avcodec_open (AVCodecContext *avctx, AVCodec *codec, CodecExtraInfo *pInfo);
-int gst_ffmpeg_avcodec_close (AVCodecContext *avctx, CodecExtraInfo *pInfo);
+int gst_ffmpeg_avcodec_open (AVCodecContext *avctx, AVCodec *codec, CodecInfo *pInfo);
+int gst_ffmpeg_avcodec_close (AVCodecContext *avctx, CodecInfo *pInfo);
int gst_ffmpeg_av_find_stream_info(AVFormatContext *ic);
G_END_DECLS
diff --git a/ext/ffmpeg/gstffmpegdec.c b/ext/ffmpeg/gstffmpegdec.c
index 6f759ab..b4a35bb 100644
--- a/ext/ffmpeg/gstffmpegdec.c
+++ b/ext/ffmpeg/gstffmpegdec.c
@@ -146,7 +146,7 @@ struct _GstFFMpegDec
gboolean can_allocate_aligned;
/* Extra info which can determine codec Context on the Host side(QEMU) */
- CodecExtraInfo codecInfo;
+ CodecInfo codecInfo;
};
typedef struct _GstFFMpegDecClass GstFFMpegDecClass;
@@ -441,20 +441,6 @@ gst_ffmpegdec_init (GstFFMpegDec * ffmpegdec)
ffmpegdec->context = avcodec_alloc_context ();
ffmpegdec->picture = avcodec_alloc_frame ();
-#if 0
-#ifndef EMUL_CODEC
- CODEC_LOG (2, "allocate context and frame for emul\n");
- emul_avcodec_alloc_context (&ffmpegdec->codecInfo);
- CODEC_LOG (2, "Context Index:%d\n", ffmpegdec->codecInfo.contextIndex);
- if (ffmpegdec->codecInfo.contextIndex < 0) {
- CODEC_LOG (1, "index of codec context is %d\n",
- ffmpegdec->codecInfo.contextIndex);
- }
- emul_avcodec_alloc_frame (&ffmpegdec->codecInfo);
- CODEC_LOG (2, "after allocate context and frame\n");
-#endif
-#endif
-
ffmpegdec->pctx = NULL;
ffmpegdec->pcache = NULL;
ffmpegdec->par = NULL;
@@ -481,21 +467,21 @@ gst_ffmpegdec_finalize (GObject * object)
{
GstFFMpegDec *ffmpegdec = (GstFFMpegDec *) object;
+#ifndef EMUL_CODEC
+ CODEC_LOG (2, "free AVCodecContext and AVFrame\n");
+ emul_close_codec_device (ffmpegdec->context->codec_type,
+ &ffmpegdec->codecInfo);
+#endif
+
if (ffmpegdec->context != NULL) {
- CODEC_LOG (2, "free AVCodecContext\n");
av_free (ffmpegdec->context);
ffmpegdec->context = NULL;
}
if (ffmpegdec->picture != NULL) {
- CODEC_LOG (2, "free AVFrame\n");
av_free (ffmpegdec->picture);
ffmpegdec->picture = NULL;
}
-#ifndef EMUL_CODEC
- emul_av_free (&ffmpegdec->codecInfo);
- emul_close_codec_device (&ffmpegdec->codecInfo);
-#endif
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -1824,9 +1810,10 @@ gst_ffmpegdec_video_frame (GstFFMpegDec * ffmpegdec,
/* now decode the frame */
gst_avpacket_init (&packet, data, size);
- CODEC_LOG (2, "before decode data:%p, size:%d\n", data, size);
CODEC_LOG (2, "before decoding video, codec_type:%d codec_id:%d\n",
ffmpegdec->context->codec_type, ffmpegdec->context->codec_id);
+ CODEC_LOG (2, "decode data:%p, size:%d\n", data, size);
+
#ifdef EMUL_CODEC
len = avcodec_decode_video2 (ffmpegdec->context,
ffmpegdec->picture, &have_data, &packet);
@@ -1834,12 +1821,7 @@ gst_ffmpegdec_video_frame (GstFFMpegDec * ffmpegdec,
len = emul_avcodec_decode_video (ffmpegdec->context,
ffmpegdec->picture, &have_data, &packet, &ffmpegdec->codecInfo);
#endif
- if (len == 0 || len < 0) {
- CODEC_LOG (2, "after decoding video. idx:%ld, len:%d\n", dec_info->idx,
- len);
- } else {
- CODEC_LOG (2, "after decode len : %d, input data:%p\n", len, data);
- }
+ CODEC_LOG (2, "after decoding video. len:%d\n", len);
/* restore previous state */
if (!decode)
@@ -2229,6 +2211,7 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
gst_avpacket_init (&packet, data, size);
CODEC_LOG (2, "before avcodec_decode_audio. size:%d\n", size);
+
#ifdef EMUL_CODEC
len = avcodec_decode_audio3 (ffmpegdec->context,
(int16_t *) GST_BUFFER_DATA (*outbuf), &have_data, &packet);
@@ -2237,6 +2220,7 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
(int16_t *) GST_BUFFER_DATA (*outbuf), &have_data, &packet,
&ffmpegdec->codecInfo);
#endif
+
GST_DEBUG_OBJECT (ffmpegdec,
"Decode audio: len=%d, have_data=%d", len, have_data);
diff --git a/ext/ffmpeg/gstffmpegdef.c b/ext/ffmpeg/gstffmpegdef.c
index 15536ed..b9c6cfc 100644
--- a/ext/ffmpeg/gstffmpegdef.c
+++ b/ext/ffmpeg/gstffmpegdef.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact:
+ * Contact:
* KiTae Kim <kt920.kim@samsung.com>
* SeokYeon Hwang <syeon.hwang@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
@@ -22,13 +22,6 @@
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
- */
-
-/* First, include the header file for the plugin, to bring in the
- * object definition and other useful things.
- */
-
-/*
*
* Contributors:
* - S-Core Co., Ltd
@@ -50,14 +43,16 @@
#include "gstffmpegdef.h"
#define CODEC_DEV "/dev/codec"
-#define CODEC_MMAP_SIZE (16 * 1024 * 1024)
-#define CODEC_VERSION "1.3"
+#define VIDEO_CODEC_MMAP_SIZE (16 * 1024 * 1024)
+#define AUDIO_CODEC_MMAP_SIZE (256 * 1024)
+#define CODEC_VERSION 14
static CodecParam codec_param;
static ParserBuf parser_buffer;
static int is_registered = 0;
-static sem_t codec_sema;
static int access_mem = 0;
+static sem_t codec_sema;
+
static uint32_t codec_debug_level = 1;
/*
@@ -186,7 +181,7 @@ emul_deserialize_frame (const uint8_t * buff, AVFrame * elem)
* Open Codec Device
*/
int
-emul_open_codec_device (CodecExtraInfo * codec_info)
+emul_open_codec_device (CodecInfo * codec_info)
{
int fd;
@@ -206,8 +201,6 @@ emul_open_codec_device (CodecExtraInfo * codec_info)
return -1;
}
CODEC_LOG (2, "register all codecs\n");
- emul_av_register_all (codec_info);
-// is_registered++;
}
CODEC_LOG (2, "Leave\n");
@@ -220,11 +213,11 @@ emul_open_codec_device (CodecExtraInfo * codec_info)
* And then, close codec device.
*/
void
-emul_close_codec_device (CodecExtraInfo * codec_info)
+emul_close_codec_device (int codec_type, CodecInfo * codec_info)
{
void *buf;
int fd;
- int result;
+ int result = 0;
CODEC_LOG (2, "Enter\n");
buf = codec_info->buffer;
@@ -234,7 +227,17 @@ emul_close_codec_device (CodecExtraInfo * codec_info)
}
CODEC_LOG (1, "release buffer of mapping region:%p\n", buf);
- result = munmap(buf, CODEC_MMAP_SIZE);
+ switch (codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
+ result = munmap(buf, VIDEO_CODEC_MMAP_SIZE);
+ break;
+ case AVMEDIA_TYPE_AUDIO:
+ result = munmap(buf, AUDIO_CODEC_MMAP_SIZE);
+ break;
+ default:
+ break;
+ }
+
if (result != 0) {
CODEC_LOG (1, "failure munmap(), ret:%d\n", result);
}
@@ -258,87 +261,14 @@ emul_close_codec_device (CodecExtraInfo * codec_info)
CODEC_LOG (2, "Leave\n");
}
-void
-emul_av_register_all (CodecExtraInfo * codec_info)
-{
- int fd;
- CODEC_LOG (2, "Enter\n");
-
- fd = codec_info->codec_fd;
- if (fd < 0) {
- CODEC_LOG (1, "Codec device has not been opened yet.\n");
- return;
- }
-
- CODEC_PARAM_INIT (&codec_param, CodecParam);
- codec_param.api_index = EMUL_AV_REGISTER_ALL;
- CODEC_WRITE (fd, &codec_param, 1);
-
- CODEC_LOG (2, "Leave\n");
-}
-
-int
-emul_check_version (CodecExtraInfo * codec_info)
-{
- int fd;
- char codec_ver[32];
- void *buf;
-
- CODEC_LOG (2, "Enter\n");
-
- fd = codec_info->codec_fd;
- if (fd < 0) {
- CODEC_LOG (1, "Codec device has not been opened yet.\n");
- return -1;
- }
-
- buf = codec_info->buffer;
- if (!buf) {
- CODEC_LOG (1, "mapping address is null\n");
- return -1;
- }
-
- while (1) {
- ioctl(fd, EMUL_LOCK_MEM_REGION, &access_mem);
- CODEC_LOG (2, "lock memory region, %d\n", access_mem);
- if (access_mem == 1) {
- CODEC_PARAM_INIT (&codec_param, CodecParam);
- codec_param.api_index = EMUL_GET_CODEC_VER;
- codec_param.ctx_index = codec_info->ctx_idx;
- codec_param.mmap_offset = codec_info->mmap_offset;
- CODEC_WRITE (fd, &codec_param, 1);
-
- memset (codec_ver, 0x00, sizeof(codec_ver));
- memcpy (codec_ver, (uint8_t *) buf, sizeof(codec_ver));
- if (strcmp (codec_ver, CODEC_VERSION) != 0) {
- CODEC_LOG (1, "found conflicts between different versions of"
- "sdk tools and this platform.\nSDK:%s, Platform:%s\n",
- codec_ver, CODEC_VERSION);
- return -1;
- }
- CODEC_LOG (1, "codec version:%s\n", codec_ver);
- break;
- }
- sleep (1);
- CODEC_LOG (1, "cannot access memory region now.\n");
- continue;
- }
- ioctl(fd, EMUL_UNLOCK_MEM_REGION, &access_mem);
- CODEC_LOG (2, "unlock memory region, %d\n", access_mem);
-
- CODEC_LOG (2, "Leave\n");
- return 0;
-}
-
int
emul_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
- CodecExtraInfo * codec_info)
+ CodecInfo * codec_info)
{
- int fd;
- int ret;
- int size;
+ int fd = 0;
+ int ret = 0, size = 0;
int encode = codec->encode ? 1 : 0;
- void *buf;
+ void *buf = NULL;
CODEC_LOG (2, "Enter\n");
@@ -354,12 +284,13 @@ emul_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
return -1;
}
+ avctx->priv_data = (void * )av_mallocz(codec->priv_data_size);
+
while (1) {
ioctl(fd, EMUL_LOCK_MEM_REGION, &access_mem);
CODEC_LOG (2, "lock memory region, %d\n", access_mem);
if (access_mem == 1) {
- CODEC_LOG (2, "codec type:%d, codec id:%x\n", codec->type, codec->id);
memcpy ((uint8_t *) buf, &avctx->bit_rate, sizeof (int));
size = sizeof (int);
memcpy ((uint8_t *) buf + size, &avctx->bit_rate_tolerance, sizeof (int));
@@ -390,8 +321,8 @@ emul_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
memcpy ((uint8_t *) buf + size, &avctx->rc_qsquish, sizeof (float));
size += sizeof (float);
size +=
- emul_serialize_rational (&avctx->sample_aspect_ratio,
- (uint8_t *) buf + size);
+ emul_serialize_rational (&avctx->sample_aspect_ratio,
+ (uint8_t *) buf + size);
memcpy ((uint8_t *) buf + size, &avctx->qmin, sizeof (int));
size += sizeof (int);
memcpy ((uint8_t *) buf + size, &avctx->qmax, sizeof (int));
@@ -413,11 +344,14 @@ emul_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
CODEC_PARAM_INIT (&codec_param, CodecParam);
codec_param.api_index = EMUL_AVCODEC_OPEN;
codec_param.ctx_index = codec_info->ctx_idx;
+ codec_param.mem_index = codec_info->mem_idx;
codec_param.mmap_offset = codec_info->mmap_offset;
CODEC_WRITE (fd, &codec_param, 1);
- memcpy (&avctx->pix_fmt, (uint8_t *) buf, sizeof (int));
+ memcpy (&codec_info->ctx_idx, buf, sizeof (int));
size = sizeof (int);
+ memcpy (&avctx->pix_fmt, (uint8_t *) buf + size, sizeof (int));
+ size += sizeof (int);
size += emul_deserialize_rational ((uint8_t *) buf + size, &avctx->time_base);
memcpy (&avctx->channels, (uint8_t *) buf + size, sizeof (int));
size += sizeof (int);
@@ -452,10 +386,10 @@ emul_avcodec_open (AVCodecContext * avctx, AVCodec * codec,
}
int
-emul_avcodec_close (AVCodecContext * avctx, CodecExtraInfo * codec_info)
+emul_avcodec_close (AVCodecContext * avctx, CodecInfo * codec_info)
{
int fd;
- int result;
+ int result = 0;
void *buf;
CODEC_LOG (2, "Enter\n");
@@ -489,33 +423,7 @@ emul_avcodec_close (AVCodecContext * avctx, CodecExtraInfo * codec_info)
}
void
-emul_av_free (CodecExtraInfo * codec_info)
-{
- int fd;
-
- CODEC_LOG (2, "Enter\n");
- sem_wait (&codec_sema);
-
- fd = codec_info->codec_fd;
- if (fd < 0) {
- CODEC_LOG (1, "Codec device has not been opened yet.\n");
- sem_post (&codec_sema);
- return;
- }
-
- CODEC_PARAM_INIT (&codec_param, CodecParam);
- codec_param.api_index = EMUL_AV_FREE;
- codec_param.ctx_index = codec_info->ctx_idx;
- codec_param.mmap_offset = codec_info->mmap_offset;
- CODEC_WRITE (fd, &codec_param, 1);
-
- sem_post (&codec_sema);
- CODEC_LOG (2, "Leave\n");
-}
-
-
-void
-emul_avcodec_flush_buffers (AVCodecContext * avctx, CodecExtraInfo * codec_info)
+emul_avcodec_flush_buffers (AVCodecContext * avctx, CodecInfo * codec_info)
{
int fd;
@@ -541,7 +449,7 @@ emul_avcodec_flush_buffers (AVCodecContext * avctx, CodecExtraInfo * codec_info)
int
emul_avcodec_decode_video (AVCodecContext * ctx, AVFrame * frame,
- int *got_picture_ptr, AVPacket * packet, CodecExtraInfo * codec_info)
+ int *got_picture_ptr, AVPacket * packet, CodecInfo * codec_info)
{
int fd;
int result;
@@ -566,11 +474,11 @@ emul_avcodec_decode_video (AVCodecContext * ctx, AVFrame * frame,
}
CODEC_LOG (2, "codec close, codec_type:%d, context index:%d\n",
- ctx->codec_type, codec_info->ctx_idx);
- while (1) {
+ ctx->codec_type, codec_info->ctx_idx);
+ while (1) {
ioctl(fd, EMUL_LOCK_MEM_REGION, &access_mem);
CODEC_LOG (2, "lock memory region, %d\n", access_mem);
-
+
if (access_mem == 1) {
memcpy ((uint8_t *) buf, &ctx->reordered_opaque, sizeof (int64_t));
size = sizeof (int64_t);
@@ -602,8 +510,7 @@ emul_avcodec_decode_video (AVCodecContext * ctx, AVFrame * frame,
memcpy (&ctx->frame_number, (uint8_t *) buf + size, sizeof (int));
size += sizeof (int);
size +=
- emul_deserialize_rational ((uint8_t *) buf + size,
- &ctx->sample_aspect_ratio);
+ emul_deserialize_rational ((uint8_t *) buf + size, &ctx->sample_aspect_ratio);
memcpy (&ctx->internal_buffer_count, (uint8_t *) buf + size, sizeof (int));
size += sizeof (int);
memcpy (&ctx->profile, (uint8_t *) buf + size, sizeof (int));
@@ -634,22 +541,26 @@ emul_avcodec_decode_video (AVCodecContext * ctx, AVFrame * frame,
int
emul_avcodec_encode_video (AVCodecContext * ctx, uint8_t * out_buf,
int buf_size, const AVFrame * pict,
- uint8_t * pict_buf, uint32_t pict_buf_size, CodecExtraInfo * codec_info)
+ uint8_t * pict_buf, uint32_t pict_buf_size, CodecInfo * codec_info)
{
void *buf;
int fd;
int flush_buf;
int size;
+ int64_t cur_pict_pts;
+ int64_t last_pict_pts;
int result = -1;
CODEC_LOG (2, "Enter\n");
sem_wait (&codec_sema);
- if (pict->pts <= codec_info->last_pts) {
+ cur_pict_pts = pict->pts;
+ last_pict_pts = codec_info->last_pts;
+ if (cur_pict_pts <= last_pict_pts) {
CODEC_LOG (2, "invalid timestamp last_pts:%lld, cur_pts:%lld.\n",
- codec_info->last_pts, pict->pts);
- sem_post (&codec_sema);
- return -1;
+ last_pict_pts, cur_pict_pts);
+ sem_post (&codec_sema);
+ return -1;
}
fd = codec_info->codec_fd;
@@ -673,18 +584,13 @@ emul_avcodec_encode_video (AVCodecContext * ctx, uint8_t * out_buf,
CODEC_LOG (2, "lock memory region, %d\n", access_mem);
if (access_mem == 1) {
size = 0;
- if (pict && pict_buf) {
- flush_buf = 0;
- memcpy ((uint8_t *) buf + size, &flush_buf, sizeof (int));
- size += sizeof (int);
- memcpy ((uint8_t *) buf + size, &buf_size, sizeof (int));
- size += sizeof (int);
- size += emul_serialize_frame (pict, (uint8_t *) buf + size);
- memcpy ((uint8_t *) buf + size, pict_buf, pict_buf_size);
- } else {
- flush_buf = 1;
- memcpy ((uint8_t *) buf + size, &flush_buf, sizeof (int));
- }
+ flush_buf = 0;
+ memcpy ((uint8_t *) buf + size, &flush_buf, sizeof (int));
+ size += sizeof (int);
+ memcpy ((uint8_t *) buf + size, &buf_size, sizeof (int));
+ size += sizeof (int);
+ size += emul_serialize_frame (pict, (uint8_t *) buf + size);
+ memcpy ((uint8_t *) buf + size, pict_buf, pict_buf_size);
CODEC_PARAM_INIT (&codec_param, CodecParam);
codec_param.api_index = EMUL_AVCODEC_ENCODE_VIDEO;
@@ -692,20 +598,15 @@ emul_avcodec_encode_video (AVCodecContext * ctx, uint8_t * out_buf,
codec_param.mmap_offset = codec_info->mmap_offset;
CODEC_WRITE (fd, &codec_param, 1);
- if (pict && pict_buf) {
- memcpy (out_buf, (uint8_t *) buf, buf_size);
- memcpy (&result, (uint8_t *) buf + buf_size, sizeof (int));
- } else {
- memcpy (&result, buf, sizeof (int));
- }
- ctx->coded_frame = pict;
+// memcpy (out_buf, (uint8_t *) buf, buf_size);
+ memcpy (&result, (uint8_t *) buf + buf_size, sizeof (int));
+ ctx->coded_frame = (AVFrame *)pict;
break;
}
sleep (1);
CODEC_LOG (1, "cannot access memory region now.\n");
continue;
}
-
ioctl(fd, EMUL_UNLOCK_MEM_REGION, &access_mem);
CODEC_LOG (2, "unlock memory region, %d\n", access_mem);
CODEC_LOG (2, "after encoding video, ret :%d\n", result);
@@ -716,7 +617,7 @@ emul_avcodec_encode_video (AVCodecContext * ctx, uint8_t * out_buf,
int
emul_avcodec_decode_audio (AVCodecContext * avctx, int16_t * samples,
- int *frame_size_ptr, AVPacket * packet, CodecExtraInfo * codec_info)
+ int *frame_size_ptr, AVPacket * packet, CodecInfo * codec_info)
{
int fd;
int result;
@@ -740,52 +641,40 @@ emul_avcodec_decode_audio (AVCodecContext * avctx, int16_t * samples,
return -1;
}
- while (1) {
- ioctl(fd, EMUL_LOCK_MEM_REGION, &access_mem);
- CODEC_LOG (2, "lock memory region, %d\n", access_mem);
-
- if (access_mem == 1) {
- memcpy ((uint8_t *) buf, &packet->size, sizeof (int));
- size = sizeof (int);
- CODEC_LOG (2, "input buffer size :%d\n", packet->size);
- if (packet->size > 0) {
- memcpy ((uint8_t *) buf + size, packet->data, packet->size);
- }
+ memcpy ((uint8_t *) buf, &packet->size, sizeof (int));
+ size = sizeof (int);
+ CODEC_LOG (2, "input buffer size :%d\n", packet->size);
+ if (packet->size > 0) {
+ memcpy ((uint8_t *) buf + size, packet->data, packet->size);
+ }
- CODEC_PARAM_INIT (&codec_param, CodecParam);
- codec_param.api_index = EMUL_AVCODEC_DECODE_AUDIO;
- codec_param.ctx_index = codec_info->ctx_idx;
- codec_param.mmap_offset = codec_info->mmap_offset;
- CODEC_WRITE (fd, &codec_param, 1);
+ CODEC_PARAM_INIT (&codec_param, CodecParam);
+ codec_param.api_index = EMUL_AVCODEC_DECODE_AUDIO;
+ codec_param.ctx_index = codec_info->ctx_idx;
+ codec_param.mmap_offset = codec_info->mmap_offset;
+ CODEC_WRITE (fd, &codec_param, 1);
- memcpy (&avctx->bit_rate, (uint8_t *) buf, sizeof (int));
- size = sizeof (int);
- memcpy (&avctx->sample_rate, (uint8_t *) buf + size, sizeof (int));
- size += sizeof (int);
- memcpy (&avctx->channels, (uint8_t *) buf + size, sizeof (int));
- size += sizeof (int);
- memcpy (&avctx->sub_id, (uint8_t *) buf + size, sizeof (int));
- size += sizeof (int);
- memcpy (&avctx->frame_size, (uint8_t *) buf + size, sizeof (int));
- size += sizeof (int);
- memcpy (&avctx->frame_number, (uint8_t *) buf + size, sizeof (int));
- size += sizeof (int);
- memcpy (samples, (uint8_t *) buf + size, AVCODEC_MAX_AUDIO_FRAME_SIZE);
- size += AVCODEC_MAX_AUDIO_FRAME_SIZE;
- memcpy (frame_size_ptr, (uint8_t *) buf + size, sizeof (int));
- size += sizeof (int);
- memcpy (&result, (uint8_t *) buf + size, sizeof (int));
- avctx->pkt = packet;
- break;
- }
- sleep (1);
- CODEC_LOG (1, "cannot access memory region now.\n");
- continue;
- }
+ memcpy (&avctx->bit_rate, (uint8_t *) buf, sizeof (int));
+ size = sizeof (int);
+ memcpy (&avctx->sample_rate, (uint8_t *) buf + size, sizeof (int));
+ size += sizeof (int);
+ memcpy (&avctx->channels, (uint8_t *) buf + size, sizeof (int));
+ size += sizeof (int);
+ memcpy (&avctx->channel_layout, (uint8_t *) buf + size, sizeof (int64_t));
+ size += sizeof (int64_t);
+ memcpy (&avctx->sub_id, (uint8_t *) buf + size, sizeof (int));
+ size += sizeof (int);
+ memcpy (&avctx->frame_size, (uint8_t *) buf + size, sizeof (int));
+ size += sizeof (int);
+ memcpy (&avctx->frame_number, (uint8_t *) buf + size, sizeof (int));
+ size += sizeof (int);
+ memcpy (samples, (uint8_t *) buf + size, AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ size += AVCODEC_MAX_AUDIO_FRAME_SIZE;
+ memcpy (frame_size_ptr, (uint8_t *) buf + size, sizeof (int));
+ size += sizeof (int);
+ memcpy (&result, (uint8_t *) buf + size, sizeof (int));
+ avctx->pkt = packet;
- ioctl(fd, EMUL_UNLOCK_MEM_REGION, &access_mem);
- CODEC_LOG (2, "unlock memory region, %d\n", access_mem);
- CODEC_LOG (2, "frame_size_ptr:%d\n", *frame_size_ptr);
CODEC_LOG (2, "after decoding audio:%d\n", result);
sem_post (&codec_sema);
@@ -796,7 +685,7 @@ emul_avcodec_decode_audio (AVCodecContext * avctx, int16_t * samples,
}
void
-emul_av_picture_copy (AVPicture * dst, uint32_t fsize, CodecExtraInfo * codec_info)
+emul_av_picture_copy (AVPicture * dst, uint32_t fsize, CodecInfo * codec_info)
{
void *buf;
int fd;
@@ -850,7 +739,7 @@ emul_av_picture_copy (AVPicture * dst, uint32_t fsize, CodecExtraInfo * codec_in
}
void
-emul_av_parser_init (CodecExtraInfo * codec_info)
+emul_av_parser_init (CodecInfo * codec_info)
{
int fd;
@@ -880,7 +769,7 @@ int
emul_av_parser_parse (AVCodecParserContext * s, AVCodecContext * ctx,
uint8_t ** outbuf, int *outbuf_size,
const uint8_t * inbuf, int inbuf_size,
- int64_t pts, int64_t dts, int64_t pos, CodecExtraInfo * codec_info)
+ int64_t pts, int64_t dts, int64_t pos, CodecInfo * codec_info)
{
void *buf;
int fd;
@@ -943,10 +832,10 @@ emul_av_parser_parse (AVCodecParserContext * s, AVCodecContext * ctx,
out_size = *outbuf_size;
CODEC_LOG (2, "input :%d, output:%d, res:%d\n",
- inbuf_size, out_size, result);
+ inbuf_size, out_size, result);
if (*outbuf_size > 0) {
CODEC_LOG (2, "allocate output buffer :%d\n", out_size);
- parser_buffer.buf = av_malloc (out_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ parser_buffer.buf = av_mallocz (out_size + FF_INPUT_BUFFER_PADDING_SIZE);
parser_buffer.size = out_size;
memcpy (parser_buffer.buf, (uint8_t *) buf + size, out_size);
*outbuf = parser_buffer.buf;
@@ -978,7 +867,7 @@ emul_av_parser_parse (AVCodecParserContext * s, AVCodecContext * ctx,
}
void
-emul_av_parser_close (CodecExtraInfo * codec_info)
+emul_av_parser_close (CodecInfo * codec_info)
{
int fd;
@@ -1004,59 +893,47 @@ emul_av_parser_close (CodecExtraInfo * codec_info)
}
int
-emul_codec_mmap (CodecExtraInfo * codec_info)
+emul_codec_mmap (CodecInfo * codec_info, int codec_type)
{
- int fd;
+ int fd = -1;
int ret = 0;
fd = codec_info->codec_fd;
-
-#if 0
- if (codec_info->codec_type == AVMEDIA_TYPE_VIDEO) {
- CODEC_LOG (1, "mapped memory region for video type\n");
- codec_info->video_buf =
- mmap (NULL, CODEC_MMAP_SIZE,
- PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- codec_info->mmap_offset = 0;
- if (!codec_info->video_buf) {
- perror ("failed to mmap.");
- codec_info->video_buf = NULL;
- ret = -1;
- }
- } else if (codec_info->codec_type == AVMEDIA_TYPE_AUDIO) {
- CODEC_LOG (1, "mapped memory region for audio type\n");
- codec_info->audio_buf =
- mmap (NULL, CODEC_MMAP_SIZE, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, CODEC_MMAP_SIZE);
- codec_info->mmap_offset = CODEC_MMAP_SIZE;
- if (!codec_info->audio_buf) {
- perror ("failed to mmap.");
- codec_info->audio_buf = NULL;
- ret = -1;
- }
- } else {
- CODEC_LOG (1, "unknown media type\n");
- ret = -1;
+ if (fd < 0) {
+ CODEC_LOG (1, "Codec device has not been opened yet.\n");
+ sem_post (&codec_sema);
+ return -1;
}
-#endif
- if (codec_info->codec_type == AVMEDIA_TYPE_VIDEO) {
+
+ switch (codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
CODEC_LOG (2, "mapped memory region for video type\n");
- codec_info->mmap_offset = 0;
- } else if (codec_info->codec_type == AVMEDIA_TYPE_AUDIO) {
+ codec_info->mmap_offset = 0;
+ codec_info->buffer =
+ mmap (NULL, VIDEO_CODEC_MMAP_SIZE, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, codec_info->mmap_offset);
+ break;
+ case AVMEDIA_TYPE_AUDIO:
CODEC_LOG (2, "mapped memory region for audio type\n");
- codec_info->mmap_offset = CODEC_MMAP_SIZE;
- } else {
+ codec_info->mmap_offset = VIDEO_CODEC_MMAP_SIZE;
+ ioctl (fd, CODEC_CMD_GET_MMAP_OFFSET, &codec_info->mem_idx);
+ CODEC_LOG (2, "memory index for audio: %d\n", codec_info->mem_idx);
+ codec_info->mmap_offset += (codec_info->mem_idx * AUDIO_CODEC_MMAP_SIZE);
+ CODEC_LOG (2, "memory offset for audio: %d\n", codec_info->mmap_offset);
+
+ codec_info->buffer =
+ mmap (NULL, AUDIO_CODEC_MMAP_SIZE, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, codec_info->mmap_offset);
+ break;
+ default:
CODEC_LOG (1, "unknown media type\n");
return -1;
}
- codec_info->buffer =
- mmap (NULL, CODEC_MMAP_SIZE, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, codec_info->mmap_offset);
if (!codec_info->buffer) {
- perror ("failed to mmap.");
- codec_info->buffer = NULL;
- ret = -1;
+ perror ("failed to mmap.");
+ codec_info->buffer = NULL;
+ ret = -1;
} else {
CODEC_LOG (1, "succeeded to mmap: %p\n", codec_info->buffer);
}
@@ -1065,70 +942,24 @@ emul_codec_mmap (CodecExtraInfo * codec_info)
}
int
-emul_avcodec_alloc_context (CodecExtraInfo * codec_info)
-{
- int fd, ctx_index;
- int ret = 0;
- void *buf;
-
- CODEC_LOG (2, "Enter\n");
- fd = codec_info->codec_fd;
- if (fd < 0) {
- CODEC_LOG (1, "Codec device has not been opened yet.\n");
- return -1;
- }
-
- buf = codec_info->buffer;
- if (!buf) {
- CODEC_LOG (1, "mapping address is null\n");
- return -1;
- }
-
- while (1) {
- ioctl(fd, EMUL_LOCK_MEM_REGION, &access_mem);
- CODEC_LOG (2, "lock memory region, %d\n", access_mem);
-
- if (access_mem == 1) {
- /* Allocate Codec Context */
- CODEC_PARAM_INIT (&codec_param, CodecParam);
- codec_param.api_index = EMUL_AVCODEC_ALLOC_CONTEXT;
- codec_param.mmap_offset = codec_info->mmap_offset;
- CODEC_WRITE (fd, &codec_param, 1);
-
- memcpy (&ctx_index, buf, sizeof (int));
- codec_info->ctx_idx = ctx_index;
- CODEC_LOG (2, "context index:%d\n", ctx_index);
- break;
- }
- sleep (1);
- CODEC_LOG (1, "cannot access memory region now.\n");
- continue;
- }
- ioctl(fd, EMUL_UNLOCK_MEM_REGION, &access_mem);
- CODEC_LOG (2, "unlock memory region, %d\n", access_mem);
-
- return ret;
-}
-
-int
emul_avcodec_init (AVCodecContext * avctx, AVCodec * codec,
- CodecExtraInfo * codec_info)
+ CodecInfo * codec_info)
{
int ret = 0;
+ int version = 0;
CODEC_LOG (2, "enter, %s\n", __func__);
- CODEC_PARAM_INIT (codec_info, CodecExtraInfo);
+ CODEC_PARAM_INIT (codec_info, CodecInfo);
if (emul_open_codec_device (codec_info) < 0) {
CODEC_LOG (1, "Codec device has not been opened yet.\n");
return -1;
}
sem_wait (&codec_sema);
-
+
/* Get mapped memory address by mmap(). */
- codec_info->codec_type = codec->type;
- if (emul_codec_mmap(codec_info) < 0) {
+ if (emul_codec_mmap(codec_info, codec->type) < 0) {
CODEC_LOG (1, "failure mmap(), %d\n", codec->type);
sem_post (&codec_sema);
return -1;
@@ -1136,19 +967,23 @@ emul_avcodec_init (AVCodecContext * avctx, AVCodec * codec,
/* Check codec module version between SDK and PLATFORM. */
if (!is_registered) {
- if (emul_check_version (codec_info) < 0) {
+ if (ioctl(codec_info->codec_fd, CODEC_CMD_GET_VERSION, &version) < 0) {
+ perror("failed to get codec version.\n");
sem_post (&codec_sema);
return -1;
+ } else {
+ if (version != CODEC_VERSION) {
+ CODEC_LOG (1, "different versions of emulator and platform.\n"
+ "emulator: %d, Platform: %d\n",
+ version, CODEC_VERSION);
+ sem_post (&codec_sema);
+ return -1;
+ }
+ CODEC_LOG (1, "codec version: %d\n", version);
}
is_registered++;
}
- if (emul_avcodec_alloc_context (codec_info) < 0) {
- CODEC_LOG (1, "failed to allocate codec context\n");
- sem_post (&codec_sema);
- return -1;
- }
-
ret = emul_avcodec_open (avctx, codec, codec_info);
CODEC_LOG (2, "after codec type:%d, id:%d\n", avctx->codec_type,
avctx->codec_id);
diff --git a/ext/ffmpeg/gstffmpegdef.h b/ext/ffmpeg/gstffmpegdef.h
index 48395ce..7cdd09e 100644
--- a/ext/ffmpeg/gstffmpegdef.h
+++ b/ext/ffmpeg/gstffmpegdef.h
@@ -3,7 +3,7 @@
*
* Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact:
+ * Contact:
* KiTae Kim <kt920.kim@samsung.com>
* SeokYeon Hwang <syeon.hwang@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
@@ -22,13 +22,6 @@
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
- */
-
-/* First, include the header file for the plugin, to bring in the
- * object definition and other useful things.
- */
-
-/*
*
* Contributors:
* - S-Core Co., Ltd
@@ -55,20 +48,21 @@
#define CODEC_PARAM_INIT(var_codec, def_codec) \
memset(var_codec, 0, sizeof(def_codec))
-typedef struct _CodecExtraInfo
+typedef struct _CodecInfo
{
int codec_fd;
- int codec_type;
void *buffer;
uint32_t ctx_idx;
+ uint32_t mem_idx;
uint32_t mmap_offset;
int64_t last_pts;
-} CodecExtraInfo;
+} CodecInfo;
typedef struct _CodecParam
{
uint32_t api_index;
uint32_t ctx_index;
+ uint32_t mem_index;
uint32_t mmap_offset;
} CodecParam;
@@ -78,13 +72,17 @@ typedef struct _ParserBuf
uint32_t size;
} ParserBuf;
-enum
-{
+enum codec_io_cmd {
+ CODEC_CMD_GET_VERSION = 5,
+ CODEC_CMD_GET_DEVICE_MEM,
+ CODEC_CMD_SET_DEVICE_MEM,
+ CODEC_CMD_GET_MMAP_OFFSET,
+};
+
+enum codec_api_index {
EMUL_AV_REGISTER_ALL = 1,
- EMUL_AVCODEC_ALLOC_CONTEXT,
EMUL_AVCODEC_OPEN,
EMUL_AVCODEC_CLOSE,
- EMUL_AV_FREE,
EMUL_AVCODEC_FLUSH_BUFFERS,
EMUL_AVCODEC_DECODE_VIDEO,
EMUL_AVCODEC_ENCODE_VIDEO,
@@ -94,18 +92,15 @@ enum
EMUL_AV_PARSER_INIT,
EMUL_AV_PARSER_PARSE,
EMUL_AV_PARSER_CLOSE,
- EMUL_GET_CODEC_VER = 50,
- EMUL_LOCK_MEM_REGION,
+ EMUL_LOCK_MEM_REGION = 50,
EMUL_UNLOCK_MEM_REGION,
};
-int emul_open_codec_device (CodecExtraInfo * info);
-
-void emul_close_codec_device (CodecExtraInfo * info);
+int emul_open_codec_device (CodecInfo * info);
-int emul_codec_mmap (CodecExtraInfo * info);
+void emul_close_codec_device (int codec_type, CodecInfo * info);
-int emul_check_version (CodecExtraInfo * info);
+int emul_codec_mmap (CodecInfo * info, int codec_type);
int emul_serialize_rational (const AVRational * elem, uint8_t * buff);
@@ -116,40 +111,36 @@ int emul_serialize_frame (const AVFrame * elem, uint8_t * buff);
int emul_deserialize_frame (const uint8_t * buff, AVFrame * elem);
/* FFMPEG API */
-void emul_av_register_all (CodecExtraInfo * info);
-
int emul_avcodec_init (AVCodecContext * avctx,
- AVCodec * codec, CodecExtraInfo * info);
+ AVCodec * codec, CodecInfo * info);
int emul_avcodec_open (AVCodecContext * avctx,
- AVCodec * codec, CodecExtraInfo * info);
-
-int emul_avcodec_close (AVCodecContext * avctx, CodecExtraInfo * info);
+ AVCodec * codec, CodecInfo * info);
-int emul_avcodec_alloc_context (CodecExtraInfo * info);
+int emul_avcodec_close (AVCodecContext * avctx, CodecInfo * info);
-void emul_av_free (CodecExtraInfo * info);
+int emul_avcodec_alloc_context (CodecInfo * info);
-void emul_avcodec_flush_buffers (AVCodecContext * ctx, CodecExtraInfo * info);
+void emul_avcodec_flush_buffers (AVCodecContext * ctx, CodecInfo * info);
int emul_avcodec_decode_video (AVCodecContext * ctx, AVFrame * frame,
- int *got_picture_ptr, AVPacket * packet, CodecExtraInfo * info);
+ int *got_picture_ptr, AVPacket * packet, CodecInfo * info);
int emul_avcodec_encode_video (AVCodecContext * ctx, uint8_t * out_buf,
int buf_size, const AVFrame * pict,
- uint8_t * pict_buf, uint32_t pict_buf_size, CodecExtraInfo * info);
+ uint8_t * pict_buf, uint32_t pict_buf_size, CodecInfo * info);
int emul_avcodec_decode_audio (AVCodecContext * avctx, int16_t * samples,
- int *frame_size_ptr, AVPacket * packet, CodecExtraInfo * info);
+ int *frame_size_ptr, AVPacket * packet, CodecInfo * info);
void emul_av_picture_copy (AVPicture * dst,
- uint32_t fsize, CodecExtraInfo * info);
+ uint32_t fsize, CodecInfo * info);
-void emul_av_parser_init (CodecExtraInfo * info);
+void emul_av_parser_init (CodecInfo * info);
int emul_av_parser_parse (AVCodecParserContext * s, AVCodecContext * ctx,
uint8_t ** outbuf, int *outbuf_size,
const uint8_t * inbuf, int inbuf_size,
- int64_t pts, int64_t dts, int64_t pos, CodecExtraInfo * info);
+ int64_t pts, int64_t dts, int64_t pos, CodecInfo * info);
-void emul_av_parser_close (CodecExtraInfo * info);
+void emul_av_parser_close (CodecInfo * info);
diff --git a/ext/ffmpeg/gstffmpegenc.c b/ext/ffmpeg/gstffmpegenc.c
index 10b8ae5..628de14 100644
--- a/ext/ffmpeg/gstffmpegenc.c
+++ b/ext/ffmpeg/gstffmpegenc.c
@@ -253,13 +253,6 @@ gst_ffmpegenc_init (GstFFMpegEnc * ffmpegenc)
/* ffmpeg objects */
ffmpegenc->context = avcodec_alloc_context ();
ffmpegenc->picture = avcodec_alloc_frame ();
-#if 0
-#ifndef EMUL_CODEC
- emul_avcodec_alloc_context (&ffmpegenc->codecInfo);
- emul_avcodec_alloc_frame (&ffmpegenc->codecInfo);
- CODEC_LOG (2, "context index: %d\n", ffmpegenc->codecInfo.contextIndex);
-#endif
-#endif
ffmpegenc->opened = FALSE;
ffmpegenc->file = NULL;
@@ -310,8 +303,8 @@ gst_ffmpegenc_finalize (GObject * object)
/* clean up remaining allocated data */
#ifndef EMUL_CODEC
CODEC_LOG (2, "free AVCodecContext and AVFrame\n");
- emul_av_free (&ffmpegenc->codecInfo);
- emul_close_codec_device (&ffmpegenc->codecInfo);
+ emul_close_codec_device (ffmpegenc->context->codec_type,
+ &ffmpegenc->codecInfo);
#endif
av_free (ffmpegenc->context);
av_free (ffmpegenc->picture);
@@ -811,6 +804,7 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstBuffer * inbuf)
ffmpegenc->context->time_base.num, ffmpegenc->context->time_base.den);
ffmpegenc_setup_working_buf (ffmpegenc);
+ CODEC_LOG (2, "wanted buffer size: %d\n", ffmpegenc->buffer_size);
CODEC_LOG (2, "before avcodec_encode_video, codec_id:%d\n",
ffmpegenc->context->codec_id);
@@ -853,7 +847,8 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstBuffer * inbuf)
GST_ERROR_SYSTEM);
outbuf = gst_buffer_new_and_alloc (ret_size);
- memcpy (GST_BUFFER_DATA (outbuf), ffmpegenc->working_buf, ret_size);
+// memcpy (GST_BUFFER_DATA (outbuf), ffmpegenc->working_buf, ret_size);
+ memcpy (GST_BUFFER_DATA (outbuf), ffmpegenc->codecInfo.buffer, ret_size);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (inbuf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (inbuf);
/* buggy codec may not set coded_frame */
diff --git a/ext/ffmpeg/gstffmpegenc.h b/ext/ffmpeg/gstffmpegenc.h
index a6dd88f..b7ef682 100644
--- a/ext/ffmpeg/gstffmpegenc.h
+++ b/ext/ffmpeg/gstffmpegenc.h
@@ -78,7 +78,7 @@ struct _GstFFMpegEnc
gboolean force_keyframe;
/* Extra info which can determine codec Context on the Host side(QEMU)*/
- CodecExtraInfo codecInfo;
+ CodecInfo codecInfo;
};
typedef struct _GstFFMpegEncClass GstFFMpegEncClass;