* limitations under the License.
*
*/
+#include <stdbool.h>
#include "mm_util_gstcs_internal.h"
#include <gst/check/gstcheck.h>
#include <gst/video/video-format.h>
static void
_mm_link_pipeline(gstreamer_s* pGstreamer_s, int value)
{
+ gstcs_fenter();
+
/* set property */
gst_bin_add_many(GST_BIN(pGstreamer_s->pipeline), pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL);
if (!gst_element_link_many(pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL))
/*g_object_set(pGstreamer_s->appsink, "drop", TRUE, NULL);*/
g_object_set(pGstreamer_s->appsink, "emit-signals", TRUE, "sync", FALSE, NULL);
+
+ gstcs_fleave();
}
static GstVideoFormat _mm_get_video_format(mm_util_color_format_e color_format)
{
int size = 0;
- gstcs_debug("color_format: %d", color_format);
+ gstcs_debug("color_format [%d] width [%d] height [%d]", color_format, width, height);
switch (color_format) {
case MM_UTIL_COLOR_YUV420:
return size;
}
-static int
-_mm_push_buffer_into_pipeline(imgp_info_s* pImgp_info, unsigned char *src, gstreamer_s * pGstreamer_s)
+static int _mm_push_buffer_into_pipeline(imgp_info_s* pImgp_info, unsigned char *src, gstreamer_s * pGstreamer_s)
{
int ret = GSTCS_ERROR_NONE;
+ gsize data_size = 0;
+ GstBuffer* gst_buf = NULL;
- if (pGstreamer_s->pipeline == NULL) {
- gstcs_error("pipeline is NULL\n");
- return GSTCS_ERROR_INVALID_PARAMETER;
- }
+ gstcs_fenter();
- gsize data_size = _mm_setup_image_size(pImgp_info->src_format, pImgp_info->src_width, pImgp_info->src_height);
- GstBuffer* gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, src, data_size, 0, data_size, NULL, NULL);
+ gstcs_retvm_if(pGstreamer_s->pipeline == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid pipeline");
- if (gst_buf == NULL) {
- gstcs_error("buffer is NULL\n");
- return GSTCS_ERROR_INVALID_PARAMETER;
- }
+ data_size = _mm_setup_image_size(pImgp_info->src_format, pImgp_info->src_width, pImgp_info->src_height);
+ gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, src, data_size, 0, data_size, NULL, NULL);
+
+ gstcs_retvm_if(gst_buf == NULL, GSTCS_ERROR_INVALID_OPERATION, "buffer is NULL");
gst_app_src_push_buffer(GST_APP_SRC(pGstreamer_s->appsrc), gst_buf); /* push buffer to pipeline */
+
+ gstcs_fleave();
+
return ret;
}
-static int
-_mm_push_buffer_into_pipeline_new(image_format_s *input_format, unsigned char *src, gstreamer_s * pGstreamer_s)
+static int _mm_push_buffer_into_pipeline_new(image_format_s *input_format, unsigned char *src, gstreamer_s * pGstreamer_s)
{
int ret = GSTCS_ERROR_NONE;
GstBuffer *gst_buf = NULL;
unsigned int stride = input_format->stride;
unsigned int elevation = input_format->elevation;
- if (pGstreamer_s->pipeline == NULL) {
- gstcs_error("pipeline is NULL\n");
- return GSTCS_ERROR_INVALID_PARAMETER;
- }
+ gstcs_fenter();
+
+ gstcs_retvm_if(pGstreamer_s->pipeline == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid pipeline");
- gstcs_debug("stride: %d, elevation: %d", stride, elevation);
src_size = _mm_setup_image_size(input_format->color_format, stride, elevation);
- gstcs_debug("buffer size (src): %d", src_size);
int byte_per_pixcel = _mm_get_byte_per_pixcel(input_format->color_format);
unsigned int src_row = input_format->width * byte_per_pixcel;
unsigned int stride_row = stride * byte_per_pixcel;
unsigned int i = 0, y = 0;
- gstcs_debug("padding will be inserted to buffer");
+
data = (unsigned char *) malloc(src_size);
- if (data == NULL) {
- gstcs_error("app_buffer is NULL\n");
- return GSTCS_ERROR_INVALID_PARAMETER;
- }
+ gstcs_retvm_if(data == NULL, GSTCS_ERROR_OUT_OF_MEMORY, "data is NULL");
+
for (y = 0; y < (unsigned int)(input_format->height); y++) {
guint8 *pLine = (guint8 *) &(src[src_row * y]);
for (i = 0; i < src_row; i++)
}
gst_app_src_push_buffer(GST_APP_SRC(pGstreamer_s->appsrc), gst_buf); /* push buffer to pipeline */
+
+ gstcs_fleave();
+
return ret;
}
-static int
-_mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigned char **dst, image_format_s* input_format, image_format_s* output_format, imgp_info_s* pImgp_info)
+static int _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigned char **dst, image_format_s* input_format, image_format_s* output_format, imgp_info_s* pImgp_info)
{
GstBus *bus = NULL;
GstStateChangeReturn ret_state;
int ret = GSTCS_ERROR_NONE;
+ gstcs_fenter();
+
/*create pipeline*/
ret = _mm_create_pipeline(pGstreamer_s);
if (ret != GSTCS_ERROR_NONE)
gst_app_sink_set_caps(GST_APP_SINK(pGstreamer_s->appsink), output_format->caps);
if ((input_format->width != input_format->stride) || (input_format->height != input_format->elevation)) {
- gstcs_debug("Start _mm_push_buffer_into_pipeline_new");
ret = _mm_push_buffer_into_pipeline_new(input_format, src, pGstreamer_s);
} else {
- gstcs_debug("Start mm_push_buffer_into_pipeline");
ret = _mm_push_buffer_into_pipeline(pImgp_info, src, pGstreamer_s);
}
gst_object_unref(pGstreamer_s->pipeline);
return ret;
}
- gstcs_debug("End mm_push_buffer_into_pipeline");
/*link pipeline*/
- gstcs_debug("Start mm_link_pipeline");
_mm_link_pipeline(pGstreamer_s, pImgp_info->angle);
- gstcs_debug("End mm_link_pipeline");
/* Conecting to the new-sample signal emited by the appsink*/
gstcs_debug("Start G_CALLBACK(_mm_sink_sample)");
gst_object_unref(pGstreamer_s->pipeline);
pGstreamer_s->output_buffer = NULL;
- gstcs_debug("End gstreamer processing");
gstcs_debug("dst: %p", *dst);
+ gstcs_fleave();
+
return ret;
}
static int _gstcs_create_default_thread(gstreamer_s *gstreamer)
{
- if (gstreamer == NULL) {
- gstcs_error("ERROR - gstreamer is null ");
- return GSTCS_ERROR_INVALID_OPERATION;
- }
+ gstcs_retvm_if(gstreamer == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid gstreamer");
gstreamer->context = g_main_context_new();
- if (gstreamer->context == NULL) {
- gstcs_error("ERROR - g_main_context_new ");
- return GSTCS_ERROR_INVALID_OPERATION;
- }
+ gstcs_retvm_if(gstreamer->context == NULL, GSTCS_ERROR_INVALID_OPERATION, "ERROR - g_main_context_new");
+
gstreamer->loop = g_main_loop_new(gstreamer->context, FALSE);
if (gstreamer->loop == NULL) {
gstcs_error("ERROR - g_main_loop_new ");
}
g_main_context_push_thread_default(gstreamer->context);
+
return GSTCS_ERROR_NONE;
}
static int _gstcs_destroy_default_thread(gstreamer_s *gstreamer)
{
- if (gstreamer == NULL) {
- gstcs_error("ERROR - gstreamer is null ");
- return GSTCS_ERROR_INVALID_OPERATION;
- }
+ gstcs_retvm_if(gstreamer == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid gstreamer");
if (gstreamer->loop != NULL)
g_main_loop_unref(gstreamer->loop);
argv = malloc(sizeof(gchar*) * max_argc);
- if (!argv) {
- gstcs_error("argv is not allocated");
- return GSTCS_ERROR_OUT_OF_MEMORY;
- }
+ gstcs_retvm_if(argv == NULL, GSTCS_ERROR_OUT_OF_MEMORY, "argv is not allocated");
+
memset(argv, 0, sizeof(gchar*) * max_argc);
argv[argc] = g_strdup("mmutil_gstcs");
int ret = GSTCS_ERROR_NONE;
/* Print debug message for inout structure */
- gstcs_debug("src_width [%d] src_height [%d] dst_width [%d] dst_height [%d] rotation [%d]",
- pImgp_info->src_width, pImgp_info->src_height, pImgp_info->dst_width, pImgp_info->dst_height, pImgp_info->angle);
+ gstcs_debug("src_width [%d] src_height [%d] src_format [%d] dst_width [%d] dst_height [%d] dst_format [%d] rotation [%d]",
+ pImgp_info->src_width, pImgp_info->src_height, pImgp_info->src_format, pImgp_info->dst_width, pImgp_info->dst_height, pImgp_info->dst_format, pImgp_info->angle);
/* Initialize gstreamer */
ret = _gstcs_init(&pGstreamer_s);
}
/* Do gstreamer processing */
- gstcs_debug("Start _mm_imgp_gstcs_processing ");
ret = _mm_imgp_gstcs_processing(pGstreamer_s, src, dst, input_format, output_format, pImgp_info); /* input: buffer pointer for input image , input image format, input image width, input image height, output: buffer porinter for output image */
if (ret == GSTCS_ERROR_NONE)
return ret;
}
-int mm_imgp(imgp_info_s* pImgp_info, unsigned char *src, unsigned char **dst, imgp_type_e _imgp_type)
+static bool _mm_imgp_check_format(mm_util_color_format_e color_format)
{
- if (pImgp_info == NULL) {
- gstcs_error("Error: input vaule is NULL");
- return GSTCS_ERROR_INVALID_PARAMETER;
- }
+ if ((color_format >= MM_UTIL_COLOR_YUV420) && (color_format <= MM_UTIL_COLOR_BGRX))
+ return TRUE;
- if (src == NULL || dst == NULL) {
- gstcs_error("Error: src | dst is NULL");
- return GSTCS_ERROR_INVALID_PARAMETER;
- }
+ return FALSE;
+}
- if (_imgp_type < 0 || _imgp_type > IMGP_MAX) {
- gstcs_error("Error: imgp_type is wrong");
- return GSTCS_ERROR_INVALID_PARAMETER;
- }
+int mm_imgp(imgp_info_s* pImgp_info, unsigned char *src, unsigned char **dst, imgp_type_e _imgp_type)
+{
+ gstcs_retvm_if(pImgp_info == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid info");
+ gstcs_retvm_if(src == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid src");
+ gstcs_retvm_if(dst == NULL, GSTCS_ERROR_INVALID_PARAMETER, "Invalid dst");
+ gstcs_retvm_if((_imgp_type < 0 || _imgp_type > IMGP_MAX), GSTCS_ERROR_INVALID_PARAMETER, "Invalid _imgp_type[%d]", _imgp_type);
+ gstcs_retvm_if((_mm_imgp_check_format(pImgp_info->src_format) == FALSE), GSTCS_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", pImgp_info->src_format);
+ gstcs_retvm_if((_mm_imgp_check_format(pImgp_info->dst_format) == FALSE), GSTCS_ERROR_NOT_SUPPORTED_FORMAT, "not supported dst_format [%d]", pImgp_info->dst_format);
gstcs_debug("[src %p] [dst %p]", src, dst);