summaryrefslogtreecommitdiff
path: root/ext/ffmpeg/gstffmpegdef.c
diff options
context:
space:
mode:
authorKibum Kim <kb0929.kim@samsung.com>2012-02-27 21:16:16 +0900
committerKibum Kim <kb0929.kim@samsung.com>2012-02-27 21:16:16 +0900
commit0e2adf31fd3681185dc8fa79cd68beceb520735f (patch)
tree0333bcea42680d74b7f3b730ab06d0b3554e8cb3 /ext/ffmpeg/gstffmpegdef.c
downloadgstreamer0.10-ffmpeg-emulator-0e2adf31fd3681185dc8fa79cd68beceb520735f.tar.gz
gstreamer0.10-ffmpeg-emulator-0e2adf31fd3681185dc8fa79cd68beceb520735f.tar.bz2
gstreamer0.10-ffmpeg-emulator-0e2adf31fd3681185dc8fa79cd68beceb520735f.zip
tizen beta release
Diffstat (limited to 'ext/ffmpeg/gstffmpegdef.c')
-rw-r--r--ext/ffmpeg/gstffmpegdef.c875
1 files changed, 875 insertions, 0 deletions
diff --git a/ext/ffmpeg/gstffmpegdef.c b/ext/ffmpeg/gstffmpegdef.c
new file mode 100644
index 0000000..05c3143
--- /dev/null
+++ b/ext/ffmpeg/gstffmpegdef.c
@@ -0,0 +1,875 @@
+/*
+ * Emulator
+ *
+ * Copyright (C) 2011 - 2012 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>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy 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.
+ */
+
+/* First, include the header file for the plugin, to bring in the
+ * object definition and other useful things.
+ */
+
+/*
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include "gstffmpegdef.h"
+
+#define CODEC_DEV "/dev/codec"
+#define CODEC_MMAP_SIZE 512 * 4096
+
+CodecParam _param;
+ParserBuf _parserBuf;
+static int codecfd;
+static void *pMapBuf;
+
+int emul_open_codecdev (void)
+{
+ int fd = -1;
+
+ GST_CODEC_LOG("Enter\n");
+ if ((fd = open(CODEC_DEV, O_RDWR)) < 0) {
+ perror("Failed to open codec device");
+ GST_CODEC_LOG("Failed to open %s, ret:%d\n", CODEC_DEV, fd)
+ } else {
+ GST_CODEC_LOG("Succeeded to open %s, ret:%d\n", CODEC_DEV, fd)
+ }
+ codecfd = fd;
+
+ GST_CODEC_LOG("AVCodecContext : %d\n", sizeof(AVCodecContext));
+ GST_CODEC_LOG("AVFrame : %d\n", sizeof(AVFrame));
+ GST_CODEC_LOG("AVCodecParserContext : %d\n", sizeof(AVCodecParserContext));
+
+ GST_CODEC_LOG("Leave, fd:%d\n", fd);
+
+ return fd;
+}
+
+void emul_close_codecdev (void)
+{
+#ifndef CODEC_HOST
+ void *pBuf;
+ int ret;
+
+ pBuf = pMapBuf;
+ if (!pBuf) {
+ printf("mapping address is null\n");
+ return;
+ }
+
+ ret = munmap(pBuf, CODEC_MMAP_SIZE);
+ printf("release mapping address :%d\n", ret);
+#endif
+ GST_CODEC_LOG("Enter\n")
+ if (codecfd > 0) {
+ close(codecfd);
+ codecfd = -1;
+ }
+ GST_CODEC_LOG("Leave, close %s device and fd:%d\n", CODEC_DEV, codecfd)
+}
+
+void restore_codec_context(AVCodecContext *dstctx,
+ AVCodecContext *srcctx) {
+ dstctx->av_class = srcctx->av_class;
+ dstctx->codec = srcctx->codec;
+ dstctx->extradata = srcctx->extradata;
+ dstctx->opaque = srcctx->opaque;
+ dstctx->get_buffer = srcctx->get_buffer;
+ dstctx->release_buffer = srcctx->release_buffer;
+ dstctx->stats_out = srcctx->stats_out;
+ dstctx->stats_in = srcctx->stats_in;
+ dstctx->rc_override = srcctx->rc_override;
+ dstctx->rc_eq = srcctx->rc_eq;
+ dstctx->slice_offset = srcctx->slice_offset;
+ dstctx->get_format = srcctx->get_format;
+ dstctx->internal_buffer = srcctx->internal_buffer;
+ dstctx->intra_matrix = srcctx->intra_matrix;
+ dstctx->inter_matrix = srcctx->inter_matrix;
+ dstctx->reget_buffer = srcctx->reget_buffer;
+ dstctx->execute = srcctx->execute;
+ dstctx->thread_opaque = srcctx->thread_opaque;
+ dstctx->execute2 = srcctx->execute2;
+}
+
+int get_picture_size (int pix_fmt, int width, int height)
+{
+ int size;
+
+ switch (pix_fmt) {
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_YUV422P:
+ case PIX_FMT_YUV444P:
+ case PIX_FMT_YUV410P:
+ case PIX_FMT_YUV411P:
+ case PIX_FMT_YUVJ420P:
+ case PIX_FMT_YUVJ422P:
+ case PIX_FMT_YUVJ444P:
+ size = (width * height * 3) / 2;
+ break;
+ case PIX_FMT_RGB24:
+ case PIX_FMT_BGR24:
+ size = width * height * 3;
+ break;
+ default:
+ size = -1;
+ }
+ return size;
+}
+
+void emul_av_register_all (void)
+{
+ int fd;
+ GST_CODEC_LOG("Enter\n")
+
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_REGISTER_ALL;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("Leave\n")
+}
+
+#ifdef CODEC_HOST
+int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec)
+{
+ int fd;
+ int result = -1;
+ int priv_data_size;
+
+ GST_CODEC_LOG("Enter\n")
+
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ fd = emul_open_codecdev();
+ if (fd < 0) {
+ return -1;
+ }
+ }
+
+ priv_data_size = codec->priv_data_size;
+ avctx->priv_data = (void*)av_mallocz(priv_data_size);
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_OPEN;
+ _param.in_args_num = 2;
+ _param.in_args[0] = (uint32_t)avctx;
+ _param.in_args[1] = (uint32_t)codec;
+ _param.ret_args = (uint32_t)&result;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("after codec type:%d, id:%d\n", avctx->codec_type, avctx->codec_id)
+ GST_CODEC_LOG("Leave, ret : %d\n", result)
+
+ return result;
+}
+#else
+int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec)
+{
+ int fd;
+ int result = -1;
+ int priv_data_size;
+ int size;
+ void *buf;
+ AVCodecContext tmpCtx;
+
+ GST_CODEC_LOG("Enter\n")
+
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ priv_data_size = codec->priv_data_size;
+ avctx->priv_data = (void*)av_mallocz(priv_data_size);
+
+ buf = mmap(NULL, CODEC_MMAP_SIZE, PROT_READ | PROT_WRITE,
+ MAP_SHARED, codecfd, 0);
+ if (buf) {
+ GST_CODEC_LOG("success mmap : %x\n", pMapBuf);
+ pMapBuf = buf;
+ } else {
+ GST_CODEC_LOG("failure mmap\n");
+ pMapBuf = NULL;
+ }
+
+ size = sizeof(AVCodecContext);
+ memcpy(&tmpCtx, avctx, size);
+ memcpy(buf, avctx, size);
+ memcpy((uint8_t*)buf + size, codec, sizeof(AVCodec));
+ size += sizeof(AVCodec);
+ memcpy((uint8_t*)buf + size, avctx->extradata, avctx->extradata_size);
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_OPEN;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("after write system call\n")
+
+ size = sizeof(AVCodecContext);
+ memcpy(avctx, buf, size);
+ restore_codec_context(avctx, &tmpCtx);
+ avctx->codec = codec;
+ memcpy(&result, (uint8_t*)buf + size, sizeof(int));
+
+ GST_CODEC_LOG("after codec type:%d, id:%d\n", avctx->codec_type, avctx->codec_id)
+ GST_CODEC_LOG("Leave, ret : %d\n", result)
+
+ return result;
+}
+#endif
+
+#ifdef CODEC_HOST
+int emul_avcodec_close(AVCodecContext *avctx)
+{
+ int fd;
+ int result;
+
+ GST_CODEC_LOG("Enter\n")
+
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_CLOSE;
+ _param.in_args_num = 1;
+ _param.in_args[0] = (uint32_t)avctx;
+ _param.ret_args = (uint32_t)&result;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("Leave, ret : %d\n", result)
+
+ return result;
+}
+#else
+int emul_avcodec_close(AVCodecContext *avctx)
+{
+ int fd;
+ int result;
+ int size;
+ void *pBuf;
+
+ GST_CODEC_LOG("Enter\n")
+
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ pBuf = pMapBuf;
+ if (!pBuf) {
+ printf("mapping address is null\n");
+ return -1;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_CLOSE;
+ write(fd, &_param, 1);
+
+ memcpy(&result, pBuf, sizeof(int));
+
+ GST_CODEC_LOG("Leave, ret : %d\n", result)
+
+ return result;
+}
+#endif
+
+void emul_avcodec_alloc_context (void)
+{
+ int fd;
+
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ fd = emul_open_codecdev();
+ if (fd < 0) {
+ return;
+ }
+ }
+
+ GST_CODEC_LOG("Enter\n")
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_ALLOC_CONTEXT;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}
+
+void emul_avcodec_alloc_frame (void)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_ALLOC_FRAME;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}
+
+void emul_av_free_context (void)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_FREE_CONTEXT;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}
+
+void emul_av_free_picture (void)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_FREE_PICTURE;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}
+
+void emul_av_free_palctrl (void)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_FREE_PALCTRL;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}
+
+void emul_av_free_extradata (void)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_FREE_EXTRADATA;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}
+
+#ifdef CODEC_HOST
+void emul_avcodec_flush_buffers(AVCodecContext *avctx)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_FLUSH_BUFFERS;
+ _param.in_args_num = 1;
+ _param.in_args[0] = (uint32_t)avctx;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}
+#else
+void emul_avcodec_flush_buffers(AVCodecContext *avctx)
+{
+ int fd;
+ void *pBuf;
+// AVCodecContext tmpCtx;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+/* pBuf = pMapBuf;
+ if (!pBuf) {
+ printf("mapping address is null\n");
+ return -1;
+ } */
+
+// memcpy(&tmpCtx, avctx, sizeof(AVCodecContext);
+// memcpy(pBuf, avctx, sizeof(AVCodecContext));
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_FLUSH_BUFFERS;
+ write(fd, &_param, 1);
+
+// memcpy(avctx, pBuf, sizeof(AVCodecContext));
+// restore_codec_context(avctx, &tmpCtx);
+
+ GST_CODEC_LOG("Leave\n")
+}
+#endif
+
+#ifdef CODEC_HOST
+int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame,
+ int *got_picture_ptr, uint8_t *buf, int buf_size)
+{
+ int fd;
+ int result;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_DECODE_VIDEO;
+ _param.in_args_num = 5;
+ _param.in_args[0] = (uint32_t)ctx;
+ _param.in_args[1] = (uint32_t)frame;
+ _param.in_args[2] = (uint32_t)got_picture_ptr;
+ _param.in_args[3] = (uint32_t)buf;
+ _param.in_args[4] = (uint32_t)&buf_size;
+ _param.ret_args = (uint32_t)&result;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("Leave, ret:%d\n", result)
+
+ return result;
+}
+#else
+int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame,
+ int *got_picture_ptr, uint8_t *buf, int buf_size)
+{
+ int fd;
+ int result;
+ int size;
+ void *pBuf;
+ AVCodecContext tmpCtx;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ pBuf = pMapBuf;
+ if (!pBuf) {
+ printf("mapping address is null\n");
+ return -1;
+ }
+
+ size = sizeof(int);
+ memcpy(pBuf, &buf_size, size);
+ GST_CODEC_LOG("input buffer size :%d\n", buf_size);
+ if (buf_size > 0) {
+ memcpy((uint8_t*)pBuf + size, buf, buf_size);
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_DECODE_VIDEO;
+ write(fd, &_param, 1);
+
+ size = sizeof(AVCodecContext);
+ memcpy(&tmpCtx, ctx, size);
+ memcpy(ctx, pBuf, size);
+ restore_codec_context(ctx, &tmpCtx);
+ ctx->coded_frame = frame;
+
+ memcpy(frame, (uint8_t*)pBuf + size, sizeof(AVFrame));
+ size += sizeof(AVFrame);
+ memcpy(got_picture_ptr, (uint8_t*)pBuf + size, sizeof(int));
+ GST_CODEC_LOG("have_data:%d\n", *got_picture_ptr)
+ size += sizeof(int);
+ memcpy(&result, (uint8_t*)pBuf + size, sizeof(int));
+
+ GST_CODEC_LOG("Leave, ret:%d\n", result)
+
+ return result;
+}
+#endif
+
+
+#ifdef CODEC_HOST
+int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf,
+ int buf_size, const AVFrame *pict,
+ uint8_t *pict_buf)
+{
+ int fd;
+ int result = -1;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ ctx->coded_frame = avcodec_alloc_frame();
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_ENCODE_VIDEO;
+ _param.in_args_num = 5;
+ _param.in_args[0] = (uint32_t)ctx;
+ _param.in_args[1] = (uint32_t)buf;
+ _param.in_args[2] = (uint32_t)&buf_size;
+ _param.in_args[3] = (uint32_t)pict;
+ _param.in_args[4] = (uint32_t)pict_buf;
+ _param.ret_args = (uint32_t)&result;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("after encoding video, ret :%d\n", result)
+ return result;
+}
+#else
+int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf,
+ int buf_size, const AVFrame *pict,
+ uint8_t *pict_buf)
+{
+ void *pBuf;
+ int fd;
+ int inputSize;
+ int flush_buf;
+ int size;
+ int result = -1;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ ctx->coded_frame = avcodec_alloc_frame();
+
+ pBuf = pMapBuf;
+ if (!pBuf) {
+ printf("mapping address is null\n");
+ return -1;
+ }
+ GST_CODEC_LOG("output buffer size :%d\n", buf_size);
+ inputSize = get_picture_size(ctx->pix_fmt, ctx->height, ctx->width);
+ if (pict && pict_buf) {
+ flush_buf = 0;
+ size = sizeof(int);
+ memcpy(pBuf, &flush_buf, size);
+ memcpy((uint8_t*)pBuf + size, &buf_size, size);
+ size += sizeof(int);
+ memcpy((uint8_t*)pBuf + size, pict, sizeof(AVFrame));
+ size += sizeof(AVFrame);
+ memcpy((uint8_t*)pBuf + size, pict_buf, inputSize);
+ } else {
+ flush_buf = 1;
+ memcpy(pBuf, &flush_buf, sizeof(int));
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AVCODEC_ENCODE_VIDEO;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("after write system call\n")
+
+ if (pict && pict_buf) {
+ memcpy(buf, (uint8_t*)pBuf, buf_size);
+ memcpy(&result, (uint8_t*)pBuf + buf_size, sizeof(int));
+ } else {
+ memcpy(&result, pBuf, sizeof(int));
+ }
+
+ GST_CODEC_LOG("after encoding video, ret :%d\n", result)
+ return result;
+}
+#endif
+
+#ifdef CODEC_HOST
+void emul_av_picture_copy(AVPicture *dst, const AVPicture *src,
+ enum PixelFormat pix_fmt, int width, int height)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_PICTURE_COPY;
+ _param.in_args_num = 5;
+ _param.in_args[0] = (uint32_t)dst;
+ _param.in_args[1] = (uint32_t)&pix_fmt;
+ _param.in_args[2] = (uint32_t)&width;
+ _param.in_args[3] = (uint32_t)&height;
+ _param.in_args[4] = (uint32_t)dst->data[0];
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("Leave\n")
+}
+#else
+void emul_av_picture_copy(AVPicture *dst, const AVPicture *src,
+ enum PixelFormat pix_fmt, int width, int height)
+{
+ void *pBuf;
+ int imgSize;
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ pBuf = pMapBuf;
+ if (!pBuf) {
+ printf("mapping address is null\n");
+ return ;
+ }
+
+ imgSize = get_picture_size(pix_fmt, width, height);
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_PICTURE_COPY;
+ write(fd, &_param, 1);
+
+ memcpy(dst->data[0], pBuf, imgSize);
+
+ GST_CODEC_LOG("Leave\n")
+}
+#endif
+
+void emul_av_parser_init (void)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ PARAM_INIT(_parserBuf, ParserBuf);
+ _param.func_num = EMUL_AV_PARSER_INIT;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("Leave\n")
+}
+
+#ifdef CODEC_HOST
+int emul_av_parser_parse (AVCodecParserContext *s, AVCodecContext *ctx,
+ uint8_t **outbuf, int *outbuf_size,
+ const uint8_t *buf, int buf_size,
+ int64_t pts, int64_t dts)
+{
+ int result = -1;
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ *outbuf = NULL;
+
+ GST_CODEC_LOG("previous result:%d\n", _parserBuf.size);
+ if (_parserBuf.size > 0 && !_parserBuf.buf) {
+ GST_CODEC_LOG("allocate buffer bufsize:%d\n", _parserBuf.size);
+ *outbuf = av_malloc (_parserBuf.size);
+ _parserBuf.buf = *outbuf;
+ } else if (_parserBuf.size == -1) {
+ GST_CODEC_LOG("release previous buffer\n");
+ av_free(_parserBuf.buf);
+ _parserBuf.buf = NULL;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_PARSER_PARSE ;
+ _param.in_args_num = 8;
+ _param.in_args[0] = (uint32_t)s;
+ _param.in_args[1] = (uint32_t)ctx;
+ _param.in_args[2] = (uint32_t)*outbuf;
+ _param.in_args[3] = (uint32_t)outbuf_size;
+ _param.in_args[4] = (uint32_t)buf;
+ _param.in_args[5] = (uint32_t)&buf_size;
+ _param.in_args[6] = (uint32_t)&pts;
+ _param.in_args[7] = (uint32_t)&dts;
+ _param.ret_args = (uint32_t)&result;
+ write(fd, &_param, 1);
+
+ if (*outbuf_size == 0) {
+ *outbuf = NULL;
+ _parserBuf.size = result;
+ } else {
+ _parserBuf.size = -1;
+ }
+
+ return result;
+}
+#else
+int emul_av_parser_parse (AVCodecParserContext *s, AVCodecContext *ctx,
+ uint8_t **outbuf, int *outbuf_size,
+ const uint8_t *buf, int buf_size,
+ int64_t pts, int64_t dts)
+{
+ AVCodecContext tmpCtx;
+ void *pBuf;
+ int fd;
+ int size;
+ int result = -1;
+ *outbuf = NULL;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ pBuf = pMapBuf;
+ if (!pBuf) {
+ printf("mapping address is null\n");
+ return -1;
+ }
+
+ GST_CODEC_LOG("input buffer size :%d\n", buf_size);
+ GST_CODEC_LOG("previous result:%d\n", _parserBuf.size);
+ if (_parserBuf.size > 0 && !_parserBuf.buf) {
+ GST_CODEC_LOG("allocate buffer bufsize:%d\n", _parserBuf.size);
+ *outbuf = av_malloc (_parserBuf.size);
+ _parserBuf.buf = *outbuf;
+ } else if (_parserBuf.size == -1) {
+ GST_CODEC_LOG("release previous buffer\n");
+ av_free(_parserBuf.buf);
+ _parserBuf.buf = NULL;
+ }
+
+ memcpy(&tmpCtx, ctx, sizeof(AVCodecContext));
+
+ size = sizeof(AVCodecContext);
+ memcpy(pBuf, ctx, size);
+ memcpy((uint8_t*)pBuf + size, &pts, sizeof(int64_t));
+ size += sizeof(int64_t);
+ memcpy((uint8_t*)pBuf + size, &dts, sizeof(int64_t));
+ size += sizeof(int64_t);
+ memcpy((uint8_t*)pBuf + size, &buf_size, sizeof(int));
+ size += sizeof(int);
+ memcpy((uint8_t*)pBuf + size, buf, buf_size);
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_PARSER_PARSE;
+ write(fd, &_param, 1);
+
+ GST_CODEC_LOG("After write system call\n")
+
+ memcpy(ctx, pBuf, sizeof(AVCodecContext));
+ restore_codec_context(ctx, &tmpCtx);
+ size = sizeof(AVCodecContext);
+
+ GST_CODEC_LOG("after copying AVCodecContext :%d\n", size);
+
+ memcpy(outbuf_size, (uint8_t*)pBuf + size, sizeof(int));
+ size += sizeof(int);
+
+ GST_CODEC_LOG("after copying output buffer size :%d\n", size);
+
+ GST_CODEC_LOG("Output Buffer Size :%d\n", *outbuf_size);
+ if (*outbuf_size > 0) {
+ GST_CODEC_LOG("\n");
+ memcpy(*outbuf, (uint8_t*)pBuf + size, *outbuf_size);
+ size += *outbuf_size;
+ }
+ memcpy(&result, (uint8_t*)pBuf + size, sizeof(int));
+
+ GST_CODEC_LOG("Result :%d\n", result);
+
+ if (*outbuf_size == 0) {
+ *outbuf = NULL;
+ _parserBuf.size = result;
+ } else {
+ _parserBuf.size = -1;
+ }
+
+ GST_CODEC_LOG("Leave\n")
+
+ return result;
+}
+#endif
+
+void emul_av_parser_close (void)
+{
+ int fd;
+
+ GST_CODEC_LOG("Enter\n")
+ fd = codecfd;
+ if (fd < 0) {
+ printf("[%s] Codec device has not been opened yet.\n", __func__);
+ return -1;
+ }
+
+ PARAM_INIT(_param, CodecParam);
+ _param.func_num = EMUL_AV_PARSER_CLOSE;
+ write(fd, &_param, 1);
+ GST_CODEC_LOG("Leave\n")
+}