From 738043c14f592ddb2cde0507bad35d64147f59ba Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Thu, 5 Jul 2018 10:33:37 +0900 Subject: [PATCH] Apply tizen allocator to artik decoders Change-Id: Ib96eb357436945f84cb3ac35061d2990efdef6a3 --- configure.ac | 7 +- packaging/gst-plugins-video-dec.spec | 5 +- src/Makefile.am | 5 +- src/gstnxvideodec.c | 189 +++++++++-------------------------- src/gstnxvideodec.h | 2 +- 5 files changed, 61 insertions(+), 147 deletions(-) diff --git a/configure.ac b/configure.ac index 64d21b3..f3ff011 100644 --- a/configure.ac +++ b/configure.ac @@ -68,8 +68,11 @@ PKG_CHECK_MODULES(GST, [ ]) ]) -PKG_CHECK_MODULES(MM_COMMON, mm-common) -AC_SUBST(MM_COMMON_CFLAGS) +PKG_CHECK_MODULES([GST_ALLOCATORS], [gstreamer-allocators-1.0]) + +PKG_CHECK_MODULES(TBM, libtbm) +AC_SUBST(TBM_CFLAGS) +AC_SUBST(TBM_LIBS) dnl check if compiler understands -Wall (if yes, add -Wall to GST_CFLAGS) AC_MSG_CHECKING([to see if compiler understands -Wall]) diff --git a/packaging/gst-plugins-video-dec.spec b/packaging/gst-plugins-video-dec.spec index a0b9920..4cb280e 100644 --- a/packaging/gst-plugins-video-dec.spec +++ b/packaging/gst-plugins-video-dec.spec @@ -1,5 +1,5 @@ Name: gst-plugins-video-dec -Version: 1.0.4 +Version: 1.1.0 Release: 0 License: LGPL-2.1+ Summary: nexell video decoder gstreamer plugin @@ -13,7 +13,8 @@ BuildRequires: glibc-devel BuildRequires: gst-plugins-base-devel BuildRequires: nx-gst-meta-devel BuildRequires: nx-video-api-devel -BuildRequires: pkgconfig(mm-common) +#BuildRequires: pkgconfig(mm-common) +BuildRequires: pkgconfig(libtbm) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/Makefile.am b/src/Makefile.am index 9542366..e829796 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,12 +16,15 @@ libgstnxvideodec_la_SOURCES = gstnxvideodec.c decoder.c # compiler and linker flags used to compile this plugin, set in configure.ac libgstnxvideodec_la_CFLAGS = \ $(GST_CFLAGS) \ - $(MM_COMMON_CFLAGS) \ + $(TBM_CFLAGS) \ -DTIZEN_FEATURE_ARTIK530 \ + $(GST_ALLOCATORS_CFLAGS) \ -I$(includedir) libgstnxvideodec_la_LIBADD = \ $(GST_LIBS) \ + $(TBM_LIBS) \ + $(GST_ALLOCATORS_LIBS) \ -lgstvideo-1.0 \ -lgstpbutils-1.0 \ -lnxgstmeta \ diff --git a/src/gstnxvideodec.c b/src/gstnxvideodec.c index 6ef5baa..cf07998 100755 --- a/src/gstnxvideodec.c +++ b/src/gstnxvideodec.c @@ -68,6 +68,7 @@ #include #include #include "gstnxvideodec.h" +#include // This SUPPORT_NO_MEMORY_COPY function is disabled now. // if the video decoder mmap is supported this function, it will be enabled. @@ -92,7 +93,6 @@ static GstFlowReturn gst_nxvideodec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame); static void nxvideodec_base_init (gpointer gclass); static void nxvideodec_buffer_finalize (gpointer pData); -static GstMemory *nxvideodec_mmvideobuf_copy (GstNxVideoDec *pNxVideoDec, NX_V4L2DEC_OUT * pDecOut); #if SUPPORT_NO_MEMORY_COPY static void nxvideodec_get_offset_stride (gint width, gint height, @@ -146,38 +146,49 @@ GST_STATIC_PAD_TEMPLATE ("src", ); #ifdef CODEC_DEC_OUTPUT_DUMP /* for decoder output dump */ -static void -decoder_output_dump(MMVideoBuffer *outbuf) +static inline void +decoder_output_dump (GstBuffer *buffer) { - char *temp = (char *)outbuf->data[0]; int i = 0; char filename[100]={0}; FILE *fp = NULL; - int ret =0; + tbm_surface_h surface; + tbm_surface_info_s info; + GstMemory *mem = gst_buffer_peek_memory (buffer, 0); + unsigned char *temp; + + surface = gst_tizen_memory_get_surface(mem); - GST_ERROR ("codec dec output dump start. w = %d, h = %d", outbuf->width[0], outbuf->height[0]); + tbm_surface_get_info (surface, &info); - sprintf(filename, "/tmp/dec_output_dump_%d_%d.yuv", outbuf->width[0], outbuf->height[0]); + temp = info.planes[0].ptr; + + sprintf(filename, "/tmp/dec_output_dump_%d_%d.yuv", info.width, info.height); fp = fopen(filename, "ab"); - for (i = 0; i < outbuf->height[0]; i++) { - ret = fwrite(temp, outbuf->width[0], 1, fp); - temp += outbuf->stride_width[0]; + if(!fp) { + return; } - temp = outbuf->data[1]; - for (i = 0; i < outbuf->height[0]/2; i++) { - ret = fwrite(temp, outbuf->width[0]/2, 1, fp); - temp += outbuf->stride_width[0]/2; + for (i = 0; i < info.height; i++) { + fwrite(temp, info.width, 1, fp); + temp += info.planes[0].stride; } - temp = outbuf->data[2]; - for (i = 0; i < outbuf->height[0]/2; i++) { - ret = fwrite(temp, outbuf->width[0]/2, 1, fp); - temp += outbuf->stride_width[0]/2; + temp = info.planes[1].ptr; + + for(i = 0; i < info.height/2 ; i++) { + fwrite(temp, info.width/2, 1, fp); + temp += info.planes[1].stride; + } + + temp = info.planes[2].ptr; + + for(i = 0; i < info.height/2 ; i++) { + fwrite(temp, info.width/2, 1, fp); + temp += info.planes[2].stride; } - GST_ERROR ("codec dec output dumped!! ret = %d", ret); fclose(fp); } #endif @@ -305,6 +316,9 @@ gst_nxvideodec_init (GstNxVideoDec * pNxVideoDec) #else pNxVideoDec->bufferType = BUFFER_TYPE_GEM; #endif +#ifdef TIZEN_FEATURE_ARTIK530 + pNxVideoDec->allocator = gst_tizen_allocator_new (); +#endif pthread_mutex_init (&pNxVideoDec->mutex, NULL); FUNC_OUT (); @@ -411,6 +425,12 @@ gst_nxvideodec_stop (GstVideoDecoder * pDecoder) CloseVideoDec (pNxVideoDec->pNxVideoDecHandle); +#ifdef TIZEN_FEATURE_ARTIK530 + if (pNxVideoDec->allocator) { + gst_object_unref (pNxVideoDec->allocator); + pNxVideoDec->allocator = NULL; + } +#endif pthread_mutex_destroy (&pNxVideoDec->mutex); FUNC_OUT (); @@ -651,23 +671,19 @@ gst_nxvideodec_handle_frame (GstVideoDecoder * pDecoder, gint ret = 0; gboolean bKeyFrame = FALSE; - GstMemory *pGstmem = NULL; + GstMemory *pTmem = NULL; GstBuffer *pGstbuf = NULL; struct video_meta_mmap_buffer *pMeta = NULL; NX_VID_MEMORY_INFO *pImg = NULL; GstVideoCodecState *pState = NULL; - unsigned char *pVadd = NULL; GstVideoMeta *pVmeta = NULL; - gint videoImgSize = 0; guint n_planes = 0; gsize offset[3] = { 0, }; gint stride[3] = { 0, }; - GstMemory *pMemMMVideoData = NULL; - FUNC_IN (); if (!gst_buffer_map (pFrame->input_buffer, &mapInfo, GST_MAP_READ)) { @@ -708,30 +724,14 @@ gst_nxvideodec_handle_frame (GstVideoDecoder * pDecoder, pImg = &decOut.hImg; pMeta->v4l2BufferIdx = decOut.dispIdx; - pVadd = pImg->pBuffer[0]; pMeta->pNxVideoDec = pNxVideoDec; - videoImgSize = - pNxVideoDec->pNxVideoDecHandle->width * - pNxVideoDec->pNxVideoDecHandle->height * 1.5; - - pGstmem = gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, - pVadd, videoImgSize, 0, videoImgSize, pMeta, nxvideodec_buffer_finalize); - - if (!pGstmem) { - GST_ERROR_OBJECT (pNxVideoDec, - "failed to gst_memory_new_wrapped for mmap buffer"); - gst_video_codec_frame_unref (pFrame); - goto HANDLE_ERROR; - } - pGstbuf = gst_buffer_new (); if (!pGstbuf) { GST_ERROR_OBJECT (pNxVideoDec, "failed to gst_buffer_new"); gst_video_codec_frame_unref (pFrame); goto HANDLE_ERROR; } - gst_buffer_append_memory (pGstbuf, pGstmem); n_planes = 3; nxvideodec_get_offset_stride (pNxVideoDec->pNxVideoDecHandle->width, @@ -740,29 +740,25 @@ gst_nxvideodec_handle_frame (GstVideoDecoder * pDecoder, pState = gst_video_decoder_get_output_state (pDecoder); + pTmem = gst_tizen_allocator_alloc_surface (pNxVideoDec->allocator, &pState->info, pImg->surface, pMeta, nxvideodec_buffer_finalize); + pVmeta = gst_buffer_add_video_meta_full (pGstbuf, GST_VIDEO_FRAME_FLAG_NONE, GST_VIDEO_INFO_FORMAT (&pState->info), GST_VIDEO_INFO_WIDTH (&pState->info), GST_VIDEO_INFO_HEIGHT (&pState->info), n_planes, offset, stride); + if (!pVmeta) { GST_ERROR_OBJECT (pNxVideoDec, "failed to gst_buffer_add_video_meta_full"); gst_video_codec_state_unref (pState); gst_video_codec_frame_unref (pFrame); goto HANDLE_ERROR; } + gst_buffer_append_memory (pGstbuf, pTmem); - pMemMMVideoData = nxvideodec_mmvideobuf_copy (pNxVideoDec, &decOut); - if (!pMemMMVideoData) { - GST_ERROR ("failed to get zero copy data"); - gst_video_codec_state_unref (pState); - gst_video_codec_frame_unref (pFrame); - goto HANDLE_ERROR; - } else { - gst_buffer_append_memory (pGstbuf, pMemMMVideoData); - } - gst_buffer_add_mmvideobuffer_meta (pGstbuf, 1); - +#ifdef CODEC_DEC_OUTPUT_DUMP /* for decoder output dump */ + decoder_output_dump (pGstbuf); +#endif pFrame->output_buffer = pGstbuf; if (-1 == GetTimeStamp (pNxVideoDec->pNxVideoDecHandle, &timeStamp)) { @@ -783,9 +779,7 @@ HANDLE_ERROR: if (pGstbuf) { g_free (pGstbuf); } - if (pGstmem) { - g_free (pGstmem); - } + if (pMeta) { nxvideodec_buffer_finalize (pMeta); } @@ -806,7 +800,6 @@ gst_nxvideodec_handle_frame (GstVideoDecoder * pDecoder, GstMemory *pGstmem = NULL; GstBuffer *pGstbuf = NULL; struct video_meta_mmap_buffer *pMeta = NULL; - GstMemory *pMemMMVideoData = NULL; FUNC_IN (); @@ -844,14 +837,6 @@ gst_nxvideodec_handle_frame (GstVideoDecoder * pDecoder, goto HANDLE_ERROR; } - pMemMMVideoData = nxvideodec_mmvideobuf_copy (pNxVideoDec, &decOut); - if (!pMemMMVideoData) { - GST_ERROR ("failed to get zero copy data"); - gst_video_codec_frame_unref (pFrame); - goto HANDLE_ERROR; - } - gst_buffer_append_memory (pGstbuf, pMemMMVideoData); - pMeta = (struct video_meta_mmap_buffer *) g_malloc (sizeof (struct video_meta_mmap_buffer)); @@ -997,84 +982,6 @@ nxvideodec_buffer_finalize (gpointer pData) } } -static GstMemory * -nxvideodec_mmvideobuf_copy (GstNxVideoDec *pNxVideoDec, NX_V4L2DEC_OUT * pDecOut) -{ - GstMemory *pMeta = NULL; - MMVideoBuffer *pMMVideoBuf = NULL; - - pMMVideoBuf = (MMVideoBuffer *) g_malloc (sizeof (MMVideoBuffer)); - if (!pMMVideoBuf) { - GST_ERROR ("failed to alloc MMVideoBuffer"); - return NULL; - } - - memset ((void *) pMMVideoBuf, 0, sizeof (MMVideoBuffer)); - - if (1 == pDecOut->hImg.planes) { - pMMVideoBuf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO; - pMMVideoBuf->plane_num = 3; - pMMVideoBuf->width[0] = pDecOut->hImg.width; - pMMVideoBuf->height[0] = pDecOut->hImg.height; - pMMVideoBuf->stride_width[0] = GST_ROUND_UP_32 (pDecOut->hImg.width); - pMMVideoBuf->stride_width[1] = pMMVideoBuf->stride_width[0] >> 1; - pMMVideoBuf->stride_width[2] = pMMVideoBuf->stride_width[1]; - pMMVideoBuf->stride_height[0] = GST_ROUND_UP_16 (pDecOut->hImg.height); - pMMVideoBuf->stride_height[1] = GST_ROUND_UP_16 (pDecOut->hImg.height >> 1); - pMMVideoBuf->stride_height[2] = pMMVideoBuf->stride_height[1]; - pMMVideoBuf->size[0] = pMMVideoBuf->stride_width[0] * pMMVideoBuf->stride_height[0];; - pMMVideoBuf->size[1] = pMMVideoBuf->stride_width[1] * pMMVideoBuf->stride_height[1]; - pMMVideoBuf->size[2] = pMMVideoBuf->stride_width[2] * pMMVideoBuf->stride_height[2]; - pMMVideoBuf->data[0] = pDecOut->hImg.pBuffer[0]; - pMMVideoBuf->data[1] = pDecOut->hImg.pBuffer[0] + pMMVideoBuf->size[0]; - pMMVideoBuf->data[2] = pMMVideoBuf->data[1] + pMMVideoBuf->size[1]; - pMMVideoBuf->handle_num = 1; - pMMVideoBuf->handle_size[0] = pMMVideoBuf->stride_width[0] * pMMVideoBuf->stride_height[0]; - pMMVideoBuf->handle_size[1] = pMMVideoBuf->stride_width[1] * pMMVideoBuf->stride_height[1]; - pMMVideoBuf->handle_size[2] = pMMVideoBuf->stride_width[2] * pMMVideoBuf->stride_height[2]; -#ifdef TIZEN_FEATURE_ARTIK530 - pMMVideoBuf->handle.bo[0] = pDecOut->hImg.bo[0]; - if (!pMMVideoBuf->handle.bo[0]) - GST_ERROR ("bo = null\n"); -#endif - } else if (3 == pDecOut->hImg.planes) { - pMMVideoBuf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO; - pMMVideoBuf->format = MM_PIXEL_FORMAT_I420; - pMMVideoBuf->plane_num = 3; - pMMVideoBuf->width[0] = pDecOut->hImg.width; - pMMVideoBuf->height[0] = pDecOut->hImg.height; - pMMVideoBuf->stride_width[0] = pDecOut->hImg.stride[0]; - pMMVideoBuf->stride_width[1] = pDecOut->hImg.stride[1]; - pMMVideoBuf->stride_width[2] = pDecOut->hImg.stride[2]; - pMMVideoBuf->size[0] = pDecOut->hImg.size[0]; - pMMVideoBuf->size[1] = pDecOut->hImg.size[1]; - pMMVideoBuf->size[2] = pDecOut->hImg.size[2]; - pMMVideoBuf->data[0] = pDecOut->hImg.pBuffer[0]; - pMMVideoBuf->data[1] = pDecOut->hImg.pBuffer[1]; - pMMVideoBuf->data[2] = pDecOut->hImg.pBuffer[2]; - pMMVideoBuf->handle_num = 3; -#ifdef TIZEN_FEATURE_ARTIK530 - pMMVideoBuf->handle.bo[0] = pDecOut->hImg.bo[0]; - pMMVideoBuf->handle.bo[1] = pDecOut->hImg.bo[1]; - pMMVideoBuf->handle.bo[2] = pDecOut->hImg.bo[2]; - if (!pMMVideoBuf->handle.bo[0]) - GST_ERROR ("bo[0] = null\n"); - if (!pMMVideoBuf->handle.bo[1]) - GST_ERROR ("bo[1] = null\n"); - if (!pMMVideoBuf->handle.bo[2]) - GST_ERROR ("bo[2] = null\n"); -#endif - } -#ifdef CODEC_DEC_OUTPUT_DUMP /* for decoder output dump */ - decoder_output_dump (pMMVideoBuf); -#endif - pMeta = gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, - pMMVideoBuf, - sizeof (MMVideoBuffer), 0, sizeof (MMVideoBuffer), pMMVideoBuf, g_free); - - return pMeta; -} - static gboolean plugin_init (GstPlugin * plugin) { diff --git a/src/gstnxvideodec.h b/src/gstnxvideodec.h index 0e50e60..b994a67 100644 --- a/src/gstnxvideodec.h +++ b/src/gstnxvideodec.h @@ -72,7 +72,6 @@ typedef struct _GstNxVideoDec GstNxVideoDec; typedef struct _GstNxVideoDecClass GstNxVideoDecClass; typedef struct _GstNxDecOutBuffer GstNxDecOutBuffer; -#include #include "decoder.h" struct _GstNxDecOutBuffer @@ -91,6 +90,7 @@ struct _GstNxVideoDec GstVideoCodecState *pInputState; gint isState; pthread_mutex_t mutex; + GstAllocator *allocator; }; struct _GstNxVideoDecClass -- 2.7.4