4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
25 #include <gst/allocators/gsttizenmemory.h>
26 #include <gst/audio/audio-format.h>
27 #include <gst/video/videooverlay.h>
28 #include <gst/video/cameracontrol.h>
32 #include <tbm_bufmgr.h>
33 #include <tbm_surface.h>
34 #include <tbm_surface_internal.h>
36 #include "mm_camcorder_internal.h"
37 #include "mm_camcorder_gstcommon.h"
39 /*-----------------------------------------------------------------------
40 | GLOBAL VARIABLE DEFINITIONS for internal |
41 -----------------------------------------------------------------------*/
42 /* Table for compatibility between audio codec and file format */
43 gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
44 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
45 /*AMR*/ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
46 /*G723.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
47 /*MP3*/ { 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
48 /*OGG*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
49 /*AAC*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
50 /*WMA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 /*MMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
52 /*ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
53 /*WAVE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
54 /*WAVE_NEW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
55 /*MIDI*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
56 /*IMELODY*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
57 /*MXMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
58 /*MPA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
59 /*MP2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
60 /*G711*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
61 /*G722*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
62 /*G722.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
63 /*G722.2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
64 /*G723*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
65 /*G726*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
66 /*G728*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
67 /*G729*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
68 /*G729A*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
69 /*G729.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
70 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
71 /*AAC_LC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
72 /*AAC_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
73 /*AAC_SRS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
74 /*AAC_LTP*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
75 /*AAC_HE_V1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
76 /*AAC_HE_V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
77 /*AC3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
78 /*ALAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
79 /*ATRAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
80 /*SPEEX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
81 /*VORBIS*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
82 /*AIFF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
83 /*AU*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
84 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
85 /*PCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 /*ALAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 /*MULAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
88 /*MS_ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
91 /* Table for compatibility between video codec and file format */
92 gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
93 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
94 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
95 /*H263*/ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
96 /*H264*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
97 /*H26L*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
98 /*MPEG4*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
99 /*MPEG1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
100 /*WMV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
101 /*DIVX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
102 /*XVID*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
103 /*H261*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
104 /*H262*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
105 /*H263V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
106 /*H263V3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
107 /*MJPEG*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
108 /*MPEG2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
109 /*MPEG4_SIMPLE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
110 /*MPEG4_ADV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
111 /*MPEG4_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
112 /*MPEG4_CORE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
113 /*MPEG4_ACE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
114 /*MPEG4_ARTS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
115 /*MPEG4_AVC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
116 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
117 /*VC1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
118 /*AVS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
119 /*CINEPAK*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
120 /*INDEO*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
121 /*THEORA*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
125 /*-----------------------------------------------------------------------
126 | LOCAL VARIABLE DEFINITIONS for internal |
127 -----------------------------------------------------------------------*/
128 #define USE_AUDIO_CLOCK_TUNE
129 #define _MMCAMCORDER_WAIT_EOS_TIME 60.0 /* sec */
130 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM 6
131 #define _MMCAMCORDER_MIN_TIME_TO_PASS_FRAME 30000000 /* ns */
132 #define _MMCAMCORDER_FRAME_PASS_MIN_FPS 30
133 #define _MMCAMCORDER_NANOSEC_PER_1SEC 1000000000
134 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC 1000
137 /*-----------------------------------------------------------------------
138 | LOCAL FUNCTION PROTOTYPES: |
139 -----------------------------------------------------------------------*/
140 /* STATIC INTERNAL FUNCTION */
142 * These functions are preview video data probing function.
143 * If this function is linked with certain pad by gst_pad_add_buffer_probe(),
144 * this function will be called when data stream pass through the pad.
146 * @param[in] pad probing pad which calls this function.
147 * @param[in] buffer buffer which contains stream data.
148 * @param[in] u_data user data.
149 * @return This function returns true on success, or false value with error
151 * @see __mmcamcorder_create_preview_pipeline()
153 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
154 static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
155 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
156 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name);
158 /*=======================================================================================
159 | FUNCTION DEFINITIONS |
160 =======================================================================================*/
161 /*-----------------------------------------------------------------------
162 | GLOBAL FUNCTION DEFINITIONS: |
163 -----------------------------------------------------------------------*/
164 int _mmcamcorder_create_preview_elements(MMHandleType handle)
166 int err = MM_ERROR_NONE;
168 int camera_width = 0;
169 int camera_height = 0;
170 int camera_rotate = 0;
174 int capture_width = 0;
175 int capture_height = 0;
176 int capture_jpg_quality = 100;
177 int video_stabilization = 0;
179 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
180 const char *videosrc_name = NULL;
181 const char *videosink_name = NULL;
182 const char *videoconvert_name = NULL;
183 char *err_name = NULL;
184 char *socket_path = NULL;
186 #ifdef _MMCAMCORDER_RM_SUPPORT
187 int decoder_index = 0;
188 char decoder_name[20] = {'\0',};
189 #endif /* _MMCAMCORDER_RM_SUPPORT */
190 GstElement *sink_element = NULL;
191 GstCameraControl *control = NULL;
192 int sink_element_size = 0;
196 GList *element_list = NULL;
198 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
199 _MMCamcorderSubContext *sc = NULL;
200 type_element *VideosrcElement = NULL;
201 type_int_array *input_index = NULL;
203 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
205 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
206 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
207 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
211 /* Check existence */
212 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
213 if (sc->element[i].gst) {
214 if (((GObject *)sc->element[i].gst)->ref_count > 0)
215 gst_object_unref(sc->element[i].gst);
217 _mmcam_dbg_log("element[index:%d] is Already existed.", i);
221 /* Get video device index info */
222 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
223 CONFIGURE_CATEGORY_CTRL_CAMERA,
226 if (input_index == NULL) {
227 _mmcam_dbg_err("Failed to get input_index");
228 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
231 err = mm_camcorder_get_attributes(handle, &err_name,
232 MMCAM_CAMERA_WIDTH, &camera_width,
233 MMCAM_CAMERA_HEIGHT, &camera_height,
234 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
235 MMCAM_CAMERA_FPS, &fps,
236 MMCAM_CAMERA_ROTATION, &camera_rotate,
237 MMCAM_CAMERA_FLIP, &camera_flip,
238 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
239 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
240 MMCAM_CAPTURE_WIDTH, &capture_width,
241 MMCAM_CAPTURE_HEIGHT, &capture_height,
242 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
243 MMCAM_IMAGE_ENCODER, &codectype,
244 MMCAM_IMAGE_ENCODER_QUALITY, &capture_jpg_quality,
245 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
246 MMCAM_DISPLAY_SURFACE, &display_surface_type,
248 if (err != MM_ERROR_NONE) {
249 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
254 if (hcamcorder->support_user_buffer) {
255 err = mm_camcorder_get_attributes(handle, NULL,
256 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
258 if (err != MM_ERROR_NONE || fd_number < 1) {
259 _mmcam_dbg_err("get user buffer fd failed 0x%x, number %d", err, fd_number);
264 for (i = 0 ; i < fd_number ; i++)
265 _mmcam_dbg_log("fds[%d] %d", i, fds[i]);
269 /* Get fourcc from picture format */
270 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
272 /* Get videosrc element and its name from configure */
273 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
274 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
277 _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
280 * Create child element
282 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
284 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
286 /* init high-speed-fps */
287 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
289 /* set capture size, quality and flip setting which were set before mm_camcorder_realize */
290 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
291 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
292 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-jpg-quality", capture_jpg_quality);
293 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
295 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
297 /* set camera flip */
298 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
300 /* set video stabilization mode */
301 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
303 /* set anti handshake mode */
304 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
306 if (sc->is_modified_rate)
307 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
309 /* Set basic infomation of videosrc element */
310 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
312 /* Set video device index */
313 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
315 /* set user buffer fd to videosrc element */
316 if (hcamcorder->support_user_buffer) {
317 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
318 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
319 _mmcam_dbg_err("set user buffer fd failed");
320 goto pipeline_creation_error;
324 /* make demux and decoder for H264 stream from videosrc */
325 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
326 int preview_bitrate = 0;
327 int gop_interval = 0;
328 const char *videodecoder_name = NULL;
330 /* get recreate_decoder flag */
331 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
332 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
334 &hcamcorder->recreate_decoder);
336 /* get video decoder element and name for H.264 format */
337 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
338 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
339 "VideodecoderElementH264",
340 &sc->VideodecoderElementH264);
342 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
344 if (videodecoder_name) {
345 _mmcam_dbg_log("video decoder element [%s], recreate decoder %d",
346 videodecoder_name, hcamcorder->recreate_decoder);
347 #ifdef _MMCAMCORDER_RM_SUPPORT
348 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
351 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
352 _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
353 /* create decoder element */
354 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
355 #else /* _MMCAMCORDER_RM_SUPPORT */
356 /* create decoder element */
357 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name, "videosrc_decode", element_list, err);
358 #endif /* _MMCAMCORDER_RM_SUPPORT */
359 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
361 _mmcam_dbg_err("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
362 goto pipeline_creation_error;
365 /* set encoded preview bitrate and iframe interval */
366 mm_camcorder_get_attributes(handle, NULL,
367 MMCAM_ENCODED_PREVIEW_BITRATE, &preview_bitrate,
368 MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
371 if (!_mmcamcorder_set_encoded_preview_bitrate(handle, preview_bitrate))
372 _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_bitrate failed");
374 if (!_mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval))
375 _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_gop_interval failed");
378 _mmcam_dbg_log("Current mode[%d]", hcamcorder->type);
380 /* Get videosink name */
381 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
383 if (!videosink_name) {
384 _mmcam_dbg_err("failed to get videosink name");
385 goto pipeline_creation_error;
388 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
390 _mmcam_dbg_log("videosink_name: %s", videosink_name);
392 if (display_surface_type == MM_DISPLAY_SURFACE_REMOTE) {
393 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "ipc_sink", element_list, err);
395 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
397 err = mm_camcorder_get_attributes(handle, &err_name,
398 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
400 if (err != MM_ERROR_NONE) {
401 _mmcam_dbg_warn("Get socket path failed 0x%x", err);
403 goto pipeline_creation_error;
406 g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
408 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
409 /* get video convert name */
410 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
412 if (videoconvert_name) {
413 _mmcam_dbg_log("videoconvert element name : %s", videoconvert_name);
414 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
416 _mmcam_dbg_err("failed to get videoconvert element name");
419 /* check sink element in attribute */
420 mm_camcorder_get_attributes(handle, NULL,
421 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
426 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
428 _mmcam_dbg_log("reuse sink element %p in attribute", sink_element);
430 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
432 /* reset attribute */
434 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
435 mm_attrs_set_data(attrs, attr_index, NULL, 0);
436 mm_attrs_commit(attrs, attr_index);
438 _mmcam_dbg_warn("attribute is NULL");
439 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
440 goto pipeline_creation_error;
443 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
445 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
448 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
449 _mmcam_dbg_err("_mmcamcorder_videosink_window_set error");
450 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
451 goto pipeline_creation_error;
455 /* Set caps by rotation */
456 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
458 /* add elements to main pipeline */
459 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
460 _mmcam_dbg_err("element_list add error.");
461 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
462 goto pipeline_creation_error;
466 if (!_mmcamcorder_link_elements(element_list)) {
467 _mmcam_dbg_err("element link error.");
468 err = MM_ERROR_CAMCORDER_GST_LINK;
469 goto pipeline_creation_error;
473 g_list_free(element_list);
477 return MM_ERROR_NONE;
479 pipeline_creation_error:
480 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
481 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
482 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_QUE);
483 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS);
484 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_FILT);
485 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
486 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
487 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
488 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
491 g_list_free(element_list);
499 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
501 int err = MM_ERROR_NONE;
506 int a_enc = MM_AUDIO_CODEC_AMR;
507 int a_dev = MM_AUDIO_DEVICE_MIC;
509 char *err_name = NULL;
510 const char *audiosrc_name = NULL;
511 char *cat_name = NULL;
512 char *stream_type = NULL;
513 int stream_type_len = 0;
514 int stream_index = 0;
515 int buffer_interval = 0;
517 int replay_gain_enable = FALSE;
518 double replay_gain_ref_level = 0.0;
520 GstCaps *caps = NULL;
522 GList *element_list = NULL;
524 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
525 _MMCamcorderSubContext *sc = NULL;
526 _MMCamcorderGstElement *last_element = NULL;
527 type_element *AudiosrcElement = NULL;
529 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
531 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
532 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
533 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
537 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
538 if (err != MM_ERROR_NONE)
541 err = mm_camcorder_get_attributes(handle, &err_name,
542 MMCAM_AUDIO_DEVICE, &a_dev,
543 MMCAM_AUDIO_ENCODER, &a_enc,
544 MMCAM_AUDIO_ENCODER_BITRATE, &val,
545 MMCAM_AUDIO_SAMPLERATE, &rate,
546 MMCAM_AUDIO_FORMAT, &format,
547 MMCAM_AUDIO_CHANNEL, &channel,
548 MMCAM_AUDIO_VOLUME, &volume,
549 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
550 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
551 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
552 MMCAM_SOUND_STREAM_INDEX, &stream_index,
554 if (err != MM_ERROR_NONE) {
555 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
560 /* Check existence */
561 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
562 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
563 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
565 _mmcam_dbg_log("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
568 /* Create bin element */
569 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
571 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
572 cat_name = strdup("AudiomodemsrcElement");
574 /* MM_AUDIO_DEVICE_MIC or others */
575 cat_name = strdup("AudiosrcElement");
578 if (cat_name == NULL) {
579 _mmcam_dbg_err("strdup failed.");
580 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
581 goto pipeline_creation_error;
584 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
585 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
588 _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
593 _mmcam_dbg_log("Audio src name : %s", audiosrc_name);
595 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
597 /* set sound stream info */
598 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
600 /* set audiosrc properties in ini configuration */
601 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
604 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
605 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
606 "AudioBufferInterval",
609 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
610 _mmcam_dbg_log("set audiosrc block size %d", blocksize);
611 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
614 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
616 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
617 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
618 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
619 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
621 /* Set basic infomation */
622 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
624 const gchar* format_name = NULL;
626 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
629 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
630 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
632 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
633 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
636 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
638 format_name = "S16LE";
639 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
644 caps = gst_caps_new_simple("audio/x-raw",
645 "rate", G_TYPE_INT, rate,
646 "channels", G_TYPE_INT, channel,
647 "format", G_TYPE_STRING, format_name,
649 _mmcam_dbg_log("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
650 rate, channel, depth, volume);
652 /* what are the audio encoder which should get audio/x-raw-float? */
653 caps = gst_caps_new_simple("audio/x-raw",
654 "rate", G_TYPE_INT, rate,
655 "channels", G_TYPE_INT, channel,
656 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
658 _mmcam_dbg_log("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
659 rate, channel, BYTE_ORDER);
663 _mmcam_dbg_log("Replay gain - enable : %d, reference level : %lf",
664 replay_gain_enable, replay_gain_ref_level);
666 if (replay_gain_enable) {
667 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
668 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
669 /* If num-tracks is not set, album gain and peak event is not come. */
670 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
674 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
675 gst_caps_unref(caps);
678 _mmcam_dbg_err("create caps error");
679 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
680 goto pipeline_creation_error;
683 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
684 _mmcam_dbg_err("element add error.");
685 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
686 goto pipeline_creation_error;
689 if (!_mmcamcorder_link_elements(element_list)) {
690 _mmcam_dbg_err("element link error.");
691 err = MM_ERROR_CAMCORDER_GST_LINK;
692 goto pipeline_creation_error;
695 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
696 pad = gst_element_get_static_pad(last_element->gst, "src");
697 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
698 gst_object_unref(pad);
700 _mmcam_dbg_err("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
701 err = MM_ERROR_CAMCORDER_GST_LINK;
702 goto pipeline_creation_error;
705 gst_object_unref(pad);
709 g_list_free(element_list);
713 return MM_ERROR_NONE;
715 pipeline_creation_error:
716 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
717 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
718 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
719 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
720 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
723 g_list_free(element_list);
731 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
736 _mmcam_dbg_warn("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
741 _mmcam_dbg_warn("[type %d, codec %d] too small bitrate[%d], use default",
742 type, codec, bitrate);
746 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
747 /* audio encoder bitrate setting */
749 case MM_AUDIO_CODEC_AMR:
750 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
751 _mmcam_dbg_log("Set AMR encoder mode [%d]", set_value);
752 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
754 case MM_AUDIO_CODEC_MP3:
755 set_value = bitrate / 1000;
756 _mmcam_dbg_log("Set MP3 encoder bitrate [%d] kbps", set_value);
757 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
759 case MM_AUDIO_CODEC_AAC:
760 _mmcam_dbg_log("Set AAC encoder bitrate [%d] bps", bitrate);
761 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
764 _mmcam_dbg_warn("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
768 /* video encoder bitrate setting */
769 _mmcam_dbg_log("Set video encoder bitrate %d", bitrate);
770 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
777 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
779 int err = MM_ERROR_NONE;
784 int encodebin_profile = 0;
785 int auto_audio_convert = 0;
786 int auto_audio_resample = 0;
787 int auto_color_space = 0;
788 int cap_format = MM_PIXEL_FORMAT_INVALID;
789 const char *gst_element_venc_name = NULL;
790 const char *gst_element_aenc_name = NULL;
791 const char *gst_element_ienc_name = NULL;
792 const char *gst_element_mux_name = NULL;
793 const char *gst_element_rsink_name = NULL;
794 const char *str_profile = NULL;
795 const char *str_aac = NULL;
796 const char *str_aar = NULL;
797 const char *str_acs = NULL;
798 char *err_name = NULL;
799 const char *videoconvert_name = NULL;
800 GstCaps *audio_caps = NULL;
801 GstCaps *video_caps = NULL;
803 GList *element_list = NULL;
805 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
806 _MMCamcorderSubContext *sc = NULL;
807 type_element *VideoencElement = NULL;
808 type_element *AudioencElement = NULL;
809 type_element *ImageencElement = NULL;
810 type_element *MuxElement = NULL;
811 type_element *RecordsinkElement = NULL;
813 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
815 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
816 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
817 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
819 _mmcam_dbg_log("start - profile : %d", profile);
821 /* Check existence */
822 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
823 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
824 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
826 _mmcam_dbg_log("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
829 /* Create bin element */
830 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
832 /* Create child element */
833 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
834 GstCaps *caps_from_pad = NULL;
836 /* create appsrc and capsfilter */
837 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
839 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
841 /* release element_list, they will be placed out of encodesink bin */
843 g_list_free(element_list);
847 /* set appsrc as live source */
848 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
849 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
850 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
853 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
854 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
855 _mmcam_dbg_log("get pad from videosrc_filter");
856 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
858 _mmcam_dbg_log("get pad from videosrc_que");
859 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
862 _mmcam_dbg_err("get videosrc_que src pad failed");
863 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
864 goto pipeline_creation_error;
867 caps_from_pad = gst_pad_get_allowed_caps(pad);
868 video_caps = gst_caps_copy(caps_from_pad);
869 gst_caps_unref(caps_from_pad);
870 caps_from_pad = NULL;
871 gst_object_unref(pad);
875 video_caps = gst_caps_fixate(video_caps);
878 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
882 char *caps_str = NULL;
884 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
885 gst_caps_set_simple(video_caps,
886 "width", G_TYPE_INT, sc->info_video->video_width,
887 "height", G_TYPE_INT, sc->info_video->video_height,
891 caps_str = gst_caps_to_string(video_caps);
892 _mmcam_dbg_log("encodebin caps [%s]", caps_str);
896 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
897 gst_caps_unref(video_caps);
900 _mmcam_dbg_err("create recording pipeline caps failed");
901 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
902 goto pipeline_creation_error;
905 /* connect signal for ready to push buffer */
906 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
907 _MMCAMCORDER_HANDLER_VIDEOREC,
909 _mmcamcorder_ready_to_encode_callback,
913 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN, "encodebin", "encodesink_encbin", element_list, err);
915 /* check element availability */
916 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
917 err = mm_camcorder_get_attributes(handle, &err_name,
918 MMCAM_CAPTURE_FORMAT, &cap_format,
921 err = mm_camcorder_get_attributes(handle, &err_name,
922 MMCAM_AUDIO_ENCODER, &audio_enc,
923 MMCAM_AUDIO_CHANNEL, &channel,
924 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
925 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
929 if (err != MM_ERROR_NONE) {
931 _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
934 _mmcam_dbg_err("failed to get attributes [0x%x]", err);
937 goto pipeline_creation_error;
940 _mmcam_dbg_log("Profile[%d]", profile);
942 /* Set information */
943 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
944 str_profile = "VideoProfile";
945 str_aac = "VideoAutoAudioConvert";
946 str_aar = "VideoAutoAudioResample";
947 str_acs = "VideoAutoColorSpace";
948 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
949 str_profile = "AudioProfile";
950 str_aac = "AudioAutoAudioConvert";
951 str_aar = "AudioAutoAudioResample";
952 str_acs = "AudioAutoColorSpace";
953 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
954 str_profile = "ImageProfile";
955 str_aac = "ImageAutoAudioConvert";
956 str_aar = "ImageAutoAudioResample";
957 str_acs = "ImageAutoColorSpace";
960 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
961 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
962 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
963 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
965 _mmcam_dbg_log("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
966 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
968 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
969 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
970 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
971 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
972 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
974 /* get video convert element name */
975 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
978 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
979 int use_venc_queue = 0;
981 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
983 if (!VideoencElement) {
984 _mmcam_dbg_err("Fail to get type element");
985 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
986 goto pipeline_creation_error;
989 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
990 /* set dummy element */
991 gst_element_venc_name = "identity";
993 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
996 if (gst_element_venc_name) {
997 _mmcam_dbg_log("video encoder name [%s]", gst_element_venc_name);
999 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1000 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1002 _mmcam_dbg_err("Fail to get video encoder name");
1003 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1004 goto pipeline_creation_error;
1007 /* set color space converting element */
1008 if (auto_color_space) {
1009 _mmcam_dbg_log("set video convert element [%s]", videoconvert_name);
1011 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1012 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1014 /* set colorspace plugin property setting */
1015 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1017 /* fourcc type was removed in GST 1.0 */
1018 if (hcamcorder->use_zero_copy_format) {
1019 if (strstr(gst_element_venc_name, "omx")) {
1020 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1023 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1024 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1026 gst_caps_unref(video_caps);
1029 _mmcam_dbg_warn("failed to create caps");
1032 _mmcam_dbg_log("current video codec is not openmax but [%s]", gst_element_venc_name);
1037 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1038 CONFIGURE_CATEGORY_MAIN_RECORD,
1039 "UseVideoEncoderQueue",
1042 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1045 if (sc->audio_disable == FALSE &&
1046 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1047 int use_aenc_queue = 0;
1049 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1050 if (!AudioencElement) {
1051 _mmcam_dbg_err("Fail to get type element");
1052 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1053 goto pipeline_creation_error;
1056 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1058 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1059 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1061 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1062 audio_caps = gst_caps_new_simple("audio/x-raw",
1063 "channels", G_TYPE_INT, 1,
1065 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1066 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1067 gst_caps_unref(audio_caps);
1071 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1072 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1073 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1074 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1075 gst_caps_unref(audio_caps);
1077 _mmcam_dbg_log("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1080 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1081 CONFIGURE_CATEGORY_MAIN_RECORD,
1082 "UseAudioEncoderQueue",
1084 if (use_aenc_queue) {
1085 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1086 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1087 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1091 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1092 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1093 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1094 if (!ImageencElement) {
1095 _mmcam_dbg_err("Fail to get type element");
1096 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1097 goto pipeline_creation_error;
1100 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1102 /* raw format - set dummy element */
1103 gst_element_ienc_name = "identity";
1106 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1107 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1111 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1112 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1114 _mmcam_dbg_err("Fail to get type element");
1115 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1116 goto pipeline_creation_error;
1119 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1121 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1122 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1124 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1128 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1130 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1131 CONFIGURE_CATEGORY_MAIN_RECORD,
1132 "RecordsinkElement",
1133 &RecordsinkElement);
1134 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1136 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1138 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1141 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1144 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1145 /* property setting in ini */
1146 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1148 /* bitrate setting */
1149 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1150 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1153 if (sc->audio_disable == FALSE &&
1154 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1155 /* property setting in ini */
1156 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1158 /* bitrate setting */
1159 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1160 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1163 _mmcam_dbg_log("Element creation complete");
1165 /* Add element to bin */
1166 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1167 _mmcam_dbg_err("element add error.");
1168 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1169 goto pipeline_creation_error;
1172 _mmcam_dbg_log("Element add complete");
1174 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1175 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1176 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1177 gst_object_unref(pad);
1179 _mmcam_dbg_err("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1180 err = MM_ERROR_CAMCORDER_GST_LINK;
1181 goto pipeline_creation_error;
1183 gst_object_unref(pad);
1186 if (sc->audio_disable == FALSE) {
1187 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1188 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1189 gst_object_unref(pad);
1191 _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1192 err = MM_ERROR_CAMCORDER_GST_LINK;
1193 goto pipeline_creation_error;
1195 gst_object_unref(pad);
1198 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1199 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1200 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1201 gst_object_unref(pad);
1203 _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1204 err = MM_ERROR_CAMCORDER_GST_LINK;
1205 goto pipeline_creation_error;
1207 gst_object_unref(pad);
1211 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1212 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1213 gst_object_unref(pad);
1215 _mmcam_dbg_err("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1216 err = MM_ERROR_CAMCORDER_GST_LINK;
1217 goto pipeline_creation_error;
1219 gst_object_unref(pad);
1223 _mmcam_dbg_log("Get pad complete");
1225 /* Link internal element */
1226 if (!_mmcamcorder_link_elements(element_list)) {
1227 _mmcam_dbg_err("element link error.");
1228 err = MM_ERROR_CAMCORDER_GST_LINK;
1229 goto pipeline_creation_error;
1233 g_list_free(element_list);
1234 element_list = NULL;
1237 _mmcam_dbg_log("done");
1239 return MM_ERROR_NONE;
1241 pipeline_creation_error:
1242 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1244 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1245 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1246 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1247 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1248 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1249 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1250 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1251 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1252 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1255 g_list_free(element_list);
1256 element_list = NULL;
1263 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1265 int err = MM_ERROR_NONE;
1267 GstPad *srcpad = NULL;
1270 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1271 _MMCamcorderSubContext *sc = NULL;
1273 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1275 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1276 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1277 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1281 /** Create gstreamer element **/
1283 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1286 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1287 if (err != MM_ERROR_NONE)
1288 goto pipeline_creation_error;
1290 /* Set data probe function */
1291 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1292 _mmcam_dbg_log("add video dataprobe to videosrc queue");
1293 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1295 _mmcam_dbg_err("there is no queue plugin");
1296 goto pipeline_creation_error;
1300 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1301 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1303 gst_object_unref(srcpad);
1306 _mmcam_dbg_err("failed to get srcpad");
1307 goto pipeline_creation_error;
1310 /* set dataprobe for video recording */
1311 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264)
1312 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1314 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1316 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1317 __mmcamcorder_video_dataprobe_push_buffer_to_record, hcamcorder);
1318 gst_object_unref(srcpad);
1321 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1323 /* Register pipeline message callback */
1324 hcamcorder->pipeline_cb_event_id = gst_bus_add_watch(bus, _mmcamcorder_pipeline_cb_message, (gpointer)hcamcorder);
1326 /* set sync handler */
1327 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1329 gst_object_unref(bus);
1332 return MM_ERROR_NONE;
1334 pipeline_creation_error:
1335 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1340 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1342 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1343 _MMCamcorderSubContext *sc = NULL;
1345 /*_mmcam_dbg_log("start");*/
1347 mmf_return_if_fail(hcamcorder);
1348 mmf_return_if_fail(hcamcorder->sub_context);
1349 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1352 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1353 sc->info_video->get_first_I_frame = FALSE;
1354 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1355 _mmcam_dbg_warn("set push_encoding_buffer RUN");
1360 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1362 int err = MM_ERROR_NONE;
1367 int rect_height = 0;
1369 int rotation = MM_DISPLAY_ROTATION_NONE;
1370 int flip = MM_FLIP_NONE;
1371 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1372 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1373 int origin_size = 0;
1376 int do_scaling = FALSE;
1377 #ifdef _MMCAMCORDER_RM_SUPPORT
1378 int display_scaler = 0;
1379 #endif /* _MMCAMCORDER_RM_SUPPORT */
1380 int *overlay = NULL;
1382 char *err_name = NULL;
1383 const char *videosink_name = NULL;
1385 GstElement *vsink = NULL;
1387 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1388 _MMCamcorderSubContext *sc = NULL;
1392 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1394 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1395 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1396 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1397 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1399 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1401 /* Get video display information */
1402 err = mm_camcorder_get_attributes(handle, &err_name,
1403 MMCAM_DISPLAY_RECT_X, &rect_x,
1404 MMCAM_DISPLAY_RECT_Y, &rect_y,
1405 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1406 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1407 MMCAM_DISPLAY_ROTATION, &rotation,
1408 MMCAM_DISPLAY_FLIP, &flip,
1409 MMCAM_DISPLAY_VISIBLE, &visible,
1410 MMCAM_DISPLAY_HANDLE, (void**)&overlay, &size,
1411 MMCAM_DISPLAY_MODE, &display_mode,
1412 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1413 MMCAM_DISPLAY_SCALE, &zoom_attr,
1414 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1416 if (err != MM_ERROR_NONE) {
1418 _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
1419 SAFE_FREE(err_name);
1421 _mmcam_dbg_err("failed to get attributes [0x%x]", err);
1427 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1429 if (!videosink_name) {
1430 _mmcam_dbg_err("failed to get videosink name");
1431 return MM_ERROR_CAMCORDER_INTERNAL;
1434 _mmcam_dbg_log("(overlay=%p, size=%d)", overlay, size);
1436 /* Set display handle */
1437 if (!strcmp(videosink_name, "xvimagesink") ||
1438 !strcmp(videosink_name, "ximagesink")) {
1441 _mmcam_dbg_log("xid = %lu )", xid);
1442 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1444 _mmcam_dbg_warn("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1445 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1447 #ifdef _MMCAMCORDER_RM_SUPPORT
1448 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
1451 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", display_scaler);
1452 #endif /* _MMCAMCORDER_RM_SUPPORT */
1453 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1454 _mmcam_dbg_log("videosink : %s, handle : %p", videosink_name, overlay);
1457 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", overlay);
1458 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1460 _mmcam_dbg_err("display handle(eavs object) is NULL");
1461 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1463 } else if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink")) {
1465 _mmcam_dbg_log("wayland global surface id : %d", *(int *)(overlay));
1466 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), (guintptr)*(int *)(overlay));
1468 _mmcam_dbg_warn("Handle is NULL. skip setting.");
1471 _mmcam_dbg_warn("Who are you?? (Videosink: %s)", videosink_name);
1474 _mmcam_dbg_log("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1475 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1478 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1479 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1481 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1484 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1486 switch (zoom_attr) {
1487 case MM_DISPLAY_SCALE_DEFAULT:
1490 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1493 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1497 _mmcam_dbg_warn("Unsupported zoom value. set as default.");
1502 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1503 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1504 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1505 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1507 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1508 if (!strcmp(videosink_name, "tizenwlsink")) {
1509 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1510 rect_x, rect_y, rect_width, rect_height);
1513 "dst-roi-x", rect_x,
1514 "dst-roi-y", rect_y,
1515 "dst-roi-w", rect_width,
1516 "dst-roi-h", rect_height,
1522 return MM_ERROR_NONE;
1526 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1529 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1530 _MMCamcorderSubContext *sc = NULL;
1532 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1534 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1536 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1539 case _MMCamcorder_CMD_PREVIEW_START:
1540 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1542 case _MMCamcorder_CMD_CAPTURE:
1543 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1546 _mmcam_dbg_warn("unknown command : %d", cmd);
1547 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1550 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1551 category, "FrameStabilityCount", &sc->frame_stability_count);
1553 _mmcam_dbg_log("[cmd %d] frame stability count : %d",
1554 cmd, sc->frame_stability_count);
1556 return MM_ERROR_NONE;
1559 /* Retreive device information and set them to attributes */
1560 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
1562 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1563 _MMCamcorderSubContext *sc = NULL;
1564 GstCameraControl *control = NULL;
1565 GstCameraControlExifInfo exif_info = {0,};
1567 mmf_return_val_if_fail(hcamcorder, FALSE);
1568 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1570 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
1572 if (sc && sc->element) {
1573 int err = MM_ERROR_NONE;
1574 char *err_name = NULL;
1575 double focal_len = 0.0;
1577 /* Video input device */
1578 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
1579 /* Exif related information */
1580 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1581 if (control != NULL) {
1582 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
1583 if (exif_info.focal_len_denominator != 0)
1584 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
1586 _mmcam_dbg_err("Fail to get camera control interface!");
1591 /* Set values to attributes */
1592 err = mm_camcorder_set_attributes(handle, &err_name,
1593 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
1595 if (err != MM_ERROR_NONE) {
1596 _mmcam_dbg_err("Set attributes error(%s:%x)!", err_name, err);
1597 SAFE_FREE(err_name);
1601 _mmcam_dbg_warn("Sub context isn't exist.");
1608 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name)
1610 return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24);
1613 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
1615 int current_state = MM_CAMCORDER_STATE_NONE;
1618 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
1619 _MMCamcorderSubContext *sc = NULL;
1620 _MMCamcorderKPIMeasure *kpi = NULL;
1621 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
1623 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
1624 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
1625 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
1627 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
1628 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
1630 current_state = hcamcorder->state;
1632 if (sc->drop_vframe > 0) {
1633 if (sc->pass_first_vframe > 0) {
1634 sc->pass_first_vframe--;
1635 _mmcam_dbg_log("Pass video frame by pass_first_vframe");
1638 _mmcam_dbg_log("Drop video frame by drop_vframe");
1639 return GST_PAD_PROBE_DROP;
1641 } else if (sc->frame_stability_count > 0) {
1642 sc->frame_stability_count--;
1643 _mmcam_dbg_log("Drop video frame by frame_stability_count");
1644 return GST_PAD_PROBE_DROP;
1647 if (current_state >= MM_CAMCORDER_STATE_PREPARE) {
1649 int frame_count = 0;
1650 struct timeval current_video_time;
1653 if (kpi->init_video_time.tv_sec == kpi->last_video_time.tv_sec &&
1654 kpi->init_video_time.tv_usec == kpi->last_video_time.tv_usec &&
1655 kpi->init_video_time.tv_usec == 0) {
1657 _mmcam_dbg_log("START to measure FPS");
1659 gettimeofday(&(kpi->init_video_time), NULL);
1662 frame_count = ++(kpi->video_framecount);
1664 gettimeofday(¤t_video_time, NULL);
1665 diff_sec = current_video_time.tv_sec - kpi->last_video_time.tv_sec;
1666 if (diff_sec != 0) {
1667 kpi->current_fps = (frame_count - kpi->last_framecount) / diff_sec;
1668 if ((current_video_time.tv_sec - kpi->init_video_time.tv_sec) != 0) {
1669 int framecount = kpi->video_framecount;
1670 int elased_sec = current_video_time.tv_sec - kpi->init_video_time.tv_sec;
1671 kpi->average_fps = framecount / elased_sec;
1674 kpi->last_framecount = frame_count;
1675 kpi->last_video_time.tv_sec = current_video_time.tv_sec;
1676 kpi->last_video_time.tv_usec = current_video_time.tv_usec;
1678 _mmcam_dbg_log("current fps(%d), average(%d)", kpi->current_fps, kpi->average_fps);
1683 /* video stream callback */
1684 if (hcamcorder->vstream_cb && buffer) {
1685 int state = MM_CAMCORDER_STATE_NULL;
1687 unsigned int fourcc = 0;
1688 const gchar *string_format = NULL;
1690 MMCamcorderVideoStreamDataType stream;
1691 tbm_surface_h t_surface = NULL;
1692 tbm_surface_info_s t_info;
1694 GstCaps *caps = NULL;
1695 GstStructure *structure = NULL;
1696 GstMemory *memory = NULL;
1699 state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
1700 if (state < MM_CAMCORDER_STATE_PREPARE) {
1701 _mmcam_dbg_warn("Not ready for stream callback");
1702 return GST_PAD_PROBE_OK;
1705 caps = gst_pad_get_current_caps(pad);
1707 _mmcam_dbg_warn("Caps is NULL.");
1708 return GST_PAD_PROBE_OK;
1711 /* clear data structure */
1712 memset(&mapinfo, 0x0, sizeof(GstMapInfo));
1713 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
1715 structure = gst_caps_get_structure(caps, 0);
1716 gst_structure_get_int(structure, "width", &(stream.width));
1717 gst_structure_get_int(structure, "height", &(stream.height));
1719 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
1720 stream.format = MM_PIXEL_FORMAT_ENCODED_H264;
1722 string_format = gst_structure_get_string(structure, "format");
1723 if (string_format == NULL) {
1724 gst_caps_unref(caps);
1726 _mmcam_dbg_warn("get string error!!");
1727 return GST_PAD_PROBE_OK;
1730 fourcc = _mmcamcorder_convert_fourcc_string_to_value(string_format);
1731 stream.format = _mmcamcorder_get_pixtype(fourcc);
1734 gst_caps_unref(caps);
1738 _mmcam_dbg_log("Call video steramCb, data[%p], Width[%d],Height[%d], Format[%d]",
1739 GST_BUFFER_DATA(buffer), stream.width, stream.height, stream.format);
1742 if (stream.width == 0 || stream.height == 0) {
1743 _mmcam_dbg_warn("Wrong condition!!");
1744 return GST_PAD_PROBE_OK;
1747 /* set size and timestamp */
1748 memory = gst_buffer_peek_memory(buffer, 0);
1750 _mmcam_dbg_err("GstMemory get failed from buffer %p", buffer);
1751 return GST_PAD_PROBE_OK;
1754 if (hcamcorder->use_zero_copy_format) {
1755 t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
1757 if (tbm_surface_get_info(t_surface, &t_info) != TBM_SURFACE_ERROR_NONE) {
1758 _mmcam_dbg_err("failed to get tbm surface[%p] info", t_surface);
1759 return GST_PAD_PROBE_OK;
1762 stream.length_total = t_info.size;
1764 /* set bo, stride and elevation */
1765 num_bos = gst_tizen_memory_get_num_bos(memory);
1766 for (i = 0 ; i < num_bos ; i++)
1767 stream.bo[i] = gst_tizen_memory_get_bos(memory, i);
1769 for (i = 0 ; i < t_info.num_planes ; i++) {
1770 stream.stride[i] = t_info.planes[i].stride;
1771 stream.elevation[i] = t_info.planes[i].size / t_info.planes[i].stride;
1772 /*_mmcam_dbg_log("[%d] %dx%d", i, stream.stride[i], stream.elevation[i]);*/
1775 /* set gst buffer */
1776 stream.internal_buffer = buffer;
1778 stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
1781 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer)/1000000); /* nano sec -> mili sec */
1783 /* set data pointers */
1784 if (stream.format == MM_PIXEL_FORMAT_NV12 ||
1785 stream.format == MM_PIXEL_FORMAT_NV21 ||
1786 stream.format == MM_PIXEL_FORMAT_I420) {
1787 if (hcamcorder->use_zero_copy_format) {
1788 if (stream.format == MM_PIXEL_FORMAT_NV12 ||
1789 stream.format == MM_PIXEL_FORMAT_NV21) {
1790 stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
1791 stream.num_planes = 2;
1792 stream.data.yuv420sp.y = t_info.planes[0].ptr;
1793 stream.data.yuv420sp.length_y = t_info.planes[0].size;
1794 stream.data.yuv420sp.uv = t_info.planes[1].ptr;
1795 stream.data.yuv420sp.length_uv = t_info.planes[1].size;
1797 _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:%p,size:%d [UV]p:%p,size:%d",
1798 stream.format, stream.num_planes,
1799 stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
1800 stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
1803 stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
1804 stream.num_planes = 3;
1805 stream.data.yuv420p.y = t_info.planes[0].ptr;
1806 stream.data.yuv420p.length_y = t_info.planes[0].size;
1807 stream.data.yuv420p.u = t_info.planes[1].ptr;
1808 stream.data.yuv420p.length_u = t_info.planes[1].size;
1809 stream.data.yuv420p.v = t_info.planes[2].ptr;
1810 stream.data.yuv420p.length_v = t_info.planes[2].size;
1812 _mmcam_dbg_log("S420[num_planes:%d] [Y]p:%p,size:%d [U]p:%p,size:%d [V]p:%p,size:%d",
1814 stream.data.yuv420p.y, stream.data.yuv420p.length_y,
1815 stream.data.yuv420p.u, stream.data.yuv420p.length_u,
1816 stream.data.yuv420p.v, stream.data.yuv420p.length_v);
1820 gst_memory_map(memory, &mapinfo, GST_MAP_READWRITE);
1821 if (stream.format == MM_PIXEL_FORMAT_NV12 ||
1822 stream.format == MM_PIXEL_FORMAT_NV21) {
1823 stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
1824 stream.num_planes = 2;
1825 stream.data.yuv420sp.y = mapinfo.data;
1826 stream.data.yuv420sp.length_y = stream.width * stream.height;
1827 stream.data.yuv420sp.uv = stream.data.yuv420sp.y + stream.data.yuv420sp.length_y;
1828 stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 1;
1829 stream.stride[0] = stream.width;
1830 stream.elevation[0] = stream.height;
1831 stream.stride[1] = stream.width;
1832 stream.elevation[1] = stream.height >> 1;
1834 _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:%p,size:%d [UV]p:%p,size:%d",
1835 stream.format, stream.num_planes,
1836 stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
1837 stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
1840 stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
1841 stream.num_planes = 3;
1842 stream.data.yuv420p.y = mapinfo.data;
1843 stream.data.yuv420p.length_y = stream.width * stream.height;
1844 stream.data.yuv420p.u = stream.data.yuv420p.y + stream.data.yuv420p.length_y;
1845 stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2;
1846 stream.data.yuv420p.v = stream.data.yuv420p.u + stream.data.yuv420p.length_u;
1847 stream.data.yuv420p.length_v = stream.data.yuv420p.length_u;
1848 stream.stride[0] = stream.width;
1849 stream.elevation[0] = stream.height;
1850 stream.stride[1] = stream.width >> 1;
1851 stream.elevation[1] = stream.height >> 1;
1852 stream.stride[2] = stream.width >> 1;
1853 stream.elevation[2] = stream.height >> 1;
1855 _mmcam_dbg_log("I420[num_planes:%d] [Y]p:%p,size:%d [U]p:%p,size:%d [V]p:%p,size:%d",
1857 stream.data.yuv420p.y, stream.data.yuv420p.length_y,
1858 stream.data.yuv420p.u, stream.data.yuv420p.length_u,
1859 stream.data.yuv420p.v, stream.data.yuv420p.length_v);
1864 gst_memory_map(memory, &mapinfo, GST_MAP_READWRITE);
1866 switch (stream.format) {
1867 case MM_PIXEL_FORMAT_YUYV:
1868 case MM_PIXEL_FORMAT_UYVY:
1869 case MM_PIXEL_FORMAT_422P:
1870 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
1871 stream.data_type = MM_CAM_STREAM_DATA_YUV422;
1872 stream.data.yuv422.yuv = mapinfo.data;
1873 stream.data.yuv422.length_yuv = stream.length_total;
1874 stream.stride[0] = stream.width << 1;
1875 stream.elevation[0] = stream.height;
1877 case MM_PIXEL_FORMAT_ENCODED_H264:
1878 stream.data_type = MM_CAM_STREAM_DATA_ENCODED;
1879 stream.data.encoded.data = mapinfo.data;
1880 stream.data.encoded.length_data = stream.length_total;
1882 _mmcam_dbg_log("H264[num_planes:%d] [0]p:%p,size:%d",
1883 stream.num_planes, stream.data.encoded.data, stream.data.encoded.length_data);
1886 case MM_PIXEL_FORMAT_INVZ:
1887 stream.data_type = MM_CAM_STREAM_DATA_DEPTH;
1888 stream.data.depth.data = mapinfo.data;
1889 stream.data.depth.length_data = stream.length_total;
1890 stream.stride[0] = stream.width << 1;
1891 stream.elevation[0] = stream.height;
1893 case MM_PIXEL_FORMAT_RGBA:
1894 case MM_PIXEL_FORMAT_ARGB:
1895 stream.data_type = MM_CAM_STREAM_DATA_RGB;
1896 stream.data.rgb.data = mapinfo.data;
1897 stream.data.rgb.length_data = stream.length_total;
1898 stream.stride[0] = stream.width << 2;
1899 stream.elevation[0] = stream.height;
1902 stream.data_type = MM_CAM_STREAM_DATA_YUV420;
1903 stream.data.yuv420.yuv = mapinfo.data;
1904 stream.data.yuv420.length_yuv = stream.length_total;
1905 stream.stride[0] = (stream.width * 3) >> 1;
1906 stream.elevation[0] = stream.height;
1910 stream.num_planes = 1;
1912 _mmcam_dbg_log("%c%c%c%c[num_planes:%d] [0]p:%p,size:%d",
1913 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
1914 stream.num_planes, stream.data.yuv420.yuv, stream.data.yuv420.length_yuv);
1918 /* call application callback */
1919 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
1920 if (hcamcorder->vstream_cb) {
1921 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
1923 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
1924 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
1925 tbm_bo_unmap(stream.bo[i]);
1929 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1933 gst_memory_unmap(memory, &mapinfo);
1936 return GST_PAD_PROBE_OK;
1939 static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
1941 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
1942 _MMCamcorderSubContext *sc = NULL;
1943 GstClockTime diff = 0; /* nsec */
1944 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
1946 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
1947 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
1948 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
1950 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
1951 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
1953 /* push buffer in appsrc to encode */
1954 if (!sc->info_video) {
1955 _mmcam_dbg_warn("sc->info_video is NULL!!");
1956 return GST_PAD_PROBE_DROP;
1959 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_RUN &&
1960 sc->info_video->record_dual_stream == FALSE &&
1961 sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst) {
1963 GstClock *clock = NULL;
1966 _mmcam_dbg_log("GST_BUFFER_FLAG_DELTA_UNIT is set : %d",
1967 GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT));
1970 /* check first I frame */
1971 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264 &&
1972 sc->info_video->get_first_I_frame == FALSE) {
1973 if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
1974 _mmcam_dbg_warn("first I frame is come");
1975 sc->info_video->get_first_I_frame = TRUE;
1977 _mmcam_dbg_warn("NOT I frame.. skip this buffer");
1978 return GST_PAD_PROBE_OK;
1982 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) {
1983 if (sc->info_video->is_firstframe) {
1984 clock = GST_ELEMENT_CLOCK(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst);
1986 gst_object_ref(clock);
1987 sc->info_video->base_video_ts = GST_BUFFER_PTS(buffer) - (gst_clock_get_time(clock) - GST_ELEMENT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst)->base_time);
1988 gst_object_unref(clock);
1992 if (sc->info_video->is_firstframe) {
1993 /* for image capture with encodebin(ex:emulator) */
1994 if (sc->bencbin_capture && sc->info_image->capturing) {
1995 g_mutex_lock(&hcamcorder->task_thread_lock);
1996 _mmcam_dbg_log("send signal for sound play");
1997 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_SOUND_SOLO_PLAY_START;
1998 g_cond_signal(&hcamcorder->task_thread_cond);
1999 g_mutex_unlock(&hcamcorder->task_thread_lock);
2001 sc->info_video->base_video_ts = GST_BUFFER_PTS(buffer);
2004 GST_BUFFER_PTS(buffer) = GST_BUFFER_PTS(buffer) - sc->info_video->base_video_ts;
2005 GST_BUFFER_DTS(buffer) = GST_BUFFER_PTS(buffer);
2007 /*_mmcam_dbg_log("buffer %p, timestamp %"GST_TIME_FORMAT, buffer, GST_TIME_ARGS(GST_BUFFER_PTS(buffer)));*/
2010 GstCaps *caps = gst_pad_get_current_caps(pad);
2012 char *caps_string = gst_caps_to_string(caps);
2014 _mmcam_dbg_log("%s", caps_string);
2015 g_free(caps_string);
2018 gst_caps_unref(caps);
2021 _mmcam_dbg_warn("failed to get caps from pad");
2025 g_signal_emit_by_name(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "push-buffer", buffer, &ret);
2027 /*_mmcam_dbg_log("push buffer result : 0x%x", ret);*/
2029 if (sc->info_video->is_firstframe) {
2030 sc->info_video->is_firstframe = FALSE;
2032 /* drop buffer if it's from tizen allocator */
2033 if (gst_is_tizen_memory(gst_buffer_peek_memory(buffer, 0))) {
2034 _mmcam_dbg_warn("drop first buffer from tizen allocator to avoid copy in basesrc");
2035 return GST_PAD_PROBE_DROP;
2040 /* skip display if too fast FPS */
2041 if (sc->info_video && sc->info_video->fps > _MMCAMCORDER_FRAME_PASS_MIN_FPS) {
2042 if (sc->info_video->prev_preview_ts != 0) {
2043 diff = GST_BUFFER_PTS(buffer) - sc->info_video->prev_preview_ts;
2044 if (diff < _MMCAMCORDER_MIN_TIME_TO_PASS_FRAME) {
2045 _mmcam_dbg_log("it's too fast. drop frame...");
2046 return GST_PAD_PROBE_DROP;
2050 /*_mmcam_dbg_log("diff %llu", diff);*/
2052 sc->info_video->prev_preview_ts = GST_BUFFER_PTS(buffer);
2055 return GST_PAD_PROBE_OK;
2059 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2061 MMCamcorderMuxedStreamDataType stream;
2062 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2063 _MMCamcorderSubContext *sc = NULL;
2064 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2067 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2068 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2069 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2071 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2072 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2074 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2075 _mmcam_dbg_warn("map failed : buffer %p", buffer);
2076 return GST_PAD_PROBE_OK;
2079 /* call application callback */
2080 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2082 if (hcamcorder->mstream_cb) {
2083 stream.data = (void *)mapinfo.data;
2084 stream.length = mapinfo.size;
2085 stream.offset = sc->muxed_stream_offset;
2086 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2089 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2091 /* calculate current offset */
2092 sc->muxed_stream_offset += mapinfo.size;
2094 gst_buffer_unmap(buffer, &mapinfo);
2096 return GST_PAD_PROBE_OK;
2100 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2102 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2103 mmf_camcorder_t *hcamcorder = NULL;
2104 _MMCamcorderSubContext *sc = NULL;
2105 GstObject *parent = NULL;
2107 switch (GST_EVENT_TYPE(event)) {
2108 case GST_EVENT_UNKNOWN:
2109 /* upstream events */
2111 case GST_EVENT_SEEK:
2112 case GST_EVENT_NAVIGATION:
2113 case GST_EVENT_LATENCY:
2114 /* downstream serialized events */
2115 case GST_EVENT_BUFFERSIZE:
2116 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2120 GstTagList *tag_list = NULL;
2121 _MMCamcorderReplayGain *replay_gain = NULL;
2123 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2125 hcamcorder = MMF_CAMCORDER(u_data);
2126 if (!hcamcorder || !hcamcorder->sub_context) {
2127 _mmcam_dbg_warn("NULL handle");
2131 replay_gain = &hcamcorder->sub_context->replay_gain;
2133 gst_event_parse_tag(event, &tag_list);
2135 _mmcam_dbg_warn("failed to get tag list");
2139 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2140 _mmcam_dbg_warn("failed to get GST_TAG_TRACK_PEAK");
2144 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2145 _mmcam_dbg_warn("failed to get GST_TAG_TRACK_GAIN");
2149 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2150 _mmcam_dbg_warn("failed to get GST_TAG_ALBUM_PEAK");
2154 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2155 _mmcam_dbg_warn("failed to get GST_TAG_ALBUM_PEAK");
2159 _mmcam_dbg_log("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2160 replay_gain->track_peak, replay_gain->track_gain,
2161 replay_gain->album_peak, replay_gain->album_gain);
2164 case GST_EVENT_SEGMENT:
2165 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2167 hcamcorder = MMF_CAMCORDER(u_data);
2169 _mmcam_dbg_warn("NULL handle");
2173 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2175 _mmcam_dbg_warn("NULL sub context");
2179 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2180 _mmcam_dbg_warn("no encoder sink");
2184 parent = gst_pad_get_parent(pad);
2186 _mmcam_dbg_warn("get parent failed");
2190 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2191 const GstSegment *segment;
2192 gst_event_parse_segment(event, &segment);
2193 if (segment->format == GST_FORMAT_BYTES) {
2194 _mmcam_dbg_log("change current offset %llu -> %"G_GUINT64_FORMAT,
2195 sc->muxed_stream_offset, segment->start);
2197 sc->muxed_stream_offset = (unsigned long long)segment->start;
2201 gst_object_unref(parent);
2205 _mmcam_dbg_warn("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2207 /* bidirectional events */
2208 case GST_EVENT_FLUSH_START:
2209 case GST_EVENT_FLUSH_STOP:
2210 _mmcam_dbg_err("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2213 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2217 return GST_PAD_PROBE_OK;
2221 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2223 int result = MM_CAMCORDER_MR475;
2226 result = MM_CAMCORDER_MR475; /*AMR475*/
2227 else if (bitrate < 5900)
2228 result = MM_CAMCORDER_MR515; /*AMR515*/
2229 else if (bitrate < 6700)
2230 result = MM_CAMCORDER_MR59; /*AMR59*/
2231 else if (bitrate < 7400)
2232 result = MM_CAMCORDER_MR67; /*AMR67*/
2233 else if (bitrate < 7950)
2234 result = MM_CAMCORDER_MR74; /*AMR74*/
2235 else if (bitrate < 10200)
2236 result = MM_CAMCORDER_MR795; /*AMR795*/
2237 else if (bitrate < 12200)
2238 result = MM_CAMCORDER_MR102; /*AMR102*/
2240 result = MM_CAMCORDER_MR122; /*AMR122*/
2246 int _mmcamcorder_get_eos_message(MMHandleType handle)
2249 int ret = MM_ERROR_NONE;
2251 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2252 _MMCamcorderSubContext *sc = NULL;
2254 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2255 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2256 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2258 _mmcam_dbg_log("START");
2260 _MMCAMCORDER_LOCK(handle);
2262 if (sc->bget_eos == FALSE) {
2263 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2264 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2265 _mmcam_dbg_log("EOS signal received");
2267 _mmcam_dbg_err("EOS wait time out");
2269 if (hcamcorder->error_code == MM_ERROR_NONE)
2270 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2273 _mmcam_dbg_log("already got EOS");
2276 _MMCAMCORDER_UNLOCK(handle);
2278 if (hcamcorder->error_code == MM_ERROR_NONE) {
2279 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2280 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2281 if (sc->info_video->b_commiting)
2282 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2284 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2285 if (sc->info_audio->b_commiting)
2286 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2289 ret = hcamcorder->error_code;
2290 _mmcam_dbg_err("error 0x%x", ret);
2293 _mmcam_dbg_log("END");
2299 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2302 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2304 mmf_return_if_fail(handle && remove_element);
2305 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2309 for (i = first_elem ; i <= last_elem ; i++) {
2310 remove_element[i].gst = NULL;
2311 remove_element[i].id = _MMCAMCORDER_NONE;
2318 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2320 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2322 /* Check compatibility between codec and file format */
2323 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2324 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2325 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2326 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2327 _mmcam_dbg_err("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2328 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2331 _mmcam_dbg_log("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2333 _mmcam_dbg_err("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2334 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2336 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2337 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2338 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2339 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2340 _mmcam_dbg_err("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2341 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2344 _mmcam_dbg_log("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2346 _mmcam_dbg_err("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2347 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2351 return MM_ERROR_NONE;
2355 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2357 int err = MM_ERROR_NONE;
2358 int audio_codec = MM_AUDIO_CODEC_INVALID;
2359 int file_format = MM_FILE_FORMAT_INVALID;
2361 char *err_name = NULL;
2363 err = mm_camcorder_get_attributes(handle, &err_name,
2364 MMCAM_AUDIO_ENCODER, &audio_codec,
2365 MMCAM_FILE_FORMAT, &file_format,
2367 if (err != MM_ERROR_NONE) {
2368 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
2369 SAFE_FREE(err_name);
2373 /* Check compatibility between audio codec and file format */
2374 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2380 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2382 int err = MM_ERROR_NONE;
2383 int video_codec = MM_VIDEO_CODEC_INVALID;
2384 int file_format = MM_FILE_FORMAT_INVALID;
2386 char *err_name = NULL;
2388 err = mm_camcorder_get_attributes(handle, &err_name,
2389 MMCAM_VIDEO_ENCODER, &video_codec,
2390 MMCAM_FILE_FORMAT, &file_format,
2392 if (err != MM_ERROR_NONE) {
2393 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
2394 SAFE_FREE(err_name);
2398 /* Check compatibility between video codec and file format */
2399 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2405 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2407 const char* videosink_name = NULL;
2409 mmf_camcorder_t *hcamcorder = NULL;
2410 _MMCamcorderSubContext *sc = NULL;
2412 hcamcorder = MMF_CAMCORDER(handle);
2413 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2415 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2416 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2417 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2419 if (sc->element[videosink_index].gst) {
2420 /* Get videosink name */
2421 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2422 if (videosink_name == NULL) {
2423 _mmcam_dbg_err("Please check videosink element in configuration file");
2427 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2428 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2429 !strcmp(videosink_name, "directvideosink")) {
2430 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2431 _mmcam_dbg_log("Set display-rotate [%d] done.", display_rotate);
2433 _mmcam_dbg_warn("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2438 _mmcam_dbg_err("Videosink element is null");
2444 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2446 const char* videosink_name = NULL;
2448 mmf_camcorder_t *hcamcorder = NULL;
2449 _MMCamcorderSubContext *sc = NULL;
2451 hcamcorder = MMF_CAMCORDER(handle);
2452 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2454 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2455 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2456 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2458 if (sc->element[videosink_index].gst) {
2459 /* Get videosink name */
2460 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2461 if (videosink_name == NULL) {
2462 _mmcam_dbg_err("Please check videosink element in configuration file");
2466 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2467 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2468 !strcmp(videosink_name, "directvideosink")) {
2469 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2470 _mmcam_dbg_log("Set display flip [%d] done.", display_flip);
2472 _mmcam_dbg_warn("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2477 _mmcam_dbg_err("Videosink element is null");
2483 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2488 _MMCamcorderSubContext *sc = NULL;
2490 mmf_camcorder_t *hcamcorder = NULL;
2492 hcamcorder = MMF_CAMCORDER(handle);
2493 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2495 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2497 _mmcam_dbg_log("sub context is not initailized");
2501 mm_camcorder_get_attributes(handle, NULL,
2502 MMCAM_CAMERA_WIDTH, &width,
2503 MMCAM_CAMERA_HEIGHT, &height,
2504 MMCAM_CAMERA_FPS, &fps,
2507 _mmcam_dbg_log("set rotate %d", videosrc_rotate);
2509 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, videosrc_rotate);
2513 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2519 unsigned int caps_fourcc = 0;
2520 gboolean do_set_caps = FALSE;
2522 GstCaps *caps = NULL;
2523 #ifdef _MMCAMCORDER_PRODUCT_TV
2525 GstCaps *decsink_caps = NULL;
2526 GstStructure *decsink_struct = NULL;
2529 #endif /*_MMCAMCORDER_PRODUCT_TV */
2531 mmf_camcorder_t *hcamcorder = NULL;
2532 _MMCamcorderSubContext *sc = NULL;
2534 hcamcorder = MMF_CAMCORDER(handle);
2535 mmf_return_val_if_fail(hcamcorder, FALSE);
2537 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2539 if (!sc || !(sc->element)) {
2540 _mmcam_dbg_log("sub context is not initialized");
2544 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2545 _mmcam_dbg_err("Video src is NULL!");
2549 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2550 _mmcam_dbg_err("Video filter is NULL!");
2554 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2555 int capture_width = 0;
2556 int capture_height = 0;
2557 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2559 mm_camcorder_get_attributes(handle, NULL,
2560 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2561 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2562 MMCAM_CAPTURE_WIDTH, &capture_width,
2563 MMCAM_CAPTURE_HEIGHT, &capture_height,
2564 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2565 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2567 _mmcam_dbg_log("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2568 motion_rate, capture_width, capture_height, fps_auto,
2569 sc->info_video->video_width, sc->info_video->video_height);
2571 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2572 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2574 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2575 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2576 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2579 sc->info_video->fps = fps;
2582 /* Interleaved format does not support rotation */
2583 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2584 /* store videosrc rotation */
2585 sc->videosrc_rotate = rotate;
2587 /* Define width, height and rotate in caps */
2589 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2590 This will be applied when rotate is 0, 180 if front camera. */
2591 set_rotate = rotate * 90;
2593 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2594 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2597 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2598 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2605 set_height = height;
2608 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2611 set_height = height;
2613 _mmcam_dbg_warn("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2616 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2617 if (caps && !gst_caps_is_any(caps)) {
2618 GstStructure *structure = NULL;
2620 structure = gst_caps_get_structure(caps, 0);
2622 const gchar *format_string = NULL;
2624 int caps_height = 0;
2626 int caps_rotate = 0;
2628 format_string = gst_structure_get_string(structure, "format");
2630 caps_fourcc = _mmcamcorder_convert_fourcc_string_to_value(format_string);
2632 gst_structure_get_int(structure, "width", &caps_width);
2633 gst_structure_get_int(structure, "height", &caps_height);
2634 gst_structure_get_int(structure, "fps", &caps_fps);
2635 gst_structure_get_int(structure, "rotate", &caps_rotate);
2637 #ifdef _MMCAMCORDER_PRODUCT_TV
2638 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
2639 if (set_width == caps_width && set_height == caps_height && set_rotate == caps_rotate && fps == caps_fps) {
2640 _mmcam_dbg_log("No need to replace caps.");
2642 _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2643 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2644 caps_width, caps_height, caps_fps, caps_rotate,
2645 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2646 set_width, set_height, fps, set_rotate);
2650 if (set_width == caps_width && set_height == caps_height &&
2651 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2652 _mmcam_dbg_log("No need to replace caps.");
2654 _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2655 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2656 caps_width, caps_height, caps_fps, caps_rotate,
2657 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2658 set_width, set_height, fps, set_rotate);
2662 #else /*_MMCAMCORDER_PRODUCT_TV */
2663 if (set_width == caps_width && set_height == caps_height &&
2664 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2665 _mmcam_dbg_log("No need to replace caps.");
2667 _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2668 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2669 caps_width, caps_height, caps_fps, caps_rotate,
2670 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2671 set_width, set_height, fps, set_rotate);
2674 #endif /*_MMCAMCORDER_PRODUCT_TV */
2676 _mmcam_dbg_log("can not get structure of caps. set new one...");
2680 _mmcam_dbg_log("No caps. set new one...");
2685 gst_caps_unref(caps);
2690 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
2691 #ifdef _MMCAMCORDER_PRODUCT_TV
2692 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
2694 _mmcam_dbg_err("There are no decoder caps");
2698 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
2699 if (!decsink_caps) {
2700 gst_object_unref(sinkpad);
2701 _mmcam_dbg_err("There is no decoder sink caps");
2705 decsink_struct = gst_caps_get_structure(decsink_caps, 0);
2706 if (!decsink_struct) {
2707 _mmcam_dbg_err("There are no structure from caps");
2708 gst_object_unref(decsink_caps);
2709 gst_object_unref(sinkpad);
2713 if (gst_structure_has_field(decsink_struct, "maxwidth"))
2714 gst_structure_get_int(decsink_struct, "maxwidth", &maxwidth);
2716 if (gst_structure_has_field(decsink_struct, "maxheight"))
2717 gst_structure_get_int(decsink_struct, "maxheight", &maxheight);
2718 #endif /* _MMCAMCORDER_PRODUCT_TV */
2720 caps = gst_caps_new_simple("video/x-h264",
2721 "width", G_TYPE_INT, set_width,
2722 "height", G_TYPE_INT, set_height,
2723 "framerate", GST_TYPE_FRACTION, fps, 1,
2724 "stream-format", G_TYPE_STRING, "byte-stream",
2725 #ifdef _MMCAMCORDER_PRODUCT_TV
2726 "maxwidth", G_TYPE_INT, maxwidth,
2727 "maxheight", G_TYPE_INT, maxheight,
2728 "alignment", G_TYPE_STRING, "au",
2729 #endif /* _MMCAMCORDER_PRODUCT_TV */
2732 #ifdef _MMCAMCORDER_PRODUCT_TV
2733 gst_object_unref(decsink_caps);
2734 gst_object_unref(sinkpad);
2735 #endif /* _MMCAMCORDER_PRODUCT_TV */
2737 char fourcc_string[sizeof(fourcc)+1];
2738 strncpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
2739 fourcc_string[sizeof(fourcc)] = '\0';
2740 caps = gst_caps_new_simple("video/x-raw",
2741 "format", G_TYPE_STRING, fourcc_string,
2742 "width", G_TYPE_INT, set_width,
2743 "height", G_TYPE_INT, set_height,
2744 "framerate", GST_TYPE_FRACTION, fps, 1,
2745 "rotate", G_TYPE_INT, set_rotate,
2750 gchar *caps_str = gst_caps_to_string(caps);
2753 _mmcam_dbg_log("vidoesrc new caps set [%s]", caps_str);
2757 _mmcam_dbg_warn("caps string failed");
2760 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2761 gst_caps_unref(caps);
2764 _mmcam_dbg_err("There are no caps");
2768 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2769 /* assume that it's camera capture mode */
2770 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2777 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2779 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2780 _MMCamcorderSubContext *sc = NULL;
2782 mmf_return_val_if_fail(hcamcorder, FALSE);
2784 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2788 _mmcam_dbg_log("Set FLIP %d", videosrc_flip);
2790 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2794 /* Interleaved format does not support FLIP */
2795 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2796 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2797 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2799 _mmcam_dbg_log("videosrc flip H:%d, V:%d", hflip, vflip);
2801 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2802 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2804 _mmcam_dbg_warn("ITLV format does not support FLIP. Ignore FLIP[%d]",
2808 _mmcam_dbg_warn("element is NULL");
2816 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2818 GstCameraControl *control = NULL;
2819 _MMCamcorderSubContext *sc = NULL;
2820 GstElement *v_src = NULL;
2824 mmf_return_val_if_fail(handle, FALSE);
2826 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2830 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2833 _mmcam_dbg_warn("videosrc element is NULL");
2837 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2839 /* set anti-shake with camera control */
2840 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2841 _mmcam_dbg_warn("Can't cast Video source into camera control.");
2845 control = GST_CAMERA_CONTROL(v_src);
2846 if (gst_camera_control_set_ahs(control, set_value)) {
2847 _mmcam_dbg_log("Succeed in operating anti-handshake. value[%d]", set_value);
2850 _mmcam_dbg_warn("Failed to operate anti-handshake. value[%d]", set_value);
2857 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2859 _MMCamcorderSubContext *sc = NULL;
2860 GstElement *v_src = NULL;
2862 mmf_return_val_if_fail(handle, FALSE);
2864 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2868 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2870 _mmcam_dbg_warn("videosrc element is NULL");
2874 /* check property of videosrc element - support VDIS */
2875 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2876 int video_width = 0;
2877 int video_height = 0;
2879 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2880 _mmcam_dbg_log("ENABLE video stabilization");
2882 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2883 mm_camcorder_get_attributes(handle, NULL,
2884 MMCAM_VIDEO_WIDTH, &video_width,
2885 MMCAM_VIDEO_HEIGHT, &video_height,
2888 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2889 _mmcam_dbg_log("NV12, video size %dx%d, ENABLE video stabilization",
2890 video_width, video_height);
2892 g_object_set(G_OBJECT(v_src),
2893 "enable-vdis-mode", TRUE,
2896 _mmcam_dbg_warn("invalid preview format %c%c%c%c or video size %dx%d",
2897 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2898 video_width, video_height);
2903 g_object_set(G_OBJECT(v_src),
2904 "enable-vdis-mode", FALSE,
2907 _mmcam_dbg_log("DISABLE video stabilization");
2909 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2910 _mmcam_dbg_err("no property for video stabilization, so can not set ON");
2913 _mmcam_dbg_warn("no property for video stabilization");
2920 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2924 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2925 _MMCamcorderSubContext *sc = NULL;
2927 mmf_return_val_if_fail(hcamcorder, FALSE);
2929 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2933 mm_camcorder_get_attributes(handle, NULL,
2934 MMCAM_CAMERA_FPS, &fps,
2937 _mmcam_dbg_log("set %dx%d", width, height);
2939 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2943 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2945 _MMCamcorderSubContext *sc = NULL;
2946 GstCameraControl *CameraControl = NULL;
2947 GstCameraControlChannel *CameraControlChannel = NULL;
2948 const GList *controls = NULL;
2949 const GList *item = NULL;
2951 if ((void *)handle == NULL) {
2952 _mmcam_dbg_warn("handle is NULL");
2956 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2958 _mmcam_dbg_warn("subcontext is NULL");
2962 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2963 _mmcam_dbg_warn("videosrc plugin is NULL");
2967 _mmcam_dbg_log("set encoded preview bitrate : %d bps", bitrate);
2969 CameraControl = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2970 controls = gst_camera_control_list_channels(CameraControl);
2971 _mmcam_dbg_log("controls : %p", controls);
2972 if (controls != NULL) {
2973 for (item = controls ; item && item->data ; item = item->next) {
2974 CameraControlChannel = item->data;
2975 _mmcam_dbg_log("label : %s", CameraControlChannel->label);
2976 if (!strcmp(CameraControlChannel->label, "bitrate")) {
2977 _mmcam_dbg_log("set encoded preview bitrate %d", bitrate);
2978 return gst_camera_control_set_value(CameraControl, CameraControlChannel, bitrate);
2982 _mmcam_dbg_warn("failed to find \"bitrate\" control channel");
2989 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int interval)
2991 _MMCamcorderSubContext *sc = NULL;
2993 if ((void *)handle == NULL) {
2994 _mmcam_dbg_warn("handle is NULL");
2998 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3000 _mmcam_dbg_warn("subcontext is NULL");
3004 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3005 _mmcam_dbg_warn("videosrc plugin is NULL");
3009 _mmcam_dbg_log("set encoded preview GOP interval : %d ms", interval);
3011 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "newgop-interval", interval);
3017 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3019 GstStructure *props = NULL;
3020 char stream_props[64] = {'\0',};
3022 if (element == NULL || stream_type == NULL || stream_index < 0) {
3023 _mmcam_dbg_err("invalid argument %p %p %d", element, stream_type, stream_index);
3027 snprintf(stream_props, sizeof(stream_props) - 1,
3028 "props,media.role=%s, media.parent_id=%d",
3029 stream_type, stream_index);
3031 _mmcam_dbg_warn("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3033 props = gst_structure_from_string(stream_props, NULL);
3035 _mmcam_dbg_err("failed to create GstStructure");
3039 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3041 gst_structure_free(props);
3048 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3050 int ret = MM_ERROR_NONE;
3051 _MMCamcorderSubContext *sc = NULL;
3052 mmf_camcorder_t *hcamcorder = NULL;
3053 const char *videodecoder_name = NULL;
3054 #ifdef _MMCAMCORDER_RM_SUPPORT
3055 char decoder_name[20] = {'\0',};
3056 int decoder_index = 0;
3057 #endif /* _MMCAMCORDER_RM_SUPPORT */
3059 if ((void *)handle == NULL) {
3060 _mmcam_dbg_warn("handle is NULL");
3064 hcamcorder = MMF_CAMCORDER(handle);
3066 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3068 _mmcam_dbg_warn("subcontext is NULL");
3072 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ENCODED_H264 ||
3073 hcamcorder->recreate_decoder == FALSE) {
3074 _mmcam_dbg_log("skip this fuction - format %d, recreate decoder %d",
3075 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3079 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3080 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3081 _mmcam_dbg_warn("main pipeline or decoder plugin is NULL");
3085 _mmcam_dbg_log("start");
3087 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
3088 if (videodecoder_name == NULL) {
3089 _mmcam_dbg_err("failed to get decoder element name from %p", sc->VideodecoderElementH264);
3093 /* set state as NULL */
3094 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3095 if (ret != MM_ERROR_NONE) {
3096 _mmcam_dbg_err("failed to set NULL to decoder");
3100 /* remove decoder - pads will be unlinked automatically in remove function */
3101 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3102 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3103 _mmcam_dbg_err("failed to remove decoder from pipeline");
3107 /* check decoder element */
3108 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3109 _mmcam_dbg_log("decoder[%p] is still alive - ref count %d",
3110 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3111 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3114 #ifdef _MMCAMCORDER_RM_SUPPORT
3115 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3118 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
3119 _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
3120 /* create decoder */
3121 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(decoder_name, "videosrc_decode");
3122 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3123 _mmcam_dbg_err("Decoder[%s] creation fail", decoder_name);
3126 #else /* _MMCAMCORDER_RM_SUPPORT */
3127 /* create new decoder */
3128 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name, "videosrc_decode");
3129 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3130 _mmcam_dbg_err("Decoder [%s] creation fail", videodecoder_name);
3133 #endif /* _MMCAMCORDER_RM_SUPPORT */
3134 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
3136 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3137 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3138 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3140 /* add to pipeline */
3141 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3142 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3143 _mmcam_dbg_err("failed to add decoder to pipeline");
3144 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3149 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3150 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3151 _mmcam_dbg_log("Link videosrc_queue to decoder OK");
3153 _mmcam_dbg_err("Link videosrc_queue to decoder FAILED");
3157 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3158 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3159 _mmcam_dbg_log("Link decoder to videosink_queue OK");
3161 _mmcam_dbg_err("Link decoder to videosink_queue FAILED");
3165 /* set state READY */
3166 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3167 if (ret != MM_ERROR_NONE) {
3168 _mmcam_dbg_err("failed to set READY to decoder");
3172 _mmcam_dbg_log("done");