4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyuntae Kim <ht1211.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
25 #include "mm_streamrecorder_internal.h"
26 #include "mm_streamrecorder_video.h"
27 #include "mm_streamrecorder_gstcommon.h"
28 #include "mm_streamrecorder_recorder.h"
29 #include "mm_streamrecorder_util.h"
30 #include "mm_streamrecorder_buffer_manager.h"
31 #include "mm_streamrecorder_fileinfo.h"
32 #include "mm_streamrecorder_attribute.h"
35 #include <gst/base/gstadapter.h>
36 #include <gst/app/gstappsrc.h>
37 #include <gst/app/gstappsink.h>
40 /*---------------------------------------------------------------------------------------
41 | GLOBAL VARIABLE DEFINITIONS for internal |
42 ---------------------------------------------------------------------------------------*/
44 /*---------------------------------------------------------------------------------------
45 | LOCAL VARIABLE DEFINITIONS for internal |
46 ---------------------------------------------------------------------------------------*/
48 /*-----------------------------------------------------------------------
49 | GLOBAL VARIABLE DEFINITIONS for internal |
50 -----------------------------------------------------------------------*/
52 /*---------------------------------------------------------------------------------------
53 | LOCAL FUNCTION PROTOTYPES: |
54 ---------------------------------------------------------------------------------------*/
55 /* STATIC INTERNAL FUNCTION */
57 /*=======================================================================================
58 | FUNCTION DEFINITIONS |
59 =======================================================================================*/
60 /*---------------------------------------------------------------------------------------
61 | GLOBAL FUNCTION DEFINITIONS: |
62 ---------------------------------------------------------------------------------------*/
63 int _mmstreamrecorder_create_pipeline(MMHandleType handle)
65 int ret = MM_ERROR_NONE;
66 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
67 _MMStreamRecorderSubContext *sc = NULL;
68 GstElement *pipeline = NULL;
70 _mmstreamrec_dbg_log("handle : %x", handle);
72 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
74 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
75 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
78 ret = _mmstreamrecorder_create_recorder_pipeline(handle);
80 pipeline = sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst;
82 ret = _mmstreamrecorder_gst_set_state(handle, pipeline, GST_STATE_READY);
84 _mmstreamrec_dbg_log("ret[%x]", ret);
88 void _mmstreamrecorder_destroy_pipeline(MMHandleType handle)
90 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
91 _MMStreamRecorderSubContext *sc = NULL;
94 _MMStreamRecorderGstElement *element = NULL;
97 mmf_return_if_fail(hstreamrecorder);
99 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
100 mmf_return_if_fail(sc);
102 _mmstreamrec_dbg_log("");
104 element = sc->encode_element;
105 element_num = sc->encode_element_num;
106 if (element == NULL) {
107 _mmstreamrec_dbg_log("encode element is null!!");
111 if (sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst != NULL) {
112 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst));
114 _mmstreamrec_dbg_log("Pipeline clear!!");
116 /* Remove pipeline message callback */
117 if (hstreamrecorder->pipeline_cb_event_id != 0) {
118 g_source_remove(hstreamrecorder->pipeline_cb_event_id);
119 hstreamrecorder->pipeline_cb_event_id = 0;
122 /* Remove remained message in bus */
124 GstMessage *gst_msg = NULL;
125 while ((gst_msg = gst_bus_pop(bus)) != NULL) {
126 _mmstreamrecorder_pipeline_cb_message(bus, gst_msg, (gpointer) hstreamrecorder);
127 gst_message_unref(gst_msg);
130 gst_object_unref(bus);
134 /* Inside each pipeline destroy function, Set GST_STATE_NULL to Main pipeline */
135 _mmstreamrecorder_destroy_recorder_pipeline(handle);
138 if (element != NULL) {
139 /* checking unreleased element */
140 for (i = 0; i < element_num; i++) {
141 if (element[i].gst) {
142 if (GST_IS_ELEMENT(element[i].gst)) {
143 _mmstreamrec_dbg_warn("Still alive element - ID[%d], name [%s], ref count[%d], status[%s]", element[i].id, GST_OBJECT_NAME(element[i].gst), GST_OBJECT_REFCOUNT(element[i].gst), gst_element_state_get_name(GST_STATE(element[i].gst)));
144 g_object_weak_unref(G_OBJECT(element[i].gst), (GWeakNotify) _mmstreamrecorder_element_release_noti, sc);
146 _mmstreamrec_dbg_warn("The element[%d] is still aliving, check it", element[i].id);
149 element[i].id = _MMSTREAMRECORDER_ENCODE_NONE;
150 element[i].gst = NULL;
157 int _mmstreamrecorder_create_recorder_pipeline(MMHandleType handle)
160 int err = MM_ERROR_NONE;
161 int audio_enable = FALSE;
163 GstPad *srcpad = NULL;
164 GstPad *sinkpad = NULL;
166 unsigned int video_codec = MM_VIDEO_CODEC_INVALID;
167 unsigned int file_format = MM_FILE_FORMAT_INVALID;
168 char *err_name = NULL;
170 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
171 _MMStreamRecorderSubContext *sc = NULL;
173 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
175 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
176 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
178 _mmstreamrec_dbg_warn("start");
180 err = mm_streamrecorder_get_attributes(handle, &err_name, MMSTR_VIDEO_ENCODER, &video_codec, MMSTR_FILE_FORMAT, &file_format, NULL);
181 if (err != MM_ERROR_NONE) {
182 _mmstreamrec_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
187 err = _mmstreamrecorder_check_videocodec_fileformat_compatibility(video_codec, file_format);
188 if (err != MM_ERROR_NONE)
192 _MMSTREAMRECORDER_PIPELINE_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCODE_MAIN_PIPE, "recorder_pipeline", err);
194 /* get audio disable */
195 mm_streamrecorder_get_attributes(handle, NULL, MMSTR_AUDIO_ENABLE, &audio_enable, NULL);
196 sc->audio_enable = audio_enable;
198 _mmstreamrec_dbg_log("AUDIO DISABLE : %d", sc->audio_enable);
200 if (sc->audio_enable == TRUE) {
201 /* create audiosrc bin */
202 err = _mmstreamrecorder_create_audiosrc_bin((MMHandleType) hstreamrecorder);
203 if (err != MM_ERROR_NONE)
207 err = _mmstreamrecorder_create_encodesink_bin((MMHandleType) hstreamrecorder, MM_STREAMRECORDER_ENCBIN_PROFILE_VIDEO);
208 if (err != MM_ERROR_NONE)
211 if (sc->audio_enable == TRUE) {
212 gst_bin_add(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst), sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst);
215 /* add element and encodesink bin to encode main pipeline */
216 gst_bin_add_many(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst), sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_FILT].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, NULL);
218 /* Link each element : appsrc - capsfilter - encodesink bin */
219 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, "src");
220 sinkpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_FILT].gst, "sink");
221 _MM_GST_PAD_LINK_UNREF(srcpad, sinkpad, err, pipeline_creation_error);
223 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_FILT].gst, "src");
224 sinkpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, "video_sink0");
225 _MM_GST_PAD_LINK_UNREF(srcpad, sinkpad, err, pipeline_creation_error);
227 if (sc->audio_enable == TRUE) {
228 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, "src");
229 sinkpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, "audio_sink0");
230 _MM_GST_PAD_LINK_UNREF(srcpad, sinkpad, err, pipeline_creation_error);
233 if (sc->audio_enable == TRUE) {
234 sinkpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, "sink");
235 MMSTREAMRECORDER_ADD_BUFFER_PROBE(sinkpad, _MMSTREAMRECORDER_HANDLER_VIDEOREC, __mmstreamrecorder_audioque_dataprobe, hstreamrecorder);
236 gst_object_unref(sinkpad);
239 if (sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC_QUE].gst) {
240 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC_QUE].gst, "src");
241 MMSTREAMRECORDER_ADD_EVENT_PROBE(srcpad, _MMSTREAMRECORDER_HANDLER_VIDEOREC, __mmstreamrecorder_eventprobe_monitor, hstreamrecorder);
242 gst_object_unref(srcpad);
247 if (sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC_QUE].gst) {
248 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC_QUE].gst, "src");
249 MMSTREAMRECORDER_ADD_EVENT_PROBE(srcpad, _MMSTREAMRECORDER_HANDLER_VIDEOREC, __mmstreamrecorder_eventprobe_monitor, hstreamrecorder);
250 gst_object_unref(srcpad);
254 if (sc->audio_enable == FALSE) {
255 sinkpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst, "sink");
256 MMSTREAMRECORDER_ADD_BUFFER_PROBE(sinkpad, _MMSTREAMRECORDER_HANDLER_VIDEOREC, __mmstreamrecorder_video_dataprobe_audio_disable, hstreamrecorder);
257 gst_object_unref(sinkpad);
261 if (!strcmp(/*gst_element_rsink_name */"filesink", "filesink")) {
262 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst, "src");
263 MMSTREAMRECORDER_ADD_BUFFER_PROBE(srcpad, _MMSTREAMRECORDER_HANDLER_VIDEOREC, __mmstreamrecorder_video_dataprobe_record, hstreamrecorder);
264 gst_object_unref(srcpad);
267 if (sc->audio_enable == TRUE) {
268 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, "src");
269 MMSTREAMRECORDER_ADD_BUFFER_PROBE(srcpad, _MMSTREAMRECORDER_HANDLER_VIDEOREC, __mmstreamrecorder_audio_dataprobe_check, hstreamrecorder);
270 gst_object_unref(srcpad);
275 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst));
277 /* register pipeline message callback */
278 hstreamrecorder->encode_pipeline_cb_event_id = gst_bus_add_watch(bus, (GstBusFunc) _mmstreamrecorder_pipeline_cb_message, hstreamrecorder);
280 gst_object_unref(bus);
283 return MM_ERROR_NONE;
285 pipeline_creation_error:
286 for (i = _MMSTREAMRECORDER_AUDIOSRC_BIN; i <= _MMSTREAMRECORDER_ENCSINK_SINK; i++) {
287 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, i);
289 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCODE_MAIN_PIPE);
293 int _mmstreamrecorder_destroy_recorder_pipeline(MMHandleType handle)
295 int ret = MM_ERROR_NONE;
296 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
297 _MMStreamRecorderSubContext *sc = NULL;
301 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
302 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
303 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
305 _mmstreamrec_dbg_log("start");
307 if (!sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst) {
308 _mmstreamrec_dbg_warn("pipeline is not existed.");
309 return MM_ERROR_NONE;
312 _mmstreamrecorder_remove_all_handlers((MMHandleType) hstreamrecorder, _MMSTREAMRECORDER_HANDLER_VIDEOREC);
314 ret = _mmstreamrecorder_gst_set_state(handle, sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst, GST_STATE_NULL);
315 if (ret != MM_ERROR_NONE) {
316 _mmstreamrec_dbg_err("Faile to change encode main pipeline [0x%x]", ret);
320 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst));
322 /* Remove remained message */
324 GstMessage *gst_msg = NULL;
325 while ((gst_msg = gst_bus_pop(bus)) != NULL) {
326 _mmstreamrecorder_pipeline_cb_message(bus, gst_msg, (gpointer) hstreamrecorder);
327 gst_message_unref(gst_msg);
330 gst_object_unref(bus);
334 /* remove audio pipeline first */
335 ret = _mmstreamrecorder_destroy_audiosrc_bin(handle);
336 if (ret != MM_ERROR_NONE) {
337 _mmstreamrec_dbg_err("Fail to remove audio pipeline");
341 ret = _mmstreamrecorder_destroy_encodesink_bin(handle);
342 if (ret != MM_ERROR_NONE) {
343 _mmstreamrec_dbg_err("Fail to remove encoder pipeline");
347 /* Remove pipeline message callback */
348 if (hstreamrecorder->encode_pipeline_cb_event_id != 0) {
349 g_source_remove(hstreamrecorder->encode_pipeline_cb_event_id);
350 hstreamrecorder->encode_pipeline_cb_event_id = 0;
353 _mmstreamrec_dbg_log("done");
358 int _mmstreamrecorder_create_encodesink_bin(MMHandleType handle, MMStreamRecorderEncodebinProfile profile)
360 int err = MM_ERROR_NONE;
368 int video_height = 0;
371 int audio_src_format = 0;
372 int video_src_format = 0;
373 int audio_samplerate = 0;
374 const char *str_profile = NULL;
375 const char *str_aac = NULL;
376 const char *str_aar = NULL;
377 const char *str_acs = NULL;
378 char *err_name = NULL;
380 GstCaps *caps = NULL;
382 GList *element_list = NULL;
383 char *temp_filename = NULL;
390 _MMStreamRecorderVideoInfo *info = NULL;
391 _MMStreamRecorderFileInfo *finfo = NULL;
393 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
394 _MMStreamRecorderSubContext *sc = NULL;
395 /* type_element *VideoencElement = NULL; */
396 /* type_element *AudioencElement = NULL; */
397 /* type_element *MuxElement = NULL; */
398 /* type_element *RecordsinkElement = NULL; */
400 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
402 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
403 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
405 _mmstreamrec_dbg_log("start - profile : %d", profile);
407 info = sc->info_video;
408 finfo = sc->info_file;
410 /* check element availability */
411 mm_streamrecorder_get_attributes(handle, &err_name, MMSTR_AUDIO_ENCODER, &audio_enc, MMSTR_AUDIO_CHANNEL, &channel, MMSTR_VIDEO_BITRATE, &v_bitrate, MMSTR_VIDEO_ENCODER, &video_enc, MMSTR_AUDIO_BITRATE, &a_bitrate, MMSTR_VIDEO_RESOLUTION_WIDTH, &video_width, MMSTR_VIDEO_RESOLUTION_HEIGHT, &video_height, MMSTR_VIDEO_FRAMERATE, &video_fps, MMSTR_FILE_FORMAT, &file_format, MMSTR_AUDIO_SAMPLERATE, &audio_samplerate, MMSTR_AUDIO_SOURCE_FORMAT, &audio_src_format, MMSTR_VIDEO_SOURCE_FORMAT, &video_src_format, MMSTR_RECORDER_MODE, &rec_mode, NULL);
413 _mmstreamrec_dbg_err("audio encoder - %d , video encoder : %d", audio_enc, video_enc);
414 _mmstreamrec_dbg_err("audio channel - %d , video v_bitrate : %d", channel, v_bitrate);
415 _mmstreamrec_dbg_err("audio a_bitrate - %d , video video_width : %d ,video video_height : %d ", a_bitrate, video_width, video_height);
416 _mmstreamrec_dbg_err("video_fps - %d , video file_format : %d", video_fps, file_format);
418 /* Check existence */
419 if (sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst) {
420 if (((GObject *) sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst)->ref_count > 0)
421 gst_object_unref(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst);
423 _mmstreamrec_dbg_log("_MMSTREAMRECORDER_ENCSINK_BIN is Already existed.");
426 /* Create bin element */
427 _MMSTREAMRECORDER_BIN_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_BIN, "encodesink_bin", err);
429 /* Create child element */
430 if (hstreamrecorder->ini.encsink_bin_profile != MM_STREAMRECORDER_ENCBIN_PROFILE_AUDIO) {
431 /* create appsrc and capsfilter */
432 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_SRC, hstreamrecorder->ini.name_of_encsink_src, "encodesink_src", element_list, err);
433 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
435 caps = gst_set_videosrcpad_caps(video_src_format, video_width, video_height, video_fps, 1);
436 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, "caps", caps);
438 gst_caps_unref(caps);
442 caps = gst_set_videosrcpad_caps(video_src_format, video_width, video_height, video_fps, 1);
443 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_FILT].gst, "caps", caps);
445 gst_caps_unref(caps);
450 /* release element_list, they will be placed out of encodesink bin */
452 g_list_free(element_list);
455 if (rec_mode == MM_STREAMRECORDER_MODE_MEDIABUFFER) {
456 /* set appsrc as live source */
457 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, "is-live", hstreamrecorder->ini.encsink_src_islive);
462 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_ENCBIN, "encodebin", "encodesink_encbin", element_list, err);
464 _mmstreamrec_dbg_log("Profile[%d]", profile);
466 /* Set information */
467 if (hstreamrecorder->ini.encsink_bin_profile == MM_STREAMRECORDER_ENCBIN_PROFILE_VIDEO) {
468 str_profile = "VideoProfile";
469 str_aac = "VideoAutoAudioConvert";
470 str_aar = "VideoAutoAudioResample";
471 str_acs = "VideoAutoColorSpace";
472 } else if (hstreamrecorder->ini.encsink_bin_profile == MM_STREAMRECORDER_ENCBIN_PROFILE_AUDIO) {
473 str_profile = "AudioProfile";
474 str_aac = "AudioAutoAudioConvert";
475 str_aar = "AudioAutoAudioResample";
476 str_acs = "AudioAutoColorSpace";
479 /* TODO : check the last value ( set ) */
480 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "profile", hstreamrecorder->ini.encsink_bin_profile);
481 if (rec_mode == MM_STREAMRECORDER_MODE_MEDIABUFFER) {
482 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", hstreamrecorder->ini.encsink_bin_auto_audio_convert);
484 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", hstreamrecorder->ini.encsink_bin_auto_audio_resample);
485 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", hstreamrecorder->ini.encsink_bin_auto_colorspace);
486 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", hstreamrecorder->ini.encsink_bin_use_video_toggle);
489 if (hstreamrecorder->ini.encsink_bin_profile == MM_STREAMRECORDER_ENCBIN_PROFILE_VIDEO) {
491 case MM_VIDEO_CODEC_H263:
492 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "venc-name", hstreamrecorder->ini.h263_video_encoder);
494 case MM_VIDEO_CODEC_H264:
495 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "venc-name", hstreamrecorder->ini.h264_video_encoder);
497 case MM_VIDEO_CODEC_MPEG4:
498 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "venc-name", hstreamrecorder->ini.mpeg4_video_encoder);
501 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "venc-name", hstreamrecorder->ini.h264_video_encoder);
504 _MMSTREAMRECORDER_ENCODEBIN_ELMGET(sc, _MMSTREAMRECORDER_ENCSINK_VENC, "video-encode", err);
506 /* set color converter size */
507 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "vconv-name", hstreamrecorder->ini.name_of_encsink_bin_video_converter);
508 _MMSTREAMRECORDER_ENCODEBIN_ELMGET(sc, _MMSTREAMRECORDER_ENCSINK_VCONV, "video-convert", err);
510 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", hstreamrecorder->ini.encsink_bin_auto_colorspace);
512 if (video_src_format == MM_STREAMRECORDER_INPUT_FORMAT_NV12) {
513 video_src_format = MM_STREAMRECORDER_INPUT_FORMAT_I420;
515 caps = gst_set_videosrcpad_caps(video_src_format, video_width, video_height, video_fps, 1);
516 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "vcaps", caps);
517 if (video_src_format != MM_STREAMRECORDER_INPUT_FORMAT_NV12) {
518 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VCONV].gst, "dst-buffer-num", hstreamrecorder->ini.convert_output_buffer_num);
521 err = gst_pad_set_caps(gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst, "sink"), caps);
523 /* MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst, "state-tuning", TRUE); */
526 gst_caps_unref(caps);
529 _mmstreamrec_dbg_log("size %dx%d, dst-buffer-num %d", video_width, video_height, hstreamrecorder->ini.convert_output_buffer_num);
531 _mmstreamrec_dbg_warn("encoder set caps result : 0x%x", err);
533 if (hstreamrecorder->ini.encsink_bin_use_parser[0]) {
534 GstElement *parser = gst_element_factory_make(hstreamrecorder->ini.encsink_bin_use_parser, "parse");
535 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "use-venc-queue", parser);
536 _MMSTREAMRECORDER_ENCODEBIN_ELMGET(sc, _MMSTREAMRECORDER_ENCSINK_PARSER, "use-venc-queue", err);
540 if (sc->audio_enable == TRUE) {
542 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "aenc-name", hstreamrecorder->ini.name_of_encsink_bin_audio_encoder);
543 _MMSTREAMRECORDER_ENCODEBIN_ELMGET(sc, _MMSTREAMRECORDER_ENCSINK_AENC, "audio-encode", err);
544 _mmstreamrec_dbg_err("audio-encode err = %x ", err);
546 /* Set basic infomation */
547 if (audio_enc != MM_AUDIO_CODEC_VORBIS) {
550 if (audio_src_format == MM_STREAMRECORDER_AUDIO_FORMAT_PCM_S16_LE) {
552 } else { /* MM_STREAMRECORDER_AUDIO_FORMAT_PCM_U8 */
556 /* TODO : set rate , channel , depth */
558 caps = gst_set_audiosrcpad_caps(audio_samplerate, 2, depth, 16, 1);
559 /* MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE); */
560 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "acaps", caps);
562 gchar *type = gst_caps_to_string(caps);
564 _mmstreamrec_dbg_warn("Set srcpad caps: %s", type);
566 gst_caps_unref(caps);
569 /* what are the audio encoder which should get audio/x-raw-float? */
570 caps = gst_caps_new_simple("audio/x-raw", "rate", G_TYPE_INT, audio_samplerate, "channels", G_TYPE_INT, channel, "endianness", G_TYPE_INT, BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
571 _mmstreamrec_dbg_log("caps [x-raw-float, rate:%d, channel:%d, endianness:%d, width:32]", audio_samplerate, channel, BYTE_ORDER);
572 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
573 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "acaps", caps);
574 gst_caps_unref(caps);
579 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
580 caps = gst_caps_new_simple("audio/x-raw-int", "channels", G_TYPE_INT, 1, NULL);
581 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
582 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "acaps", caps);
583 gst_caps_unref(caps);
587 if (audio_enc == MM_AUDIO_CODEC_OGG) {
588 caps = gst_caps_new_simple("audio/x-raw-int", NULL);
589 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
590 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "acaps", caps);
591 gst_caps_unref(caps);
596 _MMSTREAMRECORDER_ENCODEBIN_ELMGET(sc, _MMSTREAMRECORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
600 switch (file_format) {
601 case MM_FILE_FORMAT_3GP:{
602 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "mux-name", hstreamrecorder->ini.name_of_encsink_bin_3GPMUXER);
606 case MM_FILE_FORMAT_MP4:{
607 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "mux-name", hstreamrecorder->ini.name_of_encsink_bin_MP4MUXER);
612 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "mux-name", hstreamrecorder->ini.name_of_encsink_bin_MP4MUXER);
617 _MMSTREAMRECORDER_ENCODEBIN_ELMGET(sc, _MMSTREAMRECORDER_ENCSINK_MUX, "mux", err);
621 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_SINK, "filesink", NULL, element_list, err);
622 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, "async", 0);
624 err = mm_streamrecorder_get_attributes(handle, &err_name,
625 MMSTR_FILE_FORMAT, &fileformat, MMSTR_FILENAME, &temp_filename, &size,
626 MMSTR_TARGET_MAX_SIZE, &imax_size,
627 MMSTR_TARGET_TIME_LIMIT, &imax_time,
630 if (err != MM_ERROR_NONE) {
631 _mmstreamrec_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
636 finfo->fileformat = fileformat;
640 info->max_size = 0; /* do not check */
642 info->max_size = ((guint64) imax_size) << 10; /* to byte */
646 info->max_time = 0; /* do not check */
648 info->max_time = ((guint64) imax_time) * 1000; /* to millisecond */
650 finfo->filename = strdup(temp_filename);
651 if (!finfo->filename) {
652 _mmstreamrec_dbg_err("strdup was failed");
656 _mmstreamrec_dbg_log("Record start : set file name using attribute - %s ", finfo->filename);
658 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, "location", finfo->filename);
660 if (profile == MM_STREAMRECORDER_ENCBIN_PROFILE_VIDEO) {
661 /* video encoder attribute setting */
663 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst, "bitrate", v_bitrate);
665 _mmstreamrec_dbg_warn("video bitrate is too small[%d], so skip setting. Use DEFAULT value.", v_bitrate);
669 if (sc->audio_enable == TRUE) {
670 /* audio encoder attribute setting */
673 case MM_AUDIO_CODEC_AMR:
674 result = _mmstreamrecorder_get_amrnb_bitrate_mode(a_bitrate);
675 _mmstreamrec_dbg_log("Set AMR encoder mode [%d]", result);
676 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, "band-mode", result);
678 case MM_AUDIO_CODEC_AAC:
679 _mmstreamrec_dbg_log("Set AAC encoder bitrate [%d]", a_bitrate);
680 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, "bitrate", a_bitrate);
683 _mmstreamrec_dbg_log("Audio codec is not AMR or AAC... you need to implement setting function for audio encoder bit-rate");
687 _mmstreamrec_dbg_warn("Setting bitrate is too small, so skip setting. Use DEFAULT value.");
691 _mmstreamrec_dbg_log("Element creation complete");
693 /* Add element to bin */
694 if (!_mmstreamrecorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst), element_list)) {
695 _mmstreamrec_dbg_err("element add error.");
696 err = MM_ERROR_STREAMRECORDER_RESOURCE_CREATION;
697 goto pipeline_creation_error;
700 _mmstreamrec_dbg_log("Element add complete");
702 if (profile == MM_STREAMRECORDER_ENCBIN_PROFILE_VIDEO) {
703 pad = gst_element_get_request_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "video");
704 if (gst_element_add_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad)) < 0) {
705 gst_object_unref(pad);
707 _mmstreamrec_dbg_err("failed to create ghost video_sink0 on _MMSTREAMRECORDER_ENCSINK_BIN.");
708 err = MM_ERROR_STREAMRECORDER_GST_LINK;
709 goto pipeline_creation_error;
711 gst_object_unref(pad);
714 if (sc->audio_enable == TRUE) {
715 pad = gst_element_get_request_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "audio");
716 if (gst_element_add_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad)) < 0) {
717 gst_object_unref(pad);
719 _mmstreamrec_dbg_err("failed to create ghost audio_sink0 on _MMSTREAMRECORDER_ENCSINK_BIN.");
720 err = MM_ERROR_STREAMRECORDER_GST_LINK;
721 goto pipeline_creation_error;
723 gst_object_unref(pad);
726 } else if (profile == MM_STREAMRECORDER_ENCBIN_PROFILE_AUDIO) {
727 pad = gst_element_get_request_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "audio");
728 if (gst_element_add_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad)) < 0) {
729 gst_object_unref(pad);
731 _mmstreamrec_dbg_err("failed to create ghost audio_sink0 on _MMSTREAMRECORDER_ENCSINK_BIN.");
732 err = MM_ERROR_STREAMRECORDER_GST_LINK;
733 goto pipeline_creation_error;
735 gst_object_unref(pad);
739 pad = gst_element_get_request_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "image");
740 if (gst_element_add_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad)) < 0) {
741 gst_object_unref(pad);
743 _mmstreamrec_dbg_err("failed to create ghost image_sink0 on _MMSTREAMRECORDER_ENCSINK_BIN.");
744 err = MM_ERROR_STREAMRECORDER_GST_LINK;
745 goto pipeline_creation_error;
747 gst_object_unref(pad);
751 _mmstreamrec_dbg_log("Get pad complete");
753 /* Link internal element */
754 if (!_mmstreamrecorder_link_elements(element_list)) {
755 _mmstreamrec_dbg_err("element link error.");
756 err = MM_ERROR_STREAMRECORDER_GST_LINK;
757 goto pipeline_creation_error;
761 g_list_free(element_list);
765 _mmstreamrec_dbg_log("done");
767 return MM_ERROR_NONE;
769 pipeline_creation_error:
770 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_ENCBIN);
771 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_SRC);
772 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_FILT);
773 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_VENC);
774 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_AENC);
775 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_IENC);
776 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_MUX);
777 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_SINK);
778 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_BIN);
781 g_list_free(element_list);
788 int _mmstreamrecorder_destroy_encodesink_bin(MMHandleType handle)
790 GstPad *reqpad = NULL;
791 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
792 _MMStreamRecorderSubContext *sc = NULL;
794 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
796 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
797 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
799 _mmstreamrec_dbg_log("");
801 if (sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst != NULL) {
802 /* release request pad */
803 reqpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "audio");
805 gst_element_release_request_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, reqpad);
806 gst_object_unref(reqpad);
810 reqpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "video");
812 gst_element_release_request_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, reqpad);
813 gst_object_unref(reqpad);
817 /* release encode main pipeline */
818 gst_object_unref(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst);
820 _mmstreamrec_dbg_log("Encoder pipeline removed");
823 return MM_ERROR_NONE;
826 int _mmstreamrecorder_create_audiosrc_bin(MMHandleType handle)
828 int err = MM_ERROR_NONE;
833 unsigned int a_enc = MM_AUDIO_CODEC_INVALID;
834 unsigned int file_format = MM_FILE_FORMAT_INVALID;
835 char *err_name = NULL;
838 GstCaps *caps = NULL;
840 GList *element_list = NULL;
842 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
843 _MMStreamRecorderSubContext *sc = NULL;
844 _MMStreamRecorderGstElement *last_element = NULL;
845 /* type_element *AudiosrcElement = NULL; */
847 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
849 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
850 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
852 _mmstreamrec_dbg_log("");
854 err = mm_streamrecorder_get_attributes(handle, &err_name, MMSTR_AUDIO_ENCODER, &a_enc, MMSTR_AUDIO_BITRATE, &val, MMSTR_AUDIO_SAMPLERATE, &rate, MMSTR_AUDIO_SOURCE_FORMAT, &format, MMSTR_AUDIO_CHANNEL, &channel, MMSTR_FILE_FORMAT, &file_format, MMSTR_RECORDER_MODE, &rec_mode, NULL);
856 if (err != MM_ERROR_NONE) {
857 _mmstreamrec_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
862 err = _mmstreamrecorder_check_audiocodec_fileformat_compatibility(a_enc, file_format);
863 if (err != MM_ERROR_NONE) {
864 _mmstreamrec_dbg_err("error name :%s , audio format %d , fileformat %d. error : %x)", err_name, a_enc, file_format, err);
869 /* Check existence */
870 if (sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst) {
871 if (((GObject *) sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
872 gst_object_unref(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst);
874 _mmstreamrec_dbg_log("_MMSTREAMRECORDER_AUDIOSRC_BIN is Already existed. Unref once...");
877 /* Create bin element */
878 _MMSTREAMRECORDER_BIN_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_BIN, "audiosource_bin", err);
880 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_SRC, "appsrc", hstreamrecorder->ini.name_of_audio_src, element_list, err);
882 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
884 /* Set basic infomation */
885 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
888 if (format == MM_STREAMRECORDER_AUDIO_FORMAT_PCM_S16_LE) {
890 } else { /* MM_STREAMRECORDER_AUDIO_FORMAT_PCM_U8 */
894 caps = gst_set_audiosrcpad_caps(rate, channel, depth, 16, 1);
896 _mmstreamrec_dbg_log("caps [x-raw-int, rate:%d, channel:%d, depth:%d]", rate, channel, depth);
898 /* what are the audio encoder which should get audio/x-raw-float? */
899 caps = gst_caps_new_simple("audio/x-raw-float", "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channel, "endianness", G_TYPE_INT, BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
900 _mmstreamrec_dbg_log("caps [x-raw-float, rate:%d, channel:%d, endianness:%d, width:32]", rate, channel, BYTE_ORDER);
904 if (rec_mode == MM_STREAMRECORDER_MODE_MEDIABUFFER) {
905 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst), "caps", caps);
907 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_FILT].gst), "caps", caps);
909 gchar *type = gst_caps_to_string(caps);
911 _mmstreamrec_dbg_err("_MMSTREAMRECORDER_AUDIOSRC_FILT %s", type);
914 gst_caps_unref(caps);
917 _mmstreamrec_dbg_err("create caps error");
918 err = MM_ERROR_STREAMRECORDER_RESOURCE_CREATION;
919 goto pipeline_creation_error;
922 if (rec_mode == MM_STREAMRECORDER_MODE_SCREENRECORD) {
924 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst), "do-timestamp", TRUE);
925 #else /* speaker mode with alsasrc */
926 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst), "device", "hw:0,8");
927 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst), "latency-time", 256000);
928 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst), "buffer-time", 10000);
929 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst), "do-timestamp", FALSE);
932 MMSTREAMRECORDER_G_OBJECT_SET((sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst), "do-timestamp", FALSE);
935 if (!_mmstreamrecorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst), element_list)) {
936 _mmstreamrec_dbg_err("element add error.");
937 err = MM_ERROR_STREAMRECORDER_RESOURCE_CREATION;
938 goto pipeline_creation_error;
941 if (!_mmstreamrecorder_link_elements(element_list)) {
942 _mmstreamrec_dbg_err("element link error.");
943 err = MM_ERROR_STREAMRECORDER_GST_LINK;
944 goto pipeline_creation_error;
947 last_element = (_MMStreamRecorderGstElement *) (g_list_last(element_list)->data);
948 pad = gst_element_get_static_pad(last_element->gst, "src");
949 if ((gst_element_add_pad(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) < 0) {
950 gst_object_unref(pad);
952 _mmstreamrec_dbg_err("failed to create ghost pad on _MMSTREAMRECORDER_AUDIOSRC_BIN.");
953 err = MM_ERROR_STREAMRECORDER_GST_LINK;
954 goto pipeline_creation_error;
957 gst_object_unref(pad);
961 g_list_free(element_list);
965 return MM_ERROR_NONE;
967 pipeline_creation_error:
968 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_SRC);
969 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_FILT);
970 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_BIN);
973 g_list_free(element_list);
980 int _mmstreamrecorder_destroy_audiosrc_bin(MMHandleType handle)
982 GstPad *srcpad = NULL;
983 GstPad *sinkpad = NULL;
984 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
985 _MMStreamRecorderSubContext *sc = NULL;
987 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
989 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
990 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
992 _mmstreamrec_dbg_log("");
994 if (sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst != NULL) {
995 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, "src");
996 sinkpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, "audio_sink0");
997 _MM_GST_PAD_UNLINK_UNREF(srcpad, sinkpad);
999 /* release audiosrc bin */
1000 gst_bin_remove(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst), sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst);
1002 _mmstreamrecorder_remove_element_handle(handle, (void *)sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_BIN, _MMSTREAMRECORDER_AUDIOSRC_FILT);
1004 _mmstreamrec_dbg_log("Audio pipeline removed");
1007 return MM_ERROR_NONE;
1010 /* COMMAND - VIDEO */
1011 int _mmstreamrecorder_video_command(MMHandleType handle, int command)
1013 int ret = MM_ERROR_NONE;
1014 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1015 _MMStreamRecorderVideoInfo *info = NULL;
1016 _MMStreamRecorderAudioInfo *info_audio = NULL;
1017 _MMStreamRecorderFileInfo *finfo = NULL;
1018 _MMStreamRecorderSubContext *sc = NULL;
1019 GstElement *pipeline = NULL;
1023 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1025 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1026 mmf_return_val_if_fail(sc && sc->encode_element, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1028 mmf_return_val_if_fail(sc->info_video, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1029 if (sc->audio_enable == TRUE) {
1030 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1032 mmf_return_val_if_fail(sc->info_file, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1034 info = sc->info_video;
1035 if (sc->audio_enable == TRUE)
1036 info_audio = sc->info_audio;
1038 finfo = sc->info_file;
1040 _mmstreamrec_dbg_log("command %d", command);
1042 pipeline = sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst;
1045 case _MM_STREAMRECORDER_CMD_RECORD:
1049 _mmstreamrec_dbg_log("Record Start");
1050 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "block", FALSE);
1052 /* Adjust display FPS */
1053 info->video_frame_count = 0;
1055 info_audio->audio_frame_count = 0;
1058 sc->ferror_send = FALSE;
1059 sc->ferror_count = 0;
1060 sc->error_occurs = FALSE;
1061 sc->bget_eos = FALSE;
1063 ret = _mmstreamrecorder_gst_set_state(handle, sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst, GST_STATE_PLAYING);
1064 if (ret != MM_ERROR_NONE) {
1065 /* Remove recorder pipeline and recording file which size maybe zero */
1066 ret = _mmstreamrecorder_destroy_recorder_pipeline(handle);
1068 if (finfo->filename) {
1069 _mmstreamrec_dbg_log("file delete(%s)", finfo->filename);
1070 unlink(finfo->filename);
1071 g_free(finfo->filename);
1072 finfo->filename = NULL;
1074 goto _ERR_STREAMRECORDER_VIDEO_COMMAND;
1079 case _MM_STREAMRECORDER_CMD_PAUSE:
1082 if (info->b_commiting) {
1083 _mmstreamrec_dbg_warn("now on commiting previous file!!(command : %d)", command);
1084 return MM_ERROR_STREAMRECORDER_CMD_IS_RUNNING;
1087 for (count = 0; count <= hstreamrecorder->ini.retrial_count; count++) {
1088 if (sc->audio_enable == FALSE) {
1089 /* check only video frame */
1090 if (info->video_frame_count >= hstreamrecorder->ini.minimum_frame) {
1092 } else if (count == hstreamrecorder->ini.retrial_count) {
1093 _mmstreamrec_dbg_err("Pause fail, frame count %" G_GUINT64_FORMAT "", info->video_frame_count);
1094 return MM_ERROR_STREAMRECORDER_INVALID_CONDITION;
1096 _mmstreamrec_dbg_warn("Waiting for enough video frame, retrial[%d], frame %" G_GUINT64_FORMAT "", count, info->video_frame_count);
1099 usleep(hstreamrecorder->ini.video_frame_wait_time);
1101 /* check both of video and audio frame */
1102 if (info->video_frame_count >= hstreamrecorder->ini.minimum_frame && info_audio->audio_frame_count) {
1104 } else if (count == hstreamrecorder->ini.retrial_count) {
1105 _mmstreamrec_dbg_err("Pause fail, frame count VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", info->video_frame_count, info_audio->audio_frame_count);
1106 return MM_ERROR_STREAMRECORDER_INVALID_CONDITION;
1108 _mmstreamrec_dbg_warn("Waiting for enough frames, retrial [%d], VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", count, info->video_frame_count, info_audio->audio_frame_count);
1111 usleep(hstreamrecorder->ini.video_frame_wait_time);
1115 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "runtime-pause", TRUE);
1120 case _MM_STREAMRECORDER_CMD_CANCEL:
1122 if (info->b_commiting) {
1123 _mmstreamrec_dbg_warn("now on commiting previous file!!(command : %d)", command);
1124 return MM_ERROR_STREAMRECORDER_CMD_IS_RUNNING;
1127 ret = _mmstreamrecorder_destroy_recorder_pipeline(handle);
1128 if (ret != MM_ERROR_NONE)
1129 goto _ERR_STREAMRECORDER_VIDEO_COMMAND;
1131 /* remove target file */
1132 if (finfo->filename) {
1133 _mmstreamrec_dbg_log("file delete(%s)", finfo->filename);
1134 unlink(finfo->filename);
1135 g_free(finfo->filename);
1136 finfo->filename = NULL;
1139 sc->isMaxsizePausing = FALSE;
1140 sc->isMaxtimePausing = FALSE;
1142 info->video_frame_count = 0;
1144 info_audio->audio_frame_count = 0;
1150 case _MM_STREAMRECORDER_CMD_COMMIT:
1151 /* video recording command */
1154 if (info->b_commiting) {
1155 _mmstreamrec_dbg_err("now on commiting previous file!!(command : %d)", command);
1156 return MM_ERROR_STREAMRECORDER_CMD_IS_RUNNING;
1158 _mmstreamrec_dbg_log("_MM_STREAMRECORDER_CMD_COMMIT : start");
1159 info->b_commiting = TRUE;
1162 for (count = 0; count <= hstreamrecorder->ini.retrial_count; count++) {
1163 if (sc->audio_enable == FALSE) {
1164 /* check only video frame */
1165 if (info->video_frame_count >= hstreamrecorder->ini.minimum_frame) {
1167 } else if (count == hstreamrecorder->ini.retrial_count) {
1168 _mmstreamrec_dbg_err("Commit fail, frame count is %" G_GUINT64_FORMAT "", info->video_frame_count);
1169 info->b_commiting = FALSE;
1170 return MM_ERROR_STREAMRECORDER_INVALID_CONDITION;
1172 _mmstreamrec_dbg_warn("Waiting for enough video frame, retrial [%d], frame %" G_GUINT64_FORMAT "", count, info->video_frame_count);
1175 usleep(hstreamrecorder->ini.video_frame_wait_time);
1177 /* check both of video and audio frame */
1178 if (info->video_frame_count >= hstreamrecorder->ini.minimum_frame && info_audio->audio_frame_count) {
1180 } else if (count == hstreamrecorder->ini.retrial_count) {
1181 _mmstreamrec_dbg_err("Commit fail, VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", info->video_frame_count, info_audio->audio_frame_count);
1183 info->b_commiting = FALSE;
1184 return MM_ERROR_STREAMRECORDER_INVALID_CONDITION;
1186 _mmstreamrec_dbg_warn("Waiting for enough frames, retrial [%d], VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", count, info->video_frame_count, info_audio->audio_frame_count);
1189 usleep(hstreamrecorder->ini.video_frame_wait_time);
1193 if (sc->error_occurs) {
1194 GstPad *video = NULL;
1195 GstPad *audio = NULL;
1197 _mmstreamrec_dbg_err("Committing Error case");
1199 video = gst_element_get_static_pad(sc->element[_MMSTREAMRECORDER_VIDEOSINK_SINK].gst, "sink");
1200 ret = gst_pad_send_event(video, gst_event_new_eos());
1201 _mmstreamrec_dbg_err("Sending EOS video sink : %d", ret);
1202 gst_object_unref(video);
1204 video = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst, "src");
1205 gst_pad_push_event(video, gst_event_new_flush_start());
1206 gst_pad_push_event(video, gst_event_new_flush_stop(TRUE));
1207 ret = gst_pad_push_event(video, gst_event_new_eos());
1208 _mmstreamrec_dbg_err("Sending EOS video encoder src pad : %d", ret);
1209 gst_object_unref(video);
1211 if (sc->audio_enable == TRUE) {
1212 audio = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, "src");
1213 gst_pad_push_event(audio, gst_event_new_flush_start());
1214 gst_pad_push_event(audio, gst_event_new_flush_stop(TRUE));
1215 ret = gst_element_send_event(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst, gst_event_new_eos());
1216 _mmstreamrec_dbg_err("Sending EOS audio encoder src pad : %d", ret);
1217 gst_object_unref(audio);
1220 if (sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst != NULL) {
1221 ret = gst_element_send_event(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, gst_event_new_eos());
1222 _mmstreamrec_dbg_warn("send eos to appsrc result : %d", ret);
1225 if (sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst != NULL) {
1226 pad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst, "src");
1227 ret = gst_element_send_event(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst, gst_event_new_eos());
1228 gst_object_unref(pad);
1231 _mmstreamrec_dbg_warn("send eos to audiosrc result : %d", ret);
1236 _mmstreamrec_dbg_log("Start to wait EOS");
1237 ret = _mmstreamrecorder_get_eos_message(handle);
1238 if (ret != MM_ERROR_NONE) {
1239 info->b_commiting = FALSE;
1240 goto _ERR_STREAMRECORDER_VIDEO_COMMAND;
1245 ret = MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT;
1248 return MM_ERROR_NONE;
1250 _ERR_STREAMRECORDER_VIDEO_COMMAND:
1251 if (ret != MM_ERROR_NONE)
1252 _mmstreamrec_dbg_err("Current Videosrc status");
1257 int _mmstreamrecorder_video_handle_eos(MMHandleType handle)
1259 int ret = MM_ERROR_NONE;
1261 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1262 _MMStreamRecorderSubContext *sc = NULL;
1263 _MMStreamRecorderVideoInfo *info = NULL;
1264 _MMStreamRecorderAudioInfo *info_audio = NULL;
1265 _MMStreamRecorderFileInfo *finfo = NULL;
1266 _MMStreamRecorderMsgItem msg;
1267 MMStreamRecordingReport *report = NULL;
1269 mmf_return_val_if_fail(hstreamrecorder, FALSE);
1271 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1272 mmf_return_val_if_fail(sc, FALSE);
1273 mmf_return_val_if_fail(sc->info_video, FALSE);
1274 if (sc->audio_enable == TRUE)
1275 mmf_return_val_if_fail(sc->info_audio, FALSE);
1277 mmf_return_val_if_fail(sc->info_file, FALSE);
1279 info = sc->info_video;
1280 if (sc->audio_enable == TRUE)
1281 info_audio = sc->info_audio;
1283 finfo = sc->info_file;
1285 _mmstreamrec_dbg_err("");
1287 /* remove blocking part */
1288 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "block", FALSE);
1290 ret = _mmstreamrecorder_destroy_recorder_pipeline(handle);
1291 if (ret != MM_ERROR_NONE)
1292 _mmstreamrec_dbg_warn("_mmstreamrecorder_destroy_recorder_pipeline failed. error[%x]", ret);
1294 /* Send recording report to application */
1295 msg.id = MM_MESSAGE_STREAMRECORDER_VIDEO_CAPTURED;
1296 report = (MMStreamRecordingReport *) malloc(sizeof(MMStreamRecordingReport));
1298 _mmstreamrec_dbg_err("Recording report fail(%s). Out of memory.", finfo->filename);
1300 report->recording_filename = strdup(finfo->filename);
1301 msg.param.data = report;
1303 _mmstreamrecorder_send_message((MMHandleType) hstreamrecorder, &msg);
1307 sc->pipeline_time = 0;
1309 sc->isMaxsizePausing = FALSE; /*In async function, this variable should set in callback function. */
1310 sc->isMaxtimePausing = FALSE;
1311 sc->error_occurs = FALSE;
1313 info->video_frame_count = 0;
1315 info_audio->audio_frame_count = 0;
1318 g_free(finfo->filename);
1319 finfo->filename = NULL;
1320 info->b_commiting = FALSE;
1322 _mmstreamrec_dbg_err("_mmstreamrecorder_video_handle_eos : end");
1329 int _mmstreamrecorder_create_audio_pipeline(MMHandleType handle)
1331 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1332 _MMStreamRecorderSubContext *sc = NULL;
1334 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1335 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1337 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1339 return _mmstreamrecorder_create_audiop_with_encodebin(handle);
1343 * This function destroy audio pipeline.
1345 * @param[in] handle Handle of streamrecorder.
1348 * @see _mmstreamrecorder_destroy_audio_pipeline()
1351 void _mmstreamrecorder_destroy_audio_pipeline(MMHandleType handle)
1353 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1354 _MMStreamRecorderSubContext *sc = NULL;
1355 _MMStreamRecorderAudioInfo *info = NULL;
1356 mmf_return_if_fail(hstreamrecorder);
1357 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1359 mmf_return_if_fail(sc && sc->info_audio);
1361 info = sc->info_audio;
1363 _mmstreamrec_dbg_log("start");
1365 if (sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst) {
1366 _mmstreamrec_dbg_warn("release audio pipeline");
1368 _mmstreamrecorder_gst_set_state(handle, sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst, GST_STATE_NULL);
1370 _mmstreamrecorder_remove_all_handlers((MMHandleType) hstreamrecorder, _MMSTREAMRECORDER_HANDLER_CATEGORY_ALL);
1372 if (info->bMuxing) {
1373 GstPad *reqpad = NULL;
1376 The ref_count of mux is always # of streams in here, i don't know why it happens.
1377 So, i unref the mux manually
1379 reqpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "audio");
1380 gst_element_release_request_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, reqpad);
1381 gst_object_unref(reqpad);
1383 if (GST_IS_ELEMENT(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_MUX].gst) && GST_OBJECT_REFCOUNT(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_MUX].gst) > 1) {
1384 gst_object_unref(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_MUX].gst);
1387 gst_object_unref(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst);
1390 _mmstreamrec_dbg_log("done");
1395 int _mmstreamrecorder_create_audiop_with_encodebin(MMHandleType handle)
1397 int err = MM_ERROR_NONE;
1398 char *aenc_name = NULL;
1399 char *mux_name = NULL;
1400 char *err_name = NULL;
1404 GstPad *srcpad = NULL;
1405 GstPad *sinkpad = NULL;
1406 GList *element_list = NULL;
1408 _MMStreamRecorderAudioInfo *info = NULL;
1409 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1410 _MMStreamRecorderSubContext *sc = NULL;
1411 /* type_element *aenc_elem = NULL; */
1412 /* type_element *mux_elem = NULL; */
1414 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1415 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1417 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1418 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1420 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1422 _mmstreamrec_dbg_log("");
1424 err = mm_streamrecorder_get_attributes(handle, &err_name, MMSTR_RECORDER_MODE, &rec_mode, NULL);
1426 if (!mux_name || !strcmp(mux_name, "wavenc")) {
1427 /* IF MUX in not chosen then record in raw file */
1428 _mmstreamrec_dbg_log("Record without muxing.");
1429 info->bMuxing = FALSE;
1431 _mmstreamrec_dbg_log("Record with mux.");
1432 info->bMuxing = TRUE;
1435 /* Create GStreamer pipeline */
1436 _MMSTREAMRECORDER_PIPELINE_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCODE_MAIN_PIPE, "recorder_pipeline", err);
1438 err = _mmstreamrecorder_create_audiosrc_bin(handle);
1439 if (err != MM_ERROR_NONE)
1442 if (info->bMuxing) {
1443 /* Muxing. can use encodebin. */
1444 err = _mmstreamrecorder_create_encodesink_bin((MMHandleType) hstreamrecorder, MM_STREAMRECORDER_ENCBIN_PROFILE_AUDIO);
1445 if (err != MM_ERROR_NONE)
1449 /* without muxing. can't use encodebin. */
1451 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_AQUE, "queue", NULL, element_list, err);
1453 if (rec_mode == MM_STREAMRECORDER_MODE_MEDIABUFFER) {
1454 if (strcmp(hstreamrecorder->ini.name_of_encsink_bin_audio_encoder, "wavenc") != 0) {
1455 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_CONV, "audioconvert", NULL, element_list, err);
1459 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_AENC, aenc_name, NULL, element_list, err);
1461 _MMSTREAMRECORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMSTREAMRECORDER_ENCSINK_SINK, hstreamrecorder->ini.name_of_encsink_sink, NULL, element_list, err);
1464 /* Add and link elements */
1465 if (info->bMuxing) {
1466 /* IF MUX is indicated create MUX */
1467 gst_bin_add_many(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst), sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, NULL);
1469 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, "src");
1470 sinkpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_BIN].gst, "audio_sink0");
1471 _MM_GST_PAD_LINK_UNREF(srcpad, sinkpad, err, pipeline_creation_error);
1473 /* IF MUX in not chosen then record in raw amr file */
1474 if (!strcmp(aenc_name, "wavenc")) {
1475 gst_bin_add_many(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst), sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, NULL);
1477 if (!_MM_GST_ELEMENT_LINK_MANY(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, NULL)) {
1478 err = MM_ERROR_STREAMRECORDER_GST_LINK;
1479 goto pipeline_creation_error;
1482 if (rec_mode == MM_STREAMRECORDER_MODE_MEDIABUFFER) {
1483 gst_bin_add_many(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst), sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_CONV].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, NULL);
1485 if (!_MM_GST_ELEMENT_LINK_MANY(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_CONV].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, NULL)) {
1486 err = MM_ERROR_STREAMRECORDER_GST_LINK;
1487 goto pipeline_creation_error;
1490 gst_bin_add_many(GST_BIN(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst), sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, NULL);
1492 if (!_MM_GST_ELEMENT_LINK_MANY(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_BIN].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, NULL)) {
1493 err = MM_ERROR_STREAMRECORDER_GST_LINK;
1494 goto pipeline_creation_error;
1500 if (info->bMuxing) {
1501 MMSTREAMRECORDER_SIGNAL_CONNECT(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_MUX].gst, _MMSTREAMRECORDER_HANDLER_AUDIOREC, "pad-added", __mmstreamrecorder_audiorec_pad_added_cb, hstreamrecorder);
1503 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AENC].gst, "src");
1504 MMSTREAMRECORDER_ADD_BUFFER_PROBE(srcpad, _MMSTREAMRECORDER_HANDLER_AUDIOREC, __mmstreamrecorder_audio_dataprobe_record, hstreamrecorder);
1505 gst_object_unref(srcpad);
1509 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst));
1511 /* register message callback */
1512 hstreamrecorder->pipeline_cb_event_id = gst_bus_add_watch(bus, (GstBusFunc) _mmstreamrecorder_pipeline_cb_message, hstreamrecorder);
1514 /* set sync callback */
1515 gst_bus_set_sync_handler(bus, gst_bus_sync_signal_handler, hstreamrecorder, NULL);
1517 gst_object_unref(bus);
1521 g_list_free(element_list);
1522 element_list = NULL;
1525 return MM_ERROR_NONE;
1527 pipeline_creation_error:
1528 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCODE_MAIN_PIPE);
1529 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_AUDIOSRC_BIN);
1530 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_AQUE);
1531 if (rec_mode == MM_STREAMRECORDER_MODE_MEDIABUFFER) {
1532 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_CONV);
1534 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_AENC);
1535 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_SINK);
1536 _MMSTREAMRECORDER_ELEMENT_REMOVE(sc->encode_element, _MMSTREAMRECORDER_ENCSINK_BIN);
1539 g_list_free(element_list);
1540 element_list = NULL;
1546 int _mmstreamrecorder_audio_command(MMHandleType handle, int command)
1549 int ret = MM_ERROR_NONE;
1551 guint64 free_space = 0;
1552 guint64 cal_space = 0;
1553 char *dir_name = NULL;
1554 char *err_attr_name = NULL;
1558 GstElement *pipeline = NULL;
1559 GstElement *audioSrc = NULL;
1561 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1562 _MMStreamRecorderSubContext *sc = NULL;
1563 _MMStreamRecorderAudioInfo *info = NULL;
1564 _MMStreamRecorderFileInfo *finfo = NULL;
1566 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1567 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1569 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1570 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1571 mmf_return_val_if_fail(sc->info_file, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1572 pipeline = sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst;
1573 info = sc->info_audio;
1574 finfo = sc->info_file;
1576 _mmstreamrec_dbg_log("");
1578 pipeline = sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst;
1579 audioSrc = sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst;
1581 case _MM_STREAMRECORDER_CMD_RECORD:
1582 /* check status for resume case */
1584 guint imax_size = 0;
1585 guint imax_time = 0;
1586 char *temp_filename = NULL;
1588 if (sc->pipeline_time)
1589 gst_element_set_start_time((GstElement *) GST_PIPELINE(pipeline), sc->pipeline_time);
1591 sc->pipeline_time = hstreamrecorder->ini.reset_pause_time;
1593 ret = mm_streamrecorder_get_attributes(handle, &err_attr_name, MMSTR_TARGET_MAX_SIZE, &imax_size, MMSTR_TARGET_TIME_LIMIT, &imax_time, MMSTR_FILE_FORMAT, &(finfo->fileformat), MMSTR_FILENAME, &temp_filename, &size, NULL);
1594 if (ret != MM_ERROR_NONE) {
1595 _mmstreamrec_dbg_warn("failed to get attribute. (%s:%x)", err_attr_name, ret);
1596 SAFE_FREE(err_attr_name);
1597 goto _ERR_STREAMRECORDER_AUDIO_COMMAND;
1600 finfo->filename = strdup(temp_filename);
1601 if (!finfo->filename) {
1602 _mmstreamrec_dbg_err("STRDUP was failed");
1603 goto _ERR_STREAMRECORDER_AUDIO_COMMAND;
1606 _mmstreamrec_dbg_log("Record start : set file name using attribute - %s\n ", finfo->filename);
1608 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, "location", finfo->filename);
1610 sc->ferror_send = FALSE;
1611 sc->ferror_count = 0;
1612 sc->bget_eos = FALSE;
1617 info->max_size = 0; /* do not check */
1619 info->max_size = ((guint64) imax_size) << 10; /* to byte */
1623 info->max_time = 0; /* do not check */
1625 info->max_time = ((guint64) imax_time) * 1000; /* to millisecond */
1627 /* TODO : check free space before recording start, need to more discussion */
1628 dir_name = g_path_get_dirname(finfo->filename);
1629 err = _mmstreamrecorder_get_freespace(dir_name, &free_space);
1631 _mmstreamrec_dbg_warn("current space for recording - %s : [%" G_GUINT64_FORMAT "]", dir_name, free_space);
1637 cal_space = (guint64)(hstreamrecorder->ini.audio_frame_minimum_space);
1638 cal_space = cal_space + (5 * 1024);
1639 if ((err == -1) || free_space <= cal_space) {
1640 _mmstreamrec_dbg_err("No more space for recording");
1641 return MM_MESSAGE_STREAMRECORDER_NO_FREE_SPACE;
1645 ret = _mmstreamrecorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING);
1646 if (ret != MM_ERROR_NONE)
1647 goto _ERR_STREAMRECORDER_AUDIO_COMMAND;
1651 case _MM_STREAMRECORDER_CMD_PAUSE:
1653 GstClock *l_clock = NULL;
1655 if (info->b_commiting) {
1656 _mmstreamrec_dbg_warn("now on commiting previous file!!(cmd : %d)", cmd);
1657 return MM_ERROR_STREAMRECORDER_CMD_IS_RUNNING;
1660 for (count = 0; count <= hstreamrecorder->ini.retrial_count; count++) {
1661 if (info->filesize > 0) {
1663 } else if (count == hstreamrecorder->ini.retrial_count) {
1664 _mmstreamrec_dbg_err("Pause fail, wait 200 ms, but file size is %lld", info->filesize);
1665 return MM_ERROR_STREAMRECORDER_INVALID_CONDITION;
1667 _mmstreamrec_dbg_warn("Wait for enough audio frame, retry count[%d], file size is %lld", count, info->filesize);
1669 usleep(hstreamrecorder->ini.audio_frame_wait_time);
1672 ret = _mmstreamrecorder_gst_set_state(handle, pipeline, GST_STATE_PAUSED);
1673 if (ret != MM_ERROR_NONE)
1674 goto _ERR_STREAMRECORDER_AUDIO_COMMAND;
1676 /* FIXME: consider delay. */
1677 l_clock = gst_pipeline_get_clock(GST_PIPELINE(pipeline));
1678 sc->pipeline_time = gst_clock_get_time(l_clock) - gst_element_get_base_time(GST_ELEMENT(pipeline));
1682 case _MM_STREAMRECORDER_CMD_CANCEL:
1683 if (info->b_commiting) {
1684 _mmstreamrec_dbg_warn("now on commiting previous file!!(cmd : %d)", cmd);
1685 return MM_ERROR_STREAMRECORDER_CMD_IS_RUNNING;
1688 ret = _mmstreamrecorder_gst_set_state(handle, pipeline, GST_STATE_READY);
1689 if (ret != MM_ERROR_NONE)
1690 goto _ERR_STREAMRECORDER_AUDIO_COMMAND;
1692 if (info->bMuxing) {
1693 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "block", FALSE);
1695 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, "empty-buffers", FALSE);
1698 _mmstreamrecorder_gst_set_state(handle, sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SINK].gst, GST_STATE_NULL);
1700 sc->pipeline_time = 0;
1702 sc->isMaxsizePausing = FALSE;
1703 sc->isMaxtimePausing = FALSE;
1705 if (finfo->filename) {
1706 _mmstreamrec_dbg_log("file delete(%s)", finfo->filename);
1707 unlink(finfo->filename);
1708 g_free(finfo->filename);
1709 finfo->filename = NULL;
1713 case _MM_STREAMRECORDER_CMD_COMMIT:
1716 _mmstreamrec_dbg_log("_MM_STREAMRECORDER_CMD_COMMIT");
1718 if (info->b_commiting) {
1719 _mmstreamrec_dbg_warn("now on commiting previous file!!(cmd : %d)", cmd);
1720 return MM_ERROR_STREAMRECORDER_CMD_IS_RUNNING;
1722 _mmstreamrec_dbg_log("_MM_STREAMRECORDER_CMD_COMMIT : start");
1723 info->b_commiting = TRUE;
1726 for (count = 0; count <= hstreamrecorder->ini.retrial_count; count++) {
1727 if (info->filesize > 0) {
1729 } else if (count == hstreamrecorder->ini.retrial_count) {
1730 _mmstreamrec_dbg_err("Commit fail, waited 200 ms, but file size is %lld", info->filesize);
1731 info->b_commiting = FALSE;
1732 return MM_ERROR_STREAMRECORDER_INVALID_CONDITION;
1734 _mmstreamrec_dbg_warn("Waiting for enough audio frame, re-count[%d], file size is %lld", count, info->filesize);
1736 usleep(hstreamrecorder->ini.audio_frame_wait_time);
1740 GstPad *pad = gst_element_get_static_pad(audioSrc, "src");
1741 ret = gst_element_send_event(audioSrc, gst_event_new_eos());
1742 gst_object_unref(pad);
1744 /* for pause -> commit case */
1745 /*if (_mmstreamrecorder_get_state((MMHandleType)hstreamrecorder) == MM_STREAMRECORDER_STATE_PAUSED) {
1746 ret = _mmstreamrecorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING);
1747 if (ret != MM_ERROR_NONE) {
1748 goto _ERR_STREAMRECORDER_AUDIO_COMMAND;
1753 /* wait until finishing EOS */
1754 _mmstreamrec_dbg_log("Start to wait EOS");
1755 if ((ret = _mmstreamrecorder_get_eos_message(handle)) != MM_ERROR_NONE)
1756 goto _ERR_STREAMRECORDER_AUDIO_COMMAND;
1761 ret = MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT;
1765 _ERR_STREAMRECORDER_AUDIO_COMMAND:
1769 int _mmstreamrecorder_audio_handle_eos(MMHandleType handle)
1771 int err = MM_ERROR_NONE;
1772 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1773 _MMStreamRecorderSubContext *sc = NULL;
1774 _MMStreamRecorderAudioInfo *info = NULL;
1775 _MMStreamRecorderFileInfo *finfo = NULL;
1776 GstElement *pipeline = NULL;
1777 _MMStreamRecorderMsgItem msg;
1778 MMStreamRecordingReport *report;
1780 mmf_return_val_if_fail(hstreamrecorder, FALSE);
1781 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1783 mmf_return_val_if_fail(sc, FALSE);
1784 mmf_return_val_if_fail(sc->info_audio, FALSE);
1785 mmf_return_val_if_fail(sc->info_file, FALSE);
1787 _mmstreamrec_dbg_err("");
1789 info = sc->info_audio;
1790 finfo = sc->info_file;
1792 pipeline = sc->encode_element[_MMSTREAMRECORDER_ENCODE_MAIN_PIPE].gst;
1794 err = _mmstreamrecorder_gst_set_state(handle, pipeline, GST_STATE_READY);
1796 if (err != MM_ERROR_NONE)
1797 _mmstreamrec_dbg_warn("Failed:_MM_STREAMRECORDER_CMD_COMMIT:GST_STATE_READY. err[%x]", err);
1799 /* Send recording report message to application */
1800 msg.id = MM_MESSAGE_STREAMRECORDER_AUDIO_CAPTURED;
1801 report = (MMStreamRecordingReport *) malloc(sizeof(MMStreamRecordingReport));
1803 _mmstreamrec_dbg_err("Recording report fail(%s). Out of memory.", finfo->filename);
1807 /* START TAG HERE */
1808 /* MM_AUDIO_CODEC_AAC + MM_FILE_FORMAT_MP4 */
1809 if (finfo->fileformat == MM_FILE_FORMAT_3GP || finfo->fileformat == MM_FILE_FORMAT_MP4)
1810 _mmstreamrecorder_audio_add_metadata_info_m4a(handle);
1813 report->recording_filename = strdup(finfo->filename);
1814 msg.param.data = report;
1816 _mmstreamrecorder_send_message(handle, &msg);
1818 if (info->bMuxing) {
1819 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_ENCBIN].gst, "block", FALSE);
1821 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_AQUE].gst, "empty-buffers", FALSE);
1824 _mmstreamrecorder_gst_set_state(handle, pipeline, GST_STATE_NULL);
1826 sc->pipeline_time = 0;
1828 sc->isMaxsizePausing = FALSE;
1829 sc->isMaxtimePausing = FALSE;
1831 g_free(finfo->filename);
1832 finfo->filename = NULL;
1834 _mmstreamrec_dbg_err("_MM_STREAMRECORDER_CMD_COMMIT : end");
1836 info->b_commiting = FALSE;
1841 int _mmstreamrecorder_push_videostream_buffer(MMHandleType handle, unsigned long timestamp, GstBuffer *buffer, int size)
1843 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1844 _MMStreamRecorderSubContext *sc = NULL;
1845 GstPad *srcpad = NULL;
1846 GstCaps *srccaps = NULL;
1847 char *err_name = NULL;
1850 int video_width = 0;
1851 int video_height = 0;
1852 int ret = MM_ERROR_NONE;
1853 int video_source_format = 0;
1855 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1857 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1858 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1860 if (buffer == NULL || size == 0) {
1861 _mmstreamrec_dbg_err("video : Buffer is %p , size %d, time stamp is %ld", buffer, size, timestamp);
1862 return MM_ERROR_STREAMRECORDER_RESOURCE_CREATION;
1865 _mmstreamrec_dbg_log("video : Buffer is %p , size %d, time stamp is %ld", buffer, size, timestamp);
1867 /* check element availability */
1868 ret = mm_streamrecorder_get_attributes(handle, &err_name, MMSTR_VIDEO_FRAMERATE, &video_fps, MMSTR_VIDEO_SOURCE_FORMAT, &video_src, MMSTR_VIDEO_RESOLUTION_WIDTH, &video_width, MMSTR_VIDEO_RESOLUTION_HEIGHT, &video_height, MMSTR_VIDEO_SOURCE_FORMAT, &video_source_format, NULL);
1870 if (sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst) {
1872 /*_mmstreamrec_dbg_log("Buffer Push start , time stamp %ld",timestamp);*/
1873 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, "src");
1874 srccaps = gst_pad_get_current_caps(srcpad);
1875 srccaps = gst_set_videosrcpad_caps(video_src, video_width, video_height, video_fps, 1);
1876 gst_app_src_set_caps((GstAppSrc *) sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, srccaps);
1877 /*_mmstreamrec_dbg_err("newbuf streamrecorder(%p) ",newbuf);*/
1879 ret = gst_app_src_push_buffer((GstAppSrc *) sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, buffer);
1881 _mmstreamrec_dbg_err("video gst_app_src_push_buffer %d", ret);
1882 ret = MM_ERROR_STREAMRECORDER_VIDEOBUFFER_PUSH;
1885 /* g_signal_emit_by_name(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_SRC].gst, "push-buffer", newbuf, &ret); */
1891 int _mmstreamrecorder_push_audiostream_buffer(MMHandleType handle, unsigned long timestamp, GstBuffer *buffer, int size)
1893 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
1894 _MMStreamRecorderSubContext *sc = NULL;
1895 _MMStreamRecorderAudioInfo *info = NULL;
1896 GstFlowReturn err = GST_FLOW_OK;
1897 GstPad *srcpad = NULL;
1898 GstCaps *srccaps = NULL;
1903 mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1905 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1906 mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1908 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1909 mmf_return_val_if_fail(info, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
1911 rate = info->iSamplingRate;
1912 depth = info->audio_encode_depth;
1913 channel = info->iChannels;
1915 /*_mmstreamrec_dbg_log("Audio Buffer Push start , time stamp %ld",timestamp); */
1917 if (sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst) {
1919 srcpad = gst_element_get_static_pad(sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst, "src");
1920 /* TODO : CHANNEL , WIDTH, DATATYPE */
1921 srccaps = gst_pad_get_current_caps(srcpad);
1922 srccaps = gst_set_audiosrcpad_caps(rate, channel, depth, 16, 1);
1923 gst_base_src_set_caps(GST_BASE_SRC(srcpad), srccaps);
1925 err = gst_app_src_push_buffer((GstAppSrc *) sc->encode_element[_MMSTREAMRECORDER_AUDIOSRC_SRC].gst, buffer);
1928 _mmstreamrec_dbg_err("Audio gst_app_src_push_buffer %d", err);
1929 return MM_ERROR_STREAMRECORDER_AUDIOBUFFER_PUSH;
1933 return MM_ERROR_NONE;