From c958b0a9e3a03d5fb4e8dc2531cd5e3e4ce5ffa8 Mon Sep 17 00:00:00 2001 From: Andrey Shelest Date: Mon, 16 Jun 2014 17:12:03 +0300 Subject: [PATCH] Updated to version 0.7.16 from tizendev Change-Id: Ia950d1ca013a6a7bc57781fa0406840db220aadc --- configure.ac | 12 +- mm-camcorder.pc.in | 4 +- packaging/libmm-camcorder.spec | 4 +- src/Makefile.am | 4 +- src/include/mm_camcorder_internal.h | 3 +- src/include/mm_camcorder_stillshot.h | 2 +- src/include/mm_camcorder_util.h | 8 +- src/mm_camcorder_attribute.c | 12 +- src/mm_camcorder_audiorec.c | 160 +++++++++++------------ src/mm_camcorder_configure.c | 16 +-- src/mm_camcorder_gstcommon.c | 149 ++++++++++++++-------- src/mm_camcorder_internal.c | 32 ++--- src/mm_camcorder_stillshot.c | 138 ++++++++++++-------- src/mm_camcorder_util.c | 29 +++-- src/mm_camcorder_videorec.c | 237 ++++++++++++++++++++++------------- test/mm_camcorder_testsuite.c | 2 +- 16 files changed, 475 insertions(+), 337 deletions(-) diff --git a/configure.ac b/configure.ac index 70256e9..ac59835 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ(2.52) -AC_INIT([libmm-camcorder], [1.0]) +AC_INIT([libmm-camcorder], [0.8.0]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_CONFIG_HEADERS([config.h:config.hin]) AC_CONFIG_MACRO_DIR([m4]) @@ -23,17 +23,17 @@ AC_PROG_GCC_TRADITIONAL AC_PROG_LIBTOOL # Checks for libraries. -PKG_CHECK_MODULES(GST, gstreamer-0.10 >= 0.10) +PKG_CHECK_MODULES(GST, gstreamer-1.0 >= 1.2.0) AC_SUBST(GST_CFLAGS) AC_SUBST(GST_LIBS) -PKG_CHECK_MODULES(GST_PLUGIN_BASE, gstreamer-base-0.10 >= 0.10) +PKG_CHECK_MODULES(GST_PLUGIN_BASE, gstreamer-base-1.0 >= 1.2.0) AC_SUBST(GST_PLUGIN_BASE_CFLAGS) AC_SUBST(GST_PLUGIN_BASE_LIBS) -PKG_CHECK_MODULES(GST_INTERFACES, gstreamer-interfaces-0.10 >= 0.10) -AC_SUBST(GST_INTERFACES_CFLAGS) -AC_SUBST(GST_INTERFACES_LIBS) +PKG_CHECK_MODULES(GST_VIDEO, gstreamer-video-1.0 >= 1.2.0) +AC_SUBST(GST_VIDEO_CFLAGS) +AC_SUBST(GST_VIDEO_LIBS) #PKG_CHECK_MODULES(GTK, gtk+-2.0) #AC_SUBST(GTK_CFLAGS) diff --git a/mm-camcorder.pc.in b/mm-camcorder.pc.in index fb785ee..5300a65 100644 --- a/mm-camcorder.pc.in +++ b/mm-camcorder.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: mm-camcorder Description: Multimedia Framework Camcorder Library -Requires: gstreamer-0.10 gstreamer-base-0.10 mm-common mm-log libexif mm-ta -Version: $VERSION +Requires: gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 mm-common mm-log libexif mm-ta +Version: @VERSION@ Libs: -L${libdir} -lmmfcamcorder Cflags: -I${includedir}/ -I${includedir}/mmf diff --git a/packaging/libmm-camcorder.spec b/packaging/libmm-camcorder.spec index 50d2776..c6452c2 100644 --- a/packaging/libmm-camcorder.spec +++ b/packaging/libmm-camcorder.spec @@ -1,6 +1,6 @@ Name: libmm-camcorder Summary: Camera and recorder library -Version: 0.7.11 +Version: 0.7.16 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 @@ -14,7 +14,7 @@ BuildRequires: pkgconfig(avsystem) BuildRequires: pkgconfig(libexif) BuildRequires: pkgconfig(mmutil-imgp) BuildRequires: pkgconfig(mm-log) -BuildRequires: pkgconfig(gstreamer-plugins-base-0.10) +BuildRequires: pkgconfig(gstreamer-plugins-base-1.0) BuildRequires: pkgconfig(mm-ta) BuildRequires: pkgconfig(sndfile) BuildRequires: pkgconfig(mm-session) diff --git a/src/Makefile.am b/src/Makefile.am index 1b04dfd..aa9e918 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,7 +35,7 @@ libmmfcamcorder_la_SOURCES = mm_camcorder.c \ libmmfcamcorder_la_CFLAGS = -I$(srcdir)/include \ $(GST_CFLAGS) \ $(GST_PLUGIN_BASE_CFLAGS) \ - $(GST_INTERFACES_CFLAGS) \ + $(GST_VIDEO_CFLAGS) \ $(MM_LOG_CFLAGS) \ $(MMTA_CFLAGS) \ $(EXIF_CFLAGS) \ @@ -52,7 +52,7 @@ libmmfcamcorder_la_CFLAGS = -I$(srcdir)/include \ libmmfcamcorder_la_LIBADD = \ $(GST_LIBS) \ $(GST_PLUGIN_BASE_LIBS) \ - $(GST_INTERFACES_LIBS) \ + $(GST_VIDEO_LIBS) \ $(MM_COMMON_LIBS) \ $(MM_LOG_LIBS) \ $(MMTA_LIBS) \ diff --git a/src/include/mm_camcorder_internal.h b/src/include/mm_camcorder_internal.h index fbd080f..2881d7b 100644 --- a/src/include/mm_camcorder_internal.h +++ b/src/include/mm_camcorder_internal.h @@ -38,6 +38,7 @@ #include #include #include +#include #include "mm_camcorder.h" #include "mm_debug.h" @@ -574,7 +575,7 @@ typedef struct { int pass_first_vframe; /**< When this value is bigger than zero, MSL won't drop video frame though "drop_vframe" is bigger then zero. */ /* INI information */ - unsigned int fourcc; /**< Get fourcc value of camera INI file */ + gchar format_name[sizeof(GST_VIDEO_FORMATS_ALL)]; /**< Get format value of camera INI file */ _MMCamcorderImageInfo *info_image; /**< extra information for image capture */ _MMCamcorderVideoInfo *info_video; /**< extra information for video recording */ _MMCamcorderAudioInfo *info_audio; /**< extra information for audio recording */ diff --git a/src/include/mm_camcorder_stillshot.h b/src/include/mm_camcorder_stillshot.h index 58525a8..b2bb2ff 100644 --- a/src/include/mm_camcorder_stillshot.h +++ b/src/include/mm_camcorder_stillshot.h @@ -144,7 +144,7 @@ int _mmcamcorder_set_resize_property(MMHandleType handle, int capture_width, int /* Function for capture */ int __mmcamcorder_set_exif_basic_info(MMHandleType handle, int image_width, int image_height); void __mmcamcorder_init_stillshot_info(MMHandleType handle); -void __mmcamcorder_get_capture_data_from_buffer(MMCamcorderCaptureDataType *capture_data, int pixtype, GstBuffer *buffer); +void __mmcamcorder_get_capture_data_from_buffer(MMCamcorderCaptureDataType *capture_data, int pixtype, GstSample *sample); void __mmcamcorder_release_jpeg_data(MMHandleType handle, MMCamcorderCaptureDataType *dest); int __mmcamcorder_capture_save_exifinfo(MMHandleType handle, MMCamcorderCaptureDataType *original, MMCamcorderCaptureDataType *thumbnail); int __mmcamcorder_set_jpeg_data(MMHandleType handle, MMCamcorderCaptureDataType *dest, MMCamcorderCaptureDataType *thumbnail); diff --git a/src/include/mm_camcorder_util.h b/src/include/mm_camcorder_util.h index 284be2b..67333c4 100644 --- a/src/include/mm_camcorder_util.h +++ b/src/include/mm_camcorder_util.h @@ -52,7 +52,7 @@ do { \ } else { \ item->object = G_OBJECT(x_pad); \ item->category = x_category; \ - item->handler_id = gst_pad_add_buffer_probe(x_pad, G_CALLBACK(x_callback), x_hcamcorder); \ + item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_BUFFER, x_callback, x_hcamcorder, NULL); \ x_hcamcorder->buffer_probes = g_list_append(x_hcamcorder->buffer_probes, item); \ _mmcam_dbg_log("Adding buffer probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \ } \ @@ -70,7 +70,7 @@ do { \ } else { \ item->object =G_OBJECT(x_pad); \ item->category = x_category; \ - item->handler_id = gst_pad_add_event_probe(x_pad, G_CALLBACK(x_callback), x_hcamcorder); \ + item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, x_callback, x_hcamcorder, NULL); \ x_hcamcorder->event_probes = g_list_append(x_hcamcorder->event_probes, item); \ _mmcam_dbg_log("Adding event probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \ } \ @@ -87,7 +87,7 @@ do { \ } else { \ item->object =G_OBJECT(x_pad); \ item->category = x_category; \ - item->handler_id = gst_pad_add_data_probe(x_pad, G_CALLBACK(x_callback), x_hcamcorder); \ + item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_DATA_BOTH, x_callback, x_hcamcorder, NULL); \ x_hcamcorder->data_probes = g_list_append(x_hcamcorder->data_probes, item); \ _mmcam_dbg_log("Adding data probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \ } \ @@ -276,7 +276,7 @@ gboolean _mmcamcroder_send_message(MMHandleType handle, _MMCamcorderMsgItem *dat void _mmcamcroder_remove_message_all(MMHandleType handle); /* Pixel format */ -int _mmcamcorder_get_pixel_format(GstBuffer *buffer); +int _mmcamcorder_get_pixel_format(GstCaps *pad); int _mmcamcorder_get_pixtype(unsigned int fourcc); unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format); diff --git a/src/mm_camcorder_attribute.c b/src/mm_camcorder_attribute.c index 4dfeef6..816fcb5 100644 --- a/src/mm_camcorder_attribute.c +++ b/src/mm_camcorder_attribute.c @@ -25,9 +25,9 @@ =======================================================================================*/ #include "mm_camcorder_internal.h" -#include -#include -#include +#include +#include +#include /*----------------------------------------------------------------------- | MACRO DEFINITIONS: | @@ -3214,7 +3214,7 @@ bool _mmcamcorder_commit_display_handle(MMHandleType handle, int attr_idx, const if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) { _mmcam_dbg_log("Commit : Set XID[%x]", *(int*)(p_handle)); - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), *(int*)(p_handle)); + gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), *(int*)(p_handle)); } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) { _mmcam_dbg_log("Commit : Set evas object [%p]", p_handle); @@ -4060,8 +4060,8 @@ static bool __mmcamcorder_set_camera_resolution(MMHandleType handle, int width, } } - caps = gst_caps_new_simple("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, sc->fourcc, + caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, sc->format_name, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, fps, 1, diff --git a/src/mm_camcorder_audiorec.c b/src/mm_camcorder_audiorec.c index 754a72e..ffdfb91 100644 --- a/src/mm_camcorder_audiorec.c +++ b/src/mm_camcorder_audiorec.c @@ -39,13 +39,13 @@ #define _MMCAMCORDER_AUDIO_MARGIN_SPACE (1*1024) #define _MMCAMCORDER_RETRIAL_COUNT 10 #define _MMCAMCORDER_FRAME_WAIT_TIME 20000 /* micro second */ -#define _MMCAMCORDER_FREE_SPACE_CHECK_INTERVAL 10 +#define _MMCAMCORDER_FREE_SPACE_CHECK_INTERVAL 5 /*--------------------------------------------------------------------------------------- | LOCAL FUNCTION PROTOTYPES: | ---------------------------------------------------------------------------------------*/ /* STATIC INTERNAL FUNCTION */ -static gboolean __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstBuffer *buffer, gpointer u_data); -static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buffer, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static int __mmcamcorder_create_audiop_with_encodebin(MMHandleType handle); static void __mmcamcorder_audiorec_pad_added_cb(GstElement *element, GstPad *pad, MMHandleType handle); @@ -256,7 +256,7 @@ static int __mmcamcorder_create_audiop_with_encodebin(MMHandleType handle) */ bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst)); hcamcorder->pipeline_cb_event_id = gst_bus_add_watch( bus, (GstBusFunc)_mmcamcorder_pipeline_cb_message, hcamcorder ); - gst_bus_set_sync_handler(bus, gst_bus_sync_signal_handler, hcamcorder); + gst_bus_set_sync_handler(bus, gst_bus_sync_signal_handler, hcamcorder, NULL); gst_object_unref(bus); return MM_ERROR_NONE; @@ -410,7 +410,7 @@ _mmcamcorder_audio_command(MMHandleType handle, int command) char *temp_filename = NULL; if(sc->pipeline_time) { - gst_pipeline_set_new_stream_time(GST_PIPELINE(pipeline), sc->pipeline_time); + gst_element_set_start_time(GST_ELEMENT(pipeline), sc->pipeline_time); } sc->pipeline_time = RESET_PAUSE_TIME; @@ -456,33 +456,26 @@ _mmcamcorder_audio_command(MMHandleType handle, int command) info->max_time = ((guint64)imax_time) * 1000; /* to millisecond */ } -/* - //set data probe function - gst_pad_add_buffer_probe(gst_element_get_pad(sc->element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "src"), - G_CALLBACK(__mmcamcorder_audio_dataprobe_voicerecorder), - hcamcorder); -*/ -/* TODO : check free space before recording start, need to more discussion */ -#if 1 dir_name = g_path_get_dirname(info->filename); - err = _mmcamcorder_get_freespace(dir_name, &free_space); - if((err == -1) || free_space <= (_MMCAMCORDER_AUDIO_MINIMUM_SPACE+(5*1024))) - { - _mmcam_dbg_err("No more space for recording - %s : [%" G_GUINT64_FORMAT "]\n ", dir_name, free_space); - if(dir_name) - { - g_free(dir_name); - dir_name = NULL; - } - return MM_MESSAGE_CAMCORDER_NO_FREE_SPACE; - } - if(dir_name) - { + if (dir_name) { + err = _mmcamcorder_get_freespace(dir_name, &free_space); + + _mmcam_dbg_warn("current space for recording - %s : [%" G_GUINT64_FORMAT "]", + dir_name, free_space); + g_free(dir_name); dir_name = NULL; + } else { + _mmcam_dbg_err("failed to get directory name"); + err = -1; + } + + if ((err == -1) || free_space <= (_MMCAMCORDER_AUDIO_MINIMUM_SPACE+(5*1024))) { + _mmcam_dbg_err("OUT of STORAGE [err:%d or free space [%" G_GUINT64_FORMAT "] is smaller than [%d]", + err, free_space, (_MMCAMCORDER_AUDIO_MINIMUM_SPACE+(5*1024))); + return MM_ERROR_OUT_OF_STORAGE; } -#endif - } + } ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING); if(ret<0) { @@ -815,8 +808,7 @@ __mmcamcorder_get_decibel(unsigned char* raw, int size, MMCamcorderAudioFormat f } -static gboolean -__mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); double volume = 0.0; @@ -826,6 +818,8 @@ __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstBuffer *buffer, gpoi _MMCamcorderMsgItem msg; int err = MM_ERROR_UNKNOWN; char *err_name = NULL; + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); + GstMapInfo mapinfo = GST_MAP_INFO_INIT; mmf_return_val_if_fail(hcamcorder, FALSE); @@ -843,12 +837,17 @@ __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstBuffer *buffer, gpoi } if(volume == 0) //mute - memset (GST_BUFFER_DATA(buffer), 0, GST_BUFFER_SIZE(buffer)); + { + gst_buffer_map(buffer, &mapinfo, GST_MAP_WRITE); + memset(mapinfo.data, 0, mapinfo.size); + gst_buffer_unmap(buffer, &mapinfo); + } /* Get current volume level of real input stream */ + gst_buffer_map(buffer, &mapinfo, GST_MAP_READ); // currms = __mmcamcorder_get_RMS(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer), depth); __ta__( "__mmcamcorder_get_decibel", - curdcb = __mmcamcorder_get_decibel(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer), format); + curdcb = __mmcamcorder_get_decibel(mapinfo.data, mapinfo.size, format); ); msg.id = MM_MESSAGE_CAMCORDER_CURRENT_VOLUME; @@ -856,14 +855,15 @@ __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstBuffer *buffer, gpoi _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); /* CALL audio stream callback */ - if ((hcamcorder->astream_cb) && buffer && GST_BUFFER_DATA(buffer)) + if ((hcamcorder->astream_cb) && buffer && mapinfo.data && mapinfo.size > 0) { MMCamcorderAudioStreamDataType stream; if (_mmcamcorder_get_state((MMHandleType)hcamcorder) < MM_CAMCORDER_STATE_PREPARE) { _mmcam_dbg_warn("Not ready for stream callback"); - return TRUE; + gst_buffer_unmap(buffer, &mapinfo); + return GST_PAD_PROBE_OK; } /* @@ -871,10 +871,10 @@ __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstBuffer *buffer, gpoi GST_BUFFER_DATA(buffer), format, channel, GST_BUFFER_SIZE(buffer), curdcb); */ - stream.data = (void *)GST_BUFFER_DATA(buffer); + stream.data = mapinfo.data; stream.format = format; stream.channel = channel; - stream.length = GST_BUFFER_SIZE(buffer); + stream.length = mapinfo.size; stream.timestamp = (unsigned int)(GST_BUFFER_TIMESTAMP(buffer)/1000000); //nano -> msecond stream.volume_dB = curdcb; @@ -887,8 +887,9 @@ __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad, GstBuffer *buffer, gpoi _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK( hcamcorder ); } + gst_buffer_unmap(buffer, &mapinfo); - return TRUE; + return GST_PAD_PROBE_OK; } @@ -913,7 +914,7 @@ __mmcamcorder_audiorec_pad_added_cb(GstElement *element, GstPad *pad, MMHandleT } -static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { static int count = 0; guint64 rec_pipe_time = 0; @@ -925,51 +926,52 @@ static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buf _MMCamcorderSubContext *sc = NULL; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); - _MMCamcorderAudioInfo *info = NULL; + _MMCamcorderAudioInfo *audioinfo = NULL; _MMCamcorderMsgItem msg; + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); mmf_return_val_if_fail(hcamcorder, FALSE); mmf_return_val_if_fail(buffer, FALSE); sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder); mmf_return_val_if_fail(sc && sc->info_audio, FALSE); - info = sc->info_audio; + audioinfo = sc->info_audio; if (sc->isMaxtimePausing || sc->isMaxsizePausing) { _mmcam_dbg_warn("isMaxtimePausing[%d],isMaxsizePausing[%d]", sc->isMaxtimePausing, sc->isMaxsizePausing); - return FALSE; + return GST_PAD_PROBE_DROP; } - buffer_size = (guint64)GST_BUFFER_SIZE(buffer); + buffer_size = gst_buffer_get_size(buffer); - if (info->filesize == 0) { - if (info->fileformat == MM_FILE_FORMAT_WAV) { - info->filesize += 44; /* wave header size */ - } else if (info->fileformat == MM_FILE_FORMAT_AMR) { - info->filesize += 6; /* amr header size */ + if (audioinfo->filesize == 0) { + if (audioinfo->fileformat == MM_FILE_FORMAT_WAV) { + audioinfo->filesize += 44; /* wave header size */ + } else if (audioinfo->fileformat == MM_FILE_FORMAT_AMR) { + audioinfo->filesize += 6; /* amr header size */ } - info->filesize += buffer_size; - return TRUE; + audioinfo->filesize += buffer_size; + return GST_PAD_PROBE_OK; } if (sc->ferror_send) { _mmcam_dbg_warn("file write error, drop frames"); - return FALSE; + return GST_PAD_PROBE_DROP; } /* get trailer size */ - if (info->fileformat == MM_FILE_FORMAT_3GP || - info->fileformat == MM_FILE_FORMAT_MP4 || - info->fileformat == MM_FILE_FORMAT_AAC) { + if (audioinfo->fileformat == MM_FILE_FORMAT_3GP || + audioinfo->fileformat == MM_FILE_FORMAT_MP4 || + audioinfo->fileformat == MM_FILE_FORMAT_AAC) { MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); /*_mmcam_dbg_log("trailer_size %d", trailer_size);*/ } else { trailer_size = 0; /* no trailer */ } - filename = info->filename; + filename = audioinfo->filename; /* to minimizing free space check overhead */ count = count % _MMCAMCORDER_FREE_SPACE_CHECK_INTERVAL; @@ -995,16 +997,16 @@ static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buf sc->ferror_count++; } - return FALSE; /* skip this buffer */ + return GST_PAD_PROBE_DROP; /* skip this buffer */ default: /* succeeded to get free space */ /* check free space for recording */ if (free_space < (guint64)(_MMCAMCORDER_AUDIO_MINIMUM_SPACE + buffer_size + trailer_size)) { _mmcam_dbg_warn("No more space for recording!!!"); _mmcam_dbg_warn("Free Space : [%" G_GUINT64_FORMAT "], file size : [%" G_GUINT64_FORMAT "]", - free_space, info->filesize); + free_space, audioinfo->filesize); - if (info->bMuxing) { + if (audioinfo->bMuxing) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); } else { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_AQUE].gst, "empty-buffers", TRUE); @@ -1014,7 +1016,7 @@ static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buf msg.id = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); - return FALSE; /* skip this buffer */ + return GST_PAD_PROBE_DROP; /* skip this buffer */ } break; } @@ -1028,11 +1030,11 @@ static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buf rec_pipe_time = GST_TIME_AS_MSECONDS(GST_BUFFER_TIMESTAMP(buffer)); /* calculate remained time can be recorded */ - if (info->max_time > 0 && info->max_time < (remained_time + rec_pipe_time)) { - remained_time = info->max_time - rec_pipe_time; - } else if (info->max_size > 0) { - long double max_size = (long double)info->max_size; - long double current_size = (long double)(info->filesize + buffer_size + trailer_size); + if (audioinfo->max_time > 0 && audioinfo->max_time < (remained_time + rec_pipe_time)) { + remained_time = audioinfo->max_time - rec_pipe_time; + } else if (audioinfo->max_size > 0) { + long double max_size = (long double)audioinfo->max_size; + long double current_size = (long double)(audioinfo->filesize + buffer_size + trailer_size); remained_time = (unsigned long long)((long double)rec_pipe_time * (max_size/current_size)) - rec_pipe_time; } @@ -1040,14 +1042,14 @@ static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buf /*_mmcam_dbg_log("remained time : %u", remained_time);*/ /* check max size of recorded file */ - if (info->max_size > 0 && - info->max_size < info->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE) { + if (audioinfo->max_size > 0 && + audioinfo->max_size < audioinfo->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE) { _mmcam_dbg_warn("Max size!!! Recording is paused."); _mmcam_dbg_warn("Max [%" G_GUINT64_FORMAT "], file [%" G_GUINT64_FORMAT "], trailer : [%" G_GUINT64_FORMAT "]", \ - info->max_size, info->filesize, trailer_size); + audioinfo->max_size, audioinfo->filesize, trailer_size); /* just same as pause status. After blocking two queue, this function will not call again. */ - if (info->bMuxing) { + if (audioinfo->bMuxing) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); } else { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_AQUE].gst, "empty-buffers", TRUE); @@ -1055,26 +1057,26 @@ static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buf msg.id = MM_MESSAGE_CAMCORDER_RECORDING_STATUS; msg.param.recording_status.elapsed = (unsigned long long)rec_pipe_time; - msg.param.recording_status.filesize = (unsigned long long)((info->filesize + trailer_size) >> 10); + msg.param.recording_status.filesize = (unsigned long long)((audioinfo->filesize + trailer_size) >> 10); msg.param.recording_status.remained_time = 0; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); - _mmcam_dbg_log("Last filesize sent by message : %d", info->filesize + trailer_size); + _mmcam_dbg_log("Last filesize sent by message : %d", audioinfo->filesize + trailer_size); sc->isMaxsizePausing = TRUE; msg.id = MM_MESSAGE_CAMCORDER_MAX_SIZE; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); /* skip this buffer */ - return FALSE; + return GST_PAD_PROBE_DROP; } /* check recording time limit and send recording status message */ - if (info->max_time > 0 && rec_pipe_time > info->max_time) { + if (audioinfo->max_time > 0 && rec_pipe_time > audioinfo->max_time) { _mmcam_dbg_warn("Current time : [%" G_GUINT64_FORMAT "], Maximum time : [%" G_GUINT64_FORMAT "]", \ - rec_pipe_time, info->max_time); + rec_pipe_time, audioinfo->max_time); - if (info->bMuxing) { + if (audioinfo->bMuxing) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); } else { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_AQUE].gst, "empty-buffers", TRUE); @@ -1085,22 +1087,22 @@ static gboolean __mmcamcorder_audio_dataprobe_record(GstPad *pad, GstBuffer *buf _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); /* skip this buffer */ - return FALSE; + return GST_PAD_PROBE_DROP; } /* send message for recording time and recorded file size */ - if (info->b_commiting == FALSE) { - info->filesize += buffer_size; + if (audioinfo->b_commiting == FALSE) { + audioinfo->filesize += buffer_size; msg.id = MM_MESSAGE_CAMCORDER_RECORDING_STATUS; msg.param.recording_status.elapsed = (unsigned long long)rec_pipe_time; - msg.param.recording_status.filesize = (unsigned long long)((info->filesize + trailer_size) >> 10); + msg.param.recording_status.filesize = (unsigned long long)((audioinfo->filesize + trailer_size) >> 10); msg.param.recording_status.remained_time = remained_time; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); - return TRUE; + return GST_PAD_PROBE_OK; } else { /* skip this buffer if commit process has been started */ - return FALSE; + return GST_PAD_PROBE_DROP; } } diff --git a/src/mm_camcorder_configure.c b/src/mm_camcorder_configure.c index ac05b02..0aeb36e 100644 --- a/src/mm_camcorder_configure.c +++ b/src/mm_camcorder_configure.c @@ -177,7 +177,7 @@ static type_element _recordsink_element_default = { */ static type_element _h263_element_default = { "H263", - "ffenc_h263", + "avenc_h263", NULL, 0, NULL, @@ -213,7 +213,7 @@ static type_element _h26l_element_default = { */ static type_element _mpeg4_element_default = { "MPEG4", - "ffenc_mpeg4", + "avenc_mpeg4", NULL, 0, NULL, @@ -225,7 +225,7 @@ static type_element _mpeg4_element_default = { */ static type_element _mpeg1_element_default = { "MPEG1", - "ffenc_mpeg1video", + "avenc_mpeg1video", NULL, 0, NULL, @@ -309,7 +309,7 @@ static type_element _mmf_element_default = { */ static type_element _adpcm_element_default = { "ADPCM", - "ffenc_adpcm_ima_qt", + "avenc_adpcm_ima_qt", NULL, 0, NULL, @@ -510,7 +510,7 @@ static type_element _xpm_element_default = { */ static type_element _3gp_element_default = { "3GP", - "ffmux_3gp", + "avmux_3gp", NULL, 0, NULL, @@ -522,7 +522,7 @@ static type_element _3gp_element_default = { */ static type_element _amrmux_element_default = { "AMR", - "ffmux_amr", + "avmux_amr", NULL, 0, NULL, @@ -534,7 +534,7 @@ static type_element _amrmux_element_default = { */ static type_element _mp4_element_default = { "MP4", - "ffmux_mp4", + "avmux_mp4", NULL, 0, NULL, @@ -642,7 +642,7 @@ static type_element _mid_element_default = { */ static type_element _mmfmux_element_default = { "MMF", - "ffmux_mmf", + "avmux_mmf", NULL, 0, NULL, diff --git a/src/mm_camcorder_gstcommon.c b/src/mm_camcorder_gstcommon.c index c943783..05c92ce 100644 --- a/src/mm_camcorder_gstcommon.c +++ b/src/mm_camcorder_gstcommon.c @@ -22,8 +22,9 @@ /*======================================================================================= | INCLUDE FILES | =======================================================================================*/ -#include -#include +#include +#include +#include #include #include @@ -139,7 +140,7 @@ gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_F * @remarks * @see __mmcamcorder_create_preview_pipeline() */ -static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *buffer, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate); @@ -165,6 +166,7 @@ int _mmcamcorder_create_videosrc_bin(MMHandleType handle) int anti_shake = 0; char *videosrc_name = NULL; char *err_name = NULL; + unsigned int pix_fourcc = 0; GList *element_list = NULL; GstCaps *caps = NULL; @@ -222,7 +224,9 @@ int _mmcamcorder_create_videosrc_bin(MMHandleType handle) } /* Get fourcc from picture format */ - sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format); + pix_fourcc= _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format); + strncpy(sc->format_name, (char*)&pix_fourcc, sizeof(pix_fourcc)); + sc->format_name[sizeof(pix_fourcc)] = '\0'; /* Get videosrc element and its name from configure */ _mmcamcorder_conf_get_element(hcamcorder->conf_main, @@ -309,8 +313,8 @@ int _mmcamcorder_create_videosrc_bin(MMHandleType handle) _mmcam_dbg_log("VideoSRC Scale[%dx%d], Method[%d]", set_width, set_height, scale_method); - caps = gst_caps_new_simple("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, sc->fourcc, + caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, sc->format_name, "width", G_TYPE_INT, set_width, "height", G_TYPE_INT, set_height, NULL); @@ -356,8 +360,8 @@ int _mmcamcorder_create_videosrc_bin(MMHandleType handle) goto pipeline_creation_error; } - video_tee0 = gst_element_get_request_pad(sc->element[_MMCAMCORDER_VIDEOSRC_TEE].gst, "src%d"); - video_tee1 = gst_element_get_request_pad(sc->element[_MMCAMCORDER_VIDEOSRC_TEE].gst, "src%d"); + video_tee0 = gst_element_get_request_pad(sc->element[_MMCAMCORDER_VIDEOSRC_TEE].gst, "src_%u"); + video_tee1 = gst_element_get_request_pad(sc->element[_MMCAMCORDER_VIDEOSRC_TEE].gst, "src_%u"); MMCAMCORDER_G_OBJECT_SET((sc->element[_MMCAMCORDER_VIDEOSRC_TEE].gst), "alloc-pad", video_tee0); @@ -529,6 +533,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle) /* Set basic infomation */ if (a_enc != MM_AUDIO_CODEC_VORBIS) { int depth = 0; + const gchar* format_name = NULL; if (volume == 0.0) { /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */ @@ -540,24 +545,25 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle) if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) { depth = 16; + format_name = "S16LE"; } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */ + format_name = "U8"; depth = 8; } - caps = gst_caps_new_simple("audio/x-raw-int", + caps = gst_caps_new_simple("audio/x-raw", "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channel, - "depth", G_TYPE_INT, depth, + "format", G_TYPE_STRING, format_name, NULL); _mmcam_dbg_log("caps [x-raw-int,rate:%d,channel:%d,depth:%d]", rate, channel, depth); } else { /* what are the audio encoder which should get audio/x-raw-float? */ - caps = gst_caps_new_simple("audio/x-raw-float", + caps = gst_caps_new_simple("audio/x-raw", "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channel, - "endianness", G_TYPE_INT, BYTE_ORDER, - "width", G_TYPE_INT, 32, + "format", G_TYPE_STRING, GST_AUDIO_NE(F32), NULL); _mmcam_dbg_log("caps [x-raw-float,rate:%d,channel:%d,endianness:%d,width:32]", rate, channel, BYTE_ORDER); @@ -690,10 +696,10 @@ int _mmcamcorder_create_videosink_bin(MMHandleType handle) !strcmp(videosink_name, "ximagesink")) { GstElementFactory *factory = gst_element_factory_find("fimcconvert"); - if ((sc->fourcc == GST_MAKE_FOURCC('S','N','2','1') || - sc->fourcc == GST_MAKE_FOURCC('S','N','1','2') || - sc->fourcc == GST_MAKE_FOURCC('S','T','1','2') || - sc->fourcc == GST_MAKE_FOURCC('S','4','2','0')) && + if ((strcmp(sc->format_name, "SN21") == 0 || + strcmp(sc->format_name, "SN12") == 0 || + strcmp(sc->format_name, "ST12") == 0 || + strcmp(sc->format_name, "S420") == 0) && factory) { int set_rotate = 0; int set_flip = 0; @@ -755,8 +761,8 @@ int _mmcamcorder_create_videosink_bin(MMHandleType handle) factory = NULL; } - __ta__(" videosink_ffmpegcolorspace", - _MMCAMCORDER_ELEMENT_MAKE(sc, _MMCAMCORDER_VIDEOSINK_CLS, "ffmpegcolorspace", NULL, element_list, err); + __ta__(" videosink_videoconvert", + _MMCAMCORDER_ELEMENT_MAKE(sc, _MMCAMCORDER_VIDEOSINK_CLS, "videoconvert", NULL, element_list, err); ); } } else if(UseVideoscale) { @@ -787,7 +793,7 @@ int _mmcamcorder_create_videosink_bin(MMHandleType handle) rect_height = camera_height; } - caps = gst_caps_new_simple("video/x-raw-yuv", + caps = gst_caps_new_simple("video/x-raw", "width", G_TYPE_INT, rect_width, "height", G_TYPE_INT, rect_height, NULL); @@ -992,15 +998,15 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin /* set color convert plugin */ if (hcamcorder->use_zero_copy_format && - sc->fourcc != GST_MAKE_FOURCC('S','N','1','2')) { + strcmp(sc->format_name,"SN12") != 0) { int dst_buffer_num = _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM; /* set fimcconvert as colorspace element */ MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", "fimcconvert"); _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err); - caps = gst_caps_new_simple("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('S','N','1','2'), + caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, "SN12", NULL); if (caps) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", caps); @@ -1029,6 +1035,13 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin if (sc->audio_disable == FALSE && profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) { int use_aenc_queue =0; + const gchar* int_formats = "{S8, U8, " + "S16LE, S16BE, U16LE, U16BE, " + "S24_32LE, S24_32BE, U24_32LE, U24_32BE, " + "S32LE, S32BE, U32LE, U32BE, " + "S24LE, S24BE, U24LE, U24BE, " + "S20LE, S20BE, U20LE, U20BE, " + "S18LE, S18BE, U18LE, U18BE}"; AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER); if (!AudioencElement) { @@ -1043,8 +1056,9 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err); if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) { - caps = gst_caps_new_simple("audio/x-raw-int", + caps = gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, 1, + "format", G_TYPE_STRING, int_formats, NULL); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", caps); @@ -1053,8 +1067,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin } if (audio_enc == MM_AUDIO_CODEC_OGG) { - caps = gst_caps_new_simple("audio/x-raw-int", - NULL); + caps = gst_caps_new_simple("audio/x-raw", "format", G_TYPE_STRING, int_formats, NULL); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", caps); gst_caps_unref (caps); @@ -1062,12 +1075,21 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin _mmcam_dbg_log("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int "); } + //AAC is marked as experimental, + //so compliance level must be set accordingly + if (audio_enc == MM_AUDIO_CODEC_AAC) + { + MMCAMCORDER_G_OBJECT_SET( sc->element[_MMCAMCORDER_ENCSINK_AENC].gst, "compliance", -2); + } + _mmcamcorder_conf_get_value_int(hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, "UseAudioEncoderQueue", &use_aenc_queue); if (use_aenc_queue) { _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst,"max-size-time",G_GUINT64_CONSTANT(0)); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst,"max-size-buffers",0); } } @@ -1472,7 +1494,7 @@ int _mmcamcorder_create_preview_pipeline(MMHandleType handle) hcamcorder->pipeline_cb_event_id = gst_bus_add_watch(bus, _mmcamcorder_pipeline_cb_message, (gpointer)hcamcorder); /* set sync handler */ - gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder); + gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL); gst_object_unref(bus); bus = NULL; @@ -1540,7 +1562,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX; int origin_size = 0; int zoom_attr = 0; - int zoom_level = 0; + float zoom_level = 0; int do_scaling = FALSE; int *overlay = NULL; gulong xid; @@ -1591,10 +1613,10 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi if (overlay) { xid = *overlay; _mmcam_dbg_log("xid = %lu )", xid); - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(vsink), xid); + gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid); } else { _mmcam_dbg_warn("Handle is NULL. Set xid as 0.. but, it's not recommended."); - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(vsink), 0); + gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0); } _mmcam_dbg_log("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[enum:%d]", @@ -1750,17 +1772,25 @@ gboolean _mmcamcorder_get_device_info(MMHandleType handle) return TRUE; } +static guint32 _mmcamcorder_convert_fourcc_to_string(const gchar* format_name) +{ + return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24); +} -static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { int current_state = MM_CAMCORDER_STATE_NONE; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); _MMCamcorderSubContext *sc = NULL; _MMCamcorderKPIMeasure *kpi = NULL; + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); + GstMemory *dataBlock = NULL; + GstMemory *metaBlock = NULL; + GstMapInfo mapinfo = GST_MAP_INFO_INIT; mmf_return_val_if_fail(buffer, FALSE); - mmf_return_val_if_fail(GST_BUFFER_DATA(buffer), FALSE); + mmf_return_val_if_fail(gst_buffer_n_memory(buffer) , FALSE); mmf_return_val_if_fail(hcamcorder, TRUE); sc = MMF_CAMCORDER_SUBCONTEXT(u_data); @@ -1775,12 +1805,12 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu } else { sc->drop_vframe--; _mmcam_dbg_log("Drop video frame by drop_vframe"); - return FALSE; + return GST_PAD_PROBE_DROP; } } else if (sc->cam_stability_count > 0) { sc->cam_stability_count--; _mmcam_dbg_log("Drop video frame by cam_stability_count"); - return FALSE; + return GST_PAD_PROBE_DROP; } if (current_state >= MM_CAMCORDER_STATE_PREPARE) { @@ -1828,13 +1858,13 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu state = _mmcamcorder_get_state((MMHandleType)hcamcorder); if (state < MM_CAMCORDER_STATE_PREPARE) { _mmcam_dbg_warn("Not ready for stream callback"); - return TRUE; + return GST_PAD_PROBE_OK; } - caps = gst_buffer_get_caps(buffer); + caps = gst_pad_get_current_caps(pad); if (caps == NULL) { _mmcam_dbg_warn( "Caps is NULL." ); - return TRUE; + return GST_PAD_PROBE_OK; } /* clear stream data structure */ @@ -1843,7 +1873,7 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu structure = gst_caps_get_structure( caps, 0 ); gst_structure_get_int(structure, "width", &(stream.width)); gst_structure_get_int(structure, "height", &(stream.height)); - gst_structure_get_fourcc(structure, "format", &fourcc); + fourcc = _mmcamcorder_convert_fourcc_to_string(gst_structure_get_string(structure, "format")); stream.format = _mmcamcorder_get_pixtype(fourcc); gst_caps_unref( caps ); caps = NULL; @@ -1855,17 +1885,20 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu if (stream.width == 0 || stream.height == 0) { _mmcam_dbg_warn("Wrong condition!!"); - return TRUE; + return GST_PAD_PROBE_OK; } /* set size and timestamp */ - stream.length_total = GST_BUFFER_SIZE(buffer); + dataBlock = gst_buffer_peek_memory(buffer, 0); + stream.length_total = gst_memory_get_sizes(dataBlock, NULL, NULL); stream.timestamp = (unsigned int)(GST_BUFFER_TIMESTAMP(buffer)/1000000); /* nano sec -> mili sec */ /* set data pointers */ if (stream.format == MM_PIXEL_FORMAT_NV12 || stream.format == MM_PIXEL_FORMAT_I420) { - if (hcamcorder->use_zero_copy_format && GST_BUFFER_MALLOCDATA(buffer)) { - SCMN_IMGB *scmn_imgb = (SCMN_IMGB *)GST_BUFFER_MALLOCDATA(buffer); + if (hcamcorder->use_zero_copy_format && gst_buffer_n_memory(buffer) > 1) { + metaBlock = gst_buffer_peek_memory(buffer, 1); + gst_memory_map(metaBlock, &mapinfo, GST_MAP_READ); + SCMN_IMGB *scmn_imgb = (SCMN_IMGB *)mapinfo.data; if (stream.format == MM_PIXEL_FORMAT_NV12) { stream.data_type = MM_CAM_STREAM_DATA_YUV420SP; @@ -1899,7 +1932,8 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu if (stream.format == MM_PIXEL_FORMAT_NV12) { stream.data_type = MM_CAM_STREAM_DATA_YUV420SP; stream.num_planes = 2; - stream.data.yuv420sp.y = GST_BUFFER_DATA(buffer); + gst_memory_map(dataBlock, &mapinfo, GST_MAP_READ); + stream.data.yuv420sp.y = mapinfo.data; stream.data.yuv420sp.length_y = stream.width * stream.height; stream.data.yuv420sp.uv = stream.data.yuv420sp.y + stream.data.yuv420sp.length_y; stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 1; @@ -1911,7 +1945,8 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu } else { stream.data_type = MM_CAM_STREAM_DATA_YUV420P; stream.num_planes = 3; - stream.data.yuv420p.y = GST_BUFFER_DATA(buffer); + gst_memory_map(dataBlock, &mapinfo, GST_MAP_READ); + stream.data.yuv420p.y = mapinfo.data; stream.data.yuv420p.length_y = stream.width * stream.height; stream.data.yuv420p.u = stream.data.yuv420p.y + stream.data.yuv420p.length_y; stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2; @@ -1931,11 +1966,13 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu stream.format == MM_PIXEL_FORMAT_422P || stream.format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) { stream.data_type = MM_CAM_STREAM_DATA_YUV422; - stream.data.yuv422.yuv = GST_BUFFER_DATA(buffer); + gst_memory_map(dataBlock, &mapinfo, GST_MAP_READ); + stream.data.yuv422.yuv = mapinfo.data; stream.data.yuv422.length_yuv = stream.length_total; } else { stream.data_type = MM_CAM_STREAM_DATA_YUV420; - stream.data.yuv420.yuv = GST_BUFFER_DATA(buffer); + gst_memory_map(dataBlock, &mapinfo, GST_MAP_READ); + stream.data.yuv420.yuv = mapinfo.data; stream.data.yuv420.length_yuv = stream.length_total; } @@ -1952,6 +1989,13 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param); } _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder); + + /* Either metaBlock was mapped, or dataBlock, but not both. */ + if (metaBlock) { + gst_memory_unmap(metaBlock, &mapinfo); + } else { + gst_memory_unmap(dataBlock, &mapinfo); + } } /* Do force flush cache */ @@ -1959,7 +2003,7 @@ static gboolean __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstBuffer *bu MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "force-flush-cache", FALSE); } - return TRUE; + return GST_PAD_PROBE_OK; } @@ -2303,7 +2347,7 @@ bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate /* correct size because ITLV does not support QCIF */ if (input_index->default_value == MM_VIDEO_DEVICE_CAMERA0 && - sc->fourcc == GST_MAKE_FOURCC('I','T','L','V')) { + strcmp(sc->format_name, "ITLV") == 0) { if ((set_width == 176 && set_height == 144) || (set_width == 144 && set_height == 176)) { set_width = set_width << 1; @@ -2348,8 +2392,8 @@ bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate } if (do_set_caps) { - caps = gst_caps_new_simple("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, sc->fourcc, + caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, sc->format_name, "width", G_TYPE_INT, set_width, "height", G_TYPE_INT, set_height, "framerate", GST_TYPE_FRACTION, fps, 1, @@ -2358,9 +2402,8 @@ bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps); gst_caps_unref(caps); caps = NULL; - _mmcam_dbg_log("vidoesrc new caps set. format[%c%c%c%c],width[%d],height[%d],fps[%d],rotate[%d]", - (sc->fourcc), (sc->fourcc)>>8, (sc->fourcc)>>16, (sc->fourcc)>>24, - set_width, set_height, fps, set_rotate); + _mmcam_dbg_log("vidoesrc new caps set. format[%s],width[%d],height[%d],fps[%d],rotate[%d]", + sc->format_name, set_width, set_height, fps, set_rotate); } return TRUE; diff --git a/src/mm_camcorder_internal.c b/src/mm_camcorder_internal.c index bc1b1f1..78c26ae 100644 --- a/src/mm_camcorder_internal.c +++ b/src/mm_camcorder_internal.c @@ -32,8 +32,8 @@ #include "mm_camcorder_internal.h" #include -#include -#include +#include +#include #include #include @@ -2379,7 +2379,7 @@ _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type) sc->element[i].gst = NULL; } - sc->fourcc = 0x80000000; + memset(sc->format_name, '\0', sizeof(sc->format_name)); sc->cam_stability_count = 0; sc->drop_vframe = 0; sc->pass_first_vframe = 0; @@ -2532,7 +2532,7 @@ gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpoi if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst) { pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst; if (message->src == (GstObject*)pipeline) { - vnewstate = (GValue*)gst_structure_get_value(message->structure, "new-state"); + vnewstate = (GValue*)gst_structure_get_value(gst_message_get_structure(message), "new-state"); newstate = (GstState)vnewstate->data[0].v_int; _mmcam_dbg_log("GST_MESSAGE_STATE_CHANGED[%s]",gst_element_state_get_name(newstate)); } @@ -2571,30 +2571,30 @@ gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpoi case GST_MESSAGE_ELEMENT: _mmcam_dbg_log("GST_MESSAGE_ELEMENT"); - if (gst_structure_has_name(message->structure, "avsysvideosrc-AF") || - gst_structure_has_name(message->structure, "camerasrc-AF")) { + if (gst_structure_has_name(gst_message_get_structure(message), "avsysvideosrc-AF") || + gst_structure_has_name(gst_message_get_structure(message), "camerasrc-AF")) { int focus_state = 0; - gst_structure_get_int(message->structure, "focus-state", &focus_state); + gst_structure_get_int(gst_message_get_structure(message), "focus-state", &focus_state); _mmcam_dbg_log("Focus State:%d", focus_state); msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED; msg.param.code = focus_state; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); - } else if (gst_structure_has_name(message->structure, "camerasrc-HDR")) { + } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) { int progress = 0; int status = 0; - gst_structure_get_int(message->structure, "progress", &progress); - gst_structure_get_int(message->structure, "status", &status); + gst_structure_get_int(gst_message_get_structure(message), "progress", &progress); + gst_structure_get_int(gst_message_get_structure(message), "status", &status); _mmcam_dbg_log("HDR progress %d percent, status %d", progress, status); msg.id = MM_MESSAGE_CAMCORDER_HDR_PROGRESS; msg.param.code = progress; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); - } else if (gst_structure_has_name(message->structure, "camerasrc-FD")) { + } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) { int i = 0; - const GValue *g_value = gst_structure_get_value(message->structure, "face-info");; + const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");; GstCameraControlFaceDetectInfo *fd_info = NULL; MMCamFaceDetectInfo *cam_fd_info = NULL; @@ -2712,8 +2712,6 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder); mmf_return_val_if_fail(sc, GST_BUS_PASS); - sc->error_code = MM_ERROR_NONE; - if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) { /* parse error message */ gst_message_parse_error(message, &err, &debug_info); @@ -3015,6 +3013,12 @@ int _mmcamcorder_create_pipeline(MMHandleType handle, int type) } #endif _mmcam_dbg_log("ret[%x]", ret); + + if (ret != MM_ERROR_NONE) { + _mmcam_dbg_err("error : destroy pipeline"); + _mmcamcorder_destroy_pipeline(handle, hcamcorder->type); + } + return ret; } diff --git a/src/mm_camcorder_stillshot.c b/src/mm_camcorder_stillshot.c index 84c433d..74c7120 100644 --- a/src/mm_camcorder_stillshot.c +++ b/src/mm_camcorder_stillshot.c @@ -24,7 +24,7 @@ =======================================================================================*/ #include #include -#include +#include #include #include "mm_camcorder_internal.h" #include "mm_camcorder_stillshot.h" @@ -59,7 +59,7 @@ int _mmcamcorder_image_cmd_capture(MMHandleType handle); int _mmcamcorder_image_cmd_preview_start(MMHandleType handle); int _mmcamcorder_image_cmd_preview_stop(MMHandleType handle); -static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffer1, GstBuffer *buffer2, GstBuffer *buffer3, gpointer u_data); +static void __mmcamcorder_image_capture_cb(GstElement *element, GstSample *sample1, GstSample *sample2, GstSample *sample3, gpointer u_data); /* Function for JPEG capture with Encode bin */ static gboolean __mmcamcorder_encodesink_handoff_callback(GstElement *fakesink, GstBuffer *buffer, GstPad *pad, gpointer u_data); @@ -471,8 +471,8 @@ int _mmcamcorder_image_cmd_capture(MMHandleType handle) set_height = info->height; } - caps = gst_caps_new_simple("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, sc->fourcc, + caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, sc->format_name, "width", G_TYPE_INT, set_width, "height", G_TYPE_INT, set_height, "framerate", GST_TYPE_FRACTION, fps, 1, @@ -672,8 +672,8 @@ int _mmcamcorder_image_cmd_preview_start(MMHandleType handle) break; } - caps = gst_caps_new_simple("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, sc->fourcc, + caps = gst_caps_new_simple("video/x-raw", + "format", G_TYPE_STRING, sc->format_name, "width", G_TYPE_INT, set_width, "height", G_TYPE_INT,set_height, "framerate", GST_TYPE_FRACTION, fps, 1, @@ -1002,14 +1002,15 @@ int __mmcamcorder_capture_save_exifinfo(MMHandleType handle, MMCamcorderCaptureD } -void __mmcamcorder_get_capture_data_from_buffer(MMCamcorderCaptureDataType *capture_data, int pixtype, GstBuffer *buffer) +void __mmcamcorder_get_capture_data_from_buffer(MMCamcorderCaptureDataType *capture_data, int pixtype, GstSample *sample) { GstCaps *caps = NULL; + GstMapInfo mapinfo = GST_MAP_INFO_INIT; const GstStructure *structure; - mmf_return_if_fail(capture_data && buffer); + mmf_return_if_fail(capture_data && sample); - caps = gst_buffer_get_caps(buffer); + caps = gst_sample_get_caps(sample); if (caps == NULL) { _mmcam_dbg_err("failed to get caps"); goto GET_FAILED; @@ -1021,18 +1022,17 @@ void __mmcamcorder_get_capture_data_from_buffer(MMCamcorderCaptureDataType *capt goto GET_FAILED; } - capture_data->data = GST_BUFFER_DATA(buffer); + gst_buffer_map(gst_sample_get_buffer(sample), &mapinfo, GST_MAP_READ); + capture_data->data = mapinfo.data; capture_data->format = pixtype; gst_structure_get_int(structure, "width", &capture_data->width); gst_structure_get_int(structure, "height", &capture_data->height); - capture_data->length = GST_BUFFER_SIZE(buffer); + capture_data->length = mapinfo.size; + gst_buffer_unmap(gst_sample_get_buffer(sample), &mapinfo); _mmcam_dbg_warn("buffer data[%p],size[%dx%d],length[%d],format[%d]", capture_data->data, capture_data->width, capture_data->height, capture_data->length, capture_data->format); - gst_caps_unref(caps); - caps = NULL; - return; GET_FAILED: @@ -1105,7 +1105,7 @@ void __mmcamcorder_release_jpeg_data(MMHandleType handle, MMCamcorderCaptureData } -static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffer1, GstBuffer *buffer2, GstBuffer *buffer3, gpointer u_data) +static void __mmcamcorder_image_capture_cb(GstElement *element, GstSample *sample1, GstSample *sample2, GstSample *sample3, gpointer u_data) { int ret = MM_ERROR_NONE; int pixtype = MM_PIXEL_FORMAT_INVALID; @@ -1128,6 +1128,9 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe MMCamcorderCaptureDataType dest = {0,}; MMCamcorderCaptureDataType thumb = {0,}; MMCamcorderCaptureDataType scrnail = {0,}; + GstMapInfo mapinfo1; + GstMapInfo mapinfo2; + GstMapInfo mapinfo3; mmf_attrs_t *attrs = NULL; mmf_attribute_t *item_screennail = NULL; @@ -1159,14 +1162,20 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe MMTA_ACUM_ITEM_END(" MSL capture callback", FALSE); /*free GstBuffer*/ - if (buffer1) { - gst_buffer_unref(buffer1); + if (sample1) { + gst_caps_unref(gst_sample_get_caps(sample1)); + gst_buffer_unref(gst_sample_get_buffer(sample1)); + gst_sample_unref(sample1); } - if (buffer2) { - gst_buffer_unref(buffer2); + if (sample2) { + gst_caps_unref(gst_sample_get_caps(sample2)); + gst_buffer_unref(gst_sample_get_buffer(sample2)); + gst_sample_unref(sample2); } - if (buffer3) { - gst_buffer_unref(buffer3); + if (sample3) { + gst_caps_unref(gst_sample_get_caps(sample3)); + gst_buffer_unref(gst_sample_get_buffer(sample3)); + gst_sample_unref(sample3); } return; @@ -1212,7 +1221,7 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe memset((void *)&scrnail, 0x0, sizeof(MMCamcorderCaptureDataType)); /* Prepare main, thumbnail buffer */ - pixtype = _mmcamcorder_get_pixel_format(buffer1); + pixtype = _mmcamcorder_get_pixel_format(gst_sample_get_caps(sample1)); if (pixtype == MM_PIXEL_FORMAT_INVALID) { _mmcam_dbg_err("Unsupported pixel type"); @@ -1222,11 +1231,13 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe } /* Main image buffer */ - if (buffer1 && GST_BUFFER_DATA(buffer1) && (GST_BUFFER_SIZE(buffer1) !=0)) { - __mmcamcorder_get_capture_data_from_buffer(&dest, pixtype, buffer1); + gst_buffer_map(gst_sample_get_buffer(sample1), &mapinfo1, GST_MAP_READ); + if (sample1 && mapinfo1.data && (mapinfo1.size !=0)) { + __mmcamcorder_get_capture_data_from_buffer(&dest, pixtype, sample1); } else { - _mmcam_dbg_err("buffer1 has wrong pointer. (buffer1=%p)",buffer1); + _mmcam_dbg_err("Sample1 has wrong pointer. (sample1=%p)",sample1); MMCAM_SEND_MESSAGE(hcamcorder, MM_MESSAGE_CAMCORDER_ERROR, MM_ERROR_CAMCORDER_INTERNAL); + gst_buffer_unmap(gst_sample_get_buffer(sample1), &mapinfo1); goto error; } @@ -1245,10 +1256,11 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe _mmcam_dbg_log("Start Internal Encode - capture_quality %d", capture_quality); __ta__(" _mmcamcorder_encode_jpeg:MAIN", - ret = _mmcamcorder_encode_jpeg(GST_BUFFER_DATA(buffer1), dest.width, dest.height, + ret = _mmcamcorder_encode_jpeg(mapinfo1.data, dest.width, dest.height, pixtype, dest.length, capture_quality, &(dest.data), &(dest.length)); ); - if (!ret) { + + if (!ret) { _mmcam_dbg_err("_mmcamcorder_encode_jpeg failed"); MMCAM_SEND_MESSAGE(hcamcorder, MM_MESSAGE_CAMCORDER_ERROR, MM_ERROR_CAMCORDER_INTERNAL); @@ -1280,7 +1292,7 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe _mmcam_dbg_log("need to resize : thumbnail size %dx%d", thumb_width, thumb_height); - if (!_mmcamcorder_resize_frame(GST_BUFFER_DATA(buffer1), dest.width, dest.height, GST_BUFFER_SIZE(buffer1), pixtype, + if (!_mmcamcorder_resize_frame(mapinfo1.data, dest.width, dest.height, GST_BUFFER_SIZE(buffer1), pixtype, &thumb_raw_data, &thumb_width, &thumb_height, &thumb_length)) { thumb_raw_data = NULL; _mmcam_dbg_warn("_mmcamcorder_resize_frame failed. skip thumbnail making..."); @@ -1291,7 +1303,7 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe _mmcam_dbg_log("NO need to resize : thumbnail size %dx%d", thumb_width, thumb_height); - thumb_raw_data = GST_BUFFER_DATA(buffer1); + thumb_raw_data = mapinfo1.data; } if (thumb_raw_data) { @@ -1309,7 +1321,7 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe _mmcam_dbg_warn("failed to encode THUMBNAIL"); } - if (thumb_raw_data != GST_BUFFER_DATA(buffer1)) { + if (thumb_raw_data != mapinfo1.data) { free(thumb_raw_data); thumb_raw_data = NULL; _mmcam_dbg_log("release thumb_raw_data"); @@ -1318,16 +1330,19 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe _mmcam_dbg_warn("thumb_raw_data is NULL"); } #endif /* _MMCAMCORDER_MAKE_THUMBNAIL_INTERNAL_ENCODE */ + gst_buffer_unmap(gst_sample_get_buffer(sample1), &mapinfo1); } else { + gst_buffer_map(gst_sample_get_buffer(sample2), &mapinfo2, GST_MAP_READ); /* Thumbnail image buffer */ - if (buffer2 && GST_BUFFER_DATA(buffer2) && (GST_BUFFER_SIZE(buffer2) !=0)) { - _mmcam_dbg_log("Thumnail (buffer2=%p)",buffer2); + if (sample2 && mapinfo2.data && (mapinfo2.size !=0)) { + _mmcam_dbg_log("Thumnail (sample2=%p)",sample2); - pixtype_sub = _mmcamcorder_get_pixel_format(buffer2); - __mmcamcorder_get_capture_data_from_buffer(&thumb, pixtype_sub, buffer2); + pixtype_sub = _mmcamcorder_get_pixel_format(gst_sample_get_caps(sample2)); + __mmcamcorder_get_capture_data_from_buffer(&thumb, pixtype_sub, sample2); } else { - _mmcam_dbg_log("buffer2 has wrong pointer. Not Error. (buffer2=%p)",buffer2); + _mmcam_dbg_log("Sample2 has wrong pointer. Not Error. (sample2=%p)",sample2); } + gst_buffer_unmap(gst_sample_get_buffer(sample2), &mapinfo2); } /* Screennail image buffer */ @@ -1335,19 +1350,21 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstBuffer *buffe mm_attrs_get_index((MMHandleType)attrs, MMCAM_CAPTURED_SCREENNAIL, &attr_index); item_screennail = &attrs->items[attr_index]; - if (buffer3 && GST_BUFFER_DATA(buffer3) && GST_BUFFER_SIZE(buffer3) != 0) { - _mmcam_dbg_log("Screennail (buffer3=%p,size=%d)", buffer3, GST_BUFFER_SIZE(buffer3)); + gst_buffer_map(gst_sample_get_buffer(sample3), &mapinfo3, GST_MAP_READ); + if (sample3 && mapinfo3.data && mapinfo3.size != 0) { + _mmcam_dbg_log("Screennail (sample3=%p,size=%d)", sample3, mapinfo3.size); - pixtype_sub = _mmcamcorder_get_pixel_format(buffer3); - __mmcamcorder_get_capture_data_from_buffer(&scrnail, pixtype_sub, buffer3); + pixtype_sub = _mmcamcorder_get_pixel_format(gst_sample_get_caps(sample3)); + __mmcamcorder_get_capture_data_from_buffer(&scrnail, pixtype_sub, sample3); /* Set screennail attribute for application */ ret = mmf_attribute_set_data(item_screennail, &scrnail, sizeof(scrnail)); _mmcam_dbg_log("Screennail set attribute data %p, size %d, ret %x", &scrnail, sizeof(scrnail), ret); } else { - _mmcam_dbg_log("buffer3 has wrong pointer. Not Error. (buffer3=%p)",buffer3); + _mmcam_dbg_log("Sample3 has wrong pointer. Not Error. (sample3=%p)",sample3); mmf_attribute_set_data(item_screennail, NULL, 0); } + gst_buffer_unmap(gst_sample_get_buffer(sample3), &mapinfo3); /* commit screennail data */ mmf_attribute_commit(item_screennail); @@ -1498,15 +1515,21 @@ error: } /*free GstBuffer*/ - if (buffer1) { - gst_buffer_unref(buffer1); - } - if (buffer2) { - gst_buffer_unref(buffer2); - } - if (buffer3) { - gst_buffer_unref(buffer3); - } + if (sample1) { + gst_caps_unref(gst_sample_get_caps(sample1)); + gst_buffer_unref(gst_sample_get_buffer(sample1)); + gst_sample_unref(sample1); + } + if (sample2) { + gst_caps_unref(gst_sample_get_caps(sample2)); + gst_buffer_unref(gst_sample_get_buffer(sample2)); + gst_sample_unref(sample2); + } + if (sample3) { + gst_caps_unref(gst_sample_get_caps(sample3)); + gst_buffer_unref(gst_sample_get_buffer(sample3)); + gst_sample_unref(sample3); + } /* destroy exif info */ __ta__(" mm_exif_destory_exif_info", @@ -1554,9 +1577,9 @@ static gboolean __mmcamcorder_encodesink_handoff_callback(GstElement *fakesink, mmf_return_val_if_fail(sc && sc->element, FALSE); _mmcam_dbg_log(""); - /* FIXME. How could you get a thumbnail? */ - __mmcamcorder_image_capture_cb(fakesink, buffer, NULL, NULL, u_data); + + __mmcamcorder_image_capture_cb(fakesink, gst_sample_new(buffer, gst_pad_get_current_caps(pad), NULL, NULL), NULL, NULL, u_data); if (sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_SINK].gst, "signal-handoffs", FALSE); @@ -2032,6 +2055,9 @@ int __mmcamcorder_set_exif_basic_info(MMHandleType handle, int image_width, int /*21. EXIF_TAG_EXPOSURE_BIAS_VALUE*/ value = 0; + MMCamAttrsInfo info; + mm_camcorder_get_attribute_info(handle, MMCAM_FILTER_BRIGHTNESS, &info); + ret = mm_camcorder_get_attributes(handle, NULL, MMCAM_FILTER_BRIGHTNESS, &value, NULL); if (ret == MM_ERROR_NONE) { unsigned char *b = NULL; @@ -2041,8 +2067,14 @@ int __mmcamcorder_set_exif_basic_info(MMHandleType handle, int image_width, int b = malloc(sizeof(ExifSRational)); if (b) { - rsData.numerator = value - 5; - rsData.denominator = 10; + if( info.int_range.min < info.int_range.max) { + rsData.numerator = (value - 4) * 5; + rsData.denominator = 10; + } + else { + rsData.numerator = 0; + rsData.denominator = 10; + } exif_set_srational(b, exif_data_get_byte_order(ed), rsData); ret = mm_exif_set_add_entry(ed, EXIF_IFD_EXIF, EXIF_TAG_EXPOSURE_BIAS_VALUE, EXIF_FORMAT_SRATIONAL, 1, b); diff --git a/src/mm_camcorder_util.c b/src/mm_camcorder_util.c index 88381ba..a8916e2 100644 --- a/src/mm_camcorder_util.c +++ b/src/mm_camcorder_util.c @@ -24,8 +24,10 @@ =======================================================================================*/ #include #include +#include #include #include /* struct statfs */ +#include #include "mm_camcorder_internal.h" #include "mm_camcorder_util.h" @@ -388,7 +390,7 @@ void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCa { _mmcam_dbg_log("Remove buffer probe on [%s:%s] - [ID : %lu], [Category : %x]", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); - gst_pad_remove_buffer_probe(GST_PAD(item->object), item->handler_id); + gst_pad_remove_probe(GST_PAD(item->object), item->handler_id); } else { @@ -446,7 +448,7 @@ void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCat { _mmcam_dbg_log("Remove event probe on [%s:%s] - [ID : %lu], [Category : %x]", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); - gst_pad_remove_event_probe(GST_PAD(item->object), item->handler_id); + gst_pad_remove_probe(GST_PAD(item->object), item->handler_id); } else { @@ -504,7 +506,7 @@ void _mmcamcorder_remove_data_probe(MMHandleType handle, _MMCamcorderHandlerCate { _mmcam_dbg_log("Remove data probe on [%s:%s] - [ID : %lu], [Category : %x]", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); - gst_pad_remove_data_probe(GST_PAD(item->object), item->handler_id); + gst_pad_remove_probe(GST_PAD(item->object), item->handler_id); } else { @@ -832,18 +834,16 @@ _mmcamcorder_err_trace_write( char *str_filename, char *func_name, int line_num, fclose( f ); } -int -_mmcamcorder_get_pixel_format(GstBuffer *buffer) +int _mmcamcorder_get_pixel_format(GstCaps *caps) { - GstCaps *caps = NULL; const GstStructure *structure; const char *media_type; + GstVideoInfo media_info; MMPixelFormatType type = 0; unsigned int fourcc = 0; - mmf_return_val_if_fail( buffer != NULL, MM_PIXEL_FORMAT_INVALID ); + mmf_return_val_if_fail( caps != NULL, MM_PIXEL_FORMAT_INVALID ); - caps = gst_buffer_get_caps (buffer); structure = gst_caps_get_structure (caps, 0); media_type = gst_structure_get_name (structure); @@ -852,10 +852,12 @@ _mmcamcorder_get_pixel_format(GstBuffer *buffer) _mmcam_dbg_log("It is jpeg."); type = MM_PIXEL_FORMAT_ENCODED; } - else if (!strcmp (media_type, "video/x-raw-yuv")) + else if (!strcmp (media_type, "video/x-raw") + && gst_video_info_from_caps(&media_info, caps) + && GST_VIDEO_INFO_IS_YUV(&media_info)) { _mmcam_dbg_log("It is yuv."); - gst_structure_get_fourcc (structure, "format", &fourcc); + fourcc = gst_video_format_to_fourcc(GST_VIDEO_INFO_FORMAT(&media_info)); type = _mmcamcorder_get_pixtype(fourcc); } else @@ -866,9 +868,6 @@ _mmcamcorder_get_pixel_format(GstBuffer *buffer) _mmcam_dbg_log( "Type [%d]", type ); - gst_caps_unref( caps ); - caps = NULL; - return type; } @@ -1127,7 +1126,7 @@ gboolean _mmcamcorder_resize_frame(unsigned char *src_data, int src_width, int s /* get length of resized image */ __ta__(" mm_util_get_image_size 2", - mm_ret = mm_util_get_image_size(input_format, *dst_width, *dst_height, dst_length); + mm_ret = mm_util_get_image_size(input_format, *dst_width, *dst_height, (unsigned int*)dst_length); ); if (mm_ret != MM_ERROR_NONE) { GST_ERROR("mm_util_get_image_size failed 0x%x", ret); @@ -1144,7 +1143,7 @@ gboolean _mmcamcorder_resize_frame(unsigned char *src_data, int src_width, int s __ta__(" mm_util_resize_image", mm_ret = mm_util_resize_image(src_data, src_width, src_height, input_format, - dst_tmp_data, dst_width, dst_height); + dst_tmp_data, (unsigned int*)dst_width, (unsigned int*)dst_height); ); if (mm_ret != MM_ERROR_NONE) { GST_ERROR("mm_util_resize_image failed 0x%x", ret); diff --git a/src/mm_camcorder_videorec.c b/src/mm_camcorder_videorec.c index 0a04eab..88a4c52 100644 --- a/src/mm_camcorder_videorec.c +++ b/src/mm_camcorder_videorec.c @@ -22,7 +22,7 @@ /*======================================================================================= | INCLUDE FILES | =======================================================================================*/ -#include +#include #include "mm_camcorder_internal.h" #include "mm_camcorder_videorec.h" @@ -45,14 +45,14 @@ | LOCAL FUNCTION PROTOTYPES: | ---------------------------------------------------------------------------------------*/ /* STATIC INTERNAL FUNCTION */ -static gboolean __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstBuffer *buffer, gpointer u_data); -static gboolean __mmcamcorder_video_dataprobe_record(GstPad *pad, GstBuffer *buffer, gpointer u_data); -static gboolean __mmcamcorder_audioque_dataprobe(GstPad *pad, GstBuffer *buffer, gpointer u_data); -static gboolean __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstBuffer *buffer, gpointer u_data); -static gboolean __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstBuffer *buffer, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static gboolean __mmcamcorder_add_locationinfo(MMHandleType handle, int fileformat); static gboolean __mmcamcorder_add_locationinfo_mp4(MMHandleType handle); -static gboolean __mmcamcorder_eventprobe_monitor(GstPad *pad, GstEvent *event, gpointer u_data); +static GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); /*======================================================================================= | FUNCTION DEFINITIONS | @@ -436,9 +436,9 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) if (_mmcamcorder_get_state((MMHandleType)hcamcorder) != MM_CAMCORDER_STATE_PAUSED) { guint imax_size = 0; guint imax_time = 0; - - /* Play record start sound */ - _mmcamcorder_sound_solo_play(handle, _MMCAMCORDER_FILEPATH_REC_START_SND, TRUE); + int ret_free_space = 0; + char *dir_name = NULL; + guint64 free_space = 0; /* Recording */ _mmcam_dbg_log("Record Start"); @@ -449,11 +449,18 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "flush-cache", TRUE); } + /* flush queue */ + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); + ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY); if (ret != MM_ERROR_NONE) { goto _ERR_CAMCORDER_VIDEO_COMMAND; } + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", FALSE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE); + _mmcamcorder_conf_get_value_int(hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, "DropVideoFrame", @@ -482,6 +489,29 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) goto _ERR_CAMCORDER_VIDEO_COMMAND; } + dir_name = g_path_get_dirname(temp_filename); + if (dir_name) { + ret_free_space = _mmcamcorder_get_freespace(dir_name, &free_space); + + _mmcam_dbg_warn("current space for recording - %s : [%" G_GUINT64_FORMAT "]", + dir_name, free_space); + + g_free(dir_name); + dir_name = NULL; + } else { + _mmcam_dbg_err("failed to get directory name"); + ret_free_space = -1; + } + + if ((ret_free_space == -1) || free_space <= (_MMCAMCORDER_MINIMUM_SPACE<<1)) { + _mmcam_dbg_err("OUT of STORAGE [ret_free_space:%d or free space [%" G_GUINT64_FORMAT "] is smaller than [%d]", + ret_free_space, free_space, (_MMCAMCORDER_MINIMUM_SPACE<<1)); + return MM_ERROR_OUT_OF_STORAGE; + } + + /* Play record start sound */ + _mmcamcorder_sound_solo_play(handle, _MMCAMCORDER_FILEPATH_REC_START_SND, TRUE); + /* set max size */ if (imax_size <= 0) { info->max_size = 0; /* do not check */ @@ -646,13 +676,18 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) return MM_ERROR_CAMCORDER_CMD_IS_RUNNING; } + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hold-af-after-capturing", FALSE); __ta__(" _MMCamcorder_CMD_CANCEL:GST_STATE_READY", ret =_mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY); ); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", FALSE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE); + if (ret != MM_ERROR_NONE) { goto _ERR_CAMCORDER_VIDEO_COMMAND; } @@ -754,7 +789,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) video = gst_element_get_static_pad(sc->element[_MMCAMCORDER_ENCSINK_VENC].gst, "src"); gst_pad_push_event (video, gst_event_new_flush_start()); - gst_pad_push_event (video, gst_event_new_flush_stop()); + gst_pad_push_event (video, gst_event_new_flush_stop(TRUE)); ret = gst_pad_push_event (video, gst_event_new_eos()); _mmcam_dbg_err("Sending EOS video encoder src pad : %d", ret); gst_object_unref(video); @@ -762,7 +797,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) if (sc->audio_disable == FALSE) { audio = gst_element_get_static_pad(sc->element[_MMCAMCORDER_ENCSINK_AENC].gst, "src"); gst_pad_push_event (audio, gst_event_new_flush_start()); - gst_pad_push_event (audio, gst_event_new_flush_stop()); + gst_pad_push_event (audio, gst_event_new_flush_stop(TRUE)); ret = gst_element_send_event(sc->element[_MMCAMCORDER_AUDIOSRC_SRC].gst, gst_event_new_eos()); _mmcam_dbg_err("Sending EOS audio encoder src pad : %d", ret); gst_object_unref(audio); @@ -857,6 +892,7 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) /* remove blocking part */ MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", FALSE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); mm_camcorder_get_attributes(handle, NULL, @@ -872,6 +908,7 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) } MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", FALSE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE); __ta__(" _MMCamcorder_CMD_COMMIT:__mmcamcorder_remove_recorder_pipeline", ret = _mmcamcorder_remove_recorder_pipeline((MMHandleType)hcamcorder); @@ -910,13 +947,13 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) _mmcam_dbg_log("Flush EOS event"); pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "sink"); gst_pad_push_event(pad, gst_event_new_flush_start()); - gst_pad_push_event(pad, gst_event_new_flush_stop()); + gst_pad_push_event(pad, gst_event_new_flush_stop(TRUE)); gst_object_unref(pad); pad = NULL; pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "src"); gst_pad_push_event(pad, gst_event_new_flush_start()); - gst_pad_push_event(pad, gst_event_new_flush_stop()); + gst_pad_push_event(pad, gst_event_new_flush_stop(TRUE)); gst_object_unref(pad); pad = NULL; @@ -989,8 +1026,9 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) * @remarks * @see */ -static gboolean __mmcamcorder_eventprobe_monitor(GstPad *pad, GstEvent *event, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { + GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info); switch (GST_EVENT_TYPE(event)) { case GST_EVENT_UNKNOWN: /* upstream events */ @@ -999,7 +1037,7 @@ static gboolean __mmcamcorder_eventprobe_monitor(GstPad *pad, GstEvent *event, g case GST_EVENT_NAVIGATION: case GST_EVENT_LATENCY: /* downstream serialized events */ - case GST_EVENT_NEWSEGMENT : + case GST_EVENT_SEGMENT : case GST_EVENT_TAG: case GST_EVENT_BUFFERSIZE: _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event)); @@ -1017,44 +1055,51 @@ static gboolean __mmcamcorder_eventprobe_monitor(GstPad *pad, GstEvent *event, g break; } - return TRUE; + return GST_PAD_PROBE_OK; } -static gboolean __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); + GstMapInfo mapinfo; + guint64 size; + gst_buffer_map(buffer, &mapinfo, GST_MAP_READ); + size = mapinfo.size; + gst_buffer_unmap(buffer, &mapinfo); + _MMCamcorderSubContext *sc = NULL; - _MMCamcorderVideoInfo *info = NULL; + _MMCamcorderVideoInfo *videoinfo = NULL; mmf_return_val_if_fail(hcamcorder, TRUE); mmf_return_val_if_fail(buffer, FALSE); sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder); mmf_return_val_if_fail(sc && sc->info_video, TRUE); - info = sc->info_video; + videoinfo = sc->info_video; /*_mmcam_dbg_err("[%" GST_TIME_FORMAT "]", GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(buffer)));*/ - if (info->audio_frame_count == 0) { - info->filesize += (guint64)GST_BUFFER_SIZE(buffer); - info->audio_frame_count++; - return TRUE; + if (videoinfo->audio_frame_count == 0) { + videoinfo->filesize += size; + videoinfo->audio_frame_count++; + return GST_PAD_PROBE_OK; } if (sc->ferror_send || sc->isMaxsizePausing) { _mmcam_dbg_warn("Recording is paused, drop frames"); - return FALSE; + return GST_PAD_PROBE_DROP; } - info->filesize += (guint64)GST_BUFFER_SIZE(buffer); - info->audio_frame_count++; + videoinfo->filesize += size; + videoinfo->audio_frame_count++; - return TRUE; + return GST_PAD_PROBE_OK; } -static gboolean __mmcamcorder_video_dataprobe_record(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { static int count = 0; gint ret = 0; @@ -1065,37 +1110,40 @@ static gboolean __mmcamcorder_video_dataprobe_record(GstPad *pad, GstBuffer *buf guint64 trailer_size = 0; guint64 queued_buffer = 0; char *filename = NULL; + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); + GstMapInfo mapinfo; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); _MMCamcorderMsgItem msg; _MMCamcorderSubContext *sc = NULL; - _MMCamcorderVideoInfo *info = NULL; + _MMCamcorderVideoInfo *videoinfo = NULL; mmf_return_val_if_fail(hcamcorder, TRUE); mmf_return_val_if_fail(buffer, FALSE); sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder); mmf_return_val_if_fail(sc && sc->info_video, TRUE); - info = sc->info_video; + videoinfo = sc->info_video; /*_mmcam_dbg_log("[%" GST_TIME_FORMAT "]", GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(buffer)));*/ if (sc->ferror_send) { _mmcam_dbg_warn("file write error, drop frames"); - return FALSE; + return GST_PAD_PROBE_DROP; } - info->video_frame_count++; - if (info->video_frame_count <= (guint64)_MMCAMCORDER_MINIMUM_FRAME) { + gst_buffer_map(buffer, &mapinfo, GST_MAP_READ); + buffer_size = mapinfo.size; + gst_buffer_unmap(buffer, &mapinfo); + videoinfo->video_frame_count++; + if (videoinfo->video_frame_count <= (guint64)_MMCAMCORDER_MINIMUM_FRAME) { /* _mmcam_dbg_log("Pass minimum frame: info->video_frame_count: %" G_GUINT64_FORMAT " ", info->video_frame_count); */ - info->filesize += (guint64)GST_BUFFER_SIZE(buffer); - return TRUE; + videoinfo->filesize += buffer_size; + return GST_PAD_PROBE_OK; } - buffer_size = GST_BUFFER_SIZE(buffer); - /* get trailer size */ - if (info->fileformat == MM_FILE_FORMAT_3GP || info->fileformat == MM_FILE_FORMAT_MP4) { + if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) { MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); } else { trailer_size = 0; @@ -1104,7 +1152,7 @@ static gboolean __mmcamcorder_video_dataprobe_record(GstPad *pad, GstBuffer *buf /* to minimizing free space check overhead */ count = count % _MMCAMCORDER_FREE_SPACE_CHECK_INTERVAL; if (count++ == 0) { - filename = info->filename; + filename = videoinfo->filename; ret = _mmcamcorder_get_freespace(filename, &free_space); /*_mmcam_dbg_log("check free space for recording");*/ @@ -1126,7 +1174,7 @@ static gboolean __mmcamcorder_video_dataprobe_record(GstPad *pad, GstBuffer *buf sc->ferror_count++; } - return FALSE; /* skip this buffer */ + return GST_PAD_PROBE_REMOVE; /* skip this buffer */ break; default: /* succeeded to get free space */ /* check free space for recording */ @@ -1155,21 +1203,21 @@ static gboolean __mmcamcorder_video_dataprobe_record(GstPad *pad, GstBuffer *buf _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); } - return FALSE; + return GST_PAD_PROBE_DROP; } break; } } /* check max size of recorded file */ - if (info->max_size > 0 && - info->max_size < info->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE) { + if (videoinfo->max_size > 0 && + videoinfo->max_size < videoinfo->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE) { GstState pipeline_state = GST_STATE_VOID_PENDING; GstElement *pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst; _mmcam_dbg_warn("Max size!!! Recording is paused."); _mmcam_dbg_warn("Max size : [%" G_GUINT64_FORMAT "], current file size : [%" G_GUINT64_FORMAT "]," \ " buffer size : [%" G_GUINT64_FORMAT "], trailer size : [%" G_GUINT64_FORMAT "]", - info->max_size, info->filesize, buffer_size, trailer_size); + videoinfo->max_size, videoinfo->filesize, buffer_size, trailer_size); if (!sc->isMaxsizePausing) { gst_element_get_state(pipeline, &pipeline_state, NULL, -1) ; @@ -1182,18 +1230,18 @@ static gboolean __mmcamcorder_video_dataprobe_record(GstPad *pad, GstBuffer *buf _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); } - return FALSE; + return GST_PAD_PROBE_DROP; } - info->filesize += (guint64)buffer_size; + videoinfo->filesize += buffer_size; - _mmcam_dbg_log("filesize %lld Byte, ", info->filesize); + _mmcam_dbg_log("filesize %lld Byte, ", videoinfo->filesize); - return TRUE; + return GST_PAD_PROBE_OK; } -static gboolean __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { guint64 trailer_size = 0; guint64 rec_pipe_time = 0; @@ -1204,7 +1252,9 @@ static gboolean __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstBuff mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); _MMCamcorderMsgItem msg; _MMCamcorderSubContext *sc = NULL; - _MMCamcorderVideoInfo *info = NULL; + _MMCamcorderVideoInfo *videoinfo = NULL; + + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); mmf_return_val_if_fail(buffer, FALSE); mmf_return_val_if_fail(hcamcorder, TRUE); @@ -1213,22 +1263,22 @@ static gboolean __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstBuff mmf_return_val_if_fail(sc, TRUE); mmf_return_val_if_fail(sc->info_video, TRUE); - info = sc->info_video; + videoinfo = sc->info_video; b_time = GST_BUFFER_TIMESTAMP(buffer); rec_pipe_time = GST_TIME_AS_MSECONDS(b_time); - if (info->fileformat == MM_FILE_FORMAT_3GP || info->fileformat == MM_FILE_FORMAT_MP4) { + if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) { MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); } else { trailer_size = 0; } /* check max time */ - if (info->max_time > 0 && rec_pipe_time > info->max_time) { + if (videoinfo->max_time > 0 && rec_pipe_time > videoinfo->max_time) { _mmcam_dbg_warn("Current time : [%" G_GUINT64_FORMAT "], Maximum time : [%" G_GUINT64_FORMAT "]", \ - rec_pipe_time, info->max_time); + rec_pipe_time, videoinfo->max_time); if (!sc->isMaxtimePausing) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); @@ -1237,7 +1287,7 @@ static gboolean __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstBuff msg.id = MM_MESSAGE_CAMCORDER_RECORDING_STATUS; msg.param.recording_status.elapsed = (unsigned long long)rec_pipe_time; - msg.param.recording_status.filesize = (unsigned long long)((info->filesize + trailer_size) >> 10); + msg.param.recording_status.filesize = (unsigned long long)((videoinfo->filesize + trailer_size) >> 10); msg.param.recording_status.remained_time = 0; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); @@ -1245,37 +1295,36 @@ static gboolean __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad, GstBuff _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); } - return FALSE; + return GST_PAD_PROBE_DROP; } /* calculate remained time can be recorded */ - if (info->max_time > 0 && info->max_time < (remained_time + rec_pipe_time)) { - remained_time = info->max_time - rec_pipe_time; - } else if (info->max_size > 0) { - long double max_size = (long double)info->max_size; - long double current_size = (long double)(info->filesize + trailer_size); + if (videoinfo->max_time > 0 && videoinfo->max_time < (remained_time + rec_pipe_time)) { + remained_time = videoinfo->max_time - rec_pipe_time; + } else if (videoinfo->max_size > 0) { + long double max_size = (long double)videoinfo->max_size; + long double current_size = (long double)(videoinfo->filesize + trailer_size); remained_time = (unsigned int)((long double)rec_pipe_time * (max_size/current_size)) - rec_pipe_time; } msg.id = MM_MESSAGE_CAMCORDER_RECORDING_STATUS; msg.param.recording_status.elapsed = (unsigned long long)rec_pipe_time; - msg.param.recording_status.filesize = (unsigned long long)((info->filesize + trailer_size) >> 10); + msg.param.recording_status.filesize = (unsigned long long)((videoinfo->filesize + trailer_size) >> 10); msg.param.recording_status.remained_time = remained_time; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); _mmcam_dbg_log("time [%" GST_TIME_FORMAT "], size [%d]", GST_TIME_ARGS(rec_pipe_time), msg.param.recording_status.filesize); - if (info->record_timestamp_ratio != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE) { - GST_BUFFER_TIMESTAMP(buffer) = b_time * (info->record_timestamp_ratio); + if (videoinfo->record_timestamp_ratio != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE) { + GST_BUFFER_TIMESTAMP(buffer) = b_time * (videoinfo->record_timestamp_ratio); } - return TRUE; + return GST_PAD_PROBE_OK; } - -static gboolean __mmcamcorder_audioque_dataprobe(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { _MMCamcorderMsgItem msg; guint64 trailer_size = 0; @@ -1283,8 +1332,9 @@ static gboolean __mmcamcorder_audioque_dataprobe(GstPad *pad, GstBuffer *buffer, _MMCamcorderSubContext *sc = NULL; GstElement *pipeline = NULL; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); - _MMCamcorderVideoInfo *info = NULL; + _MMCamcorderVideoInfo *videoinfo = NULL; unsigned int remained_time = 0; + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); mmf_return_val_if_fail(buffer, FALSE); mmf_return_val_if_fail(hcamcorder, TRUE); @@ -1294,35 +1344,35 @@ static gboolean __mmcamcorder_audioque_dataprobe(GstPad *pad, GstBuffer *buffer, mmf_return_val_if_fail(sc->info_video, TRUE); mmf_return_val_if_fail(sc->element, TRUE); - info = sc->info_video; + videoinfo = sc->info_video; pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst; if (!GST_CLOCK_TIME_IS_VALID(GST_BUFFER_TIMESTAMP(buffer))) { _mmcam_dbg_err( "Buffer timestamp is invalid, check it"); - return TRUE; + return GST_PAD_PROBE_OK; } rec_pipe_time = GST_TIME_AS_MSECONDS(GST_BUFFER_TIMESTAMP(buffer)); - if (info->fileformat == MM_FILE_FORMAT_3GP || info->fileformat == MM_FILE_FORMAT_MP4) { + if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) { MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); } else { trailer_size = 0; } /* calculate remained time can be recorded */ - if (info->max_time > 0 && info->max_time < (remained_time + rec_pipe_time)) { - remained_time = info->max_time - rec_pipe_time; - } else if (info->max_size > 0) { - long double max_size = (long double)info->max_size; - long double current_size = (long double)(info->filesize + trailer_size); + if (videoinfo->max_time > 0 && videoinfo->max_time < (remained_time + rec_pipe_time)) { + remained_time = videoinfo->max_time - rec_pipe_time; + } else if (videoinfo->max_size > 0) { + long double max_size = (long double)videoinfo->max_size; + long double current_size = (long double)(videoinfo->filesize + trailer_size); remained_time = (unsigned long long)((long double)rec_pipe_time * (max_size/current_size)) - rec_pipe_time; } - if (info->max_time > 0 && rec_pipe_time > info->max_time) { + if (videoinfo->max_time > 0 && rec_pipe_time > videoinfo->max_time) { _mmcam_dbg_warn("Current time : [%" G_GUINT64_FORMAT "], Maximum time : [%" G_GUINT64_FORMAT "]", \ - rec_pipe_time, info->max_time); + rec_pipe_time, videoinfo->max_time); if (!sc->isMaxtimePausing) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); @@ -1331,7 +1381,7 @@ static gboolean __mmcamcorder_audioque_dataprobe(GstPad *pad, GstBuffer *buffer, msg.id = MM_MESSAGE_CAMCORDER_RECORDING_STATUS; msg.param.recording_status.elapsed = (unsigned long long)rec_pipe_time; - msg.param.recording_status.filesize = (unsigned long long)((info->filesize + trailer_size) >> 10); + msg.param.recording_status.filesize = (unsigned long long)((videoinfo->filesize + trailer_size) >> 10); msg.param.recording_status.remained_time = 0; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); @@ -1339,23 +1389,23 @@ static gboolean __mmcamcorder_audioque_dataprobe(GstPad *pad, GstBuffer *buffer, _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); } - return FALSE; + return GST_PAD_PROBE_DROP; } msg.id = MM_MESSAGE_CAMCORDER_RECORDING_STATUS; msg.param.recording_status.elapsed = (unsigned long long)rec_pipe_time; - msg.param.recording_status.filesize = (unsigned long long)((info->filesize + trailer_size) >> 10); + msg.param.recording_status.filesize = (unsigned long long)((videoinfo->filesize + trailer_size) >> 10); msg.param.recording_status.remained_time = remained_time; _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg); _mmcam_dbg_log("audio data probe :: time [%" GST_TIME_FORMAT "], size [%lld KB]", GST_TIME_ARGS(rec_pipe_time), msg.param.recording_status.filesize); - return TRUE; + return GST_PAD_PROBE_OK; } -static gboolean __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstBuffer *buffer, gpointer u_data) +static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); double volume = 0.0; @@ -1363,6 +1413,8 @@ static gboolean __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstBuffer int channel = 0; int err = MM_ERROR_UNKNOWN; char *err_name = NULL; + GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); + GstMapInfo mapinfo = GST_MAP_INFO_INIT; mmf_return_val_if_fail(buffer, FALSE); mmf_return_val_if_fail(hcamcorder, FALSE); @@ -1381,25 +1433,29 @@ static gboolean __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstBuffer /* Set audio stream NULL */ if (volume == 0.0) { - memset(GST_BUFFER_DATA(buffer), 0, GST_BUFFER_SIZE(buffer)); + gst_buffer_map(buffer, &mapinfo, GST_MAP_WRITE); + memset(mapinfo.data, 0, mapinfo.size); + gst_buffer_unmap(buffer, &mapinfo); } /* CALL audio stream callback */ - if (hcamcorder->astream_cb && buffer && GST_BUFFER_DATA(buffer)) { + gst_buffer_map(buffer, &mapinfo, GST_MAP_READ); + if (hcamcorder->astream_cb && buffer && mapinfo.data && mapinfo.size > 0) { MMCamcorderAudioStreamDataType stream; if (_mmcamcorder_get_state((MMHandleType)hcamcorder) < MM_CAMCORDER_STATE_PREPARE) { _mmcam_dbg_warn("Not ready for stream callback"); - return TRUE; + gst_buffer_unmap(buffer, &mapinfo); + return GST_PAD_PROBE_OK; } /*_mmcam_dbg_log("Call video steramCb, data[%p], Width[%d],Height[%d], Format[%d]", GST_BUFFER_DATA(buffer), width, height, format);*/ - stream.data = (void *)GST_BUFFER_DATA(buffer); + stream.data = (void *)mapinfo.data; stream.format = format; stream.channel = channel; - stream.length = GST_BUFFER_SIZE(buffer); + stream.length = mapinfo.size; stream.timestamp = (unsigned int)(GST_BUFFER_TIMESTAMP(buffer)/1000000); /* nano -> milli second */ _MMCAMCORDER_LOCK_ASTREAM_CALLBACK(hcamcorder); @@ -1410,8 +1466,9 @@ static gboolean __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstBuffer _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder); } + gst_buffer_unmap(buffer, &mapinfo); - return TRUE; + return GST_PAD_PROBE_OK; } diff --git a/test/mm_camcorder_testsuite.c b/test/mm_camcorder_testsuite.c index 39e3f05..3a873bd 100644 --- a/test/mm_camcorder_testsuite.c +++ b/test/mm_camcorder_testsuite.c @@ -43,7 +43,7 @@ when who what, where, why #include "../src/include/mm_camcorder.h" #include "../src/include/mm_camcorder_internal.h" #include "../src/include/mm_camcorder_util.h" -#include +#include #include /*----------------------------------------------------------------------- -- 2.7.4