Add push_vidoe_packet for i420 format 84/204184/3 accepted/tizen/unified/20190423.113416 submit/tizen/20190422.072607
authorSeokHoon LEE <andy.shlee@samsung.com>
Mon, 22 Apr 2019 05:29:23 +0000 (14:29 +0900)
committerSeokHoon LEE <andy.shlee@samsung.com>
Mon, 22 Apr 2019 05:41:12 +0000 (14:41 +0900)
- add new function to process video packet
  that have separate plane in I420 format

Change-Id: Id1abdcf1bf2562092e02ee352779afa45b7aaf94
Signed-off-by: SeokHoon LEE <andy.shlee@samsung.com>
configure.ac
packaging/libmm-streamrecorder.spec
src/Makefile.am
src/include/mm_streamrecorder.h
src/include/mm_streamrecorder_internal.h
src/mm_streamrecorder.c
src/mm_streamrecorder_internal.c
test/Makefile.am

index b07c4c7..f28cbea 100644 (file)
@@ -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)
index 3a23d44..c78bfdb 100644 (file)
@@ -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)
index 2138fc5..a1e672c 100644 (file)
@@ -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) \
index 66902e3..b32ba7d 100644 (file)
@@ -30,6 +30,7 @@
 #include <mm_types.h>
 #include <mm_error.h>
 #include <mm_message.h>
+#include <media_packet.h>
 
 #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);
 
 /**
index 61cb31e..5bd3d2c 100644 (file)
@@ -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);
 
 /**
index d2b70b8..b4c639b 100644 (file)
@@ -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;
index 5293609..127ff69 100644 (file)
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <mm_types.h>
 #include <mm_error.h>
+#include <media_packet.h>
 
 #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;
index f22d5ae..344277e 100644 (file)
@@ -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)