diff options
Diffstat (limited to 'ext/ffmpeg/gstffmpegdef.c')
-rw-r--r-- | ext/ffmpeg/gstffmpegdef.c | 950 |
1 files changed, 672 insertions, 278 deletions
diff --git a/ext/ffmpeg/gstffmpegdef.c b/ext/ffmpeg/gstffmpegdef.c index 05c3143..b80fe37 100644 --- a/ext/ffmpeg/gstffmpegdef.c +++ b/ext/ffmpeg/gstffmpegdef.c @@ -36,59 +36,19 @@ */ #include "gstffmpegdef.h" +#include <semaphore.h> #define CODEC_DEV "/dev/codec" -#define CODEC_MMAP_SIZE 512 * 4096 +#define CODEC_MMAP_SIZE (16 * 1024 * 1024) CodecParam _param; ParserBuf _parserBuf; -static int codecfd; -static void *pMapBuf; +static int bRegister = 0; +static sem_t hCodecSem; -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) -} +/* + * Helper APIs + */ void restore_codec_context(AVCodecContext *dstctx, AVCodecContext *srcctx) { @@ -138,26 +98,230 @@ int get_picture_size (int pix_fmt, int width, int height) return size; } -void emul_av_register_all (void) +/* + * Open Codec Device + */ + +int emul_open_codecdev (CodecExtraInfo *pInfo) +{ + 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) + GST_CODEC_LOG("%d\n", errno) + } else { + GST_CODEC_LOG("Succeeded to open %s, ret:%d\n", CODEC_DEV, fd) + } + + pInfo->codecfd = fd; +#if 0 + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_INIT_MMAP_INDEX; + CODEC_WRITE(fd, &_param, 1); +#endif + + if (!bRegister) { + GST_CODEC_LOG("Initialize codec semaphore\n") + if (sem_init(&hCodecSem, 0, 1) < 0) { + printf("[%s] Semaphore Initialization Error\n", __func__); + return -1; + } + GST_CODEC_LOG("Register all codecs\n") + emul_av_register_all(pInfo); + bRegister++; + } + + GST_CODEC_LOG("Leave\n"); + + return fd; +} + +/* + * Release mmaping memory space with Codec Device Memory. + * And then, close Codec Device. + */ + +void emul_close_codecdev (CodecExtraInfo *pInfo) +{ +#ifndef CODEC_HOST + void *pBuf; + int fd; + int result; + + GST_CODEC_LOG("Enter\n") + pBuf = pInfo->pMmapBuf; + if (!pBuf) { + printf("mapping address is null\n"); + return; + } + + result = munmap(pBuf, CODEC_MMAP_SIZE); + printf("release mapping address :%d\n", result); + + fd = pInfo->codecfd; + if (fd < 0) { + printf("[%s] Codec device has not been opened yet.\n", __func__); + return; + } + +#if 0 + GST_CODEC_LOG("beore reset mmap index :%d, %d\n", pInfo->mmapIndex, EMUL_RESET_MMAP_INDEX); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_RESET_MMAP_INDEX; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + GST_CODEC_LOG("after reset mmap index\n"); +#endif + +#endif + close(fd); + pInfo->codecfd = -1; + bRegister--; + + if (!bRegister) { + GST_CODEC_LOG("destroy codec semaphore, %d\n", bRegister) + sem_destroy(&hCodecSem); + } + + GST_CODEC_LOG("Leave, close %s device and fd:%d\n", CODEC_DEV, fd) +} + +void emul_av_register_all (CodecExtraInfo *pInfo) { int fd; GST_CODEC_LOG("Enter\n") + fd = pInfo->codecfd; + if (fd < 0) { + printf("[%s] Codec device has not been opened yet.\n", __func__); + return; + } + + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_REGISTER_ALL; + CODEC_WRITE(fd, &_param, 1); + + GST_CODEC_LOG("Leave\n") +} + +#ifdef CODEC_HOST +int emul_avcodec_alloc_context (CodecExtraInfo *pInfo) +{ + int fd; + int result = -1; + fd = codecfd; if (fd < 0) { + fd = emul_open_codecdev(); + if (fd < 0) { + printf("[%s] Codec device has not been opened yet.\n", __func__); + return -1; + } + } + + GST_CODEC_LOG("Enter\n") + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_ALLOC_CONTEXT; + CODEC_WRITE(fd, &_param, 1); + GST_CODEC_LOG("Leave, ret:%d\n", result) + + return result; +} +#else +void emul_avcodec_alloc_context (CodecExtraInfo *pInfo) +{ + int fd; + int _ctxIndex = -1; + int mmapIndex = -1; + void *pBuf; + off_t offset = 0; + + GST_CODEC_LOG("Enter\n") + + GST_CODEC_LOG("before emul_open_codecdev:%d\n", fd) + PARAM_INIT(pInfo, CodecExtraInfo); + fd = emul_open_codecdev(pInfo); + 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); + sem_wait(&hCodecSem); + + PARAM_INIT(&_param, CodecParam); + + while (1) { + _param.apiIndex = EMUL_GET_MMAP_INDEX; + _param.ret_args = (uint32_t)&mmapIndex; + CODEC_WRITE(fd, &_param, 1); + if (mmapIndex != -1) { + printf("[%s] Success to get mmap index:%d\n", __func__, mmapIndex); + break; + } + sleep(1); + printf("[%s] Failure to get mmap index:%d\n", __func__, mmapIndex); + } + + pInfo->mmapIndex = mmapIndex; + + offset = mmapIndex * CODEC_MMAP_SIZE; + GST_CODEC_LOG("mmap index:%d, offset:%d\n", mmapIndex, offset) + + pBuf = mmap(NULL, CODEC_MMAP_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, offset); + if (pBuf) { + GST_CODEC_LOG("success mmap : %x\n", pBuf); + printf("success mmap : %x\n", pBuf); + pInfo->pMmapBuf = pBuf; + } else { + GST_CODEC_LOG("failure mmap\n"); + pInfo->pMmapBuf = NULL; + return; + } + + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_ALLOC_CONTEXT; + _param.mmapOffset = mmapIndex; + CODEC_WRITE(fd, &_param, 1); + + memcpy(&_ctxIndex, pBuf, sizeof(int)); + pInfo->contextIndex = _ctxIndex; + + GST_CODEC_LOG("context index : %d, mmap:%p\n", _ctxIndex, pInfo->pMmapBuf) + + sem_post(&hCodecSem); + + GST_CODEC_LOG("Leave\n") +} +#endif + +void emul_avcodec_alloc_frame (CodecExtraInfo *pInfo) +{ + int fd; + + GST_CODEC_LOG("Enter\n") + + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; + if (fd < 0) { + printf("[%s] Codec device has not been opened yet.\n", __func__); + return; + } + + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_ALLOC_FRAME; + CODEC_WRITE(fd, &_param, 1); + + sem_post(&hCodecSem); GST_CODEC_LOG("Leave\n") } #ifdef CODEC_HOST -int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec) +int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec, CodecExtraInfo *pInfo) { int fd; int result = -1; @@ -168,22 +332,20 @@ int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec) 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; - } + 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_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_OPEN; + _param.ctxIndex = pInfo->contextIndex; _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); + CODEC_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) @@ -191,18 +353,21 @@ int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec) return result; } #else -int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec) +int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec, CodecExtraInfo *pInfo) { int fd; int result = -1; int priv_data_size; int size; - void *buf; + int bEncode = 0; + void *pBuf; AVCodecContext tmpCtx; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; if (fd < 0) { printf("[%s] Codec device has not been opened yet.\n", __func__); return -1; @@ -211,44 +376,130 @@ int emul_avcodec_open (AVCodecContext *avctx, AVCodec *codec) 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; - } + pBuf = pInfo->pMmapBuf; + if (!pBuf) { + printf("mapping address is null\n"); + return result; + } + GST_CODEC_LOG("codec type:%d, codec id:%x\n", avctx->codec_type, avctx->codec_id) + +#ifndef CODEC_DUMMY + memcpy(&tmpCtx, avctx, sizeof(AVCodecContext)); + memcpy(pBuf, avctx, sizeof(AVCodecContext)); size = sizeof(AVCodecContext); - memcpy(&tmpCtx, avctx, size); - memcpy(buf, avctx, size); - memcpy((uint8_t*)buf + size, codec, sizeof(AVCodec)); + memcpy((uint8_t*)pBuf + size, codec, sizeof(AVCodec)); size += sizeof(AVCodec); - memcpy((uint8_t*)buf + size, avctx->extradata, avctx->extradata_size); + memcpy((uint8_t*)pBuf + size, avctx->extradata, avctx->extradata_size); +#else + GST_CODEC_LOG("\n") + + memcpy((uint8_t*)pBuf, &avctx->bit_rate, sizeof(int)); + size = sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->bit_rate_tolerance, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->flags, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->time_base, sizeof(AVRational)); + size += sizeof(AVRational); + memcpy((uint8_t*)pBuf + size, &avctx->width, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->height, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->gop_size, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->pix_fmt, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->sample_rate, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->channels, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->codec_tag, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->rc_strategy, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->strict_std_compliance, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->rc_qsquish, sizeof(float)); + size += sizeof(float); + memcpy((uint8_t*)pBuf + size, &avctx->sample_aspect_ratio, sizeof(AVRational)); + size += sizeof(AVRational); + memcpy((uint8_t*)pBuf + size, &avctx->mb_qmin, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->mb_qmax, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->pre_me, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &avctx->trellis, sizeof(int)); + size += sizeof(int); + GST_CODEC_LOG("extradata size :%d\n", avctx->extradata_size) + memcpy((uint8_t*)pBuf + size, &avctx->extradata_size, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &codec->id, sizeof(int)); + size += sizeof(int); + if (codec->encode) { + bEncode = 1; + } + memcpy((uint8_t*)pBuf + size, &bEncode, sizeof(int)); + memcpy((uint8_t*)pBuf + size, &codec->encode, sizeof(int)); + size += sizeof(int); + if (avctx->extradata_size > 0) { + memcpy((uint8_t*)pBuf + size, avctx->extradata, avctx->extradata_size); + } +#endif - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AVCODEC_OPEN; - write(fd, &_param, 1); + GST_CODEC_LOG("ctxIndex:%d, mmapIndex:%d\n", pInfo->contextIndex, pInfo->mmapIndex) - GST_CODEC_LOG("after write system call\n") + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_OPEN; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + GST_CODEC_LOG("after CODEC_WRITE system call\n") + +#ifndef CODEC_DUMMY size = sizeof(AVCodecContext); - memcpy(avctx, buf, size); + memcpy(avctx, pBuf, size); restore_codec_context(avctx, &tmpCtx); avctx->codec = codec; - memcpy(&result, (uint8_t*)buf + size, sizeof(int)); + memcpy(&result, (uint8_t*)pBuf + size, sizeof(int)); +#else + memcpy(&avctx->pix_fmt, (uint8_t*)pBuf, sizeof(int)); + size = sizeof(int); + memcpy(&avctx->time_base, (uint8_t*)pBuf + size, sizeof(AVRational)); + size += sizeof(AVRational); + memcpy(&avctx->sample_fmt, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->codec_type, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->codec_id, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->coded_width, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->coded_height, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->ticks_per_frame, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->chroma_sample_location, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(avctx->priv_data, (uint8_t*)pBuf + size, codec->priv_data_size); + size += codec->priv_data_size; + memcpy(&result, (uint8_t*)pBuf + size, sizeof(int)); + avctx->codec = codec; +#endif GST_CODEC_LOG("after codec type:%d, id:%d\n", avctx->codec_type, avctx->codec_id) GST_CODEC_LOG("Leave, ret : %d\n", result) + sem_post(&hCodecSem); + return result; } #endif #ifdef CODEC_HOST -int emul_avcodec_close(AVCodecContext *avctx) +int emul_avcodec_close(AVCodecContext *avctx, CodecExtraInfo *pInfo) { int fd; int result; @@ -261,212 +512,182 @@ int emul_avcodec_close(AVCodecContext *avctx) return -1; } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AVCODEC_CLOSE; + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_CLOSE; + _param.ctxIndex = pInfo->contextIndex; _param.in_args_num = 1; _param.in_args[0] = (uint32_t)avctx; _param.ret_args = (uint32_t)&result; - write(fd, &_param, 1); + CODEC_WRITE(fd, &_param, 1); GST_CODEC_LOG("Leave, ret : %d\n", result) return result; } #else -int emul_avcodec_close(AVCodecContext *avctx) +int emul_avcodec_close(AVCodecContext *avctx, CodecExtraInfo *pInfo) { int fd; int result; - int size; void *pBuf; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; if (fd < 0) { printf("[%s] Codec device has not been opened yet.\n", __func__); return -1; } - pBuf = pMapBuf; + pBuf = pInfo->pMmapBuf; if (!pBuf) { printf("mapping address is null\n"); return -1; } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AVCODEC_CLOSE; - write(fd, &_param, 1); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_CLOSE; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); memcpy(&result, pBuf, sizeof(int)); + sem_post(&hCodecSem); GST_CODEC_LOG("Leave, ret : %d\n", result) - return result; } #endif -void emul_avcodec_alloc_context (void) +void emul_av_free_context (CodecExtraInfo *pInfo) { 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; + sem_wait(&hCodecSem); - GST_CODEC_LOG("Enter\n") - fd = codecfd; + fd = pInfo->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; + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_FREE_CONTEXT; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); - GST_CODEC_LOG("Enter\n") - fd = codecfd; - if (fd < 0) { - printf("[%s] Codec device has not been opened yet.\n", __func__); - return; - } + sem_post(&hCodecSem); - 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) +void emul_av_free_picture (CodecExtraInfo *pInfo) { 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") -} + sem_wait(&hCodecSem); -void emul_av_free_palctrl (void) -{ - int fd; - - GST_CODEC_LOG("Enter\n") - fd = codecfd; + fd = pInfo->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); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_FREE_PICTURE; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + + sem_post(&hCodecSem); + GST_CODEC_LOG("Leave\n") } -void emul_av_free_extradata (void) +void emul_av_free_palctrl (CodecExtraInfo *pInfo) { int fd; GST_CODEC_LOG("Enter\n") - fd = codecfd; + + sem_wait(&hCodecSem); + + fd = pInfo->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); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_FREE_PALCTRL; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + + sem_post(&hCodecSem); + GST_CODEC_LOG("Leave\n") } -#ifdef CODEC_HOST -void emul_avcodec_flush_buffers(AVCodecContext *avctx) +void emul_av_free_extradata (CodecExtraInfo *pInfo) { int fd; GST_CODEC_LOG("Enter\n") - fd = codecfd; + + sem_wait(&hCodecSem); + fd = pInfo->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); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_FREE_EXTRADATA; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + + sem_post(&hCodecSem); + GST_CODEC_LOG("Leave\n") } -#else -void emul_avcodec_flush_buffers(AVCodecContext *avctx) + +void emul_avcodec_flush_buffers(AVCodecContext *avctx, CodecExtraInfo *pInfo) { int fd; - void *pBuf; -// AVCodecContext tmpCtx; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->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); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_FLUSH_BUFFERS; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); -// memcpy(avctx, pBuf, sizeof(AVCodecContext)); -// restore_codec_context(avctx, &tmpCtx); + sem_post(&hCodecSem); 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 *got_picture_ptr, uint8_t *buf, + int buf_size, CodecExtraInfo *pInfo) { int fd; int result; @@ -478,8 +699,9 @@ int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, return -1; } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AVCODEC_DECODE_VIDEO; + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_DECODE_VIDEO; + _param.ctxIndex = pInfo->contextIndex; _param.in_args_num = 5; _param.in_args[0] = (uint32_t)ctx; _param.in_args[1] = (uint32_t)frame; @@ -487,7 +709,7 @@ int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, _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); + CODEC_WRITE(fd, &_param, 1); GST_CODEC_LOG("Leave, ret:%d\n", result) @@ -495,7 +717,8 @@ int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, } #else int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, - int *got_picture_ptr, uint8_t *buf, int buf_size) + int *got_picture_ptr, uint8_t *buf, + int buf_size, CodecExtraInfo *pInfo) { int fd; int result; @@ -504,13 +727,15 @@ int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, AVCodecContext tmpCtx; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; if (fd < 0) { printf("[%s] Codec device has not been opened yet.\n", __func__); return -1; } - pBuf = pMapBuf; + pBuf = pInfo->pMmapBuf; if (!pBuf) { printf("mapping address is null\n"); return -1; @@ -523,14 +748,39 @@ int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, memcpy((uint8_t*)pBuf + size, buf, buf_size); } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AVCODEC_DECODE_VIDEO; - write(fd, &_param, 1); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_DECODE_VIDEO; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); +#ifndef CODEC_DUMMY size = sizeof(AVCodecContext); memcpy(&tmpCtx, ctx, size); memcpy(ctx, pBuf, size); restore_codec_context(ctx, &tmpCtx); +#else + memcpy(&ctx->pix_fmt, (uint8_t*)pBuf, sizeof(int)); + size = sizeof(int); + memcpy(&ctx->time_base, (uint8_t*)pBuf + size, sizeof(AVRational)); + size += sizeof(AVRational); + memcpy(&ctx->width, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&ctx->height, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&ctx->has_b_frames, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&ctx->frame_number, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&ctx->sample_aspect_ratio, (uint8_t*)pBuf + size, sizeof(AVRational)); + size += sizeof(AVRational); + memcpy(&ctx->internal_buffer_count, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&ctx->profile, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&ctx->level, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); +#endif ctx->coded_frame = frame; memcpy(frame, (uint8_t*)pBuf + size, sizeof(AVFrame)); @@ -540,8 +790,11 @@ int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, size += sizeof(int); memcpy(&result, (uint8_t*)pBuf + size, sizeof(int)); + GST_CODEC_LOG("have_data:%d\n", *got_picture_ptr) GST_CODEC_LOG("Leave, ret:%d\n", result) + sem_post(&hCodecSem); + return result; } #endif @@ -550,7 +803,7 @@ int emul_avcodec_decode_video(AVCodecContext *ctx, AVFrame *frame, #ifdef CODEC_HOST int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, int buf_size, const AVFrame *pict, - uint8_t *pict_buf) + uint8_t *pict_buf, CodecExtraInfo *pInfo) { int fd; int result = -1; @@ -564,8 +817,9 @@ int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, ctx->coded_frame = avcodec_alloc_frame(); - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AVCODEC_ENCODE_VIDEO; + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_ENCODE_VIDEO; + _param.ctxIndex = pInfo->contextIndex; _param.in_args_num = 5; _param.in_args[0] = (uint32_t)ctx; _param.in_args[1] = (uint32_t)buf; @@ -573,7 +827,7 @@ int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, _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); + CODEC_WRITE(fd, &_param, 1); GST_CODEC_LOG("after encoding video, ret :%d\n", result) return result; @@ -581,7 +835,7 @@ int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, #else int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, int buf_size, const AVFrame *pict, - uint8_t *pict_buf) + uint8_t *pict_buf, CodecExtraInfo *pInfo) { void *pBuf; int fd; @@ -591,7 +845,9 @@ int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, int result = -1; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; if (fd < 0) { printf("[%s] Codec device has not been opened yet.\n", __func__); return -1; @@ -599,32 +855,35 @@ int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, ctx->coded_frame = avcodec_alloc_frame(); - pBuf = pMapBuf; + pBuf = pInfo->pMmapBuf; 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); + size = 0; if (pict && pict_buf) { flush_buf = 0; - size = sizeof(int); - memcpy(pBuf, &flush_buf, size); - memcpy((uint8_t*)pBuf + size, &buf_size, size); + memcpy((uint8_t*)pBuf + size, &flush_buf, sizeof(int)); + size += sizeof(int); + memcpy((uint8_t*)pBuf + size, &buf_size, sizeof(int)); 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)); + memcpy((uint8_t*)pBuf + size, &flush_buf, sizeof(int)); } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AVCODEC_ENCODE_VIDEO; - write(fd, &_param, 1); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AVCODEC_ENCODE_VIDEO; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); - GST_CODEC_LOG("after write system call\n") + GST_CODEC_LOG("after CODEC_WRITE system call\n") if (pict && pict_buf) { memcpy(buf, (uint8_t*)pBuf, buf_size); @@ -633,14 +892,114 @@ int emul_avcodec_encode_video (AVCodecContext *ctx, uint8_t *buf, memcpy(&result, pBuf, sizeof(int)); } + sem_post(&hCodecSem); + GST_CODEC_LOG("after encoding video, ret :%d\n", result) return result; } #endif #ifdef CODEC_HOST +int emul_avcodec_decode_audio (AVCodecContext *avctx, int16_t *samples, + int *frame_size_ptr, const uint8_t *buf, + int buf_size, CodecExtraInfo *pInfo) +{ + int result = -1; + + GST_CODEC_LOG("buf_size :%d(0x%x)\n", buf_size, (uint32_t)&buf_size) + + PARAM_INIT(_param, CodecParam); + _param.apiIndex = 22; + _param.ctxIndex = ctxIndex; + _param.in_args_num = 5; + _param.in_args[0] = (uint32_t)avctx; + _param.in_args[1] = (uint32_t)samples; + _param.in_args[2] = (uint32_t)frame_size_ptr; + _param.in_args[3] = (uint32_t)buf; + _param.in_args[4] = (uint32_t)&buf_size; + _param.ret_args = (uint32_t)&result; + CODEC_WRITE(gst_codec_fd, &_param, 1); + + GST_CODEC_LOG("[audio]frame_number:%d, result:%d\n", avctx->frame_number, result) + return result; +} +#else +int emul_avcodec_decode_audio (AVCodecContext *avctx, int16_t *samples, + int *frame_size_ptr, const uint8_t *buf, + int buf_size, CodecExtraInfo *pInfo) +{ + int fd; + int result; + int size; + void *pBuf; + AVCodecContext tmpCtx; + + GST_CODEC_LOG("Enter\n") + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; + if (fd < 0) { + printf("[%s] Codec device has not been opened yet.\n", __func__); + return -1; + } + + pBuf = pInfo->pMmapBuf; + if (!pBuf) { + printf("mapping address is null\n"); + return -1; + } + + memcpy((uint8_t*)pBuf, &buf_size, sizeof(int)); + size = sizeof(int); + 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.apiIndex = EMUL_AVCODEC_DECODE_AUDIO; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + +#ifndef CODEC_DUMMY + memcpy(&tmpCtx, avctx, sizeof(AVCodecContext)); + memcpy(avctx, (uint8_t*)pBuf, sizeof(AVCodecContext)); + size = sizeof(AVCodecContext); + restore_codec_context(avctx, &tmpCtx); +#else + memcpy(&avctx->bit_rate, (uint8_t*)pBuf, sizeof(int)); + size = sizeof(int); + memcpy(&avctx->sub_id, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->frame_size, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&avctx->frame_number, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); +#endif + + memcpy(samples, (uint8_t*)pBuf + size, AVCODEC_MAX_AUDIO_FRAME_SIZE); + size += AVCODEC_MAX_AUDIO_FRAME_SIZE; + memcpy(frame_size_ptr, (uint8_t*)pBuf + size, sizeof(int)); + size += sizeof(int); + memcpy(&result, (uint8_t*)pBuf + size, sizeof(int)); + + GST_CODEC_LOG("frame_size_ptr:%d\n", *frame_size_ptr) + GST_CODEC_LOG("after decoding audio:%d\n", result) + + sem_post(&hCodecSem); + + GST_CODEC_LOG("Leave, 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) + enum PixelFormat pix_fmt, int width, + int height, CodecExtraInfo *pInfo) { int fd; @@ -651,34 +1010,38 @@ void emul_av_picture_copy(AVPicture *dst, const AVPicture *src, return; } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AV_PICTURE_COPY; + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_PICTURE_COPY; + _param.ctxIndex = pInfo->contextIndex; _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); + CODEC_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) + enum PixelFormat pix_fmt, int width, + int height, CodecExtraInfo *pInfo) { void *pBuf; int imgSize; int fd; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; if (fd < 0) { printf("[%s] Codec device has not been opened yet.\n", __func__); return; } - pBuf = pMapBuf; + pBuf = pInfo->pMmapBuf; if (!pBuf) { printf("mapping address is null\n"); return ; @@ -686,40 +1049,52 @@ void emul_av_picture_copy(AVPicture *dst, const AVPicture *src, imgSize = get_picture_size(pix_fmt, width, height); - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AV_PICTURE_COPY; - write(fd, &_param, 1); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_PICTURE_COPY; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + + GST_CODEC_LOG("after CODEC_WRITE system call\n") memcpy(dst->data[0], pBuf, imgSize); + sem_post(&hCodecSem); + GST_CODEC_LOG("Leave\n") } #endif -void emul_av_parser_init (void) +void emul_av_parser_init (CodecExtraInfo *pInfo) { int fd; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->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); + PARAM_INIT(&_param, CodecParam); + PARAM_INIT(&_parserBuf, ParserBuf); + _param.apiIndex = EMUL_AV_PARSER_INIT; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + + sem_post(&hCodecSem); 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) + uint8_t **outbuf, int *outbuf_size, + const uint8_t *buf, int buf_size, + int64_t pts, int64_t dts, CodecExtraInfo *pInfo) { int result = -1; int fd; @@ -744,8 +1119,9 @@ int emul_av_parser_parse (AVCodecParserContext *s, AVCodecContext *ctx, _parserBuf.buf = NULL; } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AV_PARSER_PARSE ; + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_PARSER_PARSE; + _param.ctxIndex = pInfo->contextIndex; _param.in_args_num = 8; _param.in_args[0] = (uint32_t)s; _param.in_args[1] = (uint32_t)ctx; @@ -756,7 +1132,7 @@ int emul_av_parser_parse (AVCodecParserContext *s, AVCodecContext *ctx, _param.in_args[6] = (uint32_t)&pts; _param.in_args[7] = (uint32_t)&dts; _param.ret_args = (uint32_t)&result; - write(fd, &_param, 1); + CODEC_WRITE(fd, &_param, 1); if (*outbuf_size == 0) { *outbuf = NULL; @@ -769,11 +1145,10 @@ int emul_av_parser_parse (AVCodecParserContext *s, AVCodecContext *ctx, } #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) + uint8_t **outbuf, int *outbuf_size, + const uint8_t *buf, int buf_size, + int64_t pts, int64_t dts, CodecExtraInfo *pInfo) { - AVCodecContext tmpCtx; void *pBuf; int fd; int size; @@ -781,58 +1156,63 @@ int emul_av_parser_parse (AVCodecParserContext *s, AVCodecContext *ctx, *outbuf = NULL; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; if (fd < 0) { printf("[%s] Codec device has not been opened yet.\n", __func__); return -1; } - pBuf = pMapBuf; + pBuf = pInfo->pMmapBuf; 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; + GST_CODEC_LOG("input buffer size :%d\n", buf_size) + GST_CODEC_LOG("previous result:%d\n", _parserBuf.size) + if (ctx->codec_type == AVMEDIA_TYPE_VIDEO) { + 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; + } + } else if (ctx->codec_type == AVMEDIA_TYPE_AUDIO) { + if (!_parserBuf.buf) { + GST_CODEC_LOG("allocate buffer for audio\n") + *outbuf = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); + _parserBuf.buf = *outbuf; + } else { + *outbuf = _parserBuf.buf; + } + } else { + printf("Codec type is wrong!!\n"); + return -1; } - 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, &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); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_PARSER_PARSE; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); - GST_CODEC_LOG("after copying AVCodecContext :%d\n", size); + GST_CODEC_LOG("After CODEC_WRITE system call\n") - memcpy(outbuf_size, (uint8_t*)pBuf + size, sizeof(int)); - size += sizeof(int); - - GST_CODEC_LOG("after copying output buffer size :%d\n", size); + memcpy(outbuf_size, (uint8_t*)pBuf, sizeof(int)); + size = sizeof(int); GST_CODEC_LOG("Output Buffer Size :%d\n", *outbuf_size); if (*outbuf_size > 0) { @@ -844,32 +1224,46 @@ int emul_av_parser_parse (AVCodecParserContext *s, AVCodecContext *ctx, GST_CODEC_LOG("Result :%d\n", result); - if (*outbuf_size == 0) { - *outbuf = NULL; - _parserBuf.size = result; - } else { - _parserBuf.size = -1; + if (ctx->codec_type == AVMEDIA_TYPE_VIDEO) { + GST_CODEC_LOG("for Video type\n") + if (*outbuf_size == 0) { + *outbuf = NULL; + _parserBuf.size = result; + GST_CODEC_LOG("parser outbuf size :%d\n", _parserBuf.size); + } else { + _parserBuf.size = -1; + GST_CODEC_LOG("parser outbuf size :%d\n", _parserBuf.size); + } } + sem_post(&hCodecSem); + GST_CODEC_LOG("Leave\n") return result; } #endif -void emul_av_parser_close (void) +void emul_av_parser_close (CodecExtraInfo *pInfo) { int fd; GST_CODEC_LOG("Enter\n") - fd = codecfd; + sem_wait(&hCodecSem); + + fd = pInfo->codecfd; if (fd < 0) { printf("[%s] Codec device has not been opened yet.\n", __func__); - return -1; + return; } - PARAM_INIT(_param, CodecParam); - _param.func_num = EMUL_AV_PARSER_CLOSE; - write(fd, &_param, 1); + PARAM_INIT(&_param, CodecParam); + _param.apiIndex = EMUL_AV_PARSER_CLOSE; + _param.ctxIndex = pInfo->contextIndex; + _param.mmapOffset = pInfo->mmapIndex; + CODEC_WRITE(fd, &_param, 1); + + sem_post(&hCodecSem); + GST_CODEC_LOG("Leave\n") } |