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 =======================================================================================*/
27 #include <sys/vfs.h> /* struct statfs */
28 #include <dbus/dbus.h>
29 #include <sys/time.h> /* gettimeofday */
31 #include "mm_camcorder_internal.h"
32 #include "mm_camcorder_util.h"
33 #include "mm_camcorder_sound.h"
34 #include <mm_util_imgp.h>
36 /*-----------------------------------------------------------------------
37 | GLOBAL VARIABLE DEFINITIONS for internal |
38 -----------------------------------------------------------------------*/
40 /*-----------------------------------------------------------------------
41 | LOCAL VARIABLE DEFINITIONS for internal |
42 -----------------------------------------------------------------------*/
43 #define TIME_STRING_MAX_LEN 64
45 #define FPUTC_CHECK(x_char, x_file)\
47 if (fputc(x_char, x_file) == EOF) \
49 _mmcam_dbg_err("[Critical] fputc() returns fail.\n"); \
53 #define FPUTS_CHECK(x_str, x_file)\
55 if (fputs(x_str, x_file) == EOF) \
57 _mmcam_dbg_err("[Critical] fputs() returns fail.\n");\
63 /*---------------------------------------------------------------------------
64 | LOCAL FUNCTION PROTOTYPES: |
65 ---------------------------------------------------------------------------*/
66 /* STATIC INTERNAL FUNCTION */
68 //static gint skip_mdat(FILE *f);
69 static guint16 get_language_code(const char *str);
70 static gchar* str_to_utf8(const gchar *str);
71 static inline gboolean write_tag(FILE *f, const gchar *tag);
72 static inline gboolean write_to_32(FILE *f, guint val);
73 static inline gboolean write_to_16(FILE *f, guint val);
74 static inline gboolean write_to_24(FILE *f, guint val);
76 /*===========================================================================================
78 | FUNCTION DEFINITIONS |
80 ========================================================================================== */
81 /*---------------------------------------------------------------------------
82 | GLOBAL FUNCTION DEFINITIONS: |
83 ---------------------------------------------------------------------------*/
85 static int __append_variant(DBusMessageIter *iter, const char *sig, char *param[])
95 for (ch = sig, i = 0; *ch != '\0'; ++i, ++ch) {
98 int_type = atoi(param[i]);
99 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
102 int_type = atoi(param[i]);
103 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
106 int64_type = atoi(param[i]);
107 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
110 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, ¶m[i]);
120 #define DBUS_REPLY_TIMEOUT (120 * 1000)
121 static DBusMessage *__invoke_dbus_method_sync(const char *dest, const char *path,
122 const char *interface, const char *method,
123 const char *sig, char *param[])
125 DBusConnection *conn;
127 DBusMessageIter iter;
132 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
134 _mmcam_dbg_err( "dbus_bus_get error");
138 msg = dbus_message_new_method_call(dest, path, interface, method);
140 _mmcam_dbg_err("dbus_message_new_method_call(%s:%s-%s)", path, interface, method);
144 dbus_message_iter_init_append(msg, &iter);
145 r = __append_variant(&iter, sig, param);
147 _mmcam_dbg_err("append_variant error(%d)", r);
151 dbus_error_init(&err);
153 reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
155 _mmcam_dbg_err("dbus_connection_send error(No reply)");
158 if (dbus_error_is_set(&err)) {
159 _mmcam_dbg_err("dbus_connection_send error(%s:%s)", err.name, err.message);
163 dbus_message_unref(msg);
164 dbus_error_free(&err);
170 gint32 _mmcamcorder_double_to_fix(gdouble d_number)
172 return (gint32) (d_number * 65536.0);
175 // find top level tag only, do not use this function for finding sub level tags
176 gint _mmcamcorder_find_tag(FILE *f, guint32 tag_fourcc, gboolean do_rewind)
178 size_t read_item = 0;
185 while ((read_item = fread(&buf, sizeof(guchar), 8, f)) > 0) {
186 unsigned long long buf_size = 0;
187 unsigned int buf_fourcc = 0;
190 _mmcam_dbg_err("fread failed : %d", read_item);
194 buf_fourcc = MMCAM_FOURCC(buf[4], buf[5], buf[6], buf[7]);
196 if (tag_fourcc == buf_fourcc) {
197 _mmcam_dbg_log("find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
200 _mmcam_dbg_log("skip [%c%c%c%c] tag", MMCAM_FOURCC_ARGS(buf_fourcc));
202 buf_size = (unsigned long long)_mmcamcorder_get_container_size(buf);
203 buf_size = buf_size - 8; /* include tag */
206 if (buf_size > _MMCAMCORDER_MAX_INT) {
207 _mmcam_dbg_log("seek %d", _MMCAMCORDER_MAX_INT);
208 if (fseek(f, _MMCAMCORDER_MAX_INT, SEEK_CUR) != 0) {
209 _mmcam_dbg_err("fseek() fail");
213 buf_size -= _MMCAMCORDER_MAX_INT;
215 _mmcam_dbg_log("seek %d", buf_size);
216 if (fseek(f, buf_size, SEEK_CUR) != 0) {
217 _mmcam_dbg_err("fseek() fail");
226 _mmcam_dbg_log("cannot find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
231 gboolean _mmcamcorder_find_fourcc(FILE *f, guint32 tag_fourcc, gboolean do_rewind)
233 size_t read_item = 0;
240 while ((read_item = fread(&buf, sizeof(guchar), 8, f)) > 0) {
241 unsigned long long buf_size = 0;
242 unsigned int buf_fourcc = 0;
245 _mmcam_dbg_err("fread failed : %d", read_item);
249 buf_fourcc = MMCAM_FOURCC(buf[4], buf[5], buf[6], buf[7]);
251 if (tag_fourcc == buf_fourcc) {
252 _mmcam_dbg_log("find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
255 else if((buf_fourcc == MMCAM_FOURCC('m','o','o','v')) && (tag_fourcc != buf_fourcc)){
256 if(_mmcamcorder_find_fourcc(f,tag_fourcc,FALSE)){
263 _mmcam_dbg_log("skip [%c%c%c%c] tag", MMCAM_FOURCC_ARGS(buf_fourcc));
265 buf_size = (unsigned long long)_mmcamcorder_get_container_size(buf);
266 buf_size = buf_size - 8; /* include tag */
269 if (buf_size > _MMCAMCORDER_MAX_INT) {
270 _mmcam_dbg_log("seek %d", _MMCAMCORDER_MAX_INT);
271 if (fseek(f, _MMCAMCORDER_MAX_INT, SEEK_CUR) != 0) {
272 _mmcam_dbg_err("fseek() fail");
276 buf_size -= _MMCAMCORDER_MAX_INT;
278 _mmcam_dbg_log("seek %d", buf_size);
279 if (fseek(f, buf_size, SEEK_CUR) != 0) {
280 _mmcam_dbg_err("fseek() fail");
289 _mmcam_dbg_log("cannot find tag : %c%c%c%c", MMCAM_FOURCC_ARGS(tag_fourcc));
294 gboolean _mmcamcorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos)
296 _mmcam_dbg_log("size : %"G_GINT64_FORMAT"", curr_pos-prev_pos);
297 if(fseek(f, prev_pos, SEEK_SET) != 0)
299 _mmcam_dbg_err("fseek() fail");
303 if (!write_to_32(f, curr_pos -prev_pos))
306 if(fseek(f, curr_pos, SEEK_SET) != 0)
308 _mmcam_dbg_err("fseek() fail");
314 // VIDEO TAG - CAMCORDER
315 gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info)
317 gint64 current_pos, pos;
322 if((pos = ftell(f))<0)
324 _mmcam_dbg_err("ftell() returns negative value");
328 if(!write_to_32(f, 0)) //size
331 if(!write_tag(f, "loci")) // type
334 FPUTC_CHECK(0, f); // version
336 if(!write_to_24(f, 0)) // flags
339 if(!write_to_16(f, get_language_code("eng"))) // language
342 str = str_to_utf8("location_name");
344 FPUTS_CHECK(str, f); // name
347 FPUTC_CHECK('\0', f);
348 FPUTC_CHECK(0, f); //role
350 if(!write_to_32(f, info.longitude)) // Longitude
353 if(!write_to_32(f, info.latitude)) // Latitude
356 if(! write_to_32(f, info.altitude)) // Altitude
359 str = str_to_utf8("Astronomical_body");
360 FPUTS_CHECK(str, f);//Astronomical_body
363 FPUTC_CHECK('\0', f);
365 str = str_to_utf8("Additional_notes");
366 FPUTS_CHECK(str, f); // Additional_notes
369 FPUTC_CHECK('\0', f);
371 if((current_pos = ftell(f))<0)
373 _mmcam_dbg_err("ftell() returns negative value");
377 if(! _mmcamcorder_update_size(f, pos, current_pos))
383 void _mmcamcorder_write_Latitude(FILE *f,int value) {
386 int l_below_decimal = 0;
388 l_decimal = value / 10000;
390 if( l_decimal == 0) {
391 snprintf(s_latitude, 5, "-%.2d.", l_decimal);
393 snprintf(s_latitude, 5, "%.2d.", l_decimal);
396 snprintf(s_latitude, 5, "+%.2d.", l_decimal);
399 l_below_decimal = value - (l_decimal * 10000);
400 if (l_below_decimal < 0) {
401 l_below_decimal = -l_below_decimal;
403 snprintf(&s_latitude[4], 5, "%.4d", l_below_decimal);
405 write_tag(f, s_latitude);
408 void _mmcamcorder_write_Longitude(FILE *f,int value) {
409 char s_longitude[10];
411 int l_below_decimal = 0;
413 l_decimal = value / 10000;
415 if( l_decimal == 0) {
416 snprintf(s_longitude, 6, "-%.3d.", l_decimal);
418 snprintf(s_longitude, 6, "%.3d.", l_decimal);
421 snprintf(s_longitude, 6, "+%.3d.", l_decimal);
424 l_below_decimal = value - (l_decimal * 10000);
425 if (l_below_decimal < 0) {
426 l_below_decimal = -l_below_decimal;
428 snprintf(&s_longitude[5], 5, "%.4d", l_below_decimal);
430 write_tag(f, s_longitude);
433 #define D_GEOGRAPH "\xA9xyz"
434 // 0x0012 -> latitude(8) + longitude(9) + seperator(1) = 18
435 // 0x15c7 -> encode in english
436 #define D_INFO_GEOGRAPH 0x001215c7
438 gboolean _mmcamcorder_write_geodata(FILE *f,_MMCamcorderLocationInfo info) {
440 gint64 current_pos, pos;
441 // gchar *str = NULL;
445 if((pos = ftell(f))<0)
447 _mmcam_dbg_err("ftell() returns negative value");
451 if(!write_to_32(f, 0)) //size
454 if(!write_tag(f, D_GEOGRAPH)) // type
457 if(!write_to_32(f, D_INFO_GEOGRAPH))
460 _mmcamcorder_write_Latitude(f,info.latitude);
461 _mmcamcorder_write_Longitude(f,info.longitude);
463 FPUTC_CHECK(0x2F, f);
465 if((current_pos = ftell(f))<0)
467 _mmcam_dbg_err("ftell() returns negative value");
471 if(! _mmcamcorder_update_size(f, pos, current_pos))
478 gboolean _mmcamcorder_write_udta(FILE *f, int gps_enable, _MMCamcorderLocationInfo info, _MMCamcorderLocationInfo geotag)
480 gint64 current_pos, pos;
482 _mmcam_dbg_log("gps enable : %d", gps_enable);
483 if (gps_enable == FALSE) {
484 _mmcam_dbg_log("no need to write udta");
488 if ((pos = ftell(f))<0) {
489 _mmcam_dbg_err("ftell() returns negative value");
494 if (!write_to_32(f, 0)) {
495 _mmcam_dbg_err("failed to write size");
500 if (!write_tag(f, "udta")) {
501 _mmcam_dbg_err("failed to write type udta");
506 if (!_mmcamcorder_write_loci(f, info)) {
507 _mmcam_dbg_err("failed to write loci");
511 if (!_mmcamcorder_write_geodata(f,geotag)) {
512 _mmcam_dbg_err("failed to write geodata");
517 if ((current_pos = ftell(f))<0) {
518 _mmcam_dbg_err("ftell() returns negative value");
522 if (!_mmcamcorder_update_size(f, pos, current_pos)) {
523 _mmcam_dbg_err("failed to update size");
527 _mmcam_dbg_log("done");
533 guint64 _mmcamcorder_get_container_size(const guchar *size)
541 result = result | (temp << 16);
543 result = result | (temp << 8);
544 result = result | size[3];
546 _mmcam_dbg_log("result : %lld", (unsigned long long)result);
552 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation)
555 guint32 a = 0x00010000;
558 guint32 d = 0x00010000;
560 switch (orientation) {
561 case MM_CAMCORDER_TAG_VIDEO_ORT_90:/* 90 degree */
567 case MM_CAMCORDER_TAG_VIDEO_ORT_180:/* 180 degree */
571 case MM_CAMCORDER_TAG_VIDEO_ORT_270:/* 270 degree */
577 case MM_CAMCORDER_TAG_VIDEO_ORT_NONE:/* 0 degree */
590 write_to_32(f, 0x40000000);
592 _mmcam_dbg_log("orientation : %d, write data 0x%x 0x%x 0x%x 0x%x",
593 orientation, a, b, c, d);
599 int _mmcamcorder_get_freespace(const gchar *path, guint64 *free_space)
605 if (!g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
606 _mmcam_dbg_log("File(%s) doesn't exist.", path);
610 if (-1 == statfs(path, &fs)) {
611 _mmcam_dbg_log("statfs failed.(%s)", path);
615 *free_space = (guint64)fs.f_bsize * fs.f_bavail;
620 int _mmcamcorder_get_file_system_type(const gchar *path, int *file_system_type)
626 if (!g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
627 _mmcam_dbg_log("File(%s) doesn't exist.", path);
631 if (-1 == statfs(path, &fs)) {
632 _mmcam_dbg_log("statfs failed.(%s)", path);
636 *file_system_type = (int)fs.f_type;
642 int _mmcamcorder_get_freespace_except_system(guint64 *free_space)
647 double total_space=0;
648 double avail_space=0;
650 msg = __invoke_dbus_method_sync("org.tizen.system.deviced", "/Org/Tizen/System/DeviceD/Storage",
651 "org.tizen.system.deviced.storage", "getstorage", NULL, NULL);
653 _mmcam_dbg_log("method_call failed");
657 dbus_error_init(&err);
659 ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT64, &total_space, DBUS_TYPE_INT64, &avail_space, DBUS_TYPE_INVALID);
661 _mmcam_dbg_log("no message : [%s:%s]", err.name, err.message);
665 dbus_message_unref(msg);
666 dbus_error_free(&err);
668 *free_space = (guint64)avail_space;
669 _mmcam_dbg_err(" free space [%" G_GUINT64_FORMAT "] ",*free_space);
674 int _mmcamcorder_get_file_size(const char *filename, guint64 *size)
678 if (stat(filename, &buf) != 0)
680 *size = (guint64)buf.st_size;
685 void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCategory category)
687 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
689 MMCamcorderHandlerItem *item = NULL;
691 mmf_return_if_fail(hcamcorder);
693 if (!hcamcorder->buffer_probes) {
694 _mmcam_dbg_warn("list for buffer probe is NULL");
698 _mmcam_dbg_log("start - category : 0x%x", category);
700 list = hcamcorder->buffer_probes;
704 _mmcam_dbg_err("Remove buffer probe faild, the item is NULL");
705 list = g_list_next(list);
709 if (item->category & category) {
710 if (item->object && GST_IS_PAD(item->object)) {
711 _mmcam_dbg_log("Remove buffer probe on [%s:%s] - [ID : %lu], [Category : %x]",
712 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category);
713 gst_pad_remove_buffer_probe(GST_PAD(item->object), item->handler_id);
715 _mmcam_dbg_warn("Remove buffer probe faild, the pad is null or not pad, just remove item from list and free it");
718 list = g_list_next(list);
719 hcamcorder->buffer_probes = g_list_remove(hcamcorder->buffer_probes, item);
722 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
723 list = g_list_next(list);
727 if (category == _MMCAMCORDER_HANDLER_CATEGORY_ALL) {
728 g_list_free(hcamcorder->buffer_probes);
729 hcamcorder->buffer_probes = NULL;
732 _mmcam_dbg_log("done");
738 void _mmcamcorder_remove_one_buffer_probe(MMHandleType handle, void *object)
740 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
742 MMCamcorderHandlerItem *item = NULL;
744 mmf_return_if_fail(hcamcorder);
746 if (!hcamcorder->buffer_probes) {
747 _mmcam_dbg_warn("list for buffer probe is NULL");
751 _mmcam_dbg_log("start - object : %p", object);
753 list = hcamcorder->buffer_probes;
757 _mmcam_dbg_err("Remove buffer probe faild, the item is NULL");
758 list = g_list_next(list);
762 if (item->object && item->object == object) {
763 if (GST_IS_PAD(item->object)) {
764 _mmcam_dbg_log("Remove buffer probe on [%s:%s] - [ID : %lu], [Category : %x]",
765 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category);
766 gst_pad_remove_buffer_probe(GST_PAD(item->object), item->handler_id);
768 _mmcam_dbg_warn("Remove buffer probe faild, the pad is null or not pad, just remove item from list and free it");
771 list = g_list_next(list);
772 hcamcorder->buffer_probes = g_list_remove(hcamcorder->buffer_probes, item);
777 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
778 list = g_list_next(list);
782 _mmcam_dbg_log("done");
788 void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCategory category)
790 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
792 MMCamcorderHandlerItem *item = NULL;
794 mmf_return_if_fail(hcamcorder);
796 if (!hcamcorder->event_probes) {
797 _mmcam_dbg_warn("list for event probe is NULL");
801 _mmcam_dbg_log("start - category : 0x%x", category);
803 list = hcamcorder->event_probes;
807 _mmcam_dbg_err("Remove event probe faild, the item is NULL");
808 list = g_list_next(list);
812 if (item->category & category) {
813 if (item->object && GST_IS_PAD(item->object)) {
814 _mmcam_dbg_log("Remove event probe on [%s:%s] - [ID : %lu], [Category : %x]",
815 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category);
816 gst_pad_remove_event_probe(GST_PAD(item->object), item->handler_id);
818 _mmcam_dbg_warn("Remove event probe faild, the pad is null or not pad, just remove item from list and free it");
821 list = g_list_next(list);
822 hcamcorder->event_probes = g_list_remove(hcamcorder->event_probes, item);
825 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
826 list = g_list_next(list);
830 if (category == _MMCAMCORDER_HANDLER_CATEGORY_ALL) {
831 g_list_free(hcamcorder->event_probes);
832 hcamcorder->event_probes = NULL;
835 _mmcam_dbg_log("done");
841 void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCategory category)
843 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
845 MMCamcorderHandlerItem *item = NULL;
847 mmf_return_if_fail(hcamcorder);
849 if (!hcamcorder->signals) {
850 _mmcam_dbg_warn("list for signal is NULL");
854 _mmcam_dbg_log("start - category : 0x%x", category);
856 list = hcamcorder->signals;
860 _mmcam_dbg_err("Fail to Disconnecting signal, the item is NULL");
861 list = g_list_next(list);
865 if (item->category & category) {
866 if (item->object && GST_IS_ELEMENT(item->object)) {
867 if (g_signal_handler_is_connected(item->object, item->handler_id)) {
868 _mmcam_dbg_log("Disconnect signal from [%s] : [ID : %lu], [Category : %x]",
869 GST_OBJECT_NAME(item->object), item->handler_id, item->category);
870 g_signal_handler_disconnect(item->object, item->handler_id);
872 _mmcam_dbg_warn("Signal was not connected, cannot disconnect it : [%s] [ID : %lu], [Category : %x]",
873 GST_OBJECT_NAME(item->object), item->handler_id, item->category);
876 _mmcam_dbg_err("Fail to Disconnecting signal, the element is null or not element, just remove item from list and free it");
879 list = g_list_next(list);
880 hcamcorder->signals = g_list_remove(hcamcorder->signals, item);
883 _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
884 list = g_list_next(list);
888 if (category == _MMCAMCORDER_HANDLER_CATEGORY_ALL) {
889 g_list_free(hcamcorder->signals);
890 hcamcorder->signals = NULL;
893 _mmcam_dbg_log("done");
899 void _mmcamcorder_remove_all_handlers(MMHandleType handle, _MMCamcorderHandlerCategory category)
901 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
903 _mmcam_dbg_log("ENTER");
905 if(hcamcorder->signals)
906 _mmcamcorder_disconnect_signal((MMHandleType)hcamcorder, category);
907 if(hcamcorder->event_probes)
908 _mmcamcorder_remove_event_probe((MMHandleType)hcamcorder, category);
909 if(hcamcorder->buffer_probes)
910 _mmcamcorder_remove_buffer_probe((MMHandleType)hcamcorder, category);
912 _mmcam_dbg_log("LEAVE");
916 void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_was)
919 _MMCamcorderSubContext *sc = (_MMCamcorderSubContext *)data;
921 mmf_return_if_fail(sc);
922 mmf_return_if_fail(sc->element);
924 for (i = 0 ; i < _MMCAMCORDER_PIPELINE_ELEMENT_NUM ; i++) {
925 if (sc->element[i].gst && (G_OBJECT(sc->element[i].gst) == where_the_object_was)) {
926 _mmcam_dbg_warn("The element[%d][%p] is finalized",
927 sc->element[i].id, sc->element[i].gst);
928 sc->element[i].gst = NULL;
929 sc->element[i].id = _MMCAMCORDER_NONE;
934 mmf_return_if_fail(sc->encode_element);
936 for (i = 0 ; i < _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM ; i++) {
937 if (sc->encode_element[i].gst && (G_OBJECT(sc->encode_element[i].gst) == where_the_object_was)) {
938 _mmcam_dbg_warn("The encode element[%d][%p] is finalized",
939 sc->encode_element[i].id, sc->encode_element[i].gst);
940 sc->encode_element[i].gst = NULL;
941 sc->encode_element[i].id = _MMCAMCORDER_ENCODE_NONE;
946 _mmcam_dbg_warn("there is no matching element %p", where_the_object_was);
953 _mmcamcroder_msg_callback(void *data)
955 _MMCamcorderMsgItem *item = (_MMCamcorderMsgItem*)data;
956 mmf_camcorder_t *hcamcorder = NULL;
957 mmf_return_val_if_fail(item, FALSE);
959 g_mutex_lock(&item->lock);
961 hcamcorder = MMF_CAMCORDER(item->handle);
962 if (hcamcorder == NULL) {
963 _mmcam_dbg_warn("msg id:%x, item:%p, handle is NULL", item->id, item);
964 goto MSG_CALLBACK_DONE;
968 /*_mmcam_dbg_log("msg id:%x, msg_cb:%p, msg_data:%p, item:%p", item->id, hcamcorder->msg_cb, hcamcorder->msg_data, item);*/
970 _MMCAMCORDER_LOCK((MMHandleType)hcamcorder);
972 /* remove item from msg data */
973 if (hcamcorder->msg_data) {
974 hcamcorder->msg_data = g_list_remove(hcamcorder->msg_data, item);
976 _mmcam_dbg_warn("msg_data is NULL but item[%p] will be removed", item);
979 _MMCAMCORDER_UNLOCK((MMHandleType)hcamcorder);
981 _MMCAMCORDER_LOCK_MESSAGE_CALLBACK(hcamcorder);
983 if ((hcamcorder) && (hcamcorder->msg_cb)) {
984 hcamcorder->msg_cb(item->id, (MMMessageParamType*)(&(item->param)), hcamcorder->msg_cb_param);
987 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
990 /* release allocated memory */
991 if (item->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
992 MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)item->param.data;
994 SAFE_FREE(cam_fd_info->face_info);
999 item->param.data = NULL;
1000 item->param.size = 0;
1003 g_mutex_unlock(&item->lock);
1004 g_mutex_clear(&item->lock);
1009 /* For not being called again */
1015 _mmcamcroder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data)
1017 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
1018 _MMCamcorderMsgItem *item = NULL;
1020 mmf_return_val_if_fail(hcamcorder, FALSE);
1021 mmf_return_val_if_fail(data, FALSE);
1025 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
1026 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
1027 data->param.union_type = MM_MSG_UNION_STATE;
1029 case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
1030 data->param.union_type = MM_MSG_UNION_RECORDING_STATUS;
1032 case MM_MESSAGE_CAMCORDER_FIRMWARE_UPDATE:
1033 data->param.union_type = MM_MSG_UNION_FIRMWARE;
1035 case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
1036 data->param.union_type = MM_MSG_UNION_REC_VOLUME_DB;
1038 case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
1039 case MM_MESSAGE_CAMCORDER_MAX_SIZE:
1040 case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:
1041 case MM_MESSAGE_CAMCORDER_ERROR:
1042 case MM_MESSAGE_CAMCORDER_FOCUS_CHANGED:
1043 case MM_MESSAGE_CAMCORDER_CAPTURED:
1044 case MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED:
1045 case MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED:
1046 case MM_MESSAGE_READY_TO_RESUME:
1048 data->param.union_type = MM_MSG_UNION_CODE;
1052 item = g_malloc(sizeof(_MMCamcorderMsgItem));
1054 memcpy(item, data, sizeof(_MMCamcorderMsgItem));
1055 item->handle = handle;
1056 g_mutex_init(&item->lock);
1058 _MMCAMCORDER_LOCK(handle);
1059 hcamcorder->msg_data = g_list_append(hcamcorder->msg_data, item);
1060 //_mmcam_dbg_log("item[%p]", item);
1062 /* Use DEFAULT priority */
1063 g_idle_add_full(G_PRIORITY_DEFAULT, _mmcamcroder_msg_callback, item, NULL);
1065 _MMCAMCORDER_UNLOCK(handle);
1067 _mmcam_dbg_err("item malloc failed : %d", sizeof(_MMCamcorderMsgItem));
1075 _mmcamcroder_remove_message_all(MMHandleType handle)
1077 mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
1078 _MMCamcorderMsgItem *item = NULL;
1079 gboolean ret = TRUE;
1082 mmf_return_if_fail(hcamcorder);
1084 _MMCAMCORDER_LOCK(handle);
1086 if (!hcamcorder->msg_data) {
1087 _mmcam_dbg_log("No message data is remained.");
1089 list = hcamcorder->msg_data;
1093 list = g_list_next(list);
1096 _mmcam_dbg_err("Fail to remove message. The item is NULL");
1098 if (g_mutex_trylock(&item->lock)) {
1099 ret = g_idle_remove_by_data (item);
1100 _mmcam_dbg_log("Remove item[%p]. ret[%d]", item, ret);
1102 hcamcorder->msg_data = g_list_remove(hcamcorder->msg_data, item);
1105 /* release allocated memory */
1106 if (item->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
1107 MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)item->param.data;
1109 SAFE_FREE(cam_fd_info->face_info);
1114 item->param.data = NULL;
1115 item->param.size = 0;
1118 g_mutex_unlock(&item->lock);
1119 g_mutex_clear(&item->lock);
1123 _mmcam_dbg_warn("Fail to remove item[%p]", item);
1125 g_mutex_unlock(&item->lock);
1128 _mmcam_dbg_warn("item lock failed. it's being called...");
1133 g_list_free(hcamcorder->msg_data);
1134 hcamcorder->msg_data = NULL;
1137 /* remove idle function for playing capture sound */
1139 ret = g_idle_remove_by_data(hcamcorder);
1140 _mmcam_dbg_log("remove idle function for playing capture sound. ret[%d]", ret);
1143 _MMCAMCORDER_UNLOCK(handle);
1149 int _mmcamcorder_get_pixel_format(GstBuffer *buffer)
1151 GstCaps *caps = NULL;
1152 const GstStructure *structure;
1153 const char *media_type;
1154 MMPixelFormatType type = 0;
1155 unsigned int fourcc = 0;
1157 mmf_return_val_if_fail( buffer != NULL, MM_PIXEL_FORMAT_INVALID );
1159 caps = gst_buffer_get_caps (buffer);
1160 structure = gst_caps_get_structure (caps, 0);
1161 media_type = gst_structure_get_name (structure);
1162 if (media_type == NULL) {
1163 _mmcam_dbg_err("failed to get media_type");
1164 return MM_PIXEL_FORMAT_INVALID;
1167 if (!strcmp (media_type, "image/jpeg") ) {
1168 _mmcam_dbg_log("It is jpeg.");
1169 type = MM_PIXEL_FORMAT_ENCODED;
1170 } else if (!strcmp (media_type, "video/x-raw-yuv")) {
1171 _mmcam_dbg_log("It is yuv.");
1172 gst_structure_get_fourcc (structure, "format", &fourcc);
1173 type = _mmcamcorder_get_pixtype(fourcc);
1174 } else if (!strcmp (media_type, "video/x-raw-rgb")) {
1175 _mmcam_dbg_log("It is rgb.");
1176 type = MM_PIXEL_FORMAT_RGB888;
1178 _mmcam_dbg_err("Not supported format");
1179 type = MM_PIXEL_FORMAT_INVALID;
1182 /*_mmcam_dbg_log( "Type [%d]", type );*/
1184 gst_caps_unref( caps );
1190 unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format)
1192 unsigned int fourcc = 0;
1194 /*_mmcam_dbg_log("pixtype(%d)", pixtype);*/
1197 case MM_PIXEL_FORMAT_NV12:
1198 if (use_zero_copy_format) {
1199 fourcc = GST_MAKE_FOURCC ('S', 'N', '1', '2');
1201 fourcc = GST_MAKE_FOURCC ('N', 'V', '1', '2');
1204 case MM_PIXEL_FORMAT_NV21:
1205 if (use_zero_copy_format) {
1206 fourcc = GST_MAKE_FOURCC ('S', 'N', '2', '1');
1208 fourcc = GST_MAKE_FOURCC ('N', 'V', '2', '1');
1211 case MM_PIXEL_FORMAT_YUYV:
1212 if (use_zero_copy_format) {
1213 fourcc = GST_MAKE_FOURCC ('S', 'U', 'Y', 'V');
1215 fourcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
1218 case MM_PIXEL_FORMAT_UYVY:
1219 if (use_zero_copy_format) {
1220 fourcc = GST_MAKE_FOURCC ('S', 'Y', 'V', 'Y');
1222 fourcc = GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
1225 case MM_PIXEL_FORMAT_I420:
1226 if (use_zero_copy_format) {
1227 fourcc = GST_MAKE_FOURCC ('S', '4', '2', '0');
1229 fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
1232 case MM_PIXEL_FORMAT_YV12:
1233 fourcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
1235 case MM_PIXEL_FORMAT_422P:
1236 fourcc = GST_MAKE_FOURCC ('4', '2', '2', 'P');
1238 case MM_PIXEL_FORMAT_RGB565:
1239 fourcc = GST_MAKE_FOURCC ('R', 'G', 'B', 'P');
1241 case MM_PIXEL_FORMAT_RGB888:
1242 fourcc = GST_MAKE_FOURCC ('R', 'G', 'B', ' ');
1244 case MM_PIXEL_FORMAT_ENCODED:
1245 if (codectype == MM_IMAGE_CODEC_JPEG) {
1246 fourcc = GST_MAKE_FOURCC ('J', 'P', 'E', 'G');
1247 } else if (codectype == MM_IMAGE_CODEC_JPEG_SRW) {
1248 fourcc = GST_MAKE_FOURCC ('J', 'P', 'E', 'G'); /*TODO: JPEG+SamsungRAW format */
1249 } else if (codectype == MM_IMAGE_CODEC_SRW) {
1250 fourcc = GST_MAKE_FOURCC ('J', 'P', 'E', 'G'); /*TODO: SamsungRAW format */
1251 } else if (codectype == MM_IMAGE_CODEC_PNG) {
1252 fourcc = GST_MAKE_FOURCC ('P', 'N', 'G', ' ');
1254 /* Please let us know what other fourcces are. ex) BMP, GIF?*/
1255 fourcc = GST_MAKE_FOURCC ('J', 'P', 'E', 'G');
1258 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
1259 fourcc = GST_MAKE_FOURCC('I','T','L','V');
1262 _mmcam_dbg_log("Not proper pixel type[%d]. Set default - I420", pixtype);
1263 if (use_zero_copy_format) {
1264 fourcc = GST_MAKE_FOURCC ('S', '4', '2', '0');
1266 fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
1275 int _mmcamcorder_get_pixtype(unsigned int fourcc)
1277 int pixtype = MM_PIXEL_FORMAT_INVALID;
1279 char *pfourcc = (char*)&fourcc;
1281 _mmcam_dbg_log("fourcc(%c%c%c%c)",
1282 pfourcc[0], pfourcc[1], pfourcc[2], pfourcc[3]);
1286 case GST_MAKE_FOURCC ('S', 'N', '1', '2'):
1287 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
1288 pixtype = MM_PIXEL_FORMAT_NV12;
1290 case GST_MAKE_FOURCC ('S', 'N', '2', '1'):
1291 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
1292 pixtype = MM_PIXEL_FORMAT_NV21;
1294 case GST_MAKE_FOURCC ('S', 'U', 'Y', 'V'):
1295 case GST_MAKE_FOURCC ('Y', 'U', 'Y', 'V'):
1296 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
1297 pixtype = MM_PIXEL_FORMAT_YUYV;
1299 case GST_MAKE_FOURCC ('S', 'Y', 'V', 'Y'):
1300 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
1301 pixtype = MM_PIXEL_FORMAT_UYVY;
1303 case GST_MAKE_FOURCC ('S', '4', '2', '0'):
1304 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
1305 pixtype = MM_PIXEL_FORMAT_I420;
1307 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
1308 pixtype = MM_PIXEL_FORMAT_YV12;
1310 case GST_MAKE_FOURCC ('4', '2', '2', 'P'):
1311 pixtype = MM_PIXEL_FORMAT_422P;
1313 case GST_MAKE_FOURCC ('R', 'G', 'B', 'P'):
1314 pixtype = MM_PIXEL_FORMAT_RGB565;
1316 case GST_MAKE_FOURCC ('R', 'G', 'B', '3'):
1317 pixtype = MM_PIXEL_FORMAT_RGB888;
1319 case GST_MAKE_FOURCC ('A', 'R', 'G', 'B'):
1320 case GST_MAKE_FOURCC ('x', 'R', 'G', 'B'):
1321 pixtype = MM_PIXEL_FORMAT_ARGB;
1323 case GST_MAKE_FOURCC ('B', 'G', 'R', 'A'):
1324 case GST_MAKE_FOURCC ('B', 'G', 'R', 'x'):
1325 case GST_MAKE_FOURCC ('S', 'R', '3', '2'):
1326 pixtype = MM_PIXEL_FORMAT_RGBA;
1328 case GST_MAKE_FOURCC ('J', 'P', 'E', 'G'):
1329 case GST_MAKE_FOURCC ('P', 'N', 'G', ' '):
1330 pixtype = MM_PIXEL_FORMAT_ENCODED;
1333 case GST_MAKE_FOURCC ('I', 'T', 'L', 'V'):
1334 pixtype = MM_PIXEL_FORMAT_ITLV_JPEG_UYVY;
1337 _mmcam_dbg_log("Not supported fourcc type(%c%c%c%c)",
1338 fourcc, fourcc>>8, fourcc>>16, fourcc>>24);
1339 pixtype = MM_PIXEL_FORMAT_INVALID;
1347 gboolean _mmcamcorder_add_elements_to_bin(GstBin *bin, GList *element_list)
1349 GList *local_list = element_list;
1350 _MMCamcorderGstElement *element = NULL;
1352 mmf_return_val_if_fail(bin && local_list, FALSE);
1354 while (local_list) {
1355 element = (_MMCamcorderGstElement*)local_list->data;
1356 if (element && element->gst) {
1357 if (!gst_bin_add(bin, GST_ELEMENT(element->gst))) {
1358 _mmcam_dbg_err( "Add element [%s] to bin [%s] FAILED",
1359 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)),
1360 GST_ELEMENT_NAME(GST_ELEMENT(bin)) );
1363 _mmcam_dbg_log("Add element [%s] to bin [%s] OK",
1364 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)),
1365 GST_ELEMENT_NAME(GST_ELEMENT(bin)));
1368 local_list = local_list->next;
1374 gboolean _mmcamcorder_link_elements(GList *element_list)
1376 GList *local_list = element_list;
1377 _MMCamcorderGstElement *element = NULL;
1378 _MMCamcorderGstElement *pre_element = NULL;
1380 mmf_return_val_if_fail(local_list, FALSE);
1382 pre_element = (_MMCamcorderGstElement*)local_list->data;
1383 local_list = local_list->next;
1385 while (local_list) {
1386 element = (_MMCamcorderGstElement*)local_list->data;
1387 if (element && element->gst) {
1388 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(pre_element->gst), GST_ELEMENT(element->gst))) {
1389 _mmcam_dbg_log("Link [%s] to [%s] OK",
1390 GST_ELEMENT_NAME(GST_ELEMENT(pre_element->gst)),
1391 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)));
1393 _mmcam_dbg_err("Link [%s] to [%s] FAILED",
1394 GST_ELEMENT_NAME(GST_ELEMENT(pre_element->gst)),
1395 GST_ELEMENT_NAME(GST_ELEMENT(element->gst)));
1400 pre_element = element;
1401 local_list = local_list->next;
1408 gboolean _mmcamcorder_resize_frame(unsigned char *src_data, unsigned int src_width, unsigned int src_height, unsigned int src_length, int src_format,
1409 unsigned char **dst_data, unsigned int *dst_width, unsigned int *dst_height, unsigned int *dst_length)
1412 int mm_ret = MM_ERROR_NONE;
1413 int input_format = MM_UTIL_IMG_FMT_YUV420;
1414 unsigned char *dst_tmp_data = NULL;
1416 if (!src_data || !dst_data || !dst_width || !dst_height || !dst_length) {
1417 _mmcam_dbg_err("something is NULL %p,%p,%p,%p,%p",
1418 src_data, dst_data, dst_width, dst_height, dst_length);
1422 /* set input format for mm-util */
1423 switch (src_format) {
1424 case MM_PIXEL_FORMAT_I420:
1425 input_format = MM_UTIL_IMG_FMT_I420;
1427 case MM_PIXEL_FORMAT_YV12:
1428 input_format = MM_UTIL_IMG_FMT_YUV420;
1430 case MM_PIXEL_FORMAT_NV12:
1431 input_format = MM_UTIL_IMG_FMT_NV12;
1433 case MM_PIXEL_FORMAT_YUYV:
1434 input_format = MM_UTIL_IMG_FMT_YUYV;
1436 case MM_PIXEL_FORMAT_UYVY:
1437 input_format = MM_UTIL_IMG_FMT_UYVY;
1439 case MM_PIXEL_FORMAT_RGB888:
1440 input_format = MM_UTIL_IMG_FMT_RGB888;
1443 _mmcam_dbg_err("NOT supported format", src_format);
1447 _mmcam_dbg_log("src size %dx%d -> dst size %dx%d",
1448 src_width, src_height, *dst_width, *dst_height);
1450 /* get length of resized image */
1451 mm_ret = mm_util_get_image_size(input_format, *dst_width, *dst_height, dst_length);
1452 if (mm_ret != MM_ERROR_NONE) {
1453 GST_ERROR("mm_util_get_image_size failed 0x%x", ret);
1457 _mmcam_dbg_log("dst_length : %d", *dst_length);
1459 dst_tmp_data = (unsigned char *)malloc(*dst_length);
1460 if (dst_tmp_data == NULL) {
1461 _mmcam_dbg_err("failed to alloc dst_thumb_size(size %d)", *dst_length);
1465 mm_ret = mm_util_resize_image(src_data, src_width, src_height, input_format,
1466 dst_tmp_data, dst_width, dst_height);
1467 if (mm_ret != MM_ERROR_NONE) {
1468 GST_ERROR("mm_util_resize_image failed 0x%x", ret);
1473 *dst_data = dst_tmp_data;
1475 _mmcam_dbg_log("resize done %p, %dx%d", *dst_data, *dst_width, *dst_height);
1481 gboolean _mmcamcorder_encode_jpeg(void *src_data, unsigned int src_width, unsigned int src_height,
1482 int src_format, unsigned int src_length, unsigned int jpeg_quality,
1483 void **result_data, unsigned int *result_length, int enc_type)
1487 guint32 src_fourcc = 0;
1488 gboolean do_encode = FALSE;
1489 jpegenc_parameter enc_param;
1490 jpegenc_info enc_info;
1492 _mmcam_dbg_log("START - enc_type [%d]", enc_type);
1494 mmf_return_val_if_fail(src_data && result_data && result_length, FALSE);
1499 camsrcjpegenc_get_info(&enc_info);
1501 src_fourcc = _mmcamcorder_get_fourcc(src_format, 0, FALSE);
1502 camsrcjpegenc_get_src_fmt(src_fourcc, &(enc_param.src_fmt));
1504 if (enc_param.src_fmt == COLOR_FORMAT_NOT_SUPPORT) {
1505 _mmcam_dbg_err("Not Supported FOURCC(format:%d)", src_format);
1509 /* check H/W encoder */
1510 if (enc_info.hw_support && enc_type == JPEG_ENCODER_HARDWARE) {
1511 _mmcam_dbg_log("check H/W encoder supported format list");
1512 /* Check supported format */
1513 for (i = 0 ; i < enc_info.hw_enc.input_fmt_num ; i++) {
1514 if (enc_param.src_fmt == enc_info.hw_enc.input_fmt_list[i]) {
1521 enc_type = JPEG_ENCODER_HARDWARE;
1525 /* check S/W encoder */
1526 if (!do_encode && enc_info.sw_support) {
1527 _mmcam_dbg_log("check S/W encoder supported format list");
1528 /* Check supported format */
1529 for (i = 0 ; i < enc_info.sw_enc.input_fmt_num ; i++) {
1530 if (enc_param.src_fmt == enc_info.sw_enc.input_fmt_list[i]) {
1537 enc_type = JPEG_ENCODER_SOFTWARE;
1542 enc_param.src_data = src_data;
1543 enc_param.width = src_width;
1544 enc_param.height = src_height;
1545 enc_param.src_len = src_length;
1546 enc_param.jpeg_mode = JPEG_MODE_BASELINE;
1547 enc_param.jpeg_quality = jpeg_quality;
1549 _mmcam_dbg_log("%ux%u, size %u, quality %u, type %d",
1550 src_width, src_height, src_length,
1551 jpeg_quality, enc_type);
1553 ret = camsrcjpegenc_encode(&enc_info, enc_type, &enc_param );
1554 if (ret == CAMSRC_JPEGENC_ERROR_NONE) {
1555 *result_data = enc_param.result_data;
1556 *result_length = enc_param.result_len;
1558 _mmcam_dbg_log("JPEG encode length(%d)", *result_length);
1562 _mmcam_dbg_err("camsrcjpegenc_encode failed(%x)", ret);
1567 _mmcam_dbg_err("No encoder supports %d format", src_format);
1573 /* make UYVY smaller as multiple size. ex: 640x480 -> 320x240 or 160x120 ... */
1574 gboolean _mmcamcorder_downscale_UYVYorYUYV(unsigned char *src, unsigned int src_width, unsigned int src_height,
1575 unsigned char **dst, unsigned int dst_width, unsigned int dst_height)
1581 int ratio_width = 0;
1582 int ratio_height = 0;
1586 unsigned char *result = NULL;
1588 if (src == NULL || dst == NULL) {
1589 _mmcam_dbg_err("src[%p] or dst[%p] is NULL", src, dst);
1593 result = (unsigned char *)malloc((dst_width * dst_height)<<1);
1595 _mmcam_dbg_err("failed to alloc dst data");
1599 ratio_width = src_width / dst_width;
1600 ratio_height = src_height / dst_height;
1601 line_width = src_width << 1;
1602 jump_width = ratio_width << 1;
1604 _mmcam_dbg_warn("[src %dx%d] [dst %dx%d] [line width %d] [ratio width %d, height %d]",
1605 src_width, src_height, dst_width, dst_height,
1606 line_width, ratio_width, ratio_height);
1608 for (i = 0 ; i < src_height ; i += ratio_height) {
1609 line_base = i * line_width;
1610 for (j = 0 ; j < line_width ; j += jump_width) {
1611 src_index = line_base + j;
1612 result[k++] = src[src_index];
1613 result[k++] = src[src_index+1];
1616 src_index = line_base + j;
1617 if (src_index % 4 == 0) {
1618 result[k++] = src[src_index+2];
1620 result[k++] = src[src_index];
1622 result[k++] = src[src_index+1];
1628 _mmcam_dbg_warn("converting done - result %p", result);
1633 gboolean _mmcamcorder_check_file_path(const gchar *path)
1635 if(strstr(path, "/opt/usr") != NULL) {
1641 static guint16 get_language_code(const char *str)
1643 return (guint16) (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F);
1646 static gchar * str_to_utf8(const gchar *str)
1648 return g_convert (str, -1, "UTF-8", "ASCII", NULL, NULL, NULL);
1651 static inline gboolean write_tag(FILE *f, const gchar *tag)
1654 FPUTC_CHECK(*tag++, f);
1659 static inline gboolean write_to_32(FILE *f, guint val)
1661 FPUTC_CHECK(val >> 24, f);
1662 FPUTC_CHECK(val >> 16, f);
1663 FPUTC_CHECK(val >> 8, f);
1664 FPUTC_CHECK(val, f);
1668 static inline gboolean write_to_16(FILE *f, guint val)
1670 FPUTC_CHECK(val >> 8, f);
1671 FPUTC_CHECK(val, f);
1675 static inline gboolean write_to_24(FILE *f, guint val)
1677 write_to_16(f, val >> 8);
1678 FPUTC_CHECK(val, f);
1682 void *_mmcamcorder_util_task_thread_func(void *data)
1684 int ret = MM_ERROR_NONE;
1685 mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *)data;
1688 _mmcam_dbg_err("handle is NULL");
1692 _mmcam_dbg_warn("start thread");
1694 pthread_mutex_lock(&(hcamcorder->task_thread_lock));
1696 while (hcamcorder->task_thread_state != _MMCAMCORDER_TASK_THREAD_STATE_EXIT) {
1697 switch (hcamcorder->task_thread_state) {
1698 case _MMCAMCORDER_TASK_THREAD_STATE_NONE:
1699 _mmcam_dbg_warn("wait for task signal");
1700 pthread_cond_wait(&(hcamcorder->task_thread_cond), &(hcamcorder->task_thread_lock));
1701 _mmcam_dbg_warn("task signal received : state %d", hcamcorder->task_thread_state);
1703 case _MMCAMCORDER_TASK_THREAD_STATE_SOUND_PLAY_START:
1704 _mmcamcorder_sound_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE, FALSE);
1705 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
1707 case _MMCAMCORDER_TASK_THREAD_STATE_ENCODE_PIPE_CREATE:
1708 ret = _mmcamcorder_video_prepare_record((MMHandleType)hcamcorder);
1710 /* Play record start sound */
1711 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_FILEPATH_REC_START_SND, FALSE);
1713 _mmcam_dbg_log("_mmcamcorder_video_prepare_record return 0x%x", ret);
1714 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
1717 _mmcam_dbg_warn("invalid task thread state %d", hcamcorder->task_thread_state);
1718 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_EXIT;
1723 pthread_mutex_unlock(&(hcamcorder->task_thread_lock));
1725 _mmcam_dbg_warn("exit thread");