summaryrefslogtreecommitdiff
path: root/ext/ffmpeg/gstffmpegdef.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ffmpeg/gstffmpegdef.c')
-rw-r--r--ext/ffmpeg/gstffmpegdef.c449
1 files changed, 142 insertions, 307 deletions
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);