4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
28 #include <sys/vfs.h> /* struct statfs */
29 #include <sys/time.h> /* gettimeofday */
31 #include <gst/video/video-info.h>
34 #include "mm_camcorder_internal.h"
35 #include "mm_camcorder_util.h"
36 #include "mm_camcorder_sound.h"
37 #include <mm_util_imgp.h>
38 #include <mm_util_jpeg.h>
42 /*-----------------------------------------------------------------------
43 | GLOBAL VARIABLE DEFINITIONS for internal |
44 -----------------------------------------------------------------------*/
46 /*-----------------------------------------------------------------------
47 | LOCAL VARIABLE DEFINITIONS for internal |
48 -----------------------------------------------------------------------*/
49 #define TIME_STRING_MAX_LEN 64
50 #define __MMCAMCORDER_CAPTURE_WAIT_TIMEOUT 5
52 #define FPUTC_CHECK(x_char, x_file) \
54 if (fputc(x_char, x_file) == EOF) { \
55 _mmcam_dbg_err("[Critical] fputc() returns fail.\n"); \
59 #define FPUTS_CHECK(x_str, x_file) \
61 if (fputs(x_str, x_file) == EOF) { \
62 _mmcam_dbg_err("[Critical] fputs() returns fail.\n"); \
68 /*---------------------------------------------------------------------------
69 | LOCAL FUNCTION PROTOTYPES: |
70 ---------------------------------------------------------------------------*/
71 /* STATIC INTERNAL FUNCTION */
73 //static gint skip_mdat(FILE *f);
74 static guint16 get_language_code(const char *str);
75 static gchar* str_to_utf8(const gchar *str);
76 static inline gboolean write_tag(FILE *f, const gchar *tag);
77 static inline gboolean write_to_32(FILE *f, guint val);
78 static inline gboolean write_to_16(FILE *f, guint val);
79 static inline gboolean write_to_24(FILE *f, guint val);
80 #ifdef _USE_YUV_TO_RGB888_
81 static gboolean _mmcamcorder_convert_YUV_to_RGB888(unsigned char *src, int src_fmt, guint width, guint height, unsigned char **dst, unsigned int *dst_len);
82 #endif /* _USE_YUV_TO_RGB888_ */
83 static gboolean _mmcamcorder_convert_YUYV_to_I420(unsigned char *src, guint width, guint height, unsigned char **dst, unsigned int *dst_len);
84 static gboolean _mmcamcorder_convert_UYVY_to_I420(unsigned char *src, guint width, guint height, unsigned char **dst, unsigned int *dst_len);
85 static gboolean _mmcamcorder_convert_NV12_to_I420(unsigned char *src, guint width, guint height, unsigned char **dst, unsigned int *dst_len);
88 /*===========================================================================================
90 | FUNCTION DEFINITIONS |
92 ========================================================================================== */
93 /*---------------------------------------------------------------------------
94 | GLOBAL FUNCTION DEFINITIONS: |
95 ---------------------------------------------------------------------------*/
97 static int __gdbus_method_call_sync(GDBusConnection *conn, const char *bus_name,
98 const char *object, const char *iface, const char *method,
99 GVariant *args, GVariant **result, bool is_sync)
101 int ret = MM_ERROR_NONE;
102 GVariant *dbus_reply = NULL;
104 if (!conn || !object || !iface || !method) {
105 _mmcam_dbg_err("Invalid Argument %p %p %p %p",
106 conn, object, iface, method);
107 return MM_ERROR_INVALID_ARGUMENT;
110 _mmcam_dbg_log("Dbus call - obj [%s], iface [%s], method [%s]", object, iface, method);
113 dbus_reply = g_dbus_connection_call_sync(conn,
114 bus_name, object, iface, method, args, NULL,
115 G_DBUS_CALL_FLAGS_NONE, G_DBUS_REPLY_TIMEOUT, NULL, NULL);
117 _mmcam_dbg_log("Method Call '%s.%s' Success", iface, method);
118 *result = dbus_reply;
120 _mmcam_dbg_err("dbus method call sync reply failed");
121 ret = MM_ERROR_CAMCORDER_INTERNAL;
124 g_dbus_connection_call(conn, bus_name, object, iface, method, args, NULL,
125 G_DBUS_CALL_FLAGS_NONE, G_DBUS_REPLY_TIMEOUT, NULL, NULL, NULL);
131 static int __gdbus_subscribe_signal(GDBusConnection *conn,
132 const char *object_name, const char *iface_name, const char *signal_name,
133 GDBusSignalCallback signal_cb, guint *subscribe_id, void *userdata)
137 if (!conn || !object_name || !iface_name || !signal_name || !signal_cb || !subscribe_id) {
138 _mmcam_dbg_err("Invalid Argument %p %p %p %p %p %p",
139 conn, object_name, iface_name, signal_name, signal_cb, subscribe_id);
140 return MM_ERROR_INVALID_ARGUMENT;
143 _mmcam_dbg_log("subscirbe signal Obj %s, iface_name %s, sig_name %s",
144 object_name, iface_name, signal_name);
146 subs_id = g_dbus_connection_signal_subscribe(conn,
147 NULL, iface_name, signal_name, object_name, NULL,
148 G_DBUS_SIGNAL_FLAGS_NONE, signal_cb, userdata, NULL);
150 _mmcam_dbg_err("g_dbus_connection_signal_subscribe() failed");
151 return MM_ERROR_CAMCORDER_INTERNAL;
153 *subscribe_id = subs_id;
154 _mmcam_dbg_log("subs_id %u", subs_id);
157 return MM_ERROR_NONE;
161 static void __gdbus_stream_eos_cb(GDBusConnection *connection,
162 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
163 const gchar *signal_name, GVariant *param, gpointer user_data)
166 _MMCamcorderGDbusCbInfo *gdbus_info = NULL;
168 _mmcam_dbg_log("entered");
170 if (!param || !user_data) {
171 _mmcam_dbg_err("invalid parameter %p %p", param, user_data);
175 gdbus_info = (_MMCamcorderGDbusCbInfo *)user_data;
177 g_variant_get(param, "(i)", &played_idx);
179 g_mutex_lock(&gdbus_info->sync_mutex);
181 _mmcam_dbg_log("gdbus_info->param %d, played_idx : %d",
182 gdbus_info->param, played_idx);
184 if (gdbus_info->param == played_idx) {
185 g_dbus_connection_signal_unsubscribe(connection, gdbus_info->subscribe_id);
187 gdbus_info->is_playing = FALSE;
188 gdbus_info->subscribe_id = 0;
189 gdbus_info->param = 0;
191 g_cond_signal(&gdbus_info->sync_cond);
194 g_mutex_unlock(&gdbus_info->sync_mutex);
199 static int __gdbus_wait_for_cb_return(_MMCamcorderGDbusCbInfo *gdbus_info, int time_out)
201 int ret = MM_ERROR_NONE;
205 _mmcam_dbg_err("invalid info");
206 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
209 g_mutex_lock(&gdbus_info->sync_mutex);
211 _mmcam_dbg_log("entered");
213 if (gdbus_info->is_playing == FALSE) {
214 _mmcam_dbg_log("callback is already returned");
215 g_mutex_unlock(&gdbus_info->sync_mutex);
216 return MM_ERROR_NONE;
219 end_time = g_get_monotonic_time() + (time_out * G_TIME_SPAN_MILLISECOND);
221 if (g_cond_wait_until(&gdbus_info->sync_cond, &gdbus_info->sync_mutex, end_time)) {
222 _mmcam_dbg_log("wait signal received");
224 _mmcam_dbg_err("wait time is expired");
225 ret = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
228 g_mutex_unlock(&gdbus_info->sync_mutex);
234 gint32 _mmcamcorder_double_to_fix(gdouble d_number)
236 return (gint32) (d_number * 65536.0);
239 // find top level tag only, do not use this function for finding sub level tags
240 gint _mmcamcorder_find_tag(FILE *f, guint32 tag_fourcc, gboolean do_rewind)
242 size_t read_item = 0;
248 while ((read_item = fread(&buf, sizeof(guchar), 8, f)) > 0) {
249 uint64_t buf_size = 0;
250 uint32_t buf_fourcc = 0;
253 _mmcam_dbg_err("fread failed : %d", read_item);
257 buf_fourcc = MMCAM_FOURCC(buf[4], buf[5], buf[6], buf[7]);
259 if (tag_fourcc == buf_fourcc) {
260 _mmcam_dbg_log("find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
263 _mmcam_dbg_log("skip [%c%c%c%c] tag", MMCAM_FOURCC_ARGS(buf_fourcc));
265 buf_size = _mmcamcorder_get_container_size(buf);
267 /* if size of mdat is 1, it means largesize is used.(bigger than 4GB) */
268 if (buf_fourcc == MMCAM_FOURCC('m', 'd', 'a', 't') &&
270 read_item = fread(&buf, sizeof(guchar), 8, f);
272 _mmcam_dbg_err("fread failed");
276 buf_size = _mmcamcorder_get_container_size64(buf);
277 buf_size = buf_size - 16; /* include tag and large file flag(size 1) */
279 buf_size = buf_size - 8; /* include tag */
282 _mmcam_dbg_log("seek %llu", buf_size);
283 if (fseeko(f, (off_t)buf_size, SEEK_CUR) != 0) {
284 _mmcam_dbg_err("fseeko() fail");
290 _mmcam_dbg_log("cannot find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
295 gboolean _mmcamcorder_find_fourcc(FILE *f, guint32 tag_fourcc, gboolean do_rewind)
297 size_t read_item = 0;
303 while ((read_item = fread(&buf, sizeof(guchar), 8, f)) > 0) {
304 uint64_t buf_size = 0;
305 uint32_t buf_fourcc = 0;
308 _mmcam_dbg_err("fread failed : %d", read_item);
312 buf_fourcc = MMCAM_FOURCC(buf[4], buf[5], buf[6], buf[7]);
314 if (tag_fourcc == buf_fourcc) {
315 _mmcam_dbg_log("find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
317 } else if (buf_fourcc == MMCAM_FOURCC('m', 'o', 'o', 'v') &&
318 tag_fourcc != buf_fourcc) {
319 if (_mmcamcorder_find_fourcc(f, tag_fourcc, FALSE))
324 _mmcam_dbg_log("skip [%c%c%c%c] tag", MMCAM_FOURCC_ARGS(buf_fourcc));
326 buf_size = _mmcamcorder_get_container_size(buf);
328 /* if size of mdat is 1, it means largesize is used.(bigger than 4GB) */
329 if (buf_fourcc == MMCAM_FOURCC('m', 'd', 'a', 't') &&
331 read_item = fread(&buf, sizeof(guchar), 8, f);
333 _mmcam_dbg_err("fread failed");
337 buf_size = _mmcamcorder_get_container_size64(buf);
338 buf_size = buf_size - 16; /* include tag and large file flag(size 1) */
340 buf_size = buf_size - 8; /* include tag */
343 _mmcam_dbg_log("seek %llu", buf_size);
344 if (fseeko(f, (off_t)buf_size, SEEK_CUR) != 0) {
345 _mmcam_dbg_err("fseeko() fail");
351 _mmcam_dbg_log("cannot find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
356 gboolean _mmcamcorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos)
358 _mmcam_dbg_log("size : %"G_GINT64_FORMAT"", curr_pos-prev_pos);
359 if (fseeko(f, prev_pos, SEEK_SET) != 0) {
360 _mmcam_dbg_err("fseeko() fail");
364 if (!write_to_32(f, curr_pos -prev_pos))
367 if (fseeko(f, curr_pos, SEEK_SET) != 0) {
368 _mmcam_dbg_err("fseeko() fail");
375 gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info)
377 gint64 current_pos, pos;
382 if ((pos = ftello(f)) < 0) {
383 _mmcam_dbg_err("ftello() returns negative value");
387 if (!write_to_32(f, 0)) //size
390 if (!write_tag(f, "loci")) // type
393 FPUTC_CHECK(0, f); // version
395 if (!write_to_24(f, 0)) // flags
398 if (!write_to_16(f, get_language_code("eng"))) // language
401 str = str_to_utf8("location_name");
403 FPUTS_CHECK(str, f); // name
406 FPUTC_CHECK('\0', f);
407 FPUTC_CHECK(0, f); //role
409 if (!write_to_32(f, info.longitude)) // Longitude
412 if (!write_to_32(f, info.latitude)) // Latitude
415 if (!write_to_32(f, info.altitude)) // Altitude
418 str = str_to_utf8("Astronomical_body");
419 FPUTS_CHECK(str, f);//Astronomical_body
422 FPUTC_CHECK('\0', f);
424 str = str_to_utf8("Additional_notes");
425 FPUTS_CHECK(str, f); // Additional_notes
428 FPUTC_CHECK('\0', f);
430 if ((current_pos = ftello(f)) < 0) {
431 _mmcam_dbg_err("ftello() returns negative value");
435 if (!_mmcamcorder_update_size(f, pos, current_pos))
441 void _mmcamcorder_write_Latitude(FILE *f, int value)
445 int l_below_decimal = 0;
447 l_decimal = value / 10000;
450 snprintf(s_latitude, 5, "-%.2d.", l_decimal);
452 snprintf(s_latitude, 5, "%.2d.", l_decimal);
454 snprintf(s_latitude, 5, "+%.2d.", l_decimal);
457 l_below_decimal = value - (l_decimal * 10000);
458 if (l_below_decimal < 0)
459 l_below_decimal = -l_below_decimal;
461 snprintf(&s_latitude[4], 5, "%.4d", l_below_decimal);
463 write_tag(f, s_latitude);
466 void _mmcamcorder_write_Longitude(FILE *f, int value)
468 char s_longitude[10];
470 int l_below_decimal = 0;
472 l_decimal = value / 10000;
475 snprintf(s_longitude, 6, "-%.3d.", l_decimal);
477 snprintf(s_longitude, 6, "%.3d.", l_decimal);
479 snprintf(s_longitude, 6, "+%.3d.", l_decimal);
482 l_below_decimal = value - (l_decimal * 10000);
483 if (l_below_decimal < 0)
484 l_below_decimal = -l_below_decimal;
486 snprintf(&s_longitude[5], 5, "%.4d", l_below_decimal);
488 write_tag(f, s_longitude);
491 #define D_GEOGRAPH "\xA9xyz"
492 // 0x0012 -> latitude(8) + longitude(9) + seperator(1) = 18
493 // 0x15c7 -> encode in english
494 #define D_INFO_GEOGRAPH 0x001215c7
496 gboolean _mmcamcorder_write_geodata(FILE *f, _MMCamcorderLocationInfo info)
498 gint64 current_pos, pos;
502 if ((pos = ftello(f)) < 0) {
503 _mmcam_dbg_err("ftello() returns negative value");
507 if (!write_to_32(f, 0)) //size
510 if (!write_tag(f, D_GEOGRAPH)) // type
513 if (!write_to_32(f, D_INFO_GEOGRAPH))
516 _mmcamcorder_write_Latitude(f, info.latitude);
517 _mmcamcorder_write_Longitude(f, info.longitude);
519 FPUTC_CHECK(0x2F, f);
521 if ((current_pos = ftello(f)) < 0) {
522 _mmcam_dbg_err("ftello() returns negative value");
526 if (!_mmcamcorder_update_size(f, pos, current_pos))
533 gboolean _mmcamcorder_write_udta(FILE *f, int gps_enable, _MMCamcorderLocationInfo info, _MMCamcorderLocationInfo geotag)
535 gint64 current_pos, pos;
537 _mmcam_dbg_log("gps enable : %d", gps_enable);
538 if (gps_enable == FALSE) {
539 _mmcam_dbg_log("no need to write udta");
543 if ((pos = ftello(f)) < 0) {
544 _mmcam_dbg_err("ftello() returns negative value");
549 if (!write_to_32(f, 0)) {
550 _mmcam_dbg_err("failed to write size");
555 if (!write_tag(f, "udta")) {
556 _mmcam_dbg_err("failed to write type udta");
561 if (!_mmcamcorder_write_loci(f, info)) {
562 _mmcam_dbg_err("failed to write loci");
566 if (!_mmcamcorder_write_geodata(f, geotag)) {
567 _mmcam_dbg_err("failed to write geodata");
572 if ((current_pos = ftello(f)) < 0) {
573 _mmcam_dbg_err("ftello() returns negative value");
577 if (!_mmcamcorder_update_size(f, pos, current_pos)) {
578 _mmcam_dbg_err("failed to update size");
582 _mmcam_dbg_log("done");
588 guint64 _mmcamcorder_get_container_size(const guchar *size)
596 result = result | (temp << 16);
598 result = result | (temp << 8);
599 result = result | size[3];
601 _mmcam_dbg_log("result : %llu", result);
607 guint64 _mmcamcorder_get_container_size64(const guchar *size)
615 result = result | (temp << 48);
617 result = result | (temp << 40);
619 result = result | (temp << 32);
621 result = result | (temp << 24);
623 result = result | (temp << 16);
625 result = result | (temp << 8);
626 result = result | size[7];
628 _mmcam_dbg_log("result : %llu", result);
634 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation)
637 guint32 a = 0x00010000;
640 guint32 d = 0x00010000;
642 switch (orientation) {
643 case MM_CAMCORDER_TAG_VIDEO_ORT_90:/* 90 degree */
649 case MM_CAMCORDER_TAG_VIDEO_ORT_180:/* 180 degree */
653 case MM_CAMCORDER_TAG_VIDEO_ORT_270:/* 270 degree */
659 case MM_CAMCORDER_TAG_VIDEO_ORT_NONE:/* 0 degree */
672 write_to_32(f, 0x40000000);
674 _mmcam_dbg_log("orientation : %d, write data 0x%x 0x%x 0x%x 0x%x",
675 orientation, a, b, c, d);
681 int _mmcamcorder_get_freespace(const gchar *path, const gchar *root_directory, guint64 *free_space)
686 int is_internal = TRUE;
687 struct stat stat_path;
688 struct stat stat_root;
690 if (path == NULL || free_space == NULL) {
691 _mmcam_dbg_err("invalid parameter %p, %p", path, free_space);
695 if (root_directory && strlen(root_directory) > 0) {
696 if (stat(path, &stat_path) != 0) {
698 _mmcam_dbg_err("failed to stat for [%s][errno %d]", path, errno);
702 if (stat(root_directory, &stat_root) != 0) {
704 _mmcam_dbg_err("failed to stat for [%s][errno %d]", root_directory, errno);
708 if (stat_path.st_dev != stat_root.st_dev)
711 _mmcam_dbg_warn("root_directory is NULL, assume that it's internal storage.");
715 ret = storage_get_internal_memory_size(&vfs);
717 ret = storage_get_external_memory_size(&vfs);
721 _mmcam_dbg_err("failed to get memory size [%s]", path);
724 *free_space = vfs.f_bsize * vfs.f_bavail;
726 _mmcam_dbg_log("vfs.f_bsize [%lu], vfs.f_bavail [%lu]", vfs.f_bsize, vfs.f_bavail);
727 _mmcam_dbg_log("memory size %llu [%s]", *free_space, path);
734 int _mmcamcorder_get_file_system_type(const gchar *path, int *file_system_type)
740 if (!g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
741 _mmcam_dbg_log("File(%s) doesn't exist.", path);
745 if (-1 == statfs(path, &fs)) {
746 _mmcam_dbg_log("statfs failed.(%s)", path);
750 *file_system_type = (int)fs.f_type;
756 int _mmcamcorder_get_device_flash_brightness(GDBusConnection *conn, int *brightness)
759 int ret = MM_ERROR_NONE;
760 GVariant *params = NULL;
761 GVariant *result = NULL;
763 ret = __gdbus_method_call_sync(conn, "org.tizen.system.deviced",
764 "/Org/Tizen/System/DeviceD/Led", "org.tizen.system.deviced.Led",
765 "GetBrightnessForCamera", params, &result, TRUE);
766 if (ret != MM_ERROR_NONE) {
767 _mmcam_dbg_err("Dbus Call on Client Error");
772 g_variant_get(result, "(i)", &get_value);
773 *brightness = get_value;
774 _mmcam_dbg_log("flash brightness : %d", *brightness);
776 _mmcam_dbg_err("replied result is null");
777 ret = MM_ERROR_CAMCORDER_INTERNAL;
784 int _mmcamcorder_send_sound_play_message(GDBusConnection *conn, _MMCamcorderGDbusCbInfo *gdbus_info,
785 const char *sample_name, const char *stream_role, const char *volume_gain, int sync_play)
788 int ret = MM_ERROR_NONE;
789 GVariant *params = NULL, *result = NULL;
792 if (!conn || !gdbus_info) {
793 _mmcam_dbg_err("Invalid parameter %p %p", conn, gdbus_info);
794 return MM_ERROR_CAMCORDER_INTERNAL;
797 params = g_variant_new("(sss)", sample_name, stream_role, volume_gain);
798 result = g_variant_new("(i)", get_value);
800 ret = __gdbus_method_call_sync(conn, "org.pulseaudio.Server",
801 "/org/pulseaudio/SoundPlayer", "org.pulseaudio.SoundPlayer",
802 "SamplePlay", params, &result, TRUE);
803 if (ret != MM_ERROR_NONE) {
804 _mmcam_dbg_err("Dbus Call on Client Error");
809 g_variant_get(result, "(i)", &get_value);
810 _mmcam_dbg_log("played index : %d", get_value);
812 _mmcam_dbg_err("replied result is null");
813 return MM_ERROR_CAMCORDER_INTERNAL;
816 g_mutex_lock(&gdbus_info->sync_mutex);
818 if (gdbus_info->subscribe_id > 0) {
819 _mmcam_dbg_warn("subscribe_id[%u] is remained. remove it.", gdbus_info->subscribe_id);
821 g_dbus_connection_signal_unsubscribe(conn, gdbus_info->subscribe_id);
823 gdbus_info->subscribe_id = 0;
826 gdbus_info->is_playing = TRUE;
827 gdbus_info->param = get_value;
829 ret = __gdbus_subscribe_signal(conn,
830 "/org/pulseaudio/SoundPlayer", "org.pulseaudio.SoundPlayer", "EOS",
831 __gdbus_stream_eos_cb, &subs_id, gdbus_info);
833 if (ret == MM_ERROR_NONE)
834 gdbus_info->subscribe_id = subs_id;
836 g_mutex_unlock(&gdbus_info->sync_mutex);
838 if (sync_play && ret == MM_ERROR_NONE)
839 ret = __gdbus_wait_for_cb_return(gdbus_info, G_DBUS_CB_TIMEOUT_MSEC);
845 int _mmcamcorder_get_file_size(const char *filename, guint64 *size)
849 if (stat(filename, &buf) != 0)
851 *size = (guint64)buf.st_size;
856 void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCategory category)
858 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
860 MMCamcorderHandlerItem *item = NULL;
862 mmf_return_if_fail(hcamcorder);
864 if (!hcamcorder->buffer_probes) {
865 _mmcam_dbg_warn("list for buffer probe is NULL");
869 _mmcam_dbg_log("start - category : 0x%x", category);
871 list = hcamcorder->buffer_probes;
875 _mmcam_dbg_err("Remove buffer probe faild, the item is NULL");
876 list = g_list_next(list);
880 if (item->category & category) {
881 if (item->object && GST_IS_PAD(item->object)) {
882 _mmcam_dbg_log("Remove buffer probe on [%s:%s] - [ID : %lu], [Category : %x]",
883 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category);
884 gst_pad_remove_probe(GST_PAD(item->object), item->handler_id);
886 _mmcam_dbg_warn("Remove buffer probe faild, the pad is null or not pad, just remove item from list and free it");
889 list = g_list_next(list);
890 hcamcorder->buffer_probes = g_list_remove(hcamcorder->buffer_probes, item);
893 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
894 list = g_list_next(list);
898 if (category == _MMCAMCORDER_HANDLER_CATEGORY_ALL) {
899 g_list_free(hcamcorder->buffer_probes);
900 hcamcorder->buffer_probes = NULL;
903 _mmcam_dbg_log("done");
909 void _mmcamcorder_remove_one_buffer_probe(MMHandleType handle, void *object)
911 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
913 MMCamcorderHandlerItem *item = NULL;
915 mmf_return_if_fail(hcamcorder);
917 if (!hcamcorder->buffer_probes) {
918 _mmcam_dbg_warn("list for buffer probe is NULL");
922 _mmcam_dbg_log("start - object : %p", object);
924 list = hcamcorder->buffer_probes;
928 _mmcam_dbg_err("Remove buffer probe faild, the item is NULL");
929 list = g_list_next(list);
933 if (item->object && item->object == object) {
934 if (GST_IS_PAD(item->object)) {
935 _mmcam_dbg_log("Remove buffer probe on [%s:%s] - [ID : %lu], [Category : %x]",
936 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category);
937 gst_pad_remove_probe(GST_PAD(item->object), item->handler_id);
939 _mmcam_dbg_warn("Remove buffer probe faild, the pad is null or not pad, just remove item from list and free it");
942 list = g_list_next(list);
943 hcamcorder->buffer_probes = g_list_remove(hcamcorder->buffer_probes, item);
948 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
949 list = g_list_next(list);
953 _mmcam_dbg_log("done");
959 void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCategory category)
961 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
963 MMCamcorderHandlerItem *item = NULL;
965 mmf_return_if_fail(hcamcorder);
967 if (!hcamcorder->event_probes) {
968 _mmcam_dbg_warn("list for event probe is NULL");
972 _mmcam_dbg_log("start - category : 0x%x", category);
974 list = hcamcorder->event_probes;
978 _mmcam_dbg_err("Remove event probe faild, the item is NULL");
979 list = g_list_next(list);
983 if (item->category & category) {
984 if (item->object && GST_IS_PAD(item->object)) {
985 _mmcam_dbg_log("Remove event probe on [%s:%s] - [ID : %lu], [Category : %x]",
986 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category);
987 gst_pad_remove_probe(GST_PAD(item->object), item->handler_id);
989 _mmcam_dbg_warn("Remove event probe faild, the pad is null or not pad, just remove item from list and free it");
992 list = g_list_next(list);
993 hcamcorder->event_probes = g_list_remove(hcamcorder->event_probes, item);
996 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
997 list = g_list_next(list);
1001 if (category == _MMCAMCORDER_HANDLER_CATEGORY_ALL) {
1002 g_list_free(hcamcorder->event_probes);
1003 hcamcorder->event_probes = NULL;
1006 _mmcam_dbg_log("done");
1012 void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCategory category)
1014 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
1016 MMCamcorderHandlerItem *item = NULL;
1018 mmf_return_if_fail(hcamcorder);
1020 if (!hcamcorder->signals) {
1021 _mmcam_dbg_warn("list for signal is NULL");
1025 _mmcam_dbg_log("start - category : 0x%x", category);
1027 list = hcamcorder->signals;
1031 _mmcam_dbg_err("Fail to Disconnecting signal, the item is NULL");
1032 list = g_list_next(list);
1036 if (item->category & category) {
1037 if (item->object && GST_IS_ELEMENT(item->object)) {
1038 if (g_signal_handler_is_connected(item->object, item->handler_id)) {
1039 _mmcam_dbg_log("Disconnect signal from [%s] : [ID : %lu], [Category : %x]",
1040 GST_OBJECT_NAME(item->object), item->handler_id, item->category);
1041 g_signal_handler_disconnect(item->object, item->handler_id);
1043 _mmcam_dbg_warn("Signal was not connected, cannot disconnect it : [%s] [ID : %lu], [Category : %x]",
1044 GST_OBJECT_NAME(item->object), item->handler_id, item->category);
1047 _mmcam_dbg_err("Fail to Disconnecting signal, the element is null or not element, just remove item from list and free it");
1050 list = g_list_next(list);
1051 hcamcorder->signals = g_list_remove(hcamcorder->signals, item);
1054 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
1055 list = g_list_next(list);
1059 if (category == _MMCAMCORDER_HANDLER_CATEGORY_ALL) {
1060 g_list_free(hcamcorder->signals);
1061 hcamcorder->signals = NULL;
1064 _mmcam_dbg_log("done");
1070 void _mmcamcorder_remove_all_handlers(MMHandleType handle, _MMCamcorderHandlerCategory category)
1072 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
1074 _mmcam_dbg_log("ENTER");
1076 if (hcamcorder->signals)
1077 _mmcamcorder_disconnect_signal((MMHandleType)hcamcorder, category);
1078 if (hcamcorder->event_probes)
1079 _mmcamcorder_remove_event_probe((MMHandleType)hcamcorder, category);
1080 if (hcamcorder->buffer_probes)
1081 _mmcamcorder_remove_buffer_probe((MMHandleType)hcamcorder, category);
1083 _mmcam_dbg_log("LEAVE");
1087 void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_was)
1090 _MMCamcorderSubContext *sc = (_MMCamcorderSubContext *)data;
1092 mmf_return_if_fail(sc);
1093 mmf_return_if_fail(sc->element);
1095 for (i = 0 ; i < _MMCAMCORDER_PIPELINE_ELEMENT_NUM ; i++) {
1096 if (sc->element[i].gst && (G_OBJECT(sc->element[i].gst) == where_the_object_was)) {
1097 _mmcam_dbg_warn("The element[%d][%p] is finalized", sc->element[i].id, sc->element[i].gst);
1098 sc->element[i].gst = NULL;
1099 sc->element[i].id = _MMCAMCORDER_NONE;
1104 mmf_return_if_fail(sc->encode_element);
1106 for (i = 0 ; i < _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM ; i++) {
1107 if (sc->encode_element[i].gst && (G_OBJECT(sc->encode_element[i].gst) == where_the_object_was)) {
1108 _mmcam_dbg_warn("The encode element[%d][%p] is finalized", sc->encode_element[i].id, sc->encode_element[i].gst);
1109 sc->encode_element[i].gst = NULL;
1110 sc->encode_element[i].id = _MMCAMCORDER_ENCODE_NONE;
1115 _mmcam_dbg_warn("there is no matching element %p", where_the_object_was);
1121 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
1122 gboolean _mmcamcorder_msg_callback(void *data)
1124 _MMCamcorderMsgItem *item = (_MMCamcorderMsgItem*)data;
1125 mmf_camcorder_t *hcamcorder = NULL;
1126 mmf_return_val_if_fail(item, FALSE);
1128 g_mutex_lock(&item->lock);
1130 hcamcorder = MMF_CAMCORDER(item->handle);
1131 if (hcamcorder == NULL) {
1132 _mmcam_dbg_warn("msg id:0x%x, item:%p, handle is NULL", item->id, item);
1133 goto MSG_CALLBACK_DONE;
1136 /*_mmcam_dbg_log("msg id:%x, msg_cb:%p, msg_data:%p, item:%p", item->id, hcamcorder->msg_cb, hcamcorder->msg_data, item);*/
1138 _MMCAMCORDER_LOCK((MMHandleType)hcamcorder);
1140 /* remove item from msg data */
1141 if (hcamcorder->msg_data) {
1142 hcamcorder->msg_data = g_list_remove(hcamcorder->msg_data, item);
1144 _mmcam_dbg_warn("msg_data is NULL but item[%p] will be removed", item);
1147 _MMCAMCORDER_UNLOCK((MMHandleType)hcamcorder);
1149 _MMCAMCORDER_LOCK_MESSAGE_CALLBACK(hcamcorder);
1151 if ((hcamcorder) && (hcamcorder->msg_cb))
1152 hcamcorder->msg_cb(item->id, (MMMessageParamType*)(&(item->param)), hcamcorder->msg_cb_param);
1154 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1156 _MMCAMCORDER_SIGNAL(hcamcorder);
1159 /* release allocated memory */
1160 if (item->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
1161 MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)item->param.data;
1163 SAFE_G_FREE(cam_fd_info->face_info);
1164 SAFE_G_FREE(cam_fd_info);
1166 item->param.data = NULL;
1167 item->param.size = 0;
1169 } else if (item->id == MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED || item->id == MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED) {
1170 MMCamRecordingReport *report = (MMCamRecordingReport *)item->param.data;
1172 if (report->recording_filename)
1173 SAFE_G_FREE(report->recording_filename);
1175 SAFE_G_FREE(report);
1176 item->param.data = NULL;
1180 g_mutex_unlock(&item->lock);
1181 g_mutex_clear(&item->lock);
1185 /* For not being called again */
1188 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
1191 gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data)
1193 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
1194 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
1195 _MMCamcorderMsgItem *item = NULL;
1196 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
1198 mmf_return_val_if_fail(hcamcorder, FALSE);
1199 mmf_return_val_if_fail(data, FALSE);
1202 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
1203 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
1204 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_RM:
1205 data->param.union_type = MM_MSG_UNION_STATE;
1207 case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
1208 data->param.union_type = MM_MSG_UNION_RECORDING_STATUS;
1210 case MM_MESSAGE_CAMCORDER_FIRMWARE_UPDATE:
1211 data->param.union_type = MM_MSG_UNION_FIRMWARE;
1213 case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
1214 data->param.union_type = MM_MSG_UNION_REC_VOLUME_DB;
1216 case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
1217 case MM_MESSAGE_CAMCORDER_MAX_SIZE:
1218 case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:
1219 case MM_MESSAGE_CAMCORDER_ERROR:
1220 case MM_MESSAGE_CAMCORDER_FOCUS_CHANGED:
1221 case MM_MESSAGE_CAMCORDER_CAPTURED:
1222 case MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED:
1223 case MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED:
1224 case MM_MESSAGE_READY_TO_RESUME:
1226 data->param.union_type = MM_MSG_UNION_CODE;
1230 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
1231 item = g_malloc(sizeof(_MMCamcorderMsgItem));
1233 memcpy(item, data, sizeof(_MMCamcorderMsgItem));
1234 item->handle = handle;
1235 g_mutex_init(&item->lock);
1237 _MMCAMCORDER_LOCK(handle);
1238 hcamcorder->msg_data = g_list_append(hcamcorder->msg_data, item);
1239 /*_mmcam_dbg_log("item[%p]", item);*/
1241 /* Use DEFAULT priority */
1242 g_idle_add_full(G_PRIORITY_DEFAULT, _mmcamcorder_msg_callback, item, NULL);
1244 _MMCAMCORDER_UNLOCK(handle);
1246 _mmcam_dbg_err("item[id:0x%x] malloc failed : %d", data->id, sizeof(_MMCamcorderMsgItem));
1248 #else /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
1249 _MMCAMCORDER_LOCK_MESSAGE_CALLBACK(hcamcorder);
1251 if (hcamcorder->msg_cb)
1252 hcamcorder->msg_cb(data->id, (MMMessageParamType*)(&(data->param)), hcamcorder->msg_cb_param);
1254 _mmcam_dbg_log("message callback is NULL. message id %d", data->id);
1256 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1258 /* release allocated memory */
1259 if (data->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
1260 MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)data->param.data;
1262 SAFE_G_FREE(cam_fd_info->face_info);
1263 SAFE_G_FREE(cam_fd_info);
1264 data->param.size = 0;
1266 } else if (data->id == MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED || data->id == MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED) {
1267 MMCamRecordingReport *report = (MMCamRecordingReport *)data->param.data;
1269 SAFE_G_FREE(report->recording_filename);
1270 data->param.data = NULL;
1272 SAFE_G_FREE(report);
1274 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
1280 void _mmcamcorder_remove_message_all(MMHandleType handle)
1282 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
1283 gboolean ret = TRUE;
1284 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
1285 _MMCamcorderMsgItem *item = NULL;
1287 gint64 end_time = 0;
1288 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
1290 mmf_return_if_fail(hcamcorder);
1292 _MMCAMCORDER_LOCK(handle);
1294 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
1295 if (!hcamcorder->msg_data) {
1296 _mmcam_dbg_log("No message data is remained.");
1298 list = hcamcorder->msg_data;
1302 list = g_list_next(list);
1305 _mmcam_dbg_err("Fail to remove message. The item is NULL");
1307 if (g_mutex_trylock(&(item->lock))) {
1308 ret = g_idle_remove_by_data(item);
1310 _mmcam_dbg_log("remove msg item[%p], ret[%d]", item, ret);
1314 _mmcam_dbg_warn("failed to remove msg cb for item %p, it will be called later with NULL handle", item);
1317 /* release allocated memory */
1318 if (item->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
1319 MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)item->param.data;
1321 SAFE_G_FREE(cam_fd_info->face_info);
1322 item->param.size = 0;
1324 SAFE_G_FREE(cam_fd_info);
1325 } else if (item->id == MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED || item->id == MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED) {
1326 MMCamRecordingReport *report = (MMCamRecordingReport *)item->param.data;
1328 SAFE_G_FREE(report->recording_filename);
1330 SAFE_G_FREE(report);
1333 hcamcorder->msg_data = g_list_remove(hcamcorder->msg_data, item);
1335 g_mutex_unlock(&(item->lock));
1338 g_mutex_clear(&item->lock);
1342 _mmcam_dbg_log("remove msg done");
1345 _mmcam_dbg_warn("item lock failed. it's being called...");
1347 end_time = g_get_monotonic_time() + (100 * G_TIME_SPAN_MILLISECOND);
1349 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time))
1350 _mmcam_dbg_warn("signal received");
1352 _mmcam_dbg_warn("timeout");
1357 g_list_free(hcamcorder->msg_data);
1358 hcamcorder->msg_data = NULL;
1360 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
1362 /* remove idle function for playing capture sound */
1364 ret = g_idle_remove_by_data(hcamcorder);
1365 _mmcam_dbg_log("remove idle function for playing capture sound. ret[%d]", ret);
1368 _MMCAMCORDER_UNLOCK(handle);
1374 int _mmcamcorder_get_pixel_format(GstCaps *caps)
1376 const GstStructure *structure;
1377 const char *media_type;
1378 GstVideoInfo media_info;
1379 MMPixelFormatType type = 0;
1380 unsigned int fourcc = 0;
1382 mmf_return_val_if_fail(caps != NULL, MM_PIXEL_FORMAT_INVALID);
1384 structure = gst_caps_get_structure(caps, 0);
1385 media_type = gst_structure_get_name(structure);
1386 if (media_type == NULL) {
1387 _mmcam_dbg_err("failed to get media_type");
1388 return MM_PIXEL_FORMAT_INVALID;
1391 gst_video_info_init(&media_info);
1393 if (!strcmp(media_type, "image/jpeg")) {
1394 _mmcam_dbg_log("It is jpeg.");
1395 type = MM_PIXEL_FORMAT_ENCODED;
1396 } else if (!strcmp(media_type, "video/x-raw") &&
1397 gst_video_info_from_caps(&media_info, caps) &&
1398 GST_VIDEO_INFO_IS_YUV(&media_info)) {
1399 _mmcam_dbg_log("It is yuv.");
1400 fourcc = gst_video_format_to_fourcc(GST_VIDEO_INFO_FORMAT(&media_info));
1401 type = _mmcamcorder_get_pixtype(fourcc);
1402 } else if (!strcmp(media_type, "video/x-raw") &&
1403 gst_video_info_from_caps(&media_info, caps) &&
1404 GST_VIDEO_INFO_IS_RGB(&media_info)) {
1405 _mmcam_dbg_log("It is rgb.");
1406 type = MM_PIXEL_FORMAT_RGB888;
1407 } else if (!strcmp(media_type, "video/x-h264")) {
1408 _mmcam_dbg_log("It is H264");
1409 type = MM_PIXEL_FORMAT_ENCODED_H264;
1411 _mmcam_dbg_err("Not supported format [%s]", media_type);
1412 type = MM_PIXEL_FORMAT_INVALID;
1415 /*_mmcam_dbg_log( "Type [%d]", type );*/
1420 unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format)
1422 unsigned int fourcc = 0;
1424 /*_mmcam_dbg_log("pixtype(%d)", pixtype);*/
1427 case MM_PIXEL_FORMAT_NV12:
1428 if (use_zero_copy_format)
1429 fourcc = GST_MAKE_FOURCC('S', 'N', '1', '2');
1431 fourcc = GST_MAKE_FOURCC('N', 'V', '1', '2');
1434 case MM_PIXEL_FORMAT_NV21:
1435 if (use_zero_copy_format)
1436 fourcc = GST_MAKE_FOURCC('S', 'N', '2', '1');
1438 fourcc = GST_MAKE_FOURCC('N', 'V', '2', '1');
1441 case MM_PIXEL_FORMAT_YUYV:
1442 if (use_zero_copy_format)
1443 fourcc = GST_MAKE_FOURCC('S', 'U', 'Y', 'V');
1445 fourcc = GST_MAKE_FOURCC('Y', 'U', 'Y', '2');
1448 case MM_PIXEL_FORMAT_UYVY:
1449 if (use_zero_copy_format)
1450 fourcc = GST_MAKE_FOURCC('S', 'Y', 'V', 'Y');
1452 fourcc = GST_MAKE_FOURCC('U', 'Y', 'V', 'Y');
1455 case MM_PIXEL_FORMAT_I420:
1456 if (use_zero_copy_format)
1457 fourcc = GST_MAKE_FOURCC('S', '4', '2', '0');
1459 fourcc = GST_MAKE_FOURCC('I', '4', '2', '0');
1462 case MM_PIXEL_FORMAT_YV12:
1463 fourcc = GST_MAKE_FOURCC('Y', 'V', '1', '2');
1465 case MM_PIXEL_FORMAT_422P:
1466 fourcc = GST_MAKE_FOURCC('4', '2', '2', 'P');
1468 case MM_PIXEL_FORMAT_RGB565:
1469 fourcc = GST_MAKE_FOURCC('R', 'G', 'B', 'P');
1471 case MM_PIXEL_FORMAT_RGB888:
1472 fourcc = GST_MAKE_FOURCC('R', 'G', 'B', ' ');
1474 case MM_PIXEL_FORMAT_ENCODED:
1475 if (codectype == MM_IMAGE_CODEC_JPEG) {
1476 fourcc = GST_MAKE_FOURCC('J', 'P', 'E', 'G');
1477 } else if (codectype == MM_IMAGE_CODEC_JPEG_SRW) {
1478 fourcc = GST_MAKE_FOURCC('J', 'P', 'E', 'G'); /*TODO: JPEG+SamsungRAW format */
1479 } else if (codectype == MM_IMAGE_CODEC_SRW) {
1480 fourcc = GST_MAKE_FOURCC('J', 'P', 'E', 'G'); /*TODO: SamsungRAW format */
1481 } else if (codectype == MM_IMAGE_CODEC_PNG) {
1482 fourcc = GST_MAKE_FOURCC('P', 'N', 'G', ' ');
1484 /* Please let us know what other fourcces are. ex) BMP, GIF?*/
1485 fourcc = GST_MAKE_FOURCC('J', 'P', 'E', 'G');
1488 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
1489 fourcc = GST_MAKE_FOURCC('I', 'T', 'L', 'V');
1491 case MM_PIXEL_FORMAT_ENCODED_H264:
1492 fourcc = GST_MAKE_FOURCC('H', '2', '6', '4');
1495 _mmcam_dbg_log("Not proper pixel type[%d]. Set default - I420", pixtype);
1496 if (use_zero_copy_format)
1497 fourcc = GST_MAKE_FOURCC('S', '4', '2', '0');
1499 fourcc = GST_MAKE_FOURCC('I', '4', '2', '0');
1508 int _mmcamcorder_get_pixtype(unsigned int fourcc)
1510 int pixtype = MM_PIXEL_FORMAT_INVALID;
1512 char *pfourcc = (char*)&fourcc;
1514 _mmcam_dbg_log("fourcc(%c%c%c%c)",
1515 pfourcc[0], pfourcc[1], pfourcc[2], pfourcc[3]);
1519 case GST_MAKE_FOURCC('S', 'N', '1', '2'):
1520 case GST_MAKE_FOURCC('N', 'V', '1', '2'):
1521 pixtype = MM_PIXEL_FORMAT_NV12;
1523 case GST_MAKE_FOURCC('S', 'N', '2', '1'):
1524 case GST_MAKE_FOURCC('N', 'V', '2', '1'):
1525 pixtype = MM_PIXEL_FORMAT_NV21;
1527 case GST_MAKE_FOURCC('S', 'U', 'Y', 'V'):
1528 case GST_MAKE_FOURCC('Y', 'U', 'Y', 'V'):
1529 case GST_MAKE_FOURCC('Y', 'U', 'Y', '2'):
1530 pixtype = MM_PIXEL_FORMAT_YUYV;
1532 case GST_MAKE_FOURCC('S', 'Y', 'V', 'Y'):
1533 case GST_MAKE_FOURCC('U', 'Y', 'V', 'Y'):
1534 pixtype = MM_PIXEL_FORMAT_UYVY;
1536 case GST_MAKE_FOURCC('S', '4', '2', '0'):
1537 case GST_MAKE_FOURCC('I', '4', '2', '0'):
1538 pixtype = MM_PIXEL_FORMAT_I420;
1540 case GST_MAKE_FOURCC('Y', 'V', '1', '2'):
1541 pixtype = MM_PIXEL_FORMAT_YV12;
1543 case GST_MAKE_FOURCC('4', '2', '2', 'P'):
1544 pixtype = MM_PIXEL_FORMAT_422P;
1546 case GST_MAKE_FOURCC('R', 'G', 'B', 'P'):
1547 pixtype = MM_PIXEL_FORMAT_RGB565;
1549 case GST_MAKE_FOURCC('R', 'G', 'B', '3'):
1550 pixtype = MM_PIXEL_FORMAT_RGB888;
1552 case GST_MAKE_FOURCC('A', 'R', 'G', 'B'):
1553 case GST_MAKE_FOURCC('x', 'R', 'G', 'B'):
1554 pixtype = MM_PIXEL_FORMAT_ARGB;
1556 case GST_MAKE_FOURCC('B', 'G', 'R', 'A'):
1557 case GST_MAKE_FOURCC('B', 'G', 'R', 'x'):
1558 case GST_MAKE_FOURCC('S', 'R', '3', '2'):
1559 pixtype = MM_PIXEL_FORMAT_RGBA;
1561 case GST_MAKE_FOURCC('J', 'P', 'E', 'G'):
1562 case GST_MAKE_FOURCC('P', 'N', 'G', ' '):
1563 pixtype = MM_PIXEL_FORMAT_ENCODED;
1566 case GST_MAKE_FOURCC('I', 'T', 'L', 'V'):
1567 pixtype = MM_PIXEL_FORMAT_ITLV_JPEG_UYVY;
1569 case GST_MAKE_FOURCC('H', '2', '6', '4'):
1570 pixtype = MM_PIXEL_FORMAT_ENCODED_H264;
1573 _mmcam_dbg_log("Not supported fourcc type(%c%c%c%c)", fourcc, fourcc>>8, fourcc>>16, fourcc>>24);
1574 pixtype = MM_PIXEL_FORMAT_INVALID;
1582 gboolean _mmcamcorder_add_elements_to_bin(GstBin *bin, GList *element_list)
1584 GList *local_list = element_list;
1585 _MMCamcorderGstElement *element = NULL;
1587 mmf_return_val_if_fail(bin && local_list, FALSE);
1589 while (local_list) {
1590 element = (_MMCamcorderGstElement*)local_list->data;
1591 if (element && element->gst) {
1592 if (!gst_bin_add(bin, GST_ELEMENT(element->gst))) {
1593 _mmcam_dbg_err("Add element [%s] to bin [%s] FAILED",
1594 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)),
1595 GST_ELEMENT_NAME(GST_ELEMENT(bin)));
1598 _mmcam_dbg_log("Add element [%s] to bin [%s] OK",
1599 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)),
1600 GST_ELEMENT_NAME(GST_ELEMENT(bin)));
1603 local_list = local_list->next;
1609 gboolean _mmcamcorder_link_elements(GList *element_list)
1611 GList *local_list = element_list;
1612 _MMCamcorderGstElement *element = NULL;
1613 _MMCamcorderGstElement *pre_element = NULL;
1615 mmf_return_val_if_fail(local_list, FALSE);
1617 pre_element = (_MMCamcorderGstElement*)local_list->data;
1618 local_list = local_list->next;
1620 while (local_list) {
1621 element = (_MMCamcorderGstElement*)local_list->data;
1622 if (pre_element && pre_element->gst && element && element->gst) {
1623 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(pre_element->gst), GST_ELEMENT(element->gst))) {
1624 _mmcam_dbg_log("Link [%s] to [%s] OK",
1625 GST_ELEMENT_NAME(GST_ELEMENT(pre_element->gst)),
1626 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)));
1628 _mmcam_dbg_err("Link [%s] to [%s] FAILED",
1629 GST_ELEMENT_NAME(GST_ELEMENT(pre_element->gst)),
1630 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)));
1635 pre_element = element;
1636 local_list = local_list->next;
1642 gboolean _mmcamcorder_resize_frame(unsigned char *src_data, unsigned int src_width, unsigned int src_height, unsigned int src_length, int src_format,
1643 unsigned char **dst_data, unsigned int *dst_width, unsigned int *dst_height, unsigned int *dst_length)
1646 int mm_ret = MM_ERROR_NONE;
1647 int input_format = MM_UTIL_IMG_FMT_YUV420;
1648 unsigned char *dst_tmp_data = NULL;
1650 if (!src_data || !dst_data || !dst_width || !dst_height || !dst_length) {
1651 _mmcam_dbg_err("something is NULL %p,%p,%p,%p,%p", src_data, dst_data, dst_width, dst_height, dst_length);
1655 /* set input format for mm-util */
1656 switch (src_format) {
1657 case MM_PIXEL_FORMAT_I420:
1658 input_format = MM_UTIL_IMG_FMT_I420;
1660 case MM_PIXEL_FORMAT_YV12:
1661 input_format = MM_UTIL_IMG_FMT_YUV420;
1663 case MM_PIXEL_FORMAT_NV12:
1664 input_format = MM_UTIL_IMG_FMT_NV12;
1666 case MM_PIXEL_FORMAT_YUYV:
1667 input_format = MM_UTIL_IMG_FMT_YUYV;
1669 case MM_PIXEL_FORMAT_UYVY:
1670 input_format = MM_UTIL_IMG_FMT_UYVY;
1672 case MM_PIXEL_FORMAT_RGB888:
1673 input_format = MM_UTIL_IMG_FMT_RGB888;
1676 _mmcam_dbg_err("NOT supported format", src_format);
1680 _mmcam_dbg_log("src size %dx%d -> dst size %dx%d", src_width, src_height, *dst_width, *dst_height);
1682 /* get length of resized image */
1683 mm_ret = mm_util_get_image_size(input_format, *dst_width, *dst_height, dst_length);
1684 if (mm_ret != MM_ERROR_NONE) {
1685 GST_ERROR("mm_util_get_image_size failed 0x%x", ret);
1689 _mmcam_dbg_log("dst_length : %d", *dst_length);
1691 dst_tmp_data = (unsigned char *)malloc(*dst_length);
1692 if (dst_tmp_data == NULL) {
1693 _mmcam_dbg_err("failed to alloc dst_thumb_size(size %d)", *dst_length);
1697 mm_ret = mm_util_resize_image(src_data, src_width, src_height, input_format, dst_tmp_data, dst_width, dst_height);
1699 if (mm_ret != MM_ERROR_NONE) {
1700 GST_ERROR("mm_util_resize_image failed 0x%x", ret);
1705 *dst_data = dst_tmp_data;
1707 _mmcam_dbg_log("resize done %p, %dx%d", *dst_data, *dst_width, *dst_height);
1713 gboolean _mmcamcorder_encode_jpeg(void *src_data, unsigned int src_width, unsigned int src_height,
1714 int src_format, unsigned int src_length, unsigned int jpeg_quality,
1715 void **result_data, unsigned int *result_length)
1718 gboolean ret_conv = TRUE;
1719 int jpeg_format = 0;
1720 unsigned char *converted_src = NULL;
1721 unsigned int converted_src_size = 0;
1723 mmf_return_val_if_fail(src_data && result_data && result_length, FALSE);
1725 switch (src_format) {
1726 case MM_PIXEL_FORMAT_NV12:
1727 //jpeg_format = MM_UTIL_JPEG_FMT_NV12;
1728 ret_conv = _mmcamcorder_convert_NV12_to_I420(src_data, src_width, src_height, &converted_src, &converted_src_size);
1729 jpeg_format = MM_UTIL_JPEG_FMT_YUV420;
1731 case MM_PIXEL_FORMAT_NV16:
1732 jpeg_format = MM_UTIL_JPEG_FMT_NV16;
1733 converted_src = src_data;
1735 case MM_PIXEL_FORMAT_NV21:
1736 jpeg_format = MM_UTIL_JPEG_FMT_NV21;
1737 converted_src = src_data;
1739 case MM_PIXEL_FORMAT_YUYV:
1740 //jpeg_format = MM_UTIL_JPEG_FMT_YUYV;
1741 ret_conv = _mmcamcorder_convert_YUYV_to_I420(src_data, src_width, src_height, &converted_src, &converted_src_size);
1742 jpeg_format = MM_UTIL_JPEG_FMT_YUV420;
1744 case MM_PIXEL_FORMAT_UYVY:
1745 //jpeg_format = MM_UTIL_JPEG_FMT_UYVY;
1746 ret_conv = _mmcamcorder_convert_UYVY_to_I420(src_data, src_width, src_height, &converted_src, &converted_src_size);
1747 jpeg_format = MM_UTIL_JPEG_FMT_YUV420;
1749 case MM_PIXEL_FORMAT_I420:
1750 jpeg_format = MM_UTIL_JPEG_FMT_YUV420;
1751 converted_src = src_data;
1753 case MM_PIXEL_FORMAT_RGB888:
1754 jpeg_format = MM_UTIL_JPEG_FMT_RGB888;
1755 converted_src = src_data;
1757 case MM_PIXEL_FORMAT_RGBA:
1758 jpeg_format = MM_UTIL_JPEG_FMT_RGBA8888;
1759 converted_src = src_data;
1761 case MM_PIXEL_FORMAT_ARGB:
1762 jpeg_format = MM_UTIL_JPEG_FMT_ARGB8888;
1763 converted_src = src_data;
1765 case MM_PIXEL_FORMAT_422P:
1766 jpeg_format = MM_UTIL_JPEG_FMT_YUV422; // not supported
1768 case MM_PIXEL_FORMAT_NV12T:
1769 case MM_PIXEL_FORMAT_YV12:
1770 case MM_PIXEL_FORMAT_RGB565:
1771 case MM_PIXEL_FORMAT_ENCODED:
1772 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
1777 if (ret_conv == FALSE) {
1778 if (converted_src &&
1779 converted_src != src_data) {
1780 free(converted_src);
1781 converted_src = NULL;
1783 _mmcam_dbg_err("color convert error source format[%d], jpeg format[%d]", src_format, jpeg_format);
1787 ret = mm_util_jpeg_encode_to_memory(result_data, (int *)result_length,
1788 converted_src, src_width, src_height, jpeg_format, jpeg_quality);
1790 if (converted_src && (converted_src != src_data)) {
1791 free(converted_src);
1792 converted_src = NULL;
1795 if (ret != MM_ERROR_NONE) {
1796 _mmcam_dbg_err("No encoder supports %d format, error code %x", src_format, ret);
1804 /* make UYVY smaller as multiple size. ex: 640x480 -> 320x240 or 160x120 ... */
1805 gboolean _mmcamcorder_downscale_UYVYorYUYV(unsigned char *src, unsigned int src_width, unsigned int src_height,
1806 unsigned char **dst, unsigned int dst_width, unsigned int dst_height)
1812 int ratio_width = 0;
1813 int ratio_height = 0;
1817 unsigned char *result = NULL;
1819 if (src == NULL || dst == NULL) {
1820 _mmcam_dbg_err("src[%p] or dst[%p] is NULL", src, dst);
1824 result = (unsigned char *)malloc((dst_width * dst_height)<<1);
1826 _mmcam_dbg_err("failed to alloc dst data");
1830 ratio_width = src_width / dst_width;
1831 ratio_height = src_height / dst_height;
1832 line_width = src_width << 1;
1833 jump_width = ratio_width << 1;
1835 _mmcam_dbg_warn("[src %dx%d] [dst %dx%d] [line width %d] [ratio width %d, height %d]",
1836 src_width, src_height, dst_width, dst_height, line_width, ratio_width, ratio_height);
1838 for (i = 0 ; i < src_height ; i += ratio_height) {
1839 line_base = i * line_width;
1840 for (j = 0 ; j < line_width ; j += jump_width) {
1841 src_index = line_base + j;
1842 result[k++] = src[src_index];
1843 result[k++] = src[src_index+1];
1846 src_index = line_base + j;
1847 if (src_index % 4 == 0)
1848 result[k++] = src[src_index+2];
1850 result[k++] = src[src_index];
1852 result[k++] = src[src_index+1];
1858 _mmcam_dbg_warn("converting done - result %p", result);
1864 static guint16 get_language_code(const char *str)
1866 return (guint16)(((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F);
1869 static gchar * str_to_utf8(const gchar *str)
1871 return g_convert(str, -1, "UTF-8", "ASCII", NULL, NULL, NULL);
1874 static inline gboolean write_tag(FILE *f, const gchar *tag)
1877 FPUTC_CHECK(*tag++, f);
1882 static inline gboolean write_to_32(FILE *f, guint val)
1884 FPUTC_CHECK(val >> 24, f);
1885 FPUTC_CHECK(val >> 16, f);
1886 FPUTC_CHECK(val >> 8, f);
1887 FPUTC_CHECK(val, f);
1891 static inline gboolean write_to_16(FILE *f, guint val)
1893 FPUTC_CHECK(val >> 8, f);
1894 FPUTC_CHECK(val, f);
1898 static inline gboolean write_to_24(FILE *f, guint val)
1900 write_to_16(f, val >> 8);
1901 FPUTC_CHECK(val, f);
1905 void *_mmcamcorder_util_task_thread_func(void *data)
1907 int ret = MM_ERROR_NONE;
1908 mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *)data;
1911 _mmcam_dbg_err("handle is NULL");
1915 _mmcam_dbg_warn("start thread");
1917 g_mutex_lock(&hcamcorder->task_thread_lock);
1919 while (hcamcorder->task_thread_state != _MMCAMCORDER_TASK_THREAD_STATE_EXIT) {
1920 switch (hcamcorder->task_thread_state) {
1921 case _MMCAMCORDER_TASK_THREAD_STATE_NONE:
1922 _mmcam_dbg_warn("wait for task signal");
1923 g_cond_wait(&hcamcorder->task_thread_cond, &hcamcorder->task_thread_lock);
1924 _mmcam_dbg_warn("task signal received : state %d", hcamcorder->task_thread_state);
1926 case _MMCAMCORDER_TASK_THREAD_STATE_SOUND_PLAY_START:
1927 _mmcamcorder_sound_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE02, FALSE);
1928 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
1930 case _MMCAMCORDER_TASK_THREAD_STATE_SOUND_SOLO_PLAY_START:
1931 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE01, FALSE);
1932 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
1934 case _MMCAMCORDER_TASK_THREAD_STATE_ENCODE_PIPE_CREATE:
1935 ret = _mmcamcorder_video_prepare_record((MMHandleType)hcamcorder);
1937 /* Play record start sound */
1938 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_REC_START, FALSE);
1940 _mmcam_dbg_log("_mmcamcorder_video_prepare_record return 0x%x", ret);
1941 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
1943 case _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING:
1945 gint64 end_time = 0;
1947 _mmcam_dbg_warn("wait for capture data in recording. wait signal...");
1949 end_time = g_get_monotonic_time() + (5 * G_TIME_SPAN_SECOND);
1951 if (g_cond_wait_until(&hcamcorder->task_thread_cond, &hcamcorder->task_thread_lock, end_time)) {
1952 _mmcam_dbg_warn("signal received");
1954 _MMCamcorderMsgItem message;
1956 memset(&message, 0x0, sizeof(_MMCamcorderMsgItem));
1958 _mmcam_dbg_err("capture data wait time out, send error message");
1960 message.id = MM_MESSAGE_CAMCORDER_ERROR;
1961 message.param.code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
1963 _mmcamcorder_send_message((MMHandleType)hcamcorder, &message);
1965 hcamcorder->capture_in_recording = FALSE;
1968 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
1972 _mmcam_dbg_warn("invalid task thread state %d", hcamcorder->task_thread_state);
1973 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_EXIT;
1978 g_mutex_unlock(&hcamcorder->task_thread_lock);
1980 _mmcam_dbg_warn("exit thread");
1985 #ifdef _USE_YUV_TO_RGB888_
1987 _mmcamcorder_convert_YUV_to_RGB888(unsigned char *src, int src_fmt, guint width, guint height, unsigned char **dst, unsigned int *dst_len)
1990 int src_cs = MM_UTIL_IMG_FMT_UYVY;
1991 int dst_cs = MM_UTIL_IMG_FMT_RGB888;
1992 unsigned int dst_size = 0;
1994 if (src_fmt == COLOR_FORMAT_YUYV) {
1995 _mmcam_dbg_log("Convert YUYV to RGB888\n");
1996 src_cs = MM_UTIL_IMG_FMT_YUYV;
1997 } else if (src_fmt == COLOR_FORMAT_UYVY) {
1998 _mmcam_dbg_log("Convert UYVY to RGB888\n");
1999 src_cs = MM_UTIL_IMG_FMT_UYVY;
2000 } else if (src_fmt == COLOR_FORMAT_NV12) {
2001 _mmcam_dbg_log("Convert NV12 to RGB888\n");
2002 src_cs = MM_UTIL_IMG_FMT_NV12;
2004 _mmcam_dbg_err("NOT supported format [%d]\n", src_fmt);
2008 ret = mm_util_get_image_size(dst_cs, width, height, &dst_size);
2010 _mmcam_dbg_err("mm_util_get_image_size failed [%x]\n", ret);
2014 *dst = malloc(dst_size);
2016 _mmcam_dbg_err("malloc failed\n");
2020 *dst_len = dst_size;
2021 ret = mm_util_convert_colorspace(src, width, height, src_cs, *dst, dst_cs);
2023 _mmcam_dbg_log("Convert [dst_size:%d] OK.\n", dst_size);
2029 _mmcam_dbg_err("Convert [size:%d] FAILED.\n", dst_size);
2033 #endif /* _USE_YUV_TO_RGB888_ */
2036 static gboolean _mmcamcorder_convert_YUYV_to_I420(unsigned char *src, guint width, guint height, unsigned char **dst, unsigned int *dst_len)
2041 int dst_y_offset = 0;
2042 int dst_u_offset = 0;
2043 int dst_v_offset = 0;
2044 int loop_length = 0;
2045 unsigned int dst_size = 0;
2046 unsigned char *dst_data = NULL;
2048 if (!src || !dst || !dst_len) {
2049 _mmcam_dbg_err("NULL pointer %p, %p, %p", src, dst, dst_len);
2053 dst_size = (width * height * 3) >> 1;
2055 _mmcam_dbg_log("YUVY -> I420 : %dx%d, dst size %d", width, height, dst_size);
2057 dst_data = (unsigned char *)malloc(dst_size);
2059 _mmcam_dbg_err("failed to alloc dst_data. size %d", dst_size);
2063 loop_length = width << 1;
2064 dst_u_offset = width * height;
2065 dst_v_offset = dst_u_offset + (dst_u_offset >> 2);
2067 _mmcam_dbg_log("offset y %d, u %d, v %d", dst_y_offset, dst_u_offset, dst_v_offset);
2069 for (i = 0 ; i < height ; i++) {
2070 for (j = 0 ; j < loop_length ; j += 2) {
2071 dst_data[dst_y_offset++] = src[src_offset++]; /*Y*/
2075 dst_data[dst_u_offset++] = src[src_offset++]; /*U*/
2077 dst_data[dst_v_offset++] = src[src_offset++]; /*V*/
2085 *dst_len = dst_size;
2087 _mmcam_dbg_log("DONE: YUVY -> I420 : %dx%d, dst data %p, size %d", width, height, *dst, dst_size);
2093 static gboolean _mmcamcorder_convert_UYVY_to_I420(unsigned char *src, guint width, guint height, unsigned char **dst, unsigned int *dst_len)
2098 int dst_y_offset = 0;
2099 int dst_u_offset = 0;
2100 int dst_v_offset = 0;
2101 int loop_length = 0;
2102 unsigned int dst_size = 0;
2103 unsigned char *dst_data = NULL;
2105 if (!src || !dst || !dst_len) {
2106 _mmcam_dbg_err("NULL pointer %p, %p, %p", src, dst, dst_len);
2110 dst_size = (width * height * 3) >> 1;
2112 _mmcam_dbg_log("UYVY -> I420 : %dx%d, dst size %d", width, height, dst_size);
2114 dst_data = (unsigned char *)malloc(dst_size);
2116 _mmcam_dbg_err("failed to alloc dst_data. size %d", dst_size);
2120 loop_length = width << 1;
2121 dst_u_offset = width * height;
2122 dst_v_offset = dst_u_offset + (dst_u_offset >> 2);
2124 _mmcam_dbg_log("offset y %d, u %d, v %d", dst_y_offset, dst_u_offset, dst_v_offset);
2126 for (i = 0 ; i < height ; i++) {
2127 for (j = 0 ; j < loop_length ; j += 2) {
2130 dst_data[dst_u_offset++] = src[src_offset++]; /*U*/
2132 dst_data[dst_v_offset++] = src[src_offset++]; /*V*/
2137 dst_data[dst_y_offset++] = src[src_offset++]; /*Y*/
2142 *dst_len = dst_size;
2144 _mmcam_dbg_log("DONE: UYVY -> I420 : %dx%d, dst data %p, size %d", width, height, *dst, dst_size);
2150 static gboolean _mmcamcorder_convert_NV12_to_I420(unsigned char *src, guint width, guint height, unsigned char **dst, unsigned int *dst_len)
2154 int dst_y_offset = 0;
2155 int dst_u_offset = 0;
2156 int dst_v_offset = 0;
2157 int loop_length = 0;
2158 unsigned int dst_size = 0;
2159 unsigned char *dst_data = NULL;
2161 if (!src || !dst || !dst_len) {
2162 _mmcam_dbg_err("NULL pointer %p, %p, %p", src, dst, dst_len);
2166 dst_size = (width * height * 3) >> 1;
2168 _mmcam_dbg_log("NV12 -> I420 : %dx%d, dst size %d", width, height, dst_size);
2170 dst_data = (unsigned char *)malloc(dst_size);
2172 _mmcam_dbg_err("failed to alloc dst_data. size %d", dst_size);
2176 loop_length = width << 1;
2177 dst_u_offset = width * height;
2178 dst_v_offset = dst_u_offset + (dst_u_offset >> 2);
2180 _mmcam_dbg_log("offset y %d, u %d, v %d", dst_y_offset, dst_u_offset, dst_v_offset);
2183 memcpy(dst_data, src, dst_u_offset);
2185 loop_length = dst_u_offset >> 1;
2186 src_offset = dst_u_offset;
2189 for (i = 0 ; i < loop_length ; i++) {
2191 dst_data[dst_u_offset++] = src[src_offset++];
2193 dst_data[dst_v_offset++] = src[src_offset++];
2197 *dst_len = dst_size;
2199 _mmcam_dbg_log("DONE: NV12 -> I420 : %dx%d, dst data %p, size %d", width, height, *dst, dst_size);