From 0e515ac8edb22e4515f5954224ebff9aa5234c92 Mon Sep 17 00:00:00 2001 From: SeokHoon LEE Date: Mon, 22 Apr 2019 14:29:23 +0900 Subject: [PATCH] Add push_vidoe_packet for i420 format - add new function to process video packet that have separate plane in I420 format Change-Id: Id1abdcf1bf2562092e02ee352779afa45b7aaf94 Signed-off-by: SeokHoon LEE --- configure.ac | 4 ++ packaging/libmm-streamrecorder.spec | 3 +- src/Makefile.am | 2 + src/include/mm_streamrecorder.h | 3 ++ src/include/mm_streamrecorder_internal.h | 2 + src/mm_streamrecorder.c | 16 ++++++++ src/mm_streamrecorder_internal.c | 70 ++++++++++++++++++++++++++++++++ test/Makefile.am | 2 + 8 files changed, 101 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b07c4c7..f28cbea 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,10 @@ PKG_CHECK_MODULES(MM_COMMON, mm-common) AC_SUBST(MM_COMMON_CFLAGS) AC_SUBST(MM_COMMON_LIBS) +PKG_CHECK_MODULES(MEDIA_TOOL, capi-media-tool) +AC_SUBST(MEDIA_TOOL_CFLAGS) +AC_SUBST(MEDIA_TOOL_LIBS) + PKG_CHECK_MODULES(DLOG, dlog) AC_SUBST(DLOG_CFLAGS) AC_SUBST(DLOG_LIBS) diff --git a/packaging/libmm-streamrecorder.spec b/packaging/libmm-streamrecorder.spec index 3a23d44..c78bfdb 100644 --- a/packaging/libmm-streamrecorder.spec +++ b/packaging/libmm-streamrecorder.spec @@ -1,6 +1,6 @@ Name: libmm-streamrecorder Summary: Media Stream Recorder library -Version: 0.0.23 +Version: 0.0.24 Release: 0 Group: Multimedia/Other License: Apache-2.0 @@ -8,6 +8,7 @@ Source0: %{name}-%{version}.tar.gz Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig BuildRequires: pkgconfig(mm-common) +BuildRequires: pkgconfig(capi-media-tool) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(gstreamer-base-1.0) BuildRequires: pkgconfig(gstreamer-video-1.0) diff --git a/src/Makefile.am b/src/Makefile.am index 2138fc5..a1e672c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,6 +39,7 @@ libmmfstreamrecorder_la_CFLAGS = -I$(srcdir)/include \ $(GST_INTERFACES_CFLAGS) \ $(DLOG_CFLAGS) \ $(MM_COMMON_CFLAGS) \ + $(MEDIA_TOOL_CFLAGS) \ $(GST_APP_CFLAGS) libmmfstreamrecorder_la_LIBADD = \ @@ -47,6 +48,7 @@ libmmfstreamrecorder_la_LIBADD = \ $(GST_VIDEO_LIBS) \ $(GST_INTERFACES_LIBS) \ $(MM_COMMON_LIBS) \ + $(MEDIA_TOOL_LIBS) \ $(DLOG_LIBS) \ $(VCONF_LIBS) \ $(GST_APP_LIBS) \ diff --git a/src/include/mm_streamrecorder.h b/src/include/mm_streamrecorder.h index 66902e3..b32ba7d 100644 --- a/src/include/mm_streamrecorder.h +++ b/src/include/mm_streamrecorder.h @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -442,6 +443,8 @@ int mm_streamrecorder_commit(MMHandleType streamrecorder); int mm_streamrecorder_cancel(MMHandleType streamrecorder); +int mm_streamrecorder_push_video_packet(MMHandleType streamrecorder, media_packet_h packet, unsigned long timestamp, void *buffer); + int mm_streamrecorder_push_stream_buffer(MMHandleType streamrecorder, MMStreamRecorderStreamType streamtype, unsigned long timestamp, void *buffer, int size); /** diff --git a/src/include/mm_streamrecorder_internal.h b/src/include/mm_streamrecorder_internal.h index 61cb31e..5bd3d2c 100644 --- a/src/include/mm_streamrecorder_internal.h +++ b/src/include/mm_streamrecorder_internal.h @@ -359,6 +359,8 @@ int _mmstreamrecorder_unrealize(MMHandleType hstreamrecorder); */ int _mmstreamrecorder_record(MMHandleType hstreamrecorder); +int _mmstreamrecorder_push_video_packet(MMHandleType handle, media_packet_h packet, unsigned long timestamp, void *buffer); + int _mmstreamrecorder_push_stream_buffer(MMHandleType handle, MMStreamRecorderStreamType streamtype, unsigned long timestamp, void *buffer, int size); /** diff --git a/src/mm_streamrecorder.c b/src/mm_streamrecorder.c index d2b70b8..b4c639b 100644 --- a/src/mm_streamrecorder.c +++ b/src/mm_streamrecorder.c @@ -160,6 +160,22 @@ int mm_streamrecorder_push_stream_buffer(MMHandleType streamrecorder, MMStreamRe return error; } +int mm_streamrecorder_push_video_packet(MMHandleType streamrecorder, media_packet_h packet, unsigned long timestamp, void *buffer) +{ + int error = MM_ERROR_NONE; + + mmf_return_val_if_fail((void *)streamrecorder, MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT); + + _mmstreamrec_dbg_log(""); + + error = _mmstreamrecorder_push_video_packet(streamrecorder, packet, timestamp, buffer); + + _mmstreamrec_dbg_log("END"); + + return error; +} + + int mm_streamrecorder_commit(MMHandleType streamrecorder) { int error = MM_ERROR_NONE; diff --git a/src/mm_streamrecorder_internal.c b/src/mm_streamrecorder_internal.c index 5293609..127ff69 100644 --- a/src/mm_streamrecorder_internal.c +++ b/src/mm_streamrecorder_internal.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "mm_streamrecorder_internal.h" #include "mm_streamrecorder_recorder.h" @@ -388,6 +389,75 @@ int _mmstreamrecorder_record(MMHandleType handle) return ret; } +int _mmstreamrecorder_push_video_packet(MMHandleType handle, media_packet_h media_packet, unsigned long timestamp, void *buffer) +{ + int ret = MM_ERROR_NONE; + unsigned int ind = 0; + uint32_t plane_num = 0; + mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle); + GstStreamRecorderBuffer *stream_buffer = NULL; + int image_width = 0; + int image_height = 0; + unsigned char *data_buffer = NULL; + int size = 0, total_size = 0; + + if (!hstreamrecorder) { + _mmstreamrec_dbg_err("Not initialized"); + ret = MM_ERROR_STREAMRECORDER_NOT_INITIALIZED; + return ret; + } + + ret = media_packet_get_number_of_video_planes(media_packet, &plane_num); + if (plane_num <= 0 || ret != MEDIA_PACKET_ERROR_NONE) { + LOGE("invalid plane_num [%d] is returned", plane_num); + return MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT; + } + + stream_buffer = (GstStreamRecorderBuffer *) malloc(sizeof(GstStreamRecorderBuffer)); + if (stream_buffer == NULL) { + _mmstreamrec_dbg_err("stream buffer allocation fail"); + return MM_ERROR_STREAMRECORDER_LOW_MEMORY; + } + + stream_buffer->str_handle = handle; + stream_buffer->buffer = gst_buffer_new(); + if (stream_buffer->buffer == NULL) { + free(stream_buffer); + stream_buffer = NULL; + _mmstreamrec_dbg_err("gst buffer allocation fail"); + return MM_ERROR_STREAMRECORDER_LOW_MEMORY; + } + stream_buffer->user_buffer = buffer; + stream_buffer->buffer->pts = timestamp; + GST_BUFFER_DURATION(stream_buffer->buffer) = GST_CLOCK_TIME_NONE; + + for (ind = 0; ind < plane_num; ++ind) { + ret = media_packet_get_video_stride_width(media_packet, ind, &image_width); + ret |= media_packet_get_video_stride_height(media_packet, ind, &image_height); + ret |= media_packet_get_video_plane_data_ptr(media_packet, ind, (void**)&data_buffer); + + if (ret != MEDIA_PACKET_ERROR_NONE) { + LOGE("media_packet_get_video_plane_data_ptr() plane[%d] failed", ind); + return MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT; + } + + size = image_width * image_height; + total_size += size; + _mmstreamrec_dbg_err("Plane[%d] info : %d x %d (%p) size = %d\n", ind, image_width, image_height, data_buffer, total_size); + + if (ind == plane_num - 1) //last plane + gst_buffer_append_memory(stream_buffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, + data_buffer, size, 0, size, stream_buffer, _mmstreamrecorder_buffer_destroy)); + else + gst_buffer_append_memory(stream_buffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, + data_buffer, size, 0, size, NULL, NULL)); + } + + ret = _mmstreamrecorder_push_videostream_buffer(handle, timestamp, stream_buffer->buffer, total_size); + + return ret; +} + int _mmstreamrecorder_push_stream_buffer(MMHandleType handle, MMStreamRecorderStreamType streamtype, unsigned long timestamp, void *buffer, int size) { int ret = MM_ERROR_NONE; diff --git a/test/Makefile.am b/test/Makefile.am index f22d5ae..344277e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -7,6 +7,7 @@ mm_streamrecorder_testsuite_CFLAGS = -fPIE \ $(GLIB_CFLAGS)\ $(GST_CFLAGS)\ $(MM_COMMON_CFLAGS)\ + $(MEDIA_TOOL_CFLAGS) \ $(MM_SOUND_CFLAGS)\ $(MDM_CFLAGS) @@ -20,6 +21,7 @@ mm_streamrecorder_testsuite_LDADD = $(top_builddir)/src/libmmfstreamrecorder.la $(GLIB_LIBS)\ $(GST_LIBS)\ $(MM_COMMON_LIBS)\ + $(MEDIA_TOOL_LIBS) \ $(MM_SOUND_LIBS)\ $(MDM_LIBS) -- 2.7.4