4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
25 #include <gst/allocators/gsttizenmemory.h>
26 #include <gst/audio/audio-format.h>
27 #include <gst/video/videooverlay.h>
28 #include <gst/video/cameracontrol.h>
32 #include <tbm_bufmgr.h>
33 #include <tbm_surface.h>
34 #include <tbm_surface_internal.h>
36 #include "mm_camcorder_internal.h"
37 #include "mm_camcorder_gstcommon.h"
39 /*-----------------------------------------------------------------------
40 | GLOBAL VARIABLE DEFINITIONS for internal |
41 -----------------------------------------------------------------------*/
42 /* Table for compatibility between audio codec and file format */
43 gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
44 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
45 /*AMR*/ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
46 /*G723.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
47 /*MP3*/ { 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
48 /*OGG*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
49 /*AAC*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
50 /*WMA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 /*MMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
52 /*ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
53 /*WAVE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
54 /*WAVE_NEW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
55 /*MIDI*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
56 /*IMELODY*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
57 /*MXMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
58 /*MPA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
59 /*MP2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
60 /*G711*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
61 /*G722*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
62 /*G722.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
63 /*G722.2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
64 /*G723*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
65 /*G726*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
66 /*G728*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
67 /*G729*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
68 /*G729A*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
69 /*G729.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
70 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
71 /*AAC_LC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
72 /*AAC_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
73 /*AAC_SRS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
74 /*AAC_LTP*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
75 /*AAC_HE_V1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
76 /*AAC_HE_V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
77 /*AC3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
78 /*ALAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
79 /*ATRAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
80 /*SPEEX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
81 /*VORBIS*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
82 /*AIFF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
83 /*AU*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
84 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
85 /*PCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 /*ALAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 /*MULAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
88 /*MS_ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
91 /* Table for compatibility between video codec and file format */
92 gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
93 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
94 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
95 /*H263*/ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
96 /*H264*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
97 /*H26L*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
98 /*MPEG4*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
99 /*MPEG1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
100 /*WMV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
101 /*DIVX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
102 /*XVID*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
103 /*H261*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
104 /*H262*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
105 /*H263V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
106 /*H263V3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
107 /*MJPEG*/ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
108 /*MPEG2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
109 /*MPEG4_SIMPLE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
110 /*MPEG4_ADV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
111 /*MPEG4_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
112 /*MPEG4_CORE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
113 /*MPEG4_ACE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
114 /*MPEG4_ARTS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
115 /*MPEG4_AVC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
116 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
117 /*VC1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
118 /*AVS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
119 /*CINEPAK*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
120 /*INDEO*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
121 /*THEORA*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
125 /*-----------------------------------------------------------------------
126 | LOCAL VARIABLE DEFINITIONS for internal |
127 -----------------------------------------------------------------------*/
128 #define USE_AUDIO_CLOCK_TUNE
129 #define _MMCAMCORDER_WAIT_EOS_TIME 60.0 /* sec */
130 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM 6
131 #define _MMCAMCORDER_NANOSEC_PER_1SEC 1000000000
132 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC 1000
135 /*-----------------------------------------------------------------------
136 | LOCAL FUNCTION PROTOTYPES: |
137 -----------------------------------------------------------------------*/
138 /* STATIC INTERNAL FUNCTION */
140 * These are video data probing functions.
141 * If there are pads which set probe callback by gst_pad_add_probe(),
142 * the functions 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 Refer #GstPadProbeReturn in gstpad.h
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_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
154 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
155 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name);
156 #ifdef _MMCAMCORDER_PRODUCT_TV
157 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height);
158 #endif /* _MMCAMCORDER_PRODUCT_TV */
160 static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info);
161 static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
163 /*=======================================================================================
164 | FUNCTION DEFINITIONS |
165 =======================================================================================*/
166 static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
168 mmf_return_val_if_fail(buffer, FALSE);
169 mmf_return_val_if_fail(map_info, FALSE);
170 mmf_return_val_if_fail(stream, FALSE);
172 switch (stream->format) {
173 case MM_PIXEL_FORMAT_NV12: /* fall through */
174 case MM_PIXEL_FORMAT_NV21:
175 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
176 stream->data.yuv420sp.y = map_info->data;
177 stream->data.yuv420sp.length_y = stream->width * stream->height;
178 stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
179 stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
180 stream->stride[0] = stream->width;
181 stream->elevation[0] = stream->height;
182 stream->stride[1] = stream->width;
183 stream->elevation[1] = stream->height >> 1;
184 stream->num_planes = 2;
187 case MM_PIXEL_FORMAT_I420:
188 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
189 stream->data.yuv420p.y = map_info->data;
190 stream->data.yuv420p.length_y = stream->width * stream->height;
191 stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
192 stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
193 stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
194 stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
195 stream->stride[0] = stream->width;
196 stream->elevation[0] = stream->height;
197 stream->stride[1] = stream->stride[2] = stream->width >> 1;
198 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
199 stream->num_planes = 3;
202 case MM_PIXEL_FORMAT_422P:
203 stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
204 stream->data.yuv422p.y = map_info->data;
205 stream->data.yuv422p.length_y = stream->width * stream->height;
206 stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
207 stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
208 stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
209 stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
210 stream->stride[0] = stream->width;
211 stream->elevation[0] = stream->height;
212 stream->stride[1] = stream->stride[2] = stream->width;
213 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
214 stream->num_planes = 3;
217 case MM_PIXEL_FORMAT_YUYV: /* fall through */
218 case MM_PIXEL_FORMAT_UYVY: /* fall through */
219 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
220 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
221 stream->data.yuv422.yuv = map_info->data;
222 stream->data.yuv422.length_yuv = stream->length_total;
223 stream->stride[0] = stream->width << 1;
224 stream->elevation[0] = stream->height;
225 stream->num_planes = 1;
228 case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
229 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
230 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
231 stream->data.encoded.data = map_info->data;
232 stream->data.encoded.length_data = stream->length_total;
233 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
234 stream->num_planes = 1;
237 case MM_PIXEL_FORMAT_INVZ:
238 stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
239 stream->data.depth.data = map_info->data;
240 stream->data.depth.length_data = stream->length_total;
241 stream->stride[0] = stream->width << 1;
242 stream->elevation[0] = stream->height;
243 stream->num_planes = 1;
246 case MM_PIXEL_FORMAT_RGBA: /* fall through */
247 case MM_PIXEL_FORMAT_ARGB:
248 stream->data_type = MM_CAM_STREAM_DATA_RGB;
249 stream->data.rgb.data = map_info->data;
250 stream->data.rgb.length_data = stream->length_total;
251 stream->stride[0] = stream->width << 2;
252 stream->elevation[0] = stream->height;
253 stream->num_planes = 1;
257 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
265 static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info)
267 mmf_return_val_if_fail(ts_info, FALSE);
268 mmf_return_val_if_fail(stream, FALSE);
270 switch (stream->format) {
271 case MM_PIXEL_FORMAT_NV12: /* fall through */
272 case MM_PIXEL_FORMAT_NV21:
273 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
274 stream->num_planes = 2;
275 stream->data.yuv420sp.y = ts_info->planes[0].ptr;
276 stream->data.yuv420sp.length_y = ts_info->planes[0].size;
277 stream->data.yuv420sp.uv = ts_info->planes[1].ptr;
278 stream->data.yuv420sp.length_uv = ts_info->planes[1].size;
281 case MM_PIXEL_FORMAT_I420:
282 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
283 stream->num_planes = 3;
284 stream->data.yuv420p.y = ts_info->planes[0].ptr;
285 stream->data.yuv420p.length_y = ts_info->planes[0].size;
286 stream->data.yuv420p.u = ts_info->planes[1].ptr;
287 stream->data.yuv420p.length_u = ts_info->planes[1].size;
288 stream->data.yuv420p.v = ts_info->planes[2].ptr;
289 stream->data.yuv420p.length_v = ts_info->planes[2].size;
293 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
301 gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstBuffer *buffer, gboolean is_preview)
305 gboolean ret_cb = TRUE;
306 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
307 _MMCamcorderSubContext *sc = NULL;
308 MMCamcorderVideoStreamDataType stream;
310 tbm_surface_h t_surface = NULL;
311 tbm_surface_info_s ts_info;
313 GstMemory *memory = NULL;
315 GstCaps *caps = NULL;
317 GstStructure *structure = NULL;
319 mmf_return_val_if_fail(hcamcorder, FALSE);
320 mmf_return_val_if_fail(buffer, FALSE);
321 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
323 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
324 mmf_return_val_if_fail(sc, FALSE);
326 /* clear data structure */
327 memset(&map_info, 0x0, sizeof(GstMapInfo));
328 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
330 stream.format = sc->info_image->preview_format;
332 /* preview buffer - get resolution from caps */
333 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
334 mmf_return_val_if_fail(pad, FALSE);
336 caps = gst_pad_get_allowed_caps(pad);
338 MMCAM_LOG_ERROR("failed to get caps from pad %p", pad);
339 gst_object_unref(pad);
343 structure = gst_caps_get_structure(caps, 0);
345 MMCAM_LOG_ERROR("failed to get structure from caps %p", caps);
346 gst_caps_unref(caps);
347 gst_object_unref(pad);
351 gst_structure_get_int(structure, "width", &stream.width);
352 gst_structure_get_int(structure, "height", &stream.height);
354 gst_caps_unref(caps);
356 gst_object_unref(pad);
359 /* video recording buffer */
360 stream.width = sc->info_video->video_width;
361 stream.height = sc->info_video->video_height;
364 /* set size and timestamp */
365 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format)) {
366 memory = gst_buffer_get_all_memory(buffer);
367 stream.internal_buffer = buffer;
369 memory = gst_buffer_peek_memory(buffer, 0);
372 MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
376 /* set zero-copy related information */
377 if (hcamcorder->use_zero_copy_format) {
378 t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
380 if (tbm_surface_get_info(t_surface, &ts_info) != TBM_SURFACE_ERROR_NONE) {
381 MMCAM_LOG_ERROR("failed to get tbm surface[%p] info", t_surface);
382 goto _INVOKE_VIDEO_STREAM_CB_DONE;
385 /* set bo, stride and elevation */
386 num_bos = gst_tizen_memory_get_num_bos(memory);
387 for (i = 0 ; i < num_bos ; i++)
388 stream.bo[i] = gst_tizen_memory_get_bos(memory, i);
390 for (i = 0 ; i < ts_info.num_planes ; i++) {
391 stream.stride[i] = ts_info.planes[i].stride;
392 stream.elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
393 MMCAM_LOG_VERBOSE(" plane[%d] %dx%d", i, stream.stride[i], stream.elevation[i]);
396 stream.length_total = ts_info.size;
397 stream.internal_buffer = buffer;
399 if (!__mmcamcorder_set_stream_data_tbm(&stream, &ts_info))
400 goto _INVOKE_VIDEO_STREAM_CB_DONE;
402 stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
404 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE) ||
405 !__mmcamcorder_set_stream_data_normal(&stream, buffer, &map_info))
406 goto _INVOKE_VIDEO_STREAM_CB_DONE;
409 MMCAM_LOG_DEBUG("VideoStreamData : resolution[%dx%d], format[%d]",
410 stream.width, stream.height, stream.format);
412 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
414 /* invoke application callback */
416 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
417 if (hcamcorder->vstream_cb)
418 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
419 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
421 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
422 if (hcamcorder->vedecision_cb)
423 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
424 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
427 _INVOKE_VIDEO_STREAM_CB_DONE:
428 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
429 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
430 tbm_bo_unmap(stream.bo[i]);
434 gst_memory_unmap(memory, &map_info);
436 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format))
437 gst_memory_unref(memory);
443 int _mmcamcorder_create_preview_elements(MMHandleType handle)
445 int err = MM_ERROR_NONE;
447 int camera_rotate = 0;
451 int capture_width = 0;
452 int capture_height = 0;
453 int capture_jpg_quality = 100;
454 int video_stabilization = 0;
456 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
457 const char *videosrc_name = NULL;
458 const char *videosink_name = NULL;
459 const char *videoconvert_name = NULL;
460 char *err_name = NULL;
461 char *socket_path = NULL;
463 #ifdef _MMCAMCORDER_RM_SUPPORT
464 int decoder_index = 0;
465 char decoder_name[20] = {'\0',};
466 #endif /* _MMCAMCORDER_RM_SUPPORT */
467 GstElement *sink_element = NULL;
468 GstCameraControl *control = NULL;
469 int sink_element_size = 0;
473 GList *element_list = NULL;
475 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
476 _MMCamcorderSubContext *sc = NULL;
477 type_element *VideosrcElement = NULL;
478 type_int_array *input_index = NULL;
480 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
482 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
483 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
484 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
488 /* Check existence */
489 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
490 if (sc->element[i].gst) {
491 if (((GObject *)sc->element[i].gst)->ref_count > 0)
492 gst_object_unref(sc->element[i].gst);
494 MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
498 /* Get video device index info */
499 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
500 CONFIGURE_CATEGORY_CTRL_CAMERA,
503 if (input_index == NULL) {
504 MMCAM_LOG_ERROR("Failed to get input_index");
505 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
508 err = mm_camcorder_get_attributes(handle, &err_name,
509 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
510 MMCAM_CAMERA_FPS, &fps,
511 MMCAM_CAMERA_ROTATION, &camera_rotate,
512 MMCAM_CAMERA_FLIP, &camera_flip,
513 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
514 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
515 MMCAM_CAPTURE_WIDTH, &capture_width,
516 MMCAM_CAPTURE_HEIGHT, &capture_height,
517 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
518 MMCAM_IMAGE_ENCODER, &codectype,
519 MMCAM_IMAGE_ENCODER_QUALITY, &capture_jpg_quality,
520 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
521 MMCAM_DISPLAY_SURFACE, &display_surface_type,
523 if (err != MM_ERROR_NONE) {
524 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
529 if (hcamcorder->support_user_buffer) {
530 err = mm_camcorder_get_attributes(handle, NULL,
531 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
533 if (err != MM_ERROR_NONE || fd_number < 1) {
534 MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
539 for (i = 0 ; i < fd_number ; i++)
540 MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
544 /* Get fourcc from picture format */
545 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
547 /* Get videosrc element and its name from configure */
548 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
549 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
552 _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
555 * Create child element
557 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
559 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
561 /* init high-speed-fps */
562 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
564 /* set capture size, quality and flip setting which were set before mm_camcorder_realize */
565 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
566 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
567 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-jpg-quality", capture_jpg_quality);
568 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
570 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
572 /* set camera flip */
573 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
575 /* set video stabilization mode */
576 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
578 /* set anti handshake mode */
579 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
581 if (sc->is_modified_rate)
582 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
584 /* Set basic information of videosrc element */
585 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
587 /* Set video device index */
588 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
589 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
591 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
594 /* set user buffer fd to videosrc element */
595 if (hcamcorder->support_user_buffer) {
596 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
597 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
598 MMCAM_LOG_ERROR("set user buffer fd failed");
599 goto pipeline_creation_error;
603 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
604 /* get recreate_decoder flag */
605 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
606 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
608 &hcamcorder->recreate_decoder);
611 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
612 int preview_bitrate = 0;
613 int gop_interval = 0;
614 mm_camcorder_get_attributes(handle, NULL,
615 MMCAM_ENCODED_PREVIEW_BITRATE, &preview_bitrate,
616 MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
619 /* set encoded preview bitrate */
620 if (!_mmcamcorder_set_encoded_preview_bitrate(handle, preview_bitrate))
621 MMCAM_LOG_WARNING("_mmcamcorder_set_encoded_preview_bitrate failed");
623 /* set encoded preview iframe interval */
624 if (!_mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval))
625 MMCAM_LOG_WARNING("_mmcamcorder_set_encoded_preview_gop_interval failed");
628 if (display_surface_type != MM_DISPLAY_SURFACE_NULL) {
629 const char *videodecoder_name = NULL;
630 /* case of decoder element */
631 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
632 /* get video decoder element and name for H.264 format */
633 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
634 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
635 "VideodecoderElementH264",
636 &sc->VideodecoderElementH264);
637 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264,
639 if (videodecoder_name) {
640 #ifdef _MMCAMCORDER_RM_SUPPORT
641 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
644 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
645 MMCAM_LOG_INFO("encoded preview decoder_name [%s], video decoder element [%s]",
646 decoder_name, videodecoder_name);
647 /* create decoder element */
648 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
649 #else /* _MMCAMCORDER_RM_SUPPORT */
650 MMCAM_LOG_INFO("video decoder element [%s]", videodecoder_name);
651 /* create decoder element */
652 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name, "videosrc_decode", element_list, err);
653 #endif /* _MMCAMCORDER_RM_SUPPORT */
654 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
656 MMCAM_LOG_ERROR("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
657 goto pipeline_creation_error;
659 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
660 #ifdef _MMCAMCORDER_RM_SUPPORT
661 /* get video decoder element and name for MJPEG format */
662 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
663 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
664 "VideodecoderElementH264",
665 &sc->VideodecoderElementH264);
666 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264,
668 if (videodecoder_name) {
669 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
670 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_uhd_mjpegdec");
672 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_mjpegdec");
673 MMCAM_LOG_INFO("encoded preview decoder_name [%s], video decoder element [%s]",
674 decoder_name, videodecoder_name);
675 /* create decoder element */
676 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
677 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
679 MMCAM_LOG_ERROR("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
680 goto pipeline_creation_error;
682 #else /* _MMCAMCORDER_RM_SUPPORT */
683 MMCAM_LOG_INFO("video decoder element [jpegdec]");
684 /* create decoder element */
685 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, "jpegdec", "videosrc_decode", element_list, err);
686 #endif /* _MMCAMCORDER_RM_SUPPORT */
690 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
692 /* Get videosink name */
693 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
695 if (!videosink_name) {
696 MMCAM_LOG_ERROR("failed to get videosink name");
697 goto pipeline_creation_error;
700 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
702 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
704 if (display_surface_type == MM_DISPLAY_SURFACE_REMOTE) {
705 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "ipc_sink", element_list, err);
707 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
709 err = mm_camcorder_get_attributes(handle, &err_name,
710 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
712 if (err != MM_ERROR_NONE) {
713 MMCAM_LOG_WARNING("Get socket path failed 0x%x", err);
715 goto pipeline_creation_error;
718 g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
720 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
721 /* get video convert name */
722 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
724 if (videoconvert_name) {
725 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
726 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
728 MMCAM_LOG_ERROR("failed to get videoconvert element name");
731 /* check sink element in attribute */
732 mm_camcorder_get_attributes(handle, NULL,
733 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
738 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
740 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
742 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
744 /* reset attribute */
746 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
747 mm_attrs_set_data(attrs, attr_index, NULL, 0);
748 mm_attrs_commit(attrs, attr_index);
750 MMCAM_LOG_WARNING("attribute is NULL");
751 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
752 goto pipeline_creation_error;
755 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
757 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
760 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
761 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
762 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
763 goto pipeline_creation_error;
767 /* Set caps by rotation */
768 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
770 /* add elements to main pipeline */
771 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
772 MMCAM_LOG_ERROR("element_list add error.");
773 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
774 goto pipeline_creation_error;
778 if (!_mmcamcorder_link_elements(element_list)) {
779 MMCAM_LOG_ERROR("element link error.");
780 err = MM_ERROR_CAMCORDER_GST_LINK;
781 goto pipeline_creation_error;
785 g_list_free(element_list);
789 return MM_ERROR_NONE;
791 pipeline_creation_error:
792 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
793 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
794 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_QUE);
795 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS);
796 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_FILT);
797 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
798 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
799 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
800 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
803 g_list_free(element_list);
811 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
813 int err = MM_ERROR_NONE;
818 int a_enc = MM_AUDIO_CODEC_AMR;
819 int a_dev = MM_AUDIO_DEVICE_MIC;
821 char *err_name = NULL;
822 const char *audiosrc_name = NULL;
823 char *cat_name = NULL;
824 char *stream_type = NULL;
825 int stream_type_len = 0;
826 int stream_index = 0;
827 int buffer_interval = 0;
829 int replay_gain_enable = FALSE;
830 double replay_gain_ref_level = 0.0;
832 GstCaps *caps = NULL;
834 GList *element_list = NULL;
836 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
837 _MMCamcorderSubContext *sc = NULL;
838 _MMCamcorderGstElement *last_element = NULL;
839 type_element *AudiosrcElement = NULL;
841 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
843 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
844 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
845 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
849 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
850 if (err != MM_ERROR_NONE)
853 err = mm_camcorder_get_attributes(handle, &err_name,
854 MMCAM_AUDIO_DEVICE, &a_dev,
855 MMCAM_AUDIO_ENCODER, &a_enc,
856 MMCAM_AUDIO_ENCODER_BITRATE, &val,
857 MMCAM_AUDIO_SAMPLERATE, &rate,
858 MMCAM_AUDIO_FORMAT, &format,
859 MMCAM_AUDIO_CHANNEL, &channel,
860 MMCAM_AUDIO_VOLUME, &volume,
861 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
862 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
863 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
864 MMCAM_SOUND_STREAM_INDEX, &stream_index,
866 if (err != MM_ERROR_NONE) {
867 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
872 /* Check existence */
873 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
874 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
875 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
877 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
880 /* Create bin element */
881 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
883 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
884 cat_name = strdup("AudiomodemsrcElement");
886 /* MM_AUDIO_DEVICE_MIC or others */
887 cat_name = strdup("AudiosrcElement");
890 if (cat_name == NULL) {
891 MMCAM_LOG_ERROR("strdup failed.");
892 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
893 goto pipeline_creation_error;
896 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
897 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
900 _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
905 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
907 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
909 /* set sound stream info */
910 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
912 /* set audiosrc properties in ini configuration */
913 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
916 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
917 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
918 "AudioBufferInterval",
921 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
922 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
923 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
926 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
928 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
929 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
930 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
931 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
933 /* Set basic information */
934 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
936 const gchar* format_name = NULL;
938 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
941 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
942 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
944 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
945 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
948 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
950 format_name = "S16LE";
951 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
956 caps = gst_caps_new_simple("audio/x-raw",
957 "rate", G_TYPE_INT, rate,
958 "channels", G_TYPE_INT, channel,
959 "format", G_TYPE_STRING, format_name,
961 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
962 rate, channel, depth, volume);
964 /* what are the audio encoder which should get audio/x-raw-float? */
965 caps = gst_caps_new_simple("audio/x-raw",
966 "rate", G_TYPE_INT, rate,
967 "channels", G_TYPE_INT, channel,
968 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
970 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
971 rate, channel, BYTE_ORDER);
975 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
976 replay_gain_enable, replay_gain_ref_level);
978 if (replay_gain_enable) {
979 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
980 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
981 /* If num-tracks is not set, album gain and peak event is not come. */
982 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
986 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
987 gst_caps_unref(caps);
990 MMCAM_LOG_ERROR("create caps error");
991 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
992 goto pipeline_creation_error;
995 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
996 MMCAM_LOG_ERROR("element add error.");
997 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
998 goto pipeline_creation_error;
1001 if (!_mmcamcorder_link_elements(element_list)) {
1002 MMCAM_LOG_ERROR("element link error.");
1003 err = MM_ERROR_CAMCORDER_GST_LINK;
1004 goto pipeline_creation_error;
1007 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
1008 pad = gst_element_get_static_pad(last_element->gst, "src");
1009 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
1010 gst_object_unref(pad);
1012 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
1013 err = MM_ERROR_CAMCORDER_GST_LINK;
1014 goto pipeline_creation_error;
1017 gst_object_unref(pad);
1021 g_list_free(element_list);
1022 element_list = NULL;
1025 return MM_ERROR_NONE;
1027 pipeline_creation_error:
1028 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1029 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1030 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1031 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1032 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1035 g_list_free(element_list);
1036 element_list = NULL;
1043 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1048 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1053 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1054 type, codec, bitrate);
1058 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1059 /* audio encoder bitrate setting */
1061 case MM_AUDIO_CODEC_AMR:
1062 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1063 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1064 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1066 case MM_AUDIO_CODEC_MP3:
1067 set_value = bitrate / 1000;
1068 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1069 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1071 case MM_AUDIO_CODEC_AAC:
1072 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1073 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1076 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1080 /* video encoder bitrate setting */
1081 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1082 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1089 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1091 int err = MM_ERROR_NONE;
1096 int encodebin_profile = 0;
1097 int auto_audio_convert = 0;
1098 int auto_audio_resample = 0;
1099 int auto_color_space = 0;
1100 int cap_format = MM_PIXEL_FORMAT_INVALID;
1101 const char *gst_element_venc_name = NULL;
1102 const char *gst_element_aenc_name = NULL;
1103 const char *gst_element_ienc_name = NULL;
1104 const char *gst_element_mux_name = NULL;
1105 const char *gst_element_rsink_name = NULL;
1106 const char *gst_element_vscale_name = NULL;
1107 const char *str_profile = NULL;
1108 const char *str_aac = NULL;
1109 const char *str_aar = NULL;
1110 const char *str_acs = NULL;
1111 char *err_name = NULL;
1112 const char *videoconvert_name = NULL;
1113 GstCaps *audio_caps = NULL;
1114 GstCaps *video_caps = NULL;
1115 GstCaps *videoscale_caps = NULL;
1117 GList *element_list = NULL;
1119 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1120 _MMCamcorderSubContext *sc = NULL;
1121 type_element *VideoencElement = NULL;
1122 type_element *AudioencElement = NULL;
1123 type_element *ImageencElement = NULL;
1124 type_element *MuxElement = NULL;
1125 type_element *RecordsinkElement = NULL;
1126 type_element *VideoscaleElement = NULL;
1128 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1130 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1131 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1132 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1134 MMCAM_LOG_INFO("start - profile : %d", profile);
1136 /* Check existence */
1137 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1138 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1139 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1141 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1144 /* Create bin element */
1145 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1147 /* Create child element */
1148 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1149 GstCaps *caps_from_pad = NULL;
1150 char *caps_str = NULL;
1152 /* create appsrc and capsfilter */
1153 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1155 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1157 /* set appsrc as live source */
1158 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1159 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1160 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1162 /* set capsfilter */
1163 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1164 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1165 MMCAM_LOG_INFO("get pad from videosrc_filter");
1166 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1168 MMCAM_LOG_INFO("get pad from videosrc_que");
1169 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1172 MMCAM_LOG_ERROR("get videosrc_que src pad failed");
1173 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1174 goto pipeline_creation_error;
1177 caps_from_pad = gst_pad_get_allowed_caps(pad);
1178 video_caps = gst_caps_copy(caps_from_pad);
1179 gst_caps_unref(caps_from_pad);
1180 caps_from_pad = NULL;
1181 gst_object_unref(pad);
1185 video_caps = gst_caps_fixate(video_caps);
1188 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1192 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1193 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1194 goto pipeline_creation_error;
1197 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1198 if (sc->info_video->use_videoscale) {
1199 gst_caps_set_simple(video_caps,
1200 "width", G_TYPE_INT, sc->info_video->preview_width,
1201 "height", G_TYPE_INT, sc->info_video->preview_height,
1203 videoscale_caps = gst_caps_copy(video_caps);
1205 gst_caps_set_simple(video_caps,
1206 "width", G_TYPE_INT, sc->info_video->video_width,
1207 "height", G_TYPE_INT, sc->info_video->video_height,
1212 caps_str = gst_caps_to_string(video_caps);
1214 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1219 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1221 gst_caps_unref(video_caps);
1225 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1226 sc->info_video->use_videoscale) {
1227 if (!videoscale_caps) {
1228 MMCAM_LOG_ERROR("no videoscale caps");
1229 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1230 goto pipeline_creation_error;
1233 gst_caps_set_simple(videoscale_caps,
1234 "width", G_TYPE_INT, sc->info_video->video_width,
1235 "height", G_TYPE_INT, sc->info_video->video_height,
1238 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1239 CONFIGURE_CATEGORY_MAIN_RECORD,
1240 "VideoscaleElement",
1241 &VideoscaleElement);
1243 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1244 MMCAM_LOG_ERROR("failed to get videoscale element name");
1245 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1246 goto pipeline_creation_error;
1249 caps_str = gst_caps_to_string(videoscale_caps);
1251 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1256 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
1257 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
1259 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
1261 gst_caps_unref(videoscale_caps);
1262 videoscale_caps = NULL;
1265 /* release element_list, they will be placed out of encodesink bin */
1267 g_list_free(element_list);
1268 element_list = NULL;
1271 /* connect signal for ready to push buffer */
1272 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1273 _MMCAMCORDER_HANDLER_VIDEOREC,
1275 _mmcamcorder_ready_to_encode_callback,
1279 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1280 "tizenencodebin", "encodesink_encbin", element_list, err);
1282 /* check element availability */
1283 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1284 err = mm_camcorder_get_attributes(handle, &err_name,
1285 MMCAM_CAPTURE_FORMAT, &cap_format,
1288 err = mm_camcorder_get_attributes(handle, &err_name,
1289 MMCAM_AUDIO_ENCODER, &audio_enc,
1290 MMCAM_AUDIO_CHANNEL, &channel,
1291 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1292 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1296 if (err != MM_ERROR_NONE) {
1298 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1299 SAFE_FREE(err_name);
1301 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1304 goto pipeline_creation_error;
1307 MMCAM_LOG_INFO("Profile[%d]", profile);
1309 /* Set information */
1310 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1311 str_profile = "VideoProfile";
1312 str_aac = "VideoAutoAudioConvert";
1313 str_aar = "VideoAutoAudioResample";
1314 str_acs = "VideoAutoColorSpace";
1315 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1316 str_profile = "AudioProfile";
1317 str_aac = "AudioAutoAudioConvert";
1318 str_aar = "AudioAutoAudioResample";
1319 str_acs = "AudioAutoColorSpace";
1320 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1321 str_profile = "ImageProfile";
1322 str_aac = "ImageAutoAudioConvert";
1323 str_aar = "ImageAutoAudioResample";
1324 str_acs = "ImageAutoColorSpace";
1327 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1328 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1329 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1330 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1332 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1333 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1335 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1336 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1337 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1338 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1339 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1341 /* get video convert element name */
1342 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1345 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1346 int use_venc_queue = 0;
1348 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1350 if (!VideoencElement) {
1351 MMCAM_LOG_ERROR("Fail to get type element");
1352 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1353 goto pipeline_creation_error;
1356 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1357 /* set dummy element */
1358 gst_element_venc_name = "identity";
1360 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1363 if (gst_element_venc_name) {
1364 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1366 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1367 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1369 MMCAM_LOG_ERROR("Fail to get video encoder name");
1370 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1371 goto pipeline_creation_error;
1374 /* set color space converting element */
1375 if (auto_color_space) {
1376 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1378 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1379 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1381 /* set colorspace plugin property setting */
1382 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1384 /* fourcc type was removed in GST 1.0 */
1385 if (hcamcorder->use_zero_copy_format) {
1386 if (strstr(gst_element_venc_name, "omx")) {
1387 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1390 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1391 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1393 gst_caps_unref(video_caps);
1396 MMCAM_LOG_WARNING("failed to create caps");
1399 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1404 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1405 CONFIGURE_CATEGORY_MAIN_RECORD,
1406 "UseVideoEncoderQueue",
1409 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1412 if (sc->audio_disable == FALSE &&
1413 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1414 int use_aenc_queue = 0;
1416 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1417 if (!AudioencElement) {
1418 MMCAM_LOG_ERROR("Fail to get type element");
1419 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1420 goto pipeline_creation_error;
1423 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1425 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1426 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1428 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1429 audio_caps = gst_caps_new_simple("audio/x-raw",
1430 "channels", G_TYPE_INT, 1,
1432 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1433 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1434 gst_caps_unref(audio_caps);
1438 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1439 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1440 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1441 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1442 gst_caps_unref(audio_caps);
1444 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1447 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1448 CONFIGURE_CATEGORY_MAIN_RECORD,
1449 "UseAudioEncoderQueue",
1451 if (use_aenc_queue) {
1452 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1453 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1454 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1458 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1459 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1460 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1461 if (!ImageencElement) {
1462 MMCAM_LOG_ERROR("Fail to get type element");
1463 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1464 goto pipeline_creation_error;
1467 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1469 /* raw format - set dummy element */
1470 gst_element_ienc_name = "identity";
1473 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1474 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1478 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1479 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1481 MMCAM_LOG_ERROR("Fail to get type element");
1482 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1483 goto pipeline_creation_error;
1486 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1488 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1489 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1491 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1495 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1497 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1498 CONFIGURE_CATEGORY_MAIN_RECORD,
1499 "RecordsinkElement",
1500 &RecordsinkElement);
1501 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1503 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1505 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1508 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1511 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1512 /* property setting in ini */
1513 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1515 /* bitrate setting */
1516 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1517 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1520 if (sc->audio_disable == FALSE &&
1521 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1522 /* property setting in ini */
1523 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1525 /* bitrate setting */
1526 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1527 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1530 MMCAM_LOG_INFO("Element creation complete");
1532 /* Add element to bin */
1533 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1534 MMCAM_LOG_ERROR("element add error.");
1535 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1536 goto pipeline_creation_error;
1539 MMCAM_LOG_INFO("Element add complete");
1541 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1542 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1543 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1544 gst_object_unref(pad);
1546 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1547 err = MM_ERROR_CAMCORDER_GST_LINK;
1548 goto pipeline_creation_error;
1550 gst_object_unref(pad);
1553 if (sc->audio_disable == FALSE) {
1554 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1555 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1556 gst_object_unref(pad);
1558 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1559 err = MM_ERROR_CAMCORDER_GST_LINK;
1560 goto pipeline_creation_error;
1562 gst_object_unref(pad);
1565 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1566 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1567 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1568 gst_object_unref(pad);
1570 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1571 err = MM_ERROR_CAMCORDER_GST_LINK;
1572 goto pipeline_creation_error;
1574 gst_object_unref(pad);
1578 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1579 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1580 gst_object_unref(pad);
1582 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1583 err = MM_ERROR_CAMCORDER_GST_LINK;
1584 goto pipeline_creation_error;
1586 gst_object_unref(pad);
1590 MMCAM_LOG_INFO("Get pad complete");
1592 /* Link internal element */
1593 if (!_mmcamcorder_link_elements(element_list)) {
1594 MMCAM_LOG_ERROR("element link error.");
1595 err = MM_ERROR_CAMCORDER_GST_LINK;
1596 goto pipeline_creation_error;
1600 g_list_free(element_list);
1602 MMCAM_LOG_INFO("done");
1604 return MM_ERROR_NONE;
1606 pipeline_creation_error:
1607 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1609 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1610 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1611 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1612 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1613 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
1614 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1615 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1616 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1617 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1618 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1619 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1622 g_list_free(element_list);
1625 gst_caps_unref(video_caps);
1627 if (videoscale_caps)
1628 gst_caps_unref(videoscale_caps);
1634 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1636 int err = MM_ERROR_NONE;
1638 GstPad *srcpad = NULL;
1641 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1642 _MMCamcorderSubContext *sc = NULL;
1644 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1646 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1647 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1648 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1652 /** Create gstreamer element **/
1654 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1657 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1658 if (err != MM_ERROR_NONE)
1659 goto pipeline_creation_error;
1661 /* Set data probe function */
1662 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1663 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1664 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1666 MMCAM_LOG_ERROR("there is no queue plugin");
1667 goto pipeline_creation_error;
1671 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1672 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1674 gst_object_unref(srcpad);
1677 MMCAM_LOG_ERROR("failed to get srcpad");
1678 goto pipeline_creation_error;
1681 /* set dataprobe for video recording if it does not support dual stream. */
1682 if (sc->info_video->record_dual_stream == FALSE) {
1683 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1684 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1686 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1688 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1689 __mmcamcorder_video_dataprobe_record, hcamcorder);
1690 gst_object_unref(srcpad);
1694 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1696 /* set sync handler */
1697 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1699 gst_object_unref(bus);
1702 return MM_ERROR_NONE;
1704 pipeline_creation_error:
1705 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1710 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1712 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1713 _MMCamcorderSubContext *sc = NULL;
1715 /*MMCAM_LOG_INFO("start");*/
1717 mmf_return_if_fail(hcamcorder);
1718 mmf_return_if_fail(hcamcorder->sub_context);
1719 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1722 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1723 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1724 MMCAM_LOG_WARNING("set push_encoding_buffer RUN");
1729 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1731 int err = MM_ERROR_NONE;
1736 int rect_height = 0;
1738 int rotation = MM_DISPLAY_ROTATION_NONE;
1739 int flip = MM_FLIP_NONE;
1740 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1741 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1742 int origin_size = 0;
1745 int do_scaling = FALSE;
1746 int *dp_handle = NULL;
1747 MMCamWindowInfo *window_info = NULL;
1749 char *err_name = NULL;
1750 const char *videosink_name = NULL;
1752 GstElement *vsink = NULL;
1754 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1755 _MMCamcorderSubContext *sc = NULL;
1759 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1761 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1762 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1763 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1764 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1766 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1768 /* Get video display information */
1769 err = mm_camcorder_get_attributes(handle, &err_name,
1770 MMCAM_DISPLAY_RECT_X, &rect_x,
1771 MMCAM_DISPLAY_RECT_Y, &rect_y,
1772 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1773 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1774 MMCAM_DISPLAY_ROTATION, &rotation,
1775 MMCAM_DISPLAY_FLIP, &flip,
1776 MMCAM_DISPLAY_VISIBLE, &visible,
1777 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1778 MMCAM_DISPLAY_MODE, &display_mode,
1779 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1780 MMCAM_DISPLAY_SCALE, &zoom_attr,
1781 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1783 if (err != MM_ERROR_NONE) {
1785 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1786 SAFE_FREE(err_name);
1788 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1794 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1796 if (!videosink_name) {
1797 MMCAM_LOG_ERROR("failed to get videosink name");
1798 return MM_ERROR_CAMCORDER_INTERNAL;
1801 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
1803 /* Set display handle */
1804 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1807 MMCAM_LOG_INFO("xid = %lu )", xid);
1808 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1810 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1811 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1813 #ifdef _MMCAMCORDER_RM_SUPPORT
1814 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1815 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1816 #endif /* _MMCAMCORDER_RM_SUPPORT */
1817 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1818 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
1821 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1822 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1824 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
1825 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1827 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1829 window_info = (MMCamWindowInfo *)dp_handle;
1830 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
1831 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1833 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
1835 } else if (!strcmp(videosink_name, "directvideosink")) {
1837 window_info = (MMCamWindowInfo *)dp_handle;
1838 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1839 window_info->surface_id,
1840 window_info->rect.x,
1841 window_info->rect.y,
1842 window_info->rect.width,
1843 window_info->rect.height);
1844 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1845 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1846 window_info->rect.x,
1847 window_info->rect.y,
1848 window_info->rect.width,
1849 window_info->rect.height);
1851 MMCAM_LOG_WARNING("dp_handle is null");
1853 #ifdef _MMCAMCORDER_RM_SUPPORT
1854 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1855 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
1856 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1857 #endif /* _MMCAMCORDER_RM_SUPPORT */
1859 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
1862 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1863 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1866 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1867 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1869 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1872 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1874 switch (zoom_attr) {
1875 case MM_DISPLAY_SCALE_DEFAULT:
1878 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1881 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1885 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
1890 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1891 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1892 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1893 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1895 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1896 if (!strcmp(videosink_name, "tizenwlsink")) {
1897 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1898 rect_x, rect_y, rect_width, rect_height);
1901 "dst-roi-x", rect_x,
1902 "dst-roi-y", rect_y,
1903 "dst-roi-w", rect_width,
1904 "dst-roi-h", rect_height,
1910 return MM_ERROR_NONE;
1914 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1917 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1918 _MMCamcorderSubContext *sc = NULL;
1920 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1922 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1924 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1927 case _MMCamcorder_CMD_PREVIEW_START:
1928 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1930 case _MMCamcorder_CMD_CAPTURE:
1931 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1934 MMCAM_LOG_WARNING("unknown command : %d", cmd);
1935 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1938 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1939 category, "FrameStabilityCount", &sc->frame_stability_count);
1941 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
1942 cmd, sc->frame_stability_count);
1944 return MM_ERROR_NONE;
1947 /* Retreive device information and set them to attributes */
1948 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
1950 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1951 _MMCamcorderSubContext *sc = NULL;
1952 GstCameraControl *control = NULL;
1953 GstCameraControlExifInfo exif_info = {0,};
1955 mmf_return_val_if_fail(hcamcorder, FALSE);
1956 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1958 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
1960 if (sc && sc->element) {
1961 int err = MM_ERROR_NONE;
1962 char *err_name = NULL;
1963 double focal_len = 0.0;
1965 /* Video input device */
1966 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
1967 /* Exif related information */
1968 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1969 if (control != NULL) {
1970 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
1971 if (exif_info.focal_len_denominator != 0)
1972 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
1974 MMCAM_LOG_ERROR("Fail to get camera control interface!");
1979 /* Set values to attributes */
1980 err = mm_camcorder_set_attributes(handle, &err_name,
1981 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
1983 if (err != MM_ERROR_NONE) {
1984 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
1985 SAFE_FREE(err_name);
1989 MMCAM_LOG_WARNING("Sub context isn't exist.");
1996 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name)
1998 return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24);
2001 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2003 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2004 _MMCamcorderSubContext *sc = NULL;
2005 _MMCamcorderKPIMeasure *kpi = NULL;
2006 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2008 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
2009 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
2010 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
2012 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
2013 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
2015 if (sc->drop_vframe > 0) {
2016 if (sc->pass_first_vframe > 0) {
2017 sc->pass_first_vframe--;
2018 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2021 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2022 return GST_PAD_PROBE_DROP;
2024 } else if (sc->frame_stability_count > 0) {
2025 sc->frame_stability_count--;
2026 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2027 return GST_PAD_PROBE_DROP;
2030 if (hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE) {
2032 int frame_count = 0;
2033 struct timeval current_video_time;
2036 if (kpi->init_video_time.tv_sec == kpi->last_video_time.tv_sec &&
2037 kpi->init_video_time.tv_usec == kpi->last_video_time.tv_usec &&
2038 kpi->init_video_time.tv_usec == 0) {
2040 MMCAM_LOG_INFO("START to measure FPS");
2042 gettimeofday(&(kpi->init_video_time), NULL);
2045 frame_count = ++(kpi->video_framecount);
2047 gettimeofday(¤t_video_time, NULL);
2048 diff_sec = current_video_time.tv_sec - kpi->last_video_time.tv_sec;
2049 if (diff_sec != 0) {
2050 kpi->current_fps = (frame_count - kpi->last_framecount) / diff_sec;
2051 if ((current_video_time.tv_sec - kpi->init_video_time.tv_sec) != 0) {
2052 int framecount = kpi->video_framecount;
2053 int elased_sec = current_video_time.tv_sec - kpi->init_video_time.tv_sec;
2054 kpi->average_fps = framecount / elased_sec;
2057 kpi->last_framecount = frame_count;
2058 kpi->last_video_time.tv_sec = current_video_time.tv_sec;
2059 kpi->last_video_time.tv_usec = current_video_time.tv_usec;
2061 MMCAM_LOG_INFO("current fps(%d), average(%d)", kpi->current_fps, kpi->average_fps);
2066 /* The first H.264 frame should not be skipped for vstream cb. */
2067 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2068 sc->info_image->preview_format != MM_PIXEL_FORMAT_ENCODED_H264) {
2069 MMCAM_LOG_WARNING("Not ready for stream callback");
2070 return GST_PAD_PROBE_OK;
2073 if (_mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, buffer, TRUE))
2074 return GST_PAD_PROBE_OK;
2076 return GST_PAD_PROBE_DROP;
2080 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2082 if (_mmcamcorder_video_push_buffer(u_data, GST_PAD_PROBE_INFO_BUFFER(info)))
2083 return GST_PAD_PROBE_OK;
2085 return GST_PAD_PROBE_DROP;
2089 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2091 MMCamcorderMuxedStreamDataType stream;
2092 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2093 _MMCamcorderSubContext *sc = NULL;
2094 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2097 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2098 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2099 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2101 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2102 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2104 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2105 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2106 return GST_PAD_PROBE_OK;
2109 /* call application callback */
2110 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2112 if (hcamcorder->mstream_cb) {
2113 stream.data = (void *)mapinfo.data;
2114 stream.length = mapinfo.size;
2115 stream.offset = sc->muxed_stream_offset;
2116 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2119 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2121 /* calculate current offset */
2122 sc->muxed_stream_offset += mapinfo.size;
2124 gst_buffer_unmap(buffer, &mapinfo);
2126 return GST_PAD_PROBE_OK;
2130 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2132 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2133 mmf_camcorder_t *hcamcorder = NULL;
2134 _MMCamcorderSubContext *sc = NULL;
2135 GstObject *parent = NULL;
2137 switch (GST_EVENT_TYPE(event)) {
2138 case GST_EVENT_UNKNOWN:
2139 /* upstream events */
2141 case GST_EVENT_SEEK:
2142 case GST_EVENT_NAVIGATION:
2143 case GST_EVENT_LATENCY:
2144 /* downstream serialized events */
2145 case GST_EVENT_BUFFERSIZE:
2146 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2150 GstTagList *tag_list = NULL;
2151 _MMCamcorderReplayGain *replay_gain = NULL;
2153 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2155 hcamcorder = MMF_CAMCORDER(u_data);
2156 if (!hcamcorder || !hcamcorder->sub_context) {
2157 MMCAM_LOG_WARNING("NULL handle");
2161 replay_gain = &hcamcorder->sub_context->replay_gain;
2163 gst_event_parse_tag(event, &tag_list);
2165 MMCAM_LOG_WARNING("failed to get tag list");
2169 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2170 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2174 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2175 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2179 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2180 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2184 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2185 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2189 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2190 replay_gain->track_peak, replay_gain->track_gain,
2191 replay_gain->album_peak, replay_gain->album_gain);
2194 case GST_EVENT_SEGMENT:
2195 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2197 hcamcorder = MMF_CAMCORDER(u_data);
2199 MMCAM_LOG_WARNING("NULL handle");
2203 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2205 MMCAM_LOG_WARNING("NULL sub context");
2209 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2210 MMCAM_LOG_WARNING("no encoder sink");
2214 parent = gst_pad_get_parent(pad);
2216 MMCAM_LOG_WARNING("get parent failed");
2220 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2221 const GstSegment *segment;
2222 gst_event_parse_segment(event, &segment);
2223 if (segment->format == GST_FORMAT_BYTES) {
2224 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2225 sc->muxed_stream_offset, segment->start);
2227 sc->muxed_stream_offset = (unsigned long long)segment->start;
2231 gst_object_unref(parent);
2235 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2237 /* bidirectional events */
2238 case GST_EVENT_FLUSH_START:
2239 case GST_EVENT_FLUSH_STOP:
2240 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2243 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2247 return GST_PAD_PROBE_OK;
2251 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2253 int result = MM_CAMCORDER_MR475;
2256 result = MM_CAMCORDER_MR475; /*AMR475*/
2257 else if (bitrate < 5900)
2258 result = MM_CAMCORDER_MR515; /*AMR515*/
2259 else if (bitrate < 6700)
2260 result = MM_CAMCORDER_MR59; /*AMR59*/
2261 else if (bitrate < 7400)
2262 result = MM_CAMCORDER_MR67; /*AMR67*/
2263 else if (bitrate < 7950)
2264 result = MM_CAMCORDER_MR74; /*AMR74*/
2265 else if (bitrate < 10200)
2266 result = MM_CAMCORDER_MR795; /*AMR795*/
2267 else if (bitrate < 12200)
2268 result = MM_CAMCORDER_MR102; /*AMR102*/
2270 result = MM_CAMCORDER_MR122; /*AMR122*/
2276 int _mmcamcorder_get_eos_message(MMHandleType handle)
2279 int ret = MM_ERROR_NONE;
2281 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2282 _MMCamcorderSubContext *sc = NULL;
2284 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2285 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2286 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2288 MMCAM_LOG_INFO("START");
2290 _MMCAMCORDER_LOCK(handle);
2292 if (sc->bget_eos == FALSE) {
2293 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2294 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2295 MMCAM_LOG_INFO("EOS signal received");
2297 MMCAM_LOG_ERROR("EOS wait time out");
2299 if (hcamcorder->error_code == MM_ERROR_NONE)
2300 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2303 MMCAM_LOG_INFO("already got EOS");
2306 _MMCAMCORDER_UNLOCK(handle);
2308 if (hcamcorder->error_code == MM_ERROR_NONE) {
2309 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2310 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2311 if (sc->info_video->b_committing)
2312 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2314 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2315 if (sc->info_audio->b_committing)
2316 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2319 ret = hcamcorder->error_code;
2320 MMCAM_LOG_ERROR("error 0x%x", ret);
2323 MMCAM_LOG_INFO("END");
2329 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2332 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2334 mmf_return_if_fail(handle && remove_element);
2335 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2339 for (i = first_elem ; i <= last_elem ; i++) {
2340 remove_element[i].gst = NULL;
2341 remove_element[i].id = _MMCAMCORDER_NONE;
2348 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2350 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2352 /* Check compatibility between codec and file format */
2353 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2354 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2355 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2356 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2357 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2358 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2361 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2363 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2364 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2366 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2367 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2368 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2369 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2370 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2371 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2374 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2376 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2377 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2381 return MM_ERROR_NONE;
2385 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2387 int err = MM_ERROR_NONE;
2388 int audio_codec = MM_AUDIO_CODEC_INVALID;
2389 int file_format = MM_FILE_FORMAT_INVALID;
2391 char *err_name = NULL;
2393 err = mm_camcorder_get_attributes(handle, &err_name,
2394 MMCAM_AUDIO_ENCODER, &audio_codec,
2395 MMCAM_FILE_FORMAT, &file_format,
2397 if (err != MM_ERROR_NONE) {
2398 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2399 SAFE_FREE(err_name);
2403 /* Check compatibility between audio codec and file format */
2404 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2410 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2412 int err = MM_ERROR_NONE;
2413 int video_codec = MM_VIDEO_CODEC_INVALID;
2414 int file_format = MM_FILE_FORMAT_INVALID;
2416 char *err_name = NULL;
2418 err = mm_camcorder_get_attributes(handle, &err_name,
2419 MMCAM_VIDEO_ENCODER, &video_codec,
2420 MMCAM_FILE_FORMAT, &file_format,
2422 if (err != MM_ERROR_NONE) {
2423 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2424 SAFE_FREE(err_name);
2428 /* Check compatibility between video codec and file format */
2429 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2435 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2437 const char* videosink_name = NULL;
2439 mmf_camcorder_t *hcamcorder = NULL;
2440 _MMCamcorderSubContext *sc = NULL;
2442 hcamcorder = MMF_CAMCORDER(handle);
2443 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2445 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2446 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2447 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2449 if (sc->element[videosink_index].gst) {
2450 /* Get videosink name */
2451 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2452 if (videosink_name == NULL) {
2453 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2457 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2458 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2459 !strcmp(videosink_name, "directvideosink")) {
2460 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2461 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2463 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2468 MMCAM_LOG_ERROR("Videosink element is null");
2474 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2476 const char* videosink_name = NULL;
2478 mmf_camcorder_t *hcamcorder = NULL;
2479 _MMCamcorderSubContext *sc = NULL;
2481 hcamcorder = MMF_CAMCORDER(handle);
2482 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2484 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2485 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2486 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2488 if (sc->element[videosink_index].gst) {
2489 /* Get videosink name */
2490 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2491 if (videosink_name == NULL) {
2492 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2496 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2497 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2498 !strcmp(videosink_name, "directvideosink")) {
2499 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2500 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2502 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2507 MMCAM_LOG_ERROR("Videosink element is null");
2513 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2516 _MMCamcorderSubContext *sc = NULL;
2518 mmf_camcorder_t *hcamcorder = NULL;
2520 hcamcorder = MMF_CAMCORDER(handle);
2521 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2523 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2525 MMCAM_LOG_INFO("sub context is not initialized");
2529 mm_camcorder_get_attributes(handle, NULL,
2530 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2531 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2532 MMCAM_CAMERA_FPS, &fps,
2535 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2537 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2538 sc->info_video->preview_width, sc->info_video->preview_height,
2539 fps, videosrc_rotate);
2543 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2549 unsigned int caps_fourcc = 0;
2550 gboolean do_set_caps = FALSE;
2552 GstCaps *caps = NULL;
2554 mmf_camcorder_t *hcamcorder = NULL;
2555 _MMCamcorderSubContext *sc = NULL;
2557 hcamcorder = MMF_CAMCORDER(handle);
2558 mmf_return_val_if_fail(hcamcorder, FALSE);
2560 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2562 if (!sc || !(sc->element)) {
2563 MMCAM_LOG_INFO("sub context is not initialized");
2567 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2568 MMCAM_LOG_ERROR("Video src is NULL!");
2572 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2573 MMCAM_LOG_ERROR("Video filter is NULL!");
2577 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2578 int capture_width = 0;
2579 int capture_height = 0;
2580 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2582 mm_camcorder_get_attributes(handle, NULL,
2583 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2584 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2585 MMCAM_CAPTURE_WIDTH, &capture_width,
2586 MMCAM_CAPTURE_HEIGHT, &capture_height,
2587 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2588 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2590 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2591 motion_rate, capture_width, capture_height, fps_auto,
2592 sc->info_video->video_width, sc->info_video->video_height);
2594 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2595 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2597 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2598 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2599 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2602 sc->info_video->fps = fps;
2605 /* Interleaved format does not support rotation */
2606 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2607 /* store videosrc rotation */
2608 sc->videosrc_rotate = rotate;
2610 /* Define width, height and rotate in caps */
2612 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2613 This will be applied when rotate is 0, 180 if front camera. */
2614 set_rotate = rotate * 90;
2616 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2617 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2620 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2621 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2628 set_height = height;
2631 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2634 set_height = height;
2636 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2639 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2640 if (caps && !gst_caps_is_any(caps)) {
2641 GstStructure *structure = NULL;
2643 structure = gst_caps_get_structure(caps, 0);
2645 const gchar *format_string = NULL;
2647 int caps_height = 0;
2649 int caps_rotate = 0;
2651 format_string = gst_structure_get_string(structure, "format");
2653 caps_fourcc = _mmcamcorder_convert_fourcc_string_to_value(format_string);
2655 gst_structure_get_int(structure, "width", &caps_width);
2656 gst_structure_get_int(structure, "height", &caps_height);
2657 gst_structure_get_int(structure, "fps", &caps_fps);
2658 gst_structure_get_int(structure, "rotate", &caps_rotate);
2660 #ifdef _MMCAMCORDER_PRODUCT_TV
2661 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2662 if (set_width == caps_width && set_height == caps_height &&
2663 set_rotate == caps_rotate && fps == caps_fps) {
2664 MMCAM_LOG_INFO("No need to replace caps.");
2666 MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2667 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2668 caps_width, caps_height, caps_fps, caps_rotate,
2669 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2670 set_width, set_height, fps, set_rotate);
2674 if (set_width == caps_width && set_height == caps_height &&
2675 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2676 MMCAM_LOG_INFO("No need to replace caps.");
2678 MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2679 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2680 caps_width, caps_height, caps_fps, caps_rotate,
2681 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2682 set_width, set_height, fps, set_rotate);
2686 #else /*_MMCAMCORDER_PRODUCT_TV */
2687 if (set_width == caps_width && set_height == caps_height &&
2688 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2689 MMCAM_LOG_INFO("No need to replace caps.");
2691 MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2692 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2693 caps_width, caps_height, caps_fps, caps_rotate,
2694 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2695 set_width, set_height, fps, set_rotate);
2698 #endif /*_MMCAMCORDER_PRODUCT_TV */
2700 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2704 MMCAM_LOG_INFO("No caps. set new one...");
2709 gst_caps_unref(caps);
2714 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
2715 #ifdef _MMCAMCORDER_PRODUCT_TV
2718 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
2719 mm_camcorder_get_attributes(handle, NULL,
2720 MMCAM_DISPLAY_SURFACE, &display_surface_type,
2723 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
2724 __mmcamcorder_find_max_resolution(handle, &maxwidth, &maxheight) == false) {
2725 MMCAM_LOG_ERROR("can not find max resolution limitation");
2727 } else if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
2728 maxwidth = set_width;
2729 maxheight = set_height;
2731 #endif /* _MMCAMCORDER_PRODUCT_TV */
2732 caps = gst_caps_new_simple("video/x-h264",
2733 "width", G_TYPE_INT, set_width,
2734 "height", G_TYPE_INT, set_height,
2735 "framerate", GST_TYPE_FRACTION, fps, 1,
2736 "stream-format", G_TYPE_STRING, "byte-stream",
2737 #ifdef _MMCAMCORDER_PRODUCT_TV
2738 "maxwidth", G_TYPE_INT, maxwidth,
2739 "maxheight", G_TYPE_INT, maxheight,
2740 "alignment", G_TYPE_STRING, "au",
2741 #endif /* _MMCAMCORDER_PRODUCT_TV */
2743 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG){
2744 #ifdef _MMCAMCORDER_PRODUCT_TV
2745 caps = gst_caps_new_simple("video/x-jpeg",
2747 caps = gst_caps_new_simple("image/jpeg",
2749 "width", G_TYPE_INT, set_width,
2750 "height", G_TYPE_INT, set_height,
2751 "framerate", GST_TYPE_FRACTION, fps, 1,
2754 char fourcc_string[sizeof(fourcc)+1];
2755 memcpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
2756 fourcc_string[sizeof(fourcc)] = '\0';
2757 caps = gst_caps_new_simple("video/x-raw",
2758 "format", G_TYPE_STRING, fourcc_string,
2759 "width", G_TYPE_INT, set_width,
2760 "height", G_TYPE_INT, set_height,
2761 "framerate", GST_TYPE_FRACTION, fps, 1,
2762 "rotate", G_TYPE_INT, set_rotate,
2767 gchar *caps_str = gst_caps_to_string(caps);
2770 MMCAM_LOG_INFO("vidoesrc new caps set [%s]", caps_str);
2774 MMCAM_LOG_WARNING("caps string failed");
2777 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2778 gst_caps_unref(caps);
2781 MMCAM_LOG_ERROR("There are no caps");
2785 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2786 /* assume that it's camera capture mode */
2787 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2794 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2796 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2797 _MMCamcorderSubContext *sc = NULL;
2799 mmf_return_val_if_fail(hcamcorder, FALSE);
2801 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2805 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
2807 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2811 /* Interleaved format does not support FLIP */
2812 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2813 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2814 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2816 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
2818 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2819 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2821 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
2825 MMCAM_LOG_WARNING("element is NULL");
2833 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2835 GstCameraControl *control = NULL;
2836 _MMCamcorderSubContext *sc = NULL;
2837 GstElement *v_src = NULL;
2841 mmf_return_val_if_fail(handle, FALSE);
2843 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2847 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2850 MMCAM_LOG_WARNING("videosrc element is NULL");
2854 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2856 /* set anti-shake with camera control */
2857 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2858 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
2862 control = GST_CAMERA_CONTROL(v_src);
2863 if (gst_camera_control_set_ahs(control, set_value)) {
2864 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
2867 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
2874 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2876 _MMCamcorderSubContext *sc = NULL;
2877 GstElement *v_src = NULL;
2879 mmf_return_val_if_fail(handle, FALSE);
2881 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2885 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2887 MMCAM_LOG_WARNING("videosrc element is NULL");
2891 /* check property of videosrc element - support VDIS */
2892 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2893 int video_width = 0;
2894 int video_height = 0;
2896 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2897 MMCAM_LOG_INFO("ENABLE video stabilization");
2899 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2900 mm_camcorder_get_attributes(handle, NULL,
2901 MMCAM_VIDEO_WIDTH, &video_width,
2902 MMCAM_VIDEO_HEIGHT, &video_height,
2905 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2906 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
2907 video_width, video_height);
2909 g_object_set(G_OBJECT(v_src),
2910 "enable-vdis-mode", TRUE,
2913 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
2914 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2915 video_width, video_height);
2920 g_object_set(G_OBJECT(v_src),
2921 "enable-vdis-mode", FALSE,
2924 MMCAM_LOG_INFO("DISABLE video stabilization");
2926 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2927 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
2930 MMCAM_LOG_WARNING("no property for video stabilization");
2937 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2941 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2942 _MMCamcorderSubContext *sc = NULL;
2944 mmf_return_val_if_fail(hcamcorder, FALSE);
2946 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2950 mm_camcorder_get_attributes(handle, NULL,
2951 MMCAM_CAMERA_FPS, &fps,
2954 MMCAM_LOG_INFO("set %dx%d", width, height);
2956 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2960 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2962 _MMCamcorderSubContext *sc = NULL;
2964 if ((void *)handle == NULL) {
2965 MMCAM_LOG_WARNING("handle is NULL");
2969 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2971 MMCAM_LOG_WARNING("subcontext is NULL");
2975 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2976 MMCAM_LOG_WARNING("videosrc plugin is NULL");
2980 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
2982 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
2988 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
2990 _MMCamcorderSubContext *sc = NULL;
2992 if ((void *)handle == NULL) {
2993 MMCAM_LOG_WARNING("handle is NULL");
2997 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2999 MMCAM_LOG_WARNING("subcontext is NULL");
3003 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3004 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3008 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
3010 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3016 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3018 GstStructure *props = NULL;
3019 char stream_props[64] = {'\0',};
3021 if (element == NULL || stream_type == NULL || stream_index < 0) {
3022 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3026 snprintf(stream_props, sizeof(stream_props) - 1,
3027 "props,media.role=%s, media.parent_id=%d",
3028 stream_type, stream_index);
3030 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3032 props = gst_structure_from_string(stream_props, NULL);
3034 MMCAM_LOG_ERROR("failed to create GstStructure");
3038 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3040 gst_structure_free(props);
3047 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3049 int ret = MM_ERROR_NONE;
3050 _MMCamcorderSubContext *sc = NULL;
3051 mmf_camcorder_t *hcamcorder = NULL;
3052 const char *videodecoder_name = NULL;
3053 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3054 #ifdef _MMCAMCORDER_RM_SUPPORT
3055 char decoder_name[20] = {'\0',};
3056 int decoder_index = 0;
3057 #endif /* _MMCAMCORDER_RM_SUPPORT */
3059 if ((void *)handle == NULL) {
3060 MMCAM_LOG_WARNING("handle is NULL");
3064 hcamcorder = MMF_CAMCORDER(handle);
3066 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3068 MMCAM_LOG_WARNING("subcontext is NULL");
3072 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3073 hcamcorder->recreate_decoder == FALSE) {
3074 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3075 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3079 mm_camcorder_get_attributes(handle, NULL,
3080 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3083 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3084 MMCAM_LOG_INFO("no need to control decoder element");
3088 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3089 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3090 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3094 MMCAM_LOG_INFO("start");
3096 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
3097 if (videodecoder_name == NULL) {
3098 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElementH264);
3102 /* set state as NULL */
3103 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3104 if (ret != MM_ERROR_NONE) {
3105 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3109 /* remove decoder - pads will be unlinked automatically in remove function */
3110 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3111 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3112 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3116 /* check decoder element */
3117 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3118 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3119 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3120 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3123 #ifdef _MMCAMCORDER_RM_SUPPORT
3124 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3125 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3128 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
3129 MMCAM_LOG_INFO("encoded preview decoder_name %s", decoder_name);
3132 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3133 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_uhd_mjpegdec");
3135 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_mjpegdec");
3136 MMCAM_LOG_INFO("encoded preview decoder_name %s", decoder_name);
3139 /* create decoder */
3140 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(decoder_name, "videosrc_decode");
3141 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3142 MMCAM_LOG_ERROR("Decoder[%s] creation fail", decoder_name);
3145 #else /* _MMCAMCORDER_RM_SUPPORT */
3146 /* create new decoder */
3147 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name, "videosrc_decode");
3148 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3149 MMCAM_LOG_ERROR("Decoder [%s] creation fail", videodecoder_name);
3152 #endif /* _MMCAMCORDER_RM_SUPPORT */
3153 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
3155 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3156 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3157 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3159 /* add to pipeline */
3160 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3161 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3162 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3163 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3168 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3169 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3170 MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
3172 MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
3176 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3177 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3178 MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
3180 MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
3184 /* set state READY */
3185 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3186 if (ret != MM_ERROR_NONE) {
3187 MMCAM_LOG_ERROR("failed to set READY to decoder");
3191 MMCAM_LOG_INFO("done");
3196 #ifdef _MMCAMCORDER_PRODUCT_TV
3197 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3199 _MMCamcorderSubContext *sc = NULL;
3200 mmf_camcorder_t *hcamcorder = NULL;
3202 const gchar *mime = NULL;
3204 GstCaps *decsink_caps = NULL;
3205 GstStructure *decsink_struct = NULL;
3207 mmf_return_val_if_fail(handle, false);
3208 mmf_return_val_if_fail(max_width, false);
3209 mmf_return_val_if_fail(max_height, false);
3211 hcamcorder = MMF_CAMCORDER(handle);
3212 mmf_return_val_if_fail(hcamcorder, false);
3214 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3216 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3218 MMCAM_LOG_ERROR("There are no decoder caps");
3222 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3223 if (!decsink_caps) {
3224 gst_object_unref(sinkpad);
3225 MMCAM_LOG_ERROR("There is no decoder sink caps");
3229 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3230 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3231 if (!decsink_struct) {
3232 MMCAM_LOG_ERROR("There are no structure from caps");
3233 gst_object_unref(decsink_caps);
3234 gst_object_unref(sinkpad);
3237 mime = gst_structure_get_name(decsink_struct);
3238 if (!strcmp(mime, "video/x-h264")) {
3239 MMCAM_LOG_INFO("h264 caps structure found");
3240 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3241 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3242 if (gst_structure_has_field(decsink_struct, "maxheight"))
3243 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3245 } else if (!strcmp(mime, "video/x-jpeg")) {
3246 MMCAM_LOG_INFO("mjpeg caps structure found");
3247 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3248 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3249 if (gst_structure_has_field(decsink_struct, "maxheight"))
3250 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3254 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3255 gst_object_unref(decsink_caps);
3256 gst_object_unref(sinkpad);
3258 if (*max_width <= 0 || *max_height <= 0)
3263 #endif /* _MMCAMCORDER_PRODUCT_TV */