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/audio/audio-format.h>
26 #include <gst/video/videooverlay.h>
27 #include <gst/video/cameracontrol.h>
28 #include <gst/wayland/wayland.h>
32 #include <tbm_bufmgr.h>
34 #include "mm_camcorder_internal.h"
35 #include "mm_camcorder_gstcommon.h"
37 /*-----------------------------------------------------------------------
38 | GLOBAL VARIABLE DEFINITIONS for internal |
39 -----------------------------------------------------------------------*/
40 /* Table for compatibility between audio codec and file format */
41 gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
42 /* 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*/
43 /*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},
44 /*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},
45 /*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},
46 /*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},
47 /*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},
48 /*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},
49 /*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},
50 /*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},
51 /*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},
52 /*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},
53 /*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},
54 /*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},
55 /*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},
56 /*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},
57 /*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},
58 /*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},
59 /*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},
60 /*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},
61 /*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},
62 /*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},
63 /*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},
64 /*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},
65 /*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},
66 /*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},
67 /*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},
68 /*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},
69 /*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},
70 /*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},
71 /*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},
72 /*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},
73 /*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},
74 /*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},
75 /*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},
76 /*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},
77 /*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},
78 /*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},
79 /*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},
80 /*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},
81 /*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},
82 /*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},
83 /*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},
84 /*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},
85 /*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},
86 /*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},
89 /* Table for compatibility between video codec and file format */
90 gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
91 /* 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*/
92 /*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},
93 /*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},
94 /*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},
95 /*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},
96 /*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},
97 /*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},
98 /*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},
99 /*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},
100 /*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},
101 /*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},
102 /*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},
103 /*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},
104 /*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},
105 /*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},
106 /*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},
107 /*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},
108 /*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},
109 /*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},
110 /*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},
111 /*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},
112 /*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},
113 /*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},
114 /*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},
115 /*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},
116 /*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},
117 /*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},
118 /*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},
119 /*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},
123 /*-----------------------------------------------------------------------
124 | LOCAL VARIABLE DEFINITIONS for internal |
125 -----------------------------------------------------------------------*/
126 #define USE_AUDIO_CLOCK_TUNE
127 #define _MMCAMCORDER_WAIT_EOS_TIME 60.0 /* sec */
128 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM 6
129 #define _MMCAMCORDER_MIN_TIME_TO_PASS_FRAME 30000000 /* ns */
130 #define _MMCAMCORDER_FRAME_PASS_MIN_FPS 30
131 #define _MMCAMCORDER_NANOSEC_PER_1SEC 1000000000
132 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC 1000
135 /*-----------------------------------------------------------------------
136 | LOCAL FUNCTION PROTOTYPES: |
137 -----------------------------------------------------------------------*/
138 /* STATIC INTERNAL FUNCTION */
140 * These functions are preview video data probing function.
141 * If this function is linked with certain pad by gst_pad_add_buffer_probe(),
142 * this function will be called when data stream pass through the pad.
144 * @param[in] pad probing pad which calls this function.
145 * @param[in] buffer buffer which contains stream data.
146 * @param[in] u_data user data.
147 * @return This function returns true on success, or false value with error
149 * @see __mmcamcorder_create_preview_pipeline()
151 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
152 static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
153 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
154 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name);
156 /*=======================================================================================
157 | FUNCTION DEFINITIONS |
158 =======================================================================================*/
159 /*-----------------------------------------------------------------------
160 | GLOBAL FUNCTION DEFINITIONS: |
161 -----------------------------------------------------------------------*/
162 int _mmcamcorder_create_preview_elements(MMHandleType handle)
164 int err = MM_ERROR_NONE;
166 int camera_width = 0;
167 int camera_height = 0;
168 int camera_rotate = 0;
172 int capture_width = 0;
173 int capture_height = 0;
174 int capture_jpg_quality = 100;
175 int video_stabilization = 0;
177 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
178 const char *videosrc_name = NULL;
179 const char *videosink_name = NULL;
180 const char *videoconvert_name = NULL;
181 char *err_name = NULL;
182 char *socket_path = NULL;
184 #ifdef _MMCAMCORDER_RM_SUPPORT
185 int decoder_index = 0;
186 char decoder_name[20] = {'\0',};
187 #endif /* _MMCAMCORDER_RM_SUPPORT */
188 GstElement *sink_element = NULL;
189 int sink_element_size = 0;
191 GList *element_list = NULL;
193 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
194 _MMCamcorderSubContext *sc = NULL;
195 type_element *VideosrcElement = NULL;
196 type_int_array *input_index = NULL;
198 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
200 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
201 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
202 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
206 /* Check existence */
207 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
208 if (sc->element[i].gst) {
209 if (((GObject *)sc->element[i].gst)->ref_count > 0)
210 gst_object_unref(sc->element[i].gst);
212 _mmcam_dbg_log("element[index:%d] is Already existed.", i);
216 /* Get video device index info */
217 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
218 CONFIGURE_CATEGORY_CTRL_CAMERA,
221 if (input_index == NULL) {
222 _mmcam_dbg_err("Failed to get input_index");
223 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
226 err = mm_camcorder_get_attributes(handle, &err_name,
227 MMCAM_CAMERA_WIDTH, &camera_width,
228 MMCAM_CAMERA_HEIGHT, &camera_height,
229 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
230 MMCAM_CAMERA_FPS, &fps,
231 MMCAM_CAMERA_ROTATION, &camera_rotate,
232 MMCAM_CAMERA_FLIP, &camera_flip,
233 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
234 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
235 MMCAM_CAPTURE_WIDTH, &capture_width,
236 MMCAM_CAPTURE_HEIGHT, &capture_height,
237 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
238 MMCAM_IMAGE_ENCODER, &codectype,
239 MMCAM_IMAGE_ENCODER_QUALITY, &capture_jpg_quality,
240 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
241 MMCAM_DISPLAY_SURFACE, &display_surface_type,
243 if (err != MM_ERROR_NONE) {
244 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
249 /* Get fourcc from picture format */
250 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
252 /* Get videosrc element and its name from configure */
253 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
254 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
257 _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
260 * Create child element
262 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
264 /* Set video device index */
265 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
267 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
269 /* init high-speed-fps */
270 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
272 /* set capture size, quality and flip setting which were set before mm_camcorder_realize */
273 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
274 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
275 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-jpg-quality", capture_jpg_quality);
276 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
278 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
280 /* set camera flip */
281 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
283 /* set video stabilization mode */
284 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
286 /* set anti handshake mode */
287 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
289 if (sc->is_modified_rate)
290 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
292 /* Set basic infomation of videosrc element */
293 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
295 /* make demux and decoder for H264 stream from videosrc */
296 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
297 int preview_bitrate = 0;
298 int gop_interval = 0;
299 const char *videodecoder_name = NULL;
301 /* get recreate_decoder flag */
302 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
303 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
305 &hcamcorder->recreate_decoder);
307 /* get video decoder element and name for H.264 format */
308 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
309 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
310 "VideodecoderElementH264",
311 &sc->VideodecoderElementH264);
313 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
315 if (videodecoder_name) {
316 _mmcam_dbg_log("video decoder element [%s], recreate decoder %d",
317 videodecoder_name, hcamcorder->recreate_decoder);
318 #ifdef _MMCAMCORDER_RM_SUPPORT
319 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
322 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
323 _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
324 /* create decoder element */
325 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
326 #else /* _MMCAMCORDER_RM_SUPPORT */
327 /* create decoder element */
328 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name, "videosrc_decode", element_list, err);
329 #endif /* _MMCAMCORDER_RM_SUPPORT */
330 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
332 _mmcam_dbg_err("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
333 goto pipeline_creation_error;
336 /* set encoded preview bitrate and iframe interval */
337 mm_camcorder_get_attributes(handle, NULL,
338 MMCAM_ENCODED_PREVIEW_BITRATE, &preview_bitrate,
339 MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
342 if (!_mmcamcorder_set_encoded_preview_bitrate(handle, preview_bitrate))
343 _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_bitrate failed");
345 if (!_mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval))
346 _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_gop_interval failed");
349 _mmcam_dbg_log("Current mode[%d]", hcamcorder->type);
351 /* Get videosink name */
352 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
354 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
356 _mmcam_dbg_log("videosink_name: %s", videosink_name);
358 if (display_surface_type == MM_DISPLAY_SURFACE_REMOTE) {
359 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "ipc_sink", element_list, err);
361 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
363 err = mm_camcorder_get_attributes(handle, &err_name,
364 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
366 if (err != MM_ERROR_NONE) {
367 _mmcam_dbg_warn("Get socket path failed 0x%x", err);
369 goto pipeline_creation_error;
372 g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
374 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "directvideosink"))) {
375 /* get video convert name */
376 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
378 if (videoconvert_name) {
379 _mmcam_dbg_log("videoconvert element name : %s", videoconvert_name);
380 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
382 _mmcam_dbg_err("failed to get videoconvert element name");
385 /* check sink element in attribute */
386 mm_camcorder_get_attributes(handle, NULL,
387 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
392 mmf_attrs_t *attrs = MMF_CAMCORDER_ATTRS(handle);
393 mmf_attribute_t *attr_item = NULL;
395 _mmcam_dbg_log("reuse sink element %p in attribute", sink_element);
397 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
399 /* reset attribute */
401 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
402 attr_item = &attrs->items[attr_index];
403 mmf_attribute_set_data(attr_item, NULL, 0);
404 mmf_attribute_commit(attr_item);
406 _mmcam_dbg_warn("attribute is NULL");
407 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
408 goto pipeline_creation_error;
411 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
413 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
416 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
417 _mmcam_dbg_err("_mmcamcorder_videosink_window_set error");
418 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
419 goto pipeline_creation_error;
423 /* Set caps by rotation */
424 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
426 /* add elements to main pipeline */
427 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
428 _mmcam_dbg_err("element_list add error.");
429 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
430 goto pipeline_creation_error;
434 if (!_mmcamcorder_link_elements(element_list)) {
435 _mmcam_dbg_err("element link error.");
436 err = MM_ERROR_CAMCORDER_GST_LINK;
437 goto pipeline_creation_error;
441 g_list_free(element_list);
445 return MM_ERROR_NONE;
447 pipeline_creation_error:
448 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
449 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
450 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_QUE);
451 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS);
452 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_FILT);
453 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
454 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
455 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
456 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
459 g_list_free(element_list);
467 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
469 int err = MM_ERROR_NONE;
474 int a_enc = MM_AUDIO_CODEC_AMR;
475 int a_dev = MM_AUDIO_DEVICE_MIC;
477 char *err_name = NULL;
478 const char *audiosrc_name = NULL;
479 char *cat_name = NULL;
480 char *stream_type = NULL;
481 char stream_type_len = 0;
482 int stream_index = 0;
484 GstCaps *caps = NULL;
486 GList *element_list = NULL;
488 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
489 _MMCamcorderSubContext *sc = NULL;
490 _MMCamcorderGstElement *last_element = NULL;
491 type_element *AudiosrcElement = NULL;
493 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
495 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
496 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
497 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
501 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
502 if (err != MM_ERROR_NONE)
505 err = mm_camcorder_get_attributes(handle, &err_name,
506 MMCAM_AUDIO_DEVICE, &a_dev,
507 MMCAM_AUDIO_ENCODER, &a_enc,
508 MMCAM_AUDIO_ENCODER_BITRATE, &val,
509 MMCAM_AUDIO_SAMPLERATE, &rate,
510 MMCAM_AUDIO_FORMAT, &format,
511 MMCAM_AUDIO_CHANNEL, &channel,
512 MMCAM_AUDIO_VOLUME, &volume,
513 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
514 MMCAM_SOUND_STREAM_INDEX, &stream_index,
516 if (err != MM_ERROR_NONE) {
517 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
522 /* Check existence */
523 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
524 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
525 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
527 _mmcam_dbg_log("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
530 /* Create bin element */
531 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
533 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
534 cat_name = strdup("AudiomodemsrcElement");
536 /* MM_AUDIO_DEVICE_MIC or others */
537 cat_name = strdup("AudiosrcElement");
540 if (cat_name == NULL) {
541 _mmcam_dbg_err("strdup failed.");
542 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
543 goto pipeline_creation_error;
546 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
547 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
550 _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
555 _mmcam_dbg_log("Audio src name : %s", audiosrc_name);
557 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
559 /* set sound stream info */
560 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
562 /* set audiosrc properties in ini configuration */
563 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
565 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
567 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
568 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
569 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
570 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
572 if (a_enc != MM_AUDIO_CODEC_VORBIS)
573 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
575 /* Set basic infomation */
576 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
578 const gchar* format_name = NULL;
581 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
582 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
584 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
585 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
588 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
590 format_name = "S16LE";
591 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
596 caps = gst_caps_new_simple("audio/x-raw",
597 "rate", G_TYPE_INT, rate,
598 "channels", G_TYPE_INT, channel,
599 "format", G_TYPE_STRING, format_name,
601 _mmcam_dbg_log("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
602 rate, channel, depth, volume);
604 /* what are the audio encoder which should get audio/x-raw-float? */
605 caps = gst_caps_new_simple("audio/x-raw",
606 "rate", G_TYPE_INT, rate,
607 "channels", G_TYPE_INT, channel,
608 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
610 _mmcam_dbg_log("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
611 rate, channel, BYTE_ORDER);
615 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
616 gst_caps_unref(caps);
619 _mmcam_dbg_err("create caps error");
620 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
621 goto pipeline_creation_error;
624 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
625 _mmcam_dbg_err("element add error.");
626 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
627 goto pipeline_creation_error;
630 if (!_mmcamcorder_link_elements(element_list)) {
631 _mmcam_dbg_err("element link error.");
632 err = MM_ERROR_CAMCORDER_GST_LINK;
633 goto pipeline_creation_error;
636 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
637 pad = gst_element_get_static_pad(last_element->gst, "src");
638 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
639 gst_object_unref(pad);
641 _mmcam_dbg_err("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
642 err = MM_ERROR_CAMCORDER_GST_LINK;
643 goto pipeline_creation_error;
646 gst_object_unref(pad);
650 g_list_free(element_list);
654 return MM_ERROR_NONE;
656 pipeline_creation_error:
657 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
658 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
659 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
660 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
661 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
664 g_list_free(element_list);
672 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
677 _mmcam_dbg_warn("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
682 _mmcam_dbg_warn("[type %d, codec %d] too small bitrate[%d], use default",
683 type, codec, bitrate);
687 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
688 /* audio encoder bitrate setting */
690 case MM_AUDIO_CODEC_AMR:
691 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
692 _mmcam_dbg_log("Set AMR encoder mode [%d]", set_value);
693 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
695 case MM_AUDIO_CODEC_MP3:
696 set_value = bitrate / 1000;
697 _mmcam_dbg_log("Set MP3 encoder bitrate [%d] kbps", set_value);
698 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
700 case MM_AUDIO_CODEC_AAC:
701 _mmcam_dbg_log("Set AAC encoder bitrate [%d] bps", bitrate);
702 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
705 _mmcam_dbg_warn("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
709 /* video encoder bitrate setting */
710 _mmcam_dbg_log("Set video encoder bitrate %d", bitrate);
711 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
718 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
720 int err = MM_ERROR_NONE;
725 int encodebin_profile = 0;
726 int auto_audio_convert = 0;
727 int auto_audio_resample = 0;
728 int auto_color_space = 0;
729 const char *gst_element_venc_name = NULL;
730 const char *gst_element_aenc_name = NULL;
731 const char *gst_element_ienc_name = NULL;
732 const char *gst_element_mux_name = NULL;
733 const char *gst_element_rsink_name = NULL;
734 const char *str_profile = NULL;
735 const char *str_aac = NULL;
736 const char *str_aar = NULL;
737 const char *str_acs = NULL;
738 char *err_name = NULL;
739 const char *videoconvert_name = NULL;
740 GstCaps *audio_caps = NULL;
741 GstCaps *video_caps = NULL;
743 GList *element_list = NULL;
745 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
746 _MMCamcorderSubContext *sc = NULL;
747 type_element *VideoencElement = NULL;
748 type_element *AudioencElement = NULL;
749 type_element *ImageencElement = NULL;
750 type_element *MuxElement = NULL;
751 type_element *RecordsinkElement = NULL;
753 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
755 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
756 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
757 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
759 _mmcam_dbg_log("start - profile : %d", profile);
761 /* Check existence */
762 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
763 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
764 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
766 _mmcam_dbg_log("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
769 /* Create bin element */
770 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
772 /* Create child element */
773 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
774 GstCaps *caps_from_pad = NULL;
776 /* create appsrc and capsfilter */
777 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
779 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
781 /* release element_list, they will be placed out of encodesink bin */
783 g_list_free(element_list);
787 /* set appsrc as live source */
788 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
789 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
790 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
793 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
794 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
795 _mmcam_dbg_log("get pad from videosrc_filter");
796 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
798 _mmcam_dbg_log("get pad from videosrc_que");
799 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
802 _mmcam_dbg_err("get videosrc_que src pad failed");
803 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
804 goto pipeline_creation_error;
807 caps_from_pad = gst_pad_get_allowed_caps(pad);
808 video_caps = gst_caps_copy(caps_from_pad);
809 gst_caps_unref(caps_from_pad);
810 caps_from_pad = NULL;
811 gst_object_unref(pad);
815 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
819 char *caps_str = NULL;
821 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
822 gst_caps_set_simple(video_caps,
823 "width", G_TYPE_INT, sc->info_video->video_width,
824 "height", G_TYPE_INT, sc->info_video->video_height,
828 caps_str = gst_caps_to_string(video_caps);
829 _mmcam_dbg_log("encodebin caps [%s]", caps_str);
833 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
834 gst_caps_unref(video_caps);
837 _mmcam_dbg_err("create recording pipeline caps failed");
838 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
839 goto pipeline_creation_error;
842 /* connect signal for ready to push buffer */
843 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
844 _MMCAMCORDER_HANDLER_VIDEOREC,
846 _mmcamcorder_ready_to_encode_callback,
850 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN, "encodebin", "encodesink_encbin", element_list, err);
852 /* check element availability */
853 err = mm_camcorder_get_attributes(handle, &err_name,
854 MMCAM_AUDIO_ENCODER, &audio_enc,
855 MMCAM_AUDIO_CHANNEL, &channel,
856 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
857 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
860 if (err != MM_ERROR_NONE) {
862 _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
865 _mmcam_dbg_err("failed to get attributes [0x%x]", err);
871 _mmcam_dbg_log("Profile[%d]", profile);
873 /* Set information */
874 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
875 str_profile = "VideoProfile";
876 str_aac = "VideoAutoAudioConvert";
877 str_aar = "VideoAutoAudioResample";
878 str_acs = "VideoAutoColorSpace";
879 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
880 str_profile = "AudioProfile";
881 str_aac = "AudioAutoAudioConvert";
882 str_aar = "AudioAutoAudioResample";
883 str_acs = "AudioAutoColorSpace";
884 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
885 str_profile = "ImageProfile";
886 str_aac = "ImageAutoAudioConvert";
887 str_aar = "ImageAutoAudioResample";
888 str_acs = "ImageAutoColorSpace";
891 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
892 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
893 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
894 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
896 _mmcam_dbg_log("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
897 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
899 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
900 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
901 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
902 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
903 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
905 /* get video convert element name */
906 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
909 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
910 int use_venc_queue = 0;
912 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
914 if (!VideoencElement) {
915 _mmcam_dbg_err("Fail to get type element");
916 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
917 goto pipeline_creation_error;
920 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264)
921 gst_element_venc_name = "capsfilter";
923 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
925 if (gst_element_venc_name) {
926 _mmcam_dbg_log("video encoder name [%s]", gst_element_venc_name);
928 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
929 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
931 _mmcam_dbg_err("Fail to get video encoder name");
932 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
933 goto pipeline_creation_error;
936 /* set color space converting element */
937 if (auto_color_space) {
938 _mmcam_dbg_log("set video convert element [%s]", videoconvert_name);
940 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
941 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
943 /* set colorspace plugin property setting */
944 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
946 /* fourcc type was removed in GST 1.0 */
947 if (hcamcorder->use_zero_copy_format) {
948 if (strstr(gst_element_venc_name, "omx")) {
949 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
952 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
953 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
955 gst_caps_unref(video_caps);
958 _mmcam_dbg_warn("failed to create caps");
961 _mmcam_dbg_log("current video codec is not openmax but [%s]", gst_element_venc_name);
966 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
967 CONFIGURE_CATEGORY_MAIN_RECORD,
968 "UseVideoEncoderQueue",
971 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
974 if (sc->audio_disable == FALSE &&
975 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
976 int use_aenc_queue = 0;
978 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
979 if (!AudioencElement) {
980 _mmcam_dbg_err("Fail to get type element");
981 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
982 goto pipeline_creation_error;
985 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
987 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
988 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
990 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
991 audio_caps = gst_caps_new_simple("audio/x-raw",
992 "channels", G_TYPE_INT, 1,
994 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
995 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
996 gst_caps_unref(audio_caps);
1000 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1001 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1002 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1003 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1004 gst_caps_unref(audio_caps);
1006 _mmcam_dbg_log("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1009 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1010 CONFIGURE_CATEGORY_MAIN_RECORD,
1011 "UseAudioEncoderQueue",
1013 if (use_aenc_queue) {
1014 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1015 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1016 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1020 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1021 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1022 if (!ImageencElement) {
1023 _mmcam_dbg_err("Fail to get type element");
1024 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1025 goto pipeline_creation_error;
1028 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1030 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1031 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1035 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1036 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1038 _mmcam_dbg_err("Fail to get type element");
1039 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1040 goto pipeline_creation_error;
1043 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1045 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1046 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1048 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1052 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1054 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1055 CONFIGURE_CATEGORY_MAIN_RECORD,
1056 "RecordsinkElement",
1057 &RecordsinkElement);
1058 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1060 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1062 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1065 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1068 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1069 /* property setting in ini */
1070 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1072 /* bitrate setting */
1073 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1074 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1077 if (sc->audio_disable == FALSE &&
1078 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1079 /* property setting in ini */
1080 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1082 /* bitrate setting */
1083 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1084 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1087 _mmcam_dbg_log("Element creation complete");
1089 /* Add element to bin */
1090 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1091 _mmcam_dbg_err("element add error.");
1092 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1093 goto pipeline_creation_error;
1096 _mmcam_dbg_log("Element add complete");
1098 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1099 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1100 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1101 gst_object_unref(pad);
1103 _mmcam_dbg_err("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1104 err = MM_ERROR_CAMCORDER_GST_LINK;
1105 goto pipeline_creation_error;
1107 gst_object_unref(pad);
1110 if (sc->audio_disable == FALSE) {
1111 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1112 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1113 gst_object_unref(pad);
1115 _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1116 err = MM_ERROR_CAMCORDER_GST_LINK;
1117 goto pipeline_creation_error;
1119 gst_object_unref(pad);
1122 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1123 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1124 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1125 gst_object_unref(pad);
1127 _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1128 err = MM_ERROR_CAMCORDER_GST_LINK;
1129 goto pipeline_creation_error;
1131 gst_object_unref(pad);
1135 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1136 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1137 gst_object_unref(pad);
1139 _mmcam_dbg_err("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1140 err = MM_ERROR_CAMCORDER_GST_LINK;
1141 goto pipeline_creation_error;
1143 gst_object_unref(pad);
1147 _mmcam_dbg_log("Get pad complete");
1149 /* Link internal element */
1150 if (!_mmcamcorder_link_elements(element_list)) {
1151 _mmcam_dbg_err("element link error.");
1152 err = MM_ERROR_CAMCORDER_GST_LINK;
1153 goto pipeline_creation_error;
1157 g_list_free(element_list);
1158 element_list = NULL;
1161 _mmcam_dbg_log("done");
1163 return MM_ERROR_NONE;
1165 pipeline_creation_error:
1166 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1168 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1169 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1170 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1171 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1172 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1173 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1174 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1175 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1176 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1179 g_list_free(element_list);
1180 element_list = NULL;
1187 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1189 int err = MM_ERROR_NONE;
1191 GstPad *srcpad = NULL;
1194 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1195 _MMCamcorderSubContext *sc = NULL;
1197 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1199 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1200 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1201 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1205 /** Create gstreamer element **/
1207 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1210 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1211 if (err != MM_ERROR_NONE)
1212 goto pipeline_creation_error;
1214 /* Set data probe function */
1215 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1216 _mmcam_dbg_log("add video dataprobe to videosrc queue");
1217 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1219 _mmcam_dbg_err("there is no queue plugin");
1220 goto pipeline_creation_error;
1224 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1225 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1227 gst_object_unref(srcpad);
1230 _mmcam_dbg_err("failed to get srcpad");
1231 goto pipeline_creation_error;
1234 /* set dataprobe for video recording */
1235 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264)
1236 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1238 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1240 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1241 __mmcamcorder_video_dataprobe_push_buffer_to_record, hcamcorder);
1242 gst_object_unref(srcpad);
1245 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1247 /* Register pipeline message callback */
1248 hcamcorder->pipeline_cb_event_id = gst_bus_add_watch(bus, _mmcamcorder_pipeline_cb_message, (gpointer)hcamcorder);
1250 /* set sync handler */
1251 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1253 gst_object_unref(bus);
1256 return MM_ERROR_NONE;
1258 pipeline_creation_error:
1259 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1264 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1266 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1267 _MMCamcorderSubContext *sc = NULL;
1269 /*_mmcam_dbg_log("start");*/
1271 mmf_return_if_fail(hcamcorder);
1272 mmf_return_if_fail(hcamcorder->sub_context);
1273 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1276 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1277 sc->info_video->get_first_I_frame = FALSE;
1278 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1279 _mmcam_dbg_warn("set push_encoding_buffer RUN");
1284 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1286 int err = MM_ERROR_NONE;
1291 int rect_height = 0;
1293 int rotation = MM_DISPLAY_ROTATION_NONE;
1294 int flip = MM_FLIP_NONE;
1295 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1296 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1297 int origin_size = 0;
1300 int do_scaling = FALSE;
1301 #ifdef _MMCAMCORDER_RM_SUPPORT
1302 int display_scaler = 0;
1303 #endif /* _MMCAMCORDER_RM_SUPPORT */
1304 int *overlay = NULL;
1306 char *err_name = NULL;
1307 const char *videosink_name = NULL;
1309 GstElement *vsink = NULL;
1311 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1312 _MMCamcorderSubContext *sc = NULL;
1316 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1318 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1319 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1320 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1321 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1323 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1325 /* Get video display information */
1326 err = mm_camcorder_get_attributes(handle, &err_name,
1327 MMCAM_DISPLAY_RECT_X, &rect_x,
1328 MMCAM_DISPLAY_RECT_Y, &rect_y,
1329 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1330 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1331 MMCAM_DISPLAY_ROTATION, &rotation,
1332 MMCAM_DISPLAY_FLIP, &flip,
1333 MMCAM_DISPLAY_VISIBLE, &visible,
1334 MMCAM_DISPLAY_HANDLE, (void**)&overlay, &size,
1335 MMCAM_DISPLAY_MODE, &display_mode,
1336 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1337 MMCAM_DISPLAY_SCALE, &zoom_attr,
1338 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1340 if (err != MM_ERROR_NONE) {
1342 _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
1343 SAFE_FREE(err_name);
1345 _mmcam_dbg_err("failed to get attributes [0x%x]", err);
1351 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1353 _mmcam_dbg_log("(overlay=%p, size=%d)", overlay, size);
1355 /* Set display handle */
1356 if (!strcmp(videosink_name, "xvimagesink") ||
1357 !strcmp(videosink_name, "ximagesink")) {
1360 _mmcam_dbg_log("xid = %lu )", xid);
1361 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1363 _mmcam_dbg_warn("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1364 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1366 #ifdef _MMCAMCORDER_RM_SUPPORT
1367 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
1370 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", display_scaler);
1371 #endif /* _MMCAMCORDER_RM_SUPPORT */
1372 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1373 _mmcam_dbg_log("videosink : %s, handle : %p", videosink_name, overlay);
1376 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", overlay);
1377 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1379 _mmcam_dbg_err("display handle(eavs object) is NULL");
1380 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1382 } else if (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "directvideosink")) {
1383 MMCamWaylandInfo *wl_info = (MMCamWaylandInfo *)overlay;
1386 _mmcam_dbg_log("wayland global surface id : %d", wl_info->global_surface_id);
1387 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), (guintptr)wl_info->global_surface_id);
1388 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1389 wl_info->window_x, wl_info->window_y, wl_info->window_width, wl_info->window_height);
1391 _mmcam_dbg_warn("Handle is NULL. skip setting.");
1394 _mmcam_dbg_warn("Who are you?? (Videosink: %s)", videosink_name);
1397 _mmcam_dbg_log("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1398 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1401 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "waylandsink") ||
1402 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1404 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1407 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1409 switch (zoom_attr) {
1410 case MM_DISPLAY_SCALE_DEFAULT:
1413 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1416 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1420 _mmcam_dbg_warn("Unsupported zoom value. set as default.");
1425 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1426 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1427 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1428 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1430 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1431 if (!strcmp(videosink_name, "waylandsink")) {
1432 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1433 rect_x, rect_y, rect_width, rect_height);
1436 "dst-roi-x", rect_x,
1437 "dst-roi-y", rect_y,
1438 "dst-roi-w", rect_width,
1439 "dst-roi-h", rect_height,
1445 return MM_ERROR_NONE;
1449 int _mmcamcorder_vframe_stablize(MMHandleType handle)
1451 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1452 _MMCamcorderSubContext *sc = NULL;
1454 _mmcam_dbg_log("%d", _MMCAMCORDER_CAMSTABLE_COUNT);
1456 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1458 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1460 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1462 if (sc->cam_stability_count != _MMCAMCORDER_CAMSTABLE_COUNT)
1463 sc->cam_stability_count = _MMCAMCORDER_CAMSTABLE_COUNT;
1465 return MM_ERROR_NONE;
1468 /* Retreive device information and set them to attributes */
1469 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
1471 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1472 _MMCamcorderSubContext *sc = NULL;
1473 GstCameraControl *control = NULL;
1474 GstCameraControlExifInfo exif_info = {0,};
1476 mmf_return_val_if_fail(hcamcorder, FALSE);
1477 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1479 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
1481 if (sc && sc->element) {
1482 int err = MM_ERROR_NONE;
1483 char *err_name = NULL;
1484 double focal_len = 0.0;
1486 /* Video input device */
1487 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
1488 /* Exif related information */
1489 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1490 if (control != NULL) {
1491 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
1492 if (exif_info.focal_len_denominator != 0)
1493 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
1495 _mmcam_dbg_err("Fail to get camera control interface!");
1500 /* Set values to attributes */
1501 err = mm_camcorder_set_attributes(handle, &err_name,
1502 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
1504 if (err != MM_ERROR_NONE) {
1505 _mmcam_dbg_err("Set attributes error(%s:%x)!", err_name, err);
1506 SAFE_FREE(err_name);
1510 _mmcam_dbg_warn("Sub context isn't exist.");
1517 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name)
1519 return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24);
1522 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
1524 int current_state = MM_CAMCORDER_STATE_NONE;
1527 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
1528 _MMCamcorderSubContext *sc = NULL;
1529 _MMCamcorderKPIMeasure *kpi = NULL;
1530 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
1531 GstMemory *dataBlock = NULL;
1532 GstMemory *metaBlock = NULL;
1535 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
1536 mmf_return_val_if_fail(gst_buffer_n_memory(buffer) , GST_PAD_PROBE_DROP);
1537 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
1539 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
1540 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
1542 memset(&mapinfo, 0x0, sizeof(GstMapInfo));
1544 current_state = hcamcorder->state;
1546 if (sc->drop_vframe > 0) {
1547 if (sc->pass_first_vframe > 0) {
1548 sc->pass_first_vframe--;
1549 _mmcam_dbg_log("Pass video frame by pass_first_vframe");
1552 _mmcam_dbg_log("Drop video frame by drop_vframe");
1553 return GST_PAD_PROBE_DROP;
1555 } else if (sc->cam_stability_count > 0) {
1556 sc->cam_stability_count--;
1557 _mmcam_dbg_log("Drop video frame by cam_stability_count");
1558 return GST_PAD_PROBE_DROP;
1561 if (current_state >= MM_CAMCORDER_STATE_PREPARE) {
1563 int frame_count = 0;
1564 struct timeval current_video_time;
1567 if (kpi->init_video_time.tv_sec == kpi->last_video_time.tv_sec &&
1568 kpi->init_video_time.tv_usec == kpi->last_video_time.tv_usec &&
1569 kpi->init_video_time.tv_usec == 0) {
1571 _mmcam_dbg_log("START to measure FPS");
1573 gettimeofday(&(kpi->init_video_time), NULL);
1576 frame_count = ++(kpi->video_framecount);
1578 gettimeofday(¤t_video_time, NULL);
1579 diff_sec = current_video_time.tv_sec - kpi->last_video_time.tv_sec;
1580 if (diff_sec != 0) {
1581 kpi->current_fps = (frame_count - kpi->last_framecount) / diff_sec;
1582 if ((current_video_time.tv_sec - kpi->init_video_time.tv_sec) != 0) {
1583 int framecount = kpi->video_framecount;
1584 int elased_sec = current_video_time.tv_sec - kpi->init_video_time.tv_sec;
1585 kpi->average_fps = framecount / elased_sec;
1588 kpi->last_framecount = frame_count;
1589 kpi->last_video_time.tv_sec = current_video_time.tv_sec;
1590 kpi->last_video_time.tv_usec = current_video_time.tv_usec;
1592 _mmcam_dbg_log("current fps(%d), average(%d)", kpi->current_fps, kpi->average_fps);
1597 /* video stream callback */
1598 if (hcamcorder->vstream_cb && buffer) {
1599 GstCaps *caps = NULL;
1600 GstStructure *structure = NULL;
1601 int state = MM_CAMCORDER_STATE_NULL;
1602 unsigned int fourcc = 0;
1603 MMCamcorderVideoStreamDataType stream;
1604 MMVideoBuffer *mm_buf = NULL;
1605 const gchar *string_format = NULL;
1607 state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
1608 if (state < MM_CAMCORDER_STATE_PREPARE) {
1609 _mmcam_dbg_warn("Not ready for stream callback");
1610 return GST_PAD_PROBE_OK;
1613 caps = gst_pad_get_current_caps(pad);
1615 _mmcam_dbg_warn("Caps is NULL.");
1616 return GST_PAD_PROBE_OK;
1619 /* clear stream data structure */
1620 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
1622 structure = gst_caps_get_structure(caps, 0);
1623 gst_structure_get_int(structure, "width", &(stream.width));
1624 gst_structure_get_int(structure, "height", &(stream.height));
1626 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
1627 stream.format = MM_PIXEL_FORMAT_ENCODED_H264;
1629 string_format = gst_structure_get_string(structure, "format");
1630 if (string_format == NULL) {
1631 gst_caps_unref(caps);
1633 _mmcam_dbg_warn("get string error!!");
1634 return GST_PAD_PROBE_OK;
1637 fourcc = _mmcamcorder_convert_fourcc_string_to_value(string_format);
1638 stream.format = _mmcamcorder_get_pixtype(fourcc);
1641 gst_caps_unref(caps);
1645 _mmcam_dbg_log("Call video steramCb, data[%p], Width[%d],Height[%d], Format[%d]",
1646 GST_BUFFER_DATA(buffer), stream.width, stream.height, stream.format);
1649 if (stream.width == 0 || stream.height == 0) {
1650 _mmcam_dbg_warn("Wrong condition!!");
1651 return GST_PAD_PROBE_OK;
1654 /* set size and timestamp */
1655 dataBlock = gst_buffer_peek_memory(buffer, 0);
1656 stream.length_total = gst_memory_get_sizes(dataBlock, NULL, NULL);
1657 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer)/1000000); /* nano sec -> mili sec */
1659 if (hcamcorder->use_zero_copy_format && gst_buffer_n_memory(buffer) > 1) {
1660 metaBlock = gst_buffer_peek_memory(buffer, 1);
1661 gst_memory_map(metaBlock, &mapinfo, GST_MAP_READ);
1662 mm_buf = (MMVideoBuffer *)mapinfo.data;
1665 /* set data pointers */
1666 if (stream.format == MM_PIXEL_FORMAT_NV12 ||
1667 stream.format == MM_PIXEL_FORMAT_NV21 ||
1668 stream.format == MM_PIXEL_FORMAT_I420) {
1670 if (stream.format == MM_PIXEL_FORMAT_NV12 ||
1671 stream.format == MM_PIXEL_FORMAT_NV21) {
1672 stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
1673 stream.num_planes = 2;
1674 stream.data.yuv420sp.y = mm_buf->data[0];
1675 stream.data.yuv420sp.length_y = stream.width * stream.height;
1676 stream.data.yuv420sp.uv = mm_buf->data[1];
1677 stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 1;
1679 _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:0x%x,size:%d [UV]p:0x%x,size:%d",
1680 stream.format, stream.num_planes,
1681 stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
1682 stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
1685 stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
1686 stream.num_planes = 3;
1687 stream.data.yuv420p.y = mm_buf->data[0];
1688 stream.data.yuv420p.length_y = stream.width * stream.height;
1689 stream.data.yuv420p.u = mm_buf->data[1];
1690 stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2;
1691 stream.data.yuv420p.v = mm_buf->data[2];
1692 stream.data.yuv420p.length_v = stream.data.yuv420p.length_u;
1694 _mmcam_dbg_log("S420[num_planes:%d] [Y]p:0x%x,size:%d [U]p:0x%x,size:%d [V]p:0x%x,size:%d",
1696 stream.data.yuv420p.y, stream.data.yuv420p.length_y,
1697 stream.data.yuv420p.u, stream.data.yuv420p.length_u,
1698 stream.data.yuv420p.v, stream.data.yuv420p.length_v);
1702 gst_memory_map(dataBlock, &mapinfo, GST_MAP_READWRITE);
1703 if (stream.format == MM_PIXEL_FORMAT_NV12 ||
1704 stream.format == MM_PIXEL_FORMAT_NV21) {
1705 stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
1706 stream.num_planes = 2;
1707 stream.data.yuv420sp.y = mapinfo.data;
1708 stream.data.yuv420sp.length_y = stream.width * stream.height;
1709 stream.data.yuv420sp.uv = stream.data.yuv420sp.y + stream.data.yuv420sp.length_y;
1710 stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 1;
1711 stream.stride[0] = stream.width;
1712 stream.elevation[0] = stream.height;
1713 stream.stride[1] = stream.width;
1714 stream.elevation[1] = stream.height >> 1;
1716 _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:0x%x,size:%d [UV]p:0x%x,size:%d",
1717 stream.format, stream.num_planes,
1718 stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
1719 stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
1722 stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
1723 stream.num_planes = 3;
1724 stream.data.yuv420p.y = mapinfo.data;
1725 stream.data.yuv420p.length_y = stream.width * stream.height;
1726 stream.data.yuv420p.u = stream.data.yuv420p.y + stream.data.yuv420p.length_y;
1727 stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2;
1728 stream.data.yuv420p.v = stream.data.yuv420p.u + stream.data.yuv420p.length_u;
1729 stream.data.yuv420p.length_v = stream.data.yuv420p.length_u;
1730 stream.stride[0] = stream.width;
1731 stream.elevation[0] = stream.height;
1732 stream.stride[1] = stream.width >> 1;
1733 stream.elevation[1] = stream.height >> 1;
1734 stream.stride[2] = stream.width >> 1;
1735 stream.elevation[2] = stream.height >> 1;
1737 _mmcam_dbg_log("I420[num_planes:%d] [Y]p:0x%x,size:%d [U]p:0x%x,size:%d [V]p:0x%x,size:%d",
1739 stream.data.yuv420p.y, stream.data.yuv420p.length_y,
1740 stream.data.yuv420p.u, stream.data.yuv420p.length_u,
1741 stream.data.yuv420p.v, stream.data.yuv420p.length_v);
1747 gst_memory_unmap(metaBlock, &mapinfo);
1750 gst_memory_map(dataBlock, &mapinfo, GST_MAP_READWRITE);
1751 if (stream.format == MM_PIXEL_FORMAT_YUYV ||
1752 stream.format == MM_PIXEL_FORMAT_UYVY ||
1753 stream.format == MM_PIXEL_FORMAT_422P ||
1754 stream.format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
1755 stream.data_type = MM_CAM_STREAM_DATA_YUV422;
1756 stream.data.yuv422.yuv = mapinfo.data;
1757 stream.data.yuv422.length_yuv = stream.length_total;
1758 stream.stride[0] = stream.width << 1;
1759 stream.elevation[0] = stream.height;
1760 } else if (stream.format == MM_PIXEL_FORMAT_ENCODED_H264) {
1761 stream.data_type = MM_CAM_STREAM_DATA_ENCODED;
1762 stream.data.encoded.data = mapinfo.data;
1763 stream.data.encoded.length_data = stream.length_total;
1764 _mmcam_dbg_log("H264[num_planes:%d] [0]p:0x%x,size:%d",
1765 fourcc, fourcc>>8, fourcc>>16, fourcc>>24, stream.num_planes,
1766 stream.data.encoded.data, stream.data.encoded.length_data);
1768 stream.data_type = MM_CAM_STREAM_DATA_YUV420;
1769 stream.data.yuv420.yuv = mapinfo.data;
1770 stream.data.yuv420.length_yuv = stream.length_total;
1771 stream.stride[0] = (stream.width * 3) >> 1;
1772 stream.elevation[0] = stream.height;
1775 stream.num_planes = 1;
1777 _mmcam_dbg_log("%c%c%c%c[num_planes:%d] [0]p:0x%x,size:%d",
1778 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
1779 stream.num_planes, stream.data.yuv420.yuv, stream.data.yuv420.length_yuv);
1784 if (mm_buf && mm_buf->type == MM_VIDEO_BUFFER_TYPE_TBM_BO) {
1785 /* set bo, stride and elevation */
1786 for (i = 0 ; i < MM_VIDEO_BUFFER_PLANE_MAX ; i++) {
1787 stream.bo[i] = (void *)mm_buf->handle.bo[i];
1788 stream.stride[i] = mm_buf->stride_width[i];
1789 stream.elevation[i] = mm_buf->stride_height[i];
1792 /* set gst buffer */
1793 stream.internal_buffer = buffer;
1796 /* call application callback */
1797 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
1798 if (hcamcorder->vstream_cb) {
1799 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
1801 for (i = 0 ; i < MM_VIDEO_BUFFER_PLANE_MAX && stream.bo[i] ; i++) {
1802 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
1803 tbm_bo_unmap(stream.bo[i]);
1807 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1808 /* Either metaBlock was mapped, or dataBlock, but not both. */
1810 gst_memory_unmap(metaBlock, &mapinfo);
1812 gst_memory_unmap(dataBlock, &mapinfo);
1815 return GST_PAD_PROBE_OK;
1818 static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
1820 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
1821 _MMCamcorderSubContext *sc = NULL;
1822 GstClockTime diff = 0; /* nsec */
1823 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
1825 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
1826 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
1827 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
1829 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
1830 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
1832 /* push buffer in appsrc to encode */
1833 if (!sc->info_video) {
1834 _mmcam_dbg_warn("sc->info_video is NULL!!");
1835 return GST_PAD_PROBE_DROP;
1838 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_RUN &&
1839 sc->info_video->record_dual_stream == FALSE &&
1840 sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst) {
1842 GstClock *clock = NULL;
1845 _mmcam_dbg_log("GST_BUFFER_FLAG_DELTA_UNIT is set : %d",
1846 GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT));
1849 /* check first I frame */
1850 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264 &&
1851 sc->info_video->get_first_I_frame == FALSE) {
1852 if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
1853 _mmcam_dbg_warn("first I frame is come");
1854 sc->info_video->get_first_I_frame = TRUE;
1856 _mmcam_dbg_warn("NOT I frame.. skip this buffer");
1857 return GST_PAD_PROBE_OK;
1861 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) {
1862 if (sc->info_video->is_firstframe) {
1863 sc->info_video->is_firstframe = FALSE;
1864 clock = GST_ELEMENT_CLOCK(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst);
1866 gst_object_ref(clock);
1867 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);
1868 gst_object_unref(clock);
1872 if (sc->info_video->is_firstframe) {
1873 /* for image capture with encodebin(ex:emulator) */
1874 if (sc->bencbin_capture && sc->info_image->capturing) {
1875 g_mutex_lock(&hcamcorder->task_thread_lock);
1876 _mmcam_dbg_log("send signal for sound play");
1877 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_SOUND_SOLO_PLAY_START;
1878 g_cond_signal(&hcamcorder->task_thread_cond);
1879 g_mutex_unlock(&hcamcorder->task_thread_lock);
1881 sc->info_video->is_firstframe = FALSE;
1882 sc->info_video->base_video_ts = GST_BUFFER_PTS(buffer);
1885 GST_BUFFER_PTS(buffer) = GST_BUFFER_PTS(buffer) - sc->info_video->base_video_ts;
1886 GST_BUFFER_DTS(buffer) = GST_BUFFER_PTS(buffer);
1888 /*_mmcam_dbg_log("buffer %p, timestamp %"GST_TIME_FORMAT, buffer, GST_TIME_ARGS(GST_BUFFER_PTS(buffer)));*/
1891 GstCaps *caps = gst_pad_get_current_caps(pad);
1893 char *caps_string = gst_caps_to_string(caps);
1895 _mmcam_dbg_log("%s", caps_string);
1896 g_free(caps_string);
1899 gst_caps_unref(caps);
1902 _mmcam_dbg_warn("failed to get caps from pad");
1906 g_signal_emit_by_name(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "push-buffer", buffer, &ret);
1908 /*_mmcam_dbg_log("push buffer result : 0x%x", ret);*/
1911 /* skip display if too fast FPS */
1912 if (sc->info_video && sc->info_video->fps > _MMCAMCORDER_FRAME_PASS_MIN_FPS) {
1913 if (sc->info_video->prev_preview_ts != 0) {
1914 diff = GST_BUFFER_PTS(buffer) - sc->info_video->prev_preview_ts;
1915 if (diff < _MMCAMCORDER_MIN_TIME_TO_PASS_FRAME) {
1916 _mmcam_dbg_log("it's too fast. drop frame...");
1917 return GST_PAD_PROBE_DROP;
1921 /*_mmcam_dbg_log("diff %llu", diff);*/
1923 sc->info_video->prev_preview_ts = GST_BUFFER_PTS(buffer);
1926 return GST_PAD_PROBE_OK;
1930 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
1932 int result = MM_CAMCORDER_MR475;
1934 if (bitrate < 5150) {
1935 result = MM_CAMCORDER_MR475; /*AMR475*/
1936 } else if (bitrate < 5900) {
1937 result = MM_CAMCORDER_MR515; /*AMR515*/
1938 } else if (bitrate < 6700) {
1939 result = MM_CAMCORDER_MR59; /*AMR59*/
1940 } else if (bitrate < 7400) {
1941 result = MM_CAMCORDER_MR67; /*AMR67*/
1942 } else if (bitrate < 7950) {
1943 result = MM_CAMCORDER_MR74; /*AMR74*/
1944 } else if (bitrate < 10200) {
1945 result = MM_CAMCORDER_MR795; /*AMR795*/
1946 } else if (bitrate < 12200) {
1947 result = MM_CAMCORDER_MR102; /*AMR102*/
1949 result = MM_CAMCORDER_MR122; /*AMR122*/
1956 int _mmcamcorder_get_eos_message(MMHandleType handle)
1959 int ret = MM_ERROR_NONE;
1961 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1962 _MMCamcorderSubContext *sc = NULL;
1964 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1965 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1966 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1968 _mmcam_dbg_log("START");
1970 _MMCAMCORDER_LOCK(handle);
1972 if (sc->bget_eos == FALSE) {
1973 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
1974 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
1975 _mmcam_dbg_log("EOS signal received");
1977 _mmcam_dbg_err("EOS wait time out");
1980 _mmcam_dbg_log("already got EOS");
1983 _MMCAMCORDER_UNLOCK(handle);
1985 if (hcamcorder->error_code == MM_ERROR_NONE) {
1986 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1987 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1988 if (sc->info_video->b_commiting)
1989 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
1991 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1992 if (sc->info_audio->b_commiting)
1993 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
1996 ret = hcamcorder->error_code;
1997 _mmcam_dbg_err("error 0x%x", ret);
2000 _mmcam_dbg_log("END");
2006 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2009 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2011 mmf_return_if_fail(handle && remove_element);
2012 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2016 for (i = first_elem ; i <= last_elem ; i++) {
2017 remove_element[i].gst = NULL;
2018 remove_element[i].id = _MMCAMCORDER_NONE;
2025 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2027 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2029 /* Check compatibility between codec and file format */
2030 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2031 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2032 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2033 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2034 _mmcam_dbg_err("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2035 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2038 _mmcam_dbg_log("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2040 _mmcam_dbg_err("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2041 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2043 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2044 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2045 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2046 if (videocodec_fileformat_compatibility_table[ codec][file_format] == 0) {
2047 _mmcam_dbg_err("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2048 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2051 _mmcam_dbg_log("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2053 _mmcam_dbg_err("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2054 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2058 return MM_ERROR_NONE;
2062 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2064 int err = MM_ERROR_NONE;
2065 int audio_codec = MM_AUDIO_CODEC_INVALID;
2066 int file_format = MM_FILE_FORMAT_INVALID;
2068 char *err_name = NULL;
2070 err = mm_camcorder_get_attributes(handle, &err_name,
2071 MMCAM_AUDIO_ENCODER, &audio_codec,
2072 MMCAM_FILE_FORMAT, &file_format,
2074 if (err != MM_ERROR_NONE) {
2075 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
2076 SAFE_FREE(err_name);
2080 /* Check compatibility between audio codec and file format */
2081 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2087 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2089 int err = MM_ERROR_NONE;
2090 int video_codec = MM_VIDEO_CODEC_INVALID;
2091 int file_format = MM_FILE_FORMAT_INVALID;
2093 char *err_name = NULL;
2095 err = mm_camcorder_get_attributes(handle, &err_name,
2096 MMCAM_VIDEO_ENCODER, &video_codec,
2097 MMCAM_FILE_FORMAT, &file_format,
2099 if (err != MM_ERROR_NONE) {
2100 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
2101 SAFE_FREE(err_name);
2105 /* Check compatibility between video codec and file format */
2106 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2112 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2114 const char* videosink_name = NULL;
2116 mmf_camcorder_t *hcamcorder = NULL;
2117 _MMCamcorderSubContext *sc = NULL;
2119 hcamcorder = MMF_CAMCORDER(handle);
2120 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2122 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2123 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2124 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2126 if (sc->element[videosink_index].gst) {
2127 /* Get videosink name */
2128 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2129 if (videosink_name == NULL) {
2130 _mmcam_dbg_err("Please check videosink element in configuration file");
2134 if (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "xvimagesink") ||
2135 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2136 !strcmp(videosink_name, "directvideosink")) {
2137 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2138 _mmcam_dbg_log("Set display-rotate [%d] done.", display_rotate);
2140 _mmcam_dbg_warn("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2145 _mmcam_dbg_err("Videosink element is null");
2151 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2153 const char* videosink_name = NULL;
2155 mmf_camcorder_t *hcamcorder = NULL;
2156 _MMCamcorderSubContext *sc = NULL;
2158 hcamcorder = MMF_CAMCORDER(handle);
2159 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2161 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2162 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2163 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2165 if (sc->element[videosink_index].gst) {
2166 /* Get videosink name */
2167 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2168 if (videosink_name == NULL) {
2169 _mmcam_dbg_err("Please check videosink element in configuration file");
2173 if (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "xvimagesink") ||
2174 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2175 !strcmp(videosink_name, "directvideosink")) {
2176 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2177 _mmcam_dbg_log("Set display flip [%d] done.", display_flip);
2179 _mmcam_dbg_warn("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2184 _mmcam_dbg_err("Videosink element is null");
2190 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2195 _MMCamcorderSubContext *sc = NULL;
2197 mmf_camcorder_t *hcamcorder = NULL;
2199 hcamcorder = MMF_CAMCORDER(handle);
2200 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2202 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2204 _mmcam_dbg_log("sub context is not initailized");
2208 mm_camcorder_get_attributes(handle, NULL,
2209 MMCAM_CAMERA_WIDTH, &width,
2210 MMCAM_CAMERA_HEIGHT, &height,
2211 MMCAM_CAMERA_FPS, &fps,
2214 _mmcam_dbg_log("set rotate %d", videosrc_rotate);
2216 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, videosrc_rotate);
2220 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2226 unsigned int caps_fourcc = 0;
2227 gboolean do_set_caps = FALSE;
2229 GstCaps *caps = NULL;
2230 #ifdef _MMCAMCORDER_PRODUCT_TV
2232 GstCaps *decsink_caps = NULL;
2233 GstStructure *decsink_struct = NULL;
2236 #endif /*_MMCAMCORDER_PRODUCT_TV */
2238 mmf_camcorder_t *hcamcorder = NULL;
2239 _MMCamcorderSubContext *sc = NULL;
2241 hcamcorder = MMF_CAMCORDER(handle);
2242 mmf_return_val_if_fail(hcamcorder, FALSE);
2244 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2246 if (!sc || !(sc->element)) {
2247 _mmcam_dbg_log("sub context is not initialized");
2251 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2252 _mmcam_dbg_err("Video src is NULL!");
2256 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2257 _mmcam_dbg_err("Video filter is NULL!");
2261 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2262 int capture_width = 0;
2263 int capture_height = 0;
2264 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2266 mm_camcorder_get_attributes(handle, NULL,
2267 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2268 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2269 MMCAM_CAPTURE_WIDTH, &capture_width,
2270 MMCAM_CAPTURE_HEIGHT, &capture_height,
2271 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2272 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2274 _mmcam_dbg_log("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2275 motion_rate, capture_width, capture_height, fps_auto,
2276 sc->info_video->video_width, sc->info_video->video_height);
2278 if (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE) {
2279 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
2281 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
2284 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2285 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2286 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2289 sc->info_video->fps = fps;
2292 /* Interleaved format does not support rotation */
2293 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2294 /* store videosrc rotation */
2295 sc->videosrc_rotate = rotate;
2297 /* Define width, height and rotate in caps */
2299 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2300 This will be applied when rotate is 0, 180 if front camera. */
2301 set_rotate = rotate * 90;
2303 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2304 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2307 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2308 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2315 set_height = height;
2318 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2321 set_height = height;
2323 _mmcam_dbg_warn("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2326 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2327 if (caps && !gst_caps_is_any(caps)) {
2328 GstStructure *structure = NULL;
2330 structure = gst_caps_get_structure(caps, 0);
2332 const gchar *format_string = NULL;
2334 int caps_height = 0;
2336 int caps_rotate = 0;
2338 format_string = gst_structure_get_string(structure, "format");
2340 caps_fourcc = _mmcamcorder_convert_fourcc_string_to_value(format_string);
2342 gst_structure_get_int(structure, "width", &caps_width);
2343 gst_structure_get_int(structure, "height", &caps_height);
2344 gst_structure_get_int(structure, "fps", &caps_fps);
2345 gst_structure_get_int(structure, "rotate", &caps_rotate);
2347 #ifdef _MMCAMCORDER_PRODUCT_TV
2348 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
2349 if (set_width == caps_width && set_height == caps_height && set_rotate == caps_rotate && fps == caps_fps) {
2350 _mmcam_dbg_log("No need to replace caps.");
2352 _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]",
2353 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2354 caps_width, caps_height, caps_fps, caps_rotate,
2355 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2356 set_width, set_height, fps, set_rotate);
2360 if (set_width == caps_width && set_height == caps_height &&
2361 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2362 _mmcam_dbg_log("No need to replace caps.");
2364 _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]",
2365 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2366 caps_width, caps_height, caps_fps, caps_rotate,
2367 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2368 set_width, set_height, fps, set_rotate);
2372 #else /*_MMCAMCORDER_PRODUCT_TV */
2373 if (set_width == caps_width && set_height == caps_height &&
2374 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2375 _mmcam_dbg_log("No need to replace caps.");
2377 _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]",
2378 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2379 caps_width, caps_height, caps_fps, caps_rotate,
2380 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2381 set_width, set_height, fps, set_rotate);
2384 #endif /*_MMCAMCORDER_PRODUCT_TV */
2386 _mmcam_dbg_log("can not get structure of caps. set new one...");
2390 _mmcam_dbg_log("No caps. set new one...");
2395 gst_caps_unref(caps);
2400 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
2401 #ifdef _MMCAMCORDER_PRODUCT_TV
2402 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
2404 _mmcam_dbg_err("There are no decoder caps");
2408 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
2409 if (!decsink_caps) {
2410 gst_object_unref(sinkpad);
2411 _mmcam_dbg_err("There is no decoder sink caps");
2415 decsink_struct = gst_caps_get_structure(decsink_caps, 0);
2416 if (!decsink_struct) {
2417 _mmcam_dbg_err("There are no structure from caps");
2418 gst_object_unref(decsink_caps);
2419 gst_object_unref(sinkpad);
2423 if (gst_structure_has_field(decsink_struct, "maxwidth"))
2424 gst_structure_get_int(decsink_struct, "maxwidth", &maxwidth);
2426 if (gst_structure_has_field(decsink_struct, "maxheight"))
2427 gst_structure_get_int(decsink_struct, "maxheight", &maxheight);
2428 #endif /* _MMCAMCORDER_PRODUCT_TV */
2430 caps = gst_caps_new_simple("video/x-h264",
2431 "width", G_TYPE_INT, set_width,
2432 "height", G_TYPE_INT, set_height,
2433 "framerate", GST_TYPE_FRACTION, fps, 1,
2434 "stream-format", G_TYPE_STRING, "byte-stream",
2435 #ifdef _MMCAMCORDER_PRODUCT_TV
2436 "maxwidth", G_TYPE_INT, maxwidth,
2437 "maxheight", G_TYPE_INT, maxheight,
2438 "alignment", G_TYPE_STRING, "au",
2439 #endif /* _MMCAMCORDER_PRODUCT_TV */
2442 #ifdef _MMCAMCORDER_PRODUCT_TV
2443 gst_object_unref(decsink_caps);
2444 gst_object_unref(sinkpad);
2445 #endif /* _MMCAMCORDER_PRODUCT_TV */
2447 char fourcc_string[sizeof(fourcc)+1];
2448 strncpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
2449 fourcc_string[sizeof(fourcc)] = '\0';
2450 caps = gst_caps_new_simple("video/x-raw",
2451 "format", G_TYPE_STRING, fourcc_string,
2452 "width", G_TYPE_INT, set_width,
2453 "height", G_TYPE_INT, set_height,
2454 "framerate", GST_TYPE_FRACTION, fps, 1,
2455 "rotate", G_TYPE_INT, set_rotate,
2460 _mmcam_dbg_log("vidoesrc new caps set. %"GST_PTR_FORMAT, caps);
2461 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2462 gst_caps_unref(caps);
2465 _mmcam_dbg_err("There are no caps");
2469 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2470 /* assume that it's camera capture mode */
2471 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2478 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2480 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2481 _MMCamcorderSubContext *sc = NULL;
2483 mmf_return_val_if_fail(hcamcorder, FALSE);
2485 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2489 _mmcam_dbg_log("Set FLIP %d", videosrc_flip);
2491 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2495 /* Interleaved format does not support FLIP */
2496 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2497 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2498 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2500 _mmcam_dbg_log("videosrc flip H:%d, V:%d", hflip, vflip);
2502 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2503 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2505 _mmcam_dbg_warn("ITLV format does not support FLIP. Ignore FLIP[%d]",
2509 _mmcam_dbg_warn("element is NULL");
2517 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2519 GstCameraControl *control = NULL;
2520 _MMCamcorderSubContext *sc = NULL;
2521 GstElement *v_src = NULL;
2525 mmf_return_val_if_fail(handle, FALSE);
2527 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2531 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2534 _mmcam_dbg_warn("videosrc element is NULL");
2538 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2540 /* set anti-shake with camera control */
2541 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2542 _mmcam_dbg_warn("Can't cast Video source into camera control.");
2546 control = GST_CAMERA_CONTROL(v_src);
2547 if (gst_camera_control_set_ahs(control, set_value)) {
2548 _mmcam_dbg_log("Succeed in operating anti-handshake. value[%d]", set_value);
2551 _mmcam_dbg_warn("Failed to operate anti-handshake. value[%d]", set_value);
2558 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2560 _MMCamcorderSubContext *sc = NULL;
2561 GstElement *v_src = NULL;
2563 mmf_return_val_if_fail(handle, FALSE);
2565 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2569 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2571 _mmcam_dbg_warn("videosrc element is NULL");
2575 /* check property of videosrc element - support VDIS */
2576 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2577 int video_width = 0;
2578 int video_height = 0;
2580 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2581 _mmcam_dbg_log("ENABLE video stabilization");
2583 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2584 mm_camcorder_get_attributes(handle, NULL,
2585 MMCAM_VIDEO_WIDTH, &video_width,
2586 MMCAM_VIDEO_HEIGHT, &video_height,
2589 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2590 _mmcam_dbg_log("NV12, video size %dx%d, ENABLE video stabilization",
2591 video_width, video_height, stabilization);
2593 g_object_set(G_OBJECT(v_src),
2594 "enable-vdis-mode", TRUE,
2597 _mmcam_dbg_warn("invalid preview format %c%c%c%c or video size %dx%d",
2598 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2599 video_width, video_height);
2604 g_object_set(G_OBJECT(v_src),
2605 "enable-vdis-mode", FALSE,
2608 _mmcam_dbg_log("DISABLE video stabilization");
2610 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2611 _mmcam_dbg_err("no property for video stabilization, so can not set ON");
2614 _mmcam_dbg_warn("no property for video stabilization");
2621 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2625 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2626 _MMCamcorderSubContext *sc = NULL;
2628 mmf_return_val_if_fail(hcamcorder, FALSE);
2630 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2634 mm_camcorder_get_attributes(handle, NULL,
2635 MMCAM_CAMERA_FPS, &fps,
2638 _mmcam_dbg_log("set %dx%d", width, height);
2640 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2644 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2646 _MMCamcorderSubContext *sc = NULL;
2647 GstCameraControl *CameraControl = NULL;
2648 GstCameraControlChannel *CameraControlChannel = NULL;
2649 const GList *controls = NULL;
2650 const GList *item = NULL;
2652 if ((void *)handle == NULL) {
2653 _mmcam_dbg_warn("handle is NULL");
2657 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2659 _mmcam_dbg_warn("subcontext is NULL");
2663 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2664 _mmcam_dbg_warn("videosrc plugin is NULL");
2668 _mmcam_dbg_log("set encoded preview bitrate : %d bps", bitrate);
2670 CameraControl = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2671 controls = gst_camera_control_list_channels(CameraControl);
2672 _mmcam_dbg_log("controls : 0x%x", controls);
2673 if (controls != NULL) {
2674 _mmcam_dbg_log("controls : 0x%x", controls);
2675 for (item = controls ; item && item->data ; item = item->next) {
2676 CameraControlChannel = item->data;
2677 _mmcam_dbg_log("label : %d", CameraControlChannel->label);
2678 if (!strcmp(CameraControlChannel->label, "bitrate")) {
2679 _mmcam_dbg_log("set encoded preview bitrate %d", bitrate);
2680 return gst_camera_control_set_value(CameraControl, CameraControlChannel, bitrate);
2685 _mmcam_dbg_warn("failed to find \"bitrate\" control channel");
2693 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int interval)
2695 _MMCamcorderSubContext *sc = NULL;
2697 if ((void *)handle == NULL) {
2698 _mmcam_dbg_warn("handle is NULL");
2702 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2704 _mmcam_dbg_warn("subcontext is NULL");
2708 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2709 _mmcam_dbg_warn("videosrc plugin is NULL");
2713 _mmcam_dbg_log("set encoded preview GOP interval : %d ms", interval);
2715 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "newgop-interval", interval);
2721 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
2723 GstStructure *props = NULL;
2724 char stream_props[64] = {'\0',};
2726 if (element == NULL || stream_type == NULL || stream_index < 0) {
2727 _mmcam_dbg_err("invalid argument %p %p %d", element, stream_type, stream_index);
2731 snprintf(stream_props, sizeof(stream_props) - 1,
2732 "props,media.role=%s, media.parent_id=%d",
2733 stream_type, stream_index);
2735 _mmcam_dbg_log("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
2737 props = gst_structure_from_string(stream_props, NULL);
2739 _mmcam_dbg_err("failed to create GstStructure");
2743 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
2745 gst_structure_free(props);
2752 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
2754 int ret = MM_ERROR_NONE;
2755 _MMCamcorderSubContext *sc = NULL;
2756 mmf_camcorder_t *hcamcorder = NULL;
2757 const char *videodecoder_name = NULL;
2758 #ifdef _MMCAMCORDER_RM_SUPPORT
2759 char decoder_name[20] = {'\0',};
2760 int decoder_index = 0;
2761 #endif /* _MMCAMCORDER_RM_SUPPORT */
2763 if ((void *)handle == NULL) {
2764 _mmcam_dbg_warn("handle is NULL");
2768 hcamcorder = MMF_CAMCORDER(handle);
2770 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2772 _mmcam_dbg_warn("subcontext is NULL");
2776 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ENCODED_H264 ||
2777 hcamcorder->recreate_decoder == FALSE) {
2778 _mmcam_dbg_log("skip this fuction - format %d, recreate decoder %d",
2779 sc->info_image->preview_format, hcamcorder->recreate_decoder);
2783 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
2784 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
2785 _mmcam_dbg_warn("main pipeline or decoder plugin is NULL");
2789 _mmcam_dbg_log("start");
2791 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
2792 if (videodecoder_name == NULL) {
2793 _mmcam_dbg_err("failed to get decoder element name from %p", sc->VideodecoderElementH264);
2797 /* set state as NULL */
2798 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
2799 if (ret != MM_ERROR_NONE) {
2800 _mmcam_dbg_err("failed to set NULL to decoder");
2804 /* remove decoder - pads will be unlinked automatically in remove function */
2805 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
2806 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
2807 _mmcam_dbg_err("failed to remove decoder from pipeline");
2811 /* check decoder element */
2812 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
2813 _mmcam_dbg_log("decoder[%p] is still alive - ref count %d",
2814 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
2815 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
2818 #ifdef _MMCAMCORDER_RM_SUPPORT
2819 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
2822 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
2823 _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
2824 /* create decoder */
2825 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(decoder_name, "videosrc_decode");
2826 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
2827 _mmcam_dbg_err("Decoder[%s] creation fail", decoder_name);
2830 #else /* _MMCAMCORDER_RM_SUPPORT */
2831 /* create new decoder */
2832 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name, "videosrc_decode");
2833 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
2834 _mmcam_dbg_err("Decoder [%s] creation fail", videodecoder_name);
2837 #endif /* _MMCAMCORDER_RM_SUPPORT */
2838 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
2840 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
2841 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
2842 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
2844 /* add to pipeline */
2845 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
2846 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
2847 _mmcam_dbg_err("failed to add decoder to pipeline");
2848 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
2853 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
2854 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
2855 _mmcam_dbg_log("Link videosrc_queue to decoder OK");
2857 _mmcam_dbg_err("Link videosrc_queue to decoder FAILED");
2861 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
2862 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
2863 _mmcam_dbg_log("Link decoder to videosink_queue OK");
2865 _mmcam_dbg_err("Link decoder to videosink_queue FAILED");
2869 /* set state READY */
2870 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
2871 if (ret != MM_ERROR_NONE) {
2872 _mmcam_dbg_err("failed to set READY to decoder");
2876 _mmcam_dbg_log("done");