#include <gstmmvideobuffermeta.h>
#include <linux/videodev2.h>
#include "gstnxvideodec.h"
+#include <gst/allocators/gsttizenmemory.h>
// This SUPPORT_NO_MEMORY_COPY function is disabled now.
// if the video decoder mmap is supported this function, it will be enabled.
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,
);
#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
#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 ();
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 ();
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)) {
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,
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)) {
if (pGstbuf) {
g_free (pGstbuf);
}
- if (pGstmem) {
- g_free (pGstmem);
- }
+
if (pMeta) {
nxvideodec_buffer_finalize (pMeta);
}
GstMemory *pGstmem = NULL;
GstBuffer *pGstbuf = NULL;
struct video_meta_mmap_buffer *pMeta = NULL;
- GstMemory *pMemMMVideoData = NULL;
FUNC_IN ();
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));
}
}
-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)
{