#include <mm_error.h>
#include <mm_types.h>
+#include <mm_util_image.h>
#include <mm_util_jpeg.h>
#include "gstcamerasrc.h"
static gboolean gst_camerasrc_jpeg_capture(GstCameraSrc *camerasrc, gint buffer_index, GstCameraBuffer *buffer)
{
- int ret = 0;
+ int ret = MM_UTIL_ERROR_NONE;
unsigned char *buffer_I420 = NULL;
- unsigned char *jpeg_result = NULL;
- unsigned int jpeg_size = 0;
+ void *jpeg_result = NULL;
+ size_t jpeg_size = 0;
GstCaps *main_caps = NULL;
GstBuffer *main_buffer = NULL;
GstSample *main_sample = NULL;
camerasrc_frame_data_t frame_data;
+ mm_util_image_h decoded = NULL;
+ size_t src_size = 0;
GST_INFO_OBJECT(camerasrc, "Start to encode image");
return FALSE;
}
- ret = mm_util_jpeg_encode_to_memory((void **)&jpeg_result, &jpeg_size,
- buffer_I420, camerasrc->width, camerasrc->height,
- MM_UTIL_COLOR_YUV420, camerasrc->cap_jpg_quality);
-
+ src_size = (camerasrc->width * camerasrc->height * 3) >> 1;
+ ret = mm_image_create_image(camerasrc->width, camerasrc->height, MM_UTIL_COLOR_YUV420, buffer_I420, src_size, &decoded);
/* release converted src buffer */
free(buffer_I420);
- buffer_I420 = NULL;
-
- if (ret != MM_ERROR_NONE || jpeg_result == NULL) {
- GST_ERROR_OBJECT(camerasrc, "jpeg encoding failed %p, 0x%x", jpeg_result, ret);
-
- if (jpeg_result) {
- free(jpeg_result);
- jpeg_result = NULL;
- }
+ if (ret != MM_UTIL_ERROR_NONE) {
+ GST_ERROR_OBJECT(camerasrc, "mm_image_create_image failed [%d]", ret);
+ return FALSE;
+ }
+ ret = mm_util_encode_to_jpeg_memory(decoded, camerasrc->cap_jpg_quality, &jpeg_result, &jpeg_size);
+ mm_image_destroy_image(decoded);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ GST_ERROR_OBJECT(camerasrc, "mm_util_encode_to_jpeg_memory failed [%d]", ret);
return FALSE;
}