Support new pixel format - VP8, VP9
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_videorec.c
index 23e15fb..64b0c99 100644 (file)
@@ -44,7 +44,7 @@
 |    LOCAL FUNCTION PROTOTYPES:                                                                                                                        |
 ---------------------------------------------------------------------------------------*/
 /* STATIC INTERNAL FUNCTION */
-static gboolean __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data);
+static void __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data);
 static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
 static GstPadProbeReturn __mmcamcorder_video_dataprobe_encoded(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
 static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
@@ -59,7 +59,7 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle);
 /*---------------------------------------------------------------------------------------
 |    GLOBAL FUNCTION DEFINITIONS:                                                      |
 ---------------------------------------------------------------------------------------*/
-gboolean _mmcamcorder_video_push_buffer(void *handle, GstBuffer *buffer)
+gboolean _mmcamcorder_video_push_buffer(void *handle, GstSample *sample)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
@@ -67,10 +67,13 @@ gboolean _mmcamcorder_video_push_buffer(void *handle, GstBuffer *buffer)
        _MMCamcorderVideoInfo *info_video = NULL;
        _MMCamcorderGstElement *element = NULL;
        GstClockTime current_ts = 0; /* nsec */
+       GstBuffer *buffer = NULL;
 
        mmf_return_val_if_fail(hcamcorder, FALSE);
        mmf_return_val_if_fail(MMF_CAMCORDER_SUBCONTEXT(hcamcorder), FALSE);
 
+       buffer = gst_sample_get_buffer(sample);
+
        mmf_return_val_if_fail(buffer, FALSE);
        mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
 
@@ -96,12 +99,12 @@ gboolean _mmcamcorder_video_push_buffer(void *handle, GstBuffer *buffer)
 
                if (info_video->is_first_frame) {
                        /* check first I frame for H.264 stream */
-                       if (info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
+                       if (_mmcamcorder_is_encoded_preview_pixel_format(info_image->preview_format)) {
                                if (GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
-                                       MMCAM_LOG_WARNING("NOT I frame.. skip this buffer");
+                                       MMCAM_LOG_WARNING("NOT key frame.. skip this buffer");
                                        return TRUE;
                                } else {
-                                       MMCAM_LOG_WARNING("[H.264] first I frame");
+                                       MMCAM_LOG_WARNING("first key frame");
                                }
                        }
 
@@ -126,7 +129,7 @@ gboolean _mmcamcorder_video_push_buffer(void *handle, GstBuffer *buffer)
                                info_video->base_video_ts = current_ts;
                        }
                } else {
-                       if (_mmcamcorder_invoke_video_stream_cb(handle, buffer, FALSE) == FALSE) {
+                       if (_mmcamcorder_invoke_video_stream_cb(handle, sample, FALSE, -1) == FALSE) {
                                /* increase base video timestamp by frame duration,
                                   it will remove delay of dropped buffer when play recorded file. */
                                info_video->base_video_ts += current_ts - info_video->last_video_ts;
@@ -183,9 +186,14 @@ _VIDEO_PUSH_BUFFER_DONE:
 }
 
 
-static gboolean __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data)
+static void __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data)
 {
-       return _mmcamcorder_video_push_buffer(u_data, gst_sample_get_buffer(sample));
+       mmf_return_if_fail(sample);
+
+       /* no need to check return value here */
+       _mmcamcorder_video_push_buffer(u_data, sample);
+
+       gst_sample_unref(sample);
 }
 
 
@@ -374,9 +382,6 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle)
 
        bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst));
 
-       /* register pipeline message callback */
-       hcamcorder->encode_pipeline_cb_event_id = gst_bus_add_watch(bus, (GstBusFunc)_mmcamcorder_pipeline_cb_message, hcamcorder);
-
        /* set sync handler */
        gst_bus_set_sync_handler(bus, _mmcamcorder_encode_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
 
@@ -555,12 +560,6 @@ int _mmcamcorder_remove_recorder_pipeline(MMHandleType handle)
                return ret;
        }
 
-       /* Remove pipeline message callback */
-       if (hcamcorder->encode_pipeline_cb_event_id != 0) {
-               g_source_remove(hcamcorder->encode_pipeline_cb_event_id);
-               hcamcorder->encode_pipeline_cb_event_id = 0;
-       }
-
        /* Remove remained message */
        if (bus) {
                GstMessage *gst_msg = NULL;
@@ -734,11 +733,10 @@ int _mmcamcorder_video_command(MMHandleType handle, int command)
 
                                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "video-width", info->video_width);
                                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "video-height", info->video_height);
-                       } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264 &&
+                       } else if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) &&
                                info->preview_width == info->video_width &&
                                info->preview_height == info->video_height) {
-                               MMCAM_LOG_INFO("H264 preview mode and same resolution");
-
+                               MMCAM_LOG_INFO("Encoded[%d] preview mode and same resolution", sc->info_image->preview_format);
                                /* No need to restart preview */
                                info->restart_preview = FALSE;
                        } else if (info->use_videoscale &&