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>
31 #include <tbm_bufmgr.h>
32 #include <tbm_surface.h>
33 #include <tbm_surface_internal.h>
35 #include "mm_camcorder_internal.h"
36 #include "mm_camcorder_gstcommon.h"
38 /*-----------------------------------------------------------------------
39 | GLOBAL VARIABLE DEFINITIONS for internal |
40 -----------------------------------------------------------------------*/
41 /* Table for compatibility between audio codec and file format */
42 static gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
43 /* 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*/
44 /*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},
45 /*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},
46 /*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},
47 /*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},
48 /*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},
49 /*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},
50 /*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},
51 /*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},
52 /*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},
53 /*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},
54 /*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},
55 /*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},
56 /*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},
57 /*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},
58 /*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},
59 /*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},
60 /*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},
61 /*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},
62 /*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},
63 /*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},
64 /*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},
65 /*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},
66 /*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},
67 /*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},
68 /*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},
69 /*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},
70 /*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},
71 /*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},
72 /*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},
73 /*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},
74 /*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},
75 /*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},
76 /*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},
77 /*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},
78 /*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},
79 /*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},
80 /*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},
81 /*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},
82 /*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},
83 /*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},
84 /*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},
85 /*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},
86 /*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},
87 /*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},
90 /* Table for compatibility between video codec and file format */
91 static gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
92 /* 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*/
93 /*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},
94 /*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},
95 /*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},
96 /*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},
97 /*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},
98 /*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},
99 /*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},
100 /*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},
101 /*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},
102 /*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},
103 /*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},
104 /*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},
105 /*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},
106 /*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},
107 /*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},
108 /*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},
109 /*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},
110 /*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},
111 /*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},
112 /*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},
113 /*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},
114 /*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},
115 /*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},
116 /*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},
117 /*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},
118 /*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},
119 /*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},
120 /*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},
124 /*-----------------------------------------------------------------------
125 | LOCAL VARIABLE DEFINITIONS for internal |
126 -----------------------------------------------------------------------*/
127 #define USE_AUDIO_CLOCK_TUNE
128 #define _MMCAMCORDER_WAIT_EOS_TIME 60.0 /* sec */
129 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM 6
130 #define _MMCAMCORDER_NANOSEC_PER_1SEC 1000000000
131 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC 1000
134 /*-----------------------------------------------------------------------
135 | LOCAL FUNCTION PROTOTYPES: |
136 -----------------------------------------------------------------------*/
137 /* STATIC INTERNAL FUNCTION */
139 * These are video data probing functions.
140 * If there are pads which set probe callback by gst_pad_add_probe(),
141 * the functions will be called when data stream pass through the pad.
143 * @param[in] pad probing pad which calls this function.
144 * @param[in] buffer buffer which contains stream data.
145 * @param[in] u_data user data.
146 * @return Refer #GstPadProbeReturn in gstpad.h
148 * @see __mmcamcorder_create_preview_pipeline()
150 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
151 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
153 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
154 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name);
155 #ifdef _MMCAMCORDER_PRODUCT_TV
156 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height);
157 #endif /* _MMCAMCORDER_PRODUCT_TV */
159 static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info);
160 static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
162 /*=======================================================================================
163 | FUNCTION DEFINITIONS |
164 =======================================================================================*/
165 static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
167 mmf_return_val_if_fail(buffer, FALSE);
168 mmf_return_val_if_fail(map_info, FALSE);
169 mmf_return_val_if_fail(stream, FALSE);
171 switch (stream->format) {
172 case MM_PIXEL_FORMAT_NV12: /* fall through */
173 case MM_PIXEL_FORMAT_NV21:
174 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
175 stream->data.yuv420sp.y = map_info->data;
176 stream->data.yuv420sp.length_y = stream->width * stream->height;
177 stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
178 stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
179 stream->stride[0] = stream->width;
180 stream->elevation[0] = stream->height;
181 stream->stride[1] = stream->width;
182 stream->elevation[1] = stream->height >> 1;
183 stream->num_planes = 2;
186 case MM_PIXEL_FORMAT_I420:
187 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
188 stream->data.yuv420p.y = map_info->data;
189 stream->data.yuv420p.length_y = stream->width * stream->height;
190 stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
191 stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
192 stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
193 stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
194 stream->stride[0] = stream->width;
195 stream->elevation[0] = stream->height;
196 stream->stride[1] = stream->stride[2] = stream->width >> 1;
197 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
198 stream->num_planes = 3;
201 case MM_PIXEL_FORMAT_422P:
202 stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
203 stream->data.yuv422p.y = map_info->data;
204 stream->data.yuv422p.length_y = stream->width * stream->height;
205 stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
206 stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
207 stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
208 stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
209 stream->stride[0] = stream->width;
210 stream->elevation[0] = stream->height;
211 stream->stride[1] = stream->stride[2] = stream->width;
212 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
213 stream->num_planes = 3;
216 case MM_PIXEL_FORMAT_YUYV: /* fall through */
217 case MM_PIXEL_FORMAT_UYVY: /* fall through */
218 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
219 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
220 stream->data.yuv422.yuv = map_info->data;
221 stream->data.yuv422.length_yuv = stream->length_total;
222 stream->stride[0] = stream->width << 1;
223 stream->elevation[0] = stream->height;
224 stream->num_planes = 1;
227 case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
228 case MM_PIXEL_FORMAT_ENCODED_MJPEG: /* fall through */
229 case MM_PIXEL_FORMAT_ENCODED_VP8: /* fall through */
230 case MM_PIXEL_FORMAT_ENCODED_VP9: /* fall through */
231 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
232 stream->data.encoded.data = map_info->data;
233 stream->data.encoded.length_data = stream->length_total;
234 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
235 stream->num_planes = 1;
238 case MM_PIXEL_FORMAT_INVZ:
239 stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
240 stream->data.depth.data = map_info->data;
241 stream->data.depth.length_data = stream->length_total;
242 stream->stride[0] = stream->width << 1;
243 stream->elevation[0] = stream->height;
244 stream->num_planes = 1;
247 case MM_PIXEL_FORMAT_RGBA: /* fall through */
248 case MM_PIXEL_FORMAT_ARGB:
249 stream->data_type = MM_CAM_STREAM_DATA_RGB;
250 stream->data.rgb.data = map_info->data;
251 stream->data.rgb.length_data = stream->length_total;
252 stream->stride[0] = stream->width << 2;
253 stream->elevation[0] = stream->height;
254 stream->num_planes = 1;
258 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
266 static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info)
268 mmf_return_val_if_fail(ts_info, FALSE);
269 mmf_return_val_if_fail(stream, FALSE);
271 switch (stream->format) {
272 case MM_PIXEL_FORMAT_NV12: /* fall through */
273 case MM_PIXEL_FORMAT_NV21:
274 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
275 stream->num_planes = 2;
276 stream->data.yuv420sp.y = ts_info->planes[0].ptr;
277 stream->data.yuv420sp.length_y = ts_info->planes[0].size;
278 stream->data.yuv420sp.uv = ts_info->planes[1].ptr;
279 stream->data.yuv420sp.length_uv = ts_info->planes[1].size;
282 case MM_PIXEL_FORMAT_I420:
283 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
284 stream->num_planes = 3;
285 stream->data.yuv420p.y = ts_info->planes[0].ptr;
286 stream->data.yuv420p.length_y = ts_info->planes[0].size;
287 stream->data.yuv420p.u = ts_info->planes[1].ptr;
288 stream->data.yuv420p.length_u = ts_info->planes[1].size;
289 stream->data.yuv420p.v = ts_info->planes[2].ptr;
290 stream->data.yuv420p.length_v = ts_info->planes[2].size;
294 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
302 gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sample, gboolean is_preview, int stream_id)
306 gboolean ret_cb = TRUE;
307 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
308 _MMCamcorderSubContext *sc = NULL;
309 MMCamcorderVideoStreamDataType stream;
311 tbm_surface_h t_surface = NULL;
312 tbm_surface_info_s ts_info;
314 GstBuffer *buffer = NULL;
315 GstMemory *memory = NULL;
317 GstCaps *caps = NULL;
318 GstStructure *structure = NULL;
320 mmf_return_val_if_fail(hcamcorder, FALSE);
322 buffer = gst_sample_get_buffer(sample);
323 mmf_return_val_if_fail(buffer, FALSE);
324 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
326 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
327 mmf_return_val_if_fail(sc, FALSE);
329 /* clear data structure */
330 memset(&map_info, 0x0, sizeof(GstMapInfo));
331 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
333 caps = gst_sample_get_caps(sample);
334 mmf_return_val_if_fail(caps, FALSE);
336 structure = gst_caps_get_structure(caps, 0);
337 mmf_return_val_if_fail(structure, FALSE);
339 /* set format and resolution */
340 gst_structure_get_int(structure, "width", &stream.width);
341 gst_structure_get_int(structure, "height", &stream.height);
342 stream.format = _mmcamcorder_get_pixel_format(caps);
344 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format)) {
345 memory = gst_buffer_get_all_memory(buffer);
346 stream.internal_buffer = buffer;
348 memory = gst_buffer_peek_memory(buffer, 0);
351 MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
355 structure = gst_mini_object_get_qdata(GST_MINI_OBJECT_CAST(buffer), hcamcorder->buffer_quark);
357 gst_structure_get_int(structure, "focus-state", &stream.focus_state);
358 gst_structure_get_int(structure, "facing-direction", &stream.facing_direction);
359 gst_structure_get_int(structure, "flip", &stream.flip);
360 gst_structure_get_int(structure, "rotation", &stream.rotation);
362 MMCAM_LOG_VERBOSE("structure[%p], [fs:%d,fd:%d,f:%d,r:%d]", structure,
363 stream.focus_state, stream.facing_direction, stream.flip, stream.rotation);
366 /* set zero-copy related information */
367 if (hcamcorder->use_zero_copy_format) {
368 t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
370 if (tbm_surface_get_info(t_surface, &ts_info) != TBM_SURFACE_ERROR_NONE) {
371 MMCAM_LOG_ERROR("failed to get tbm surface[%p] info", t_surface);
372 goto _INVOKE_VIDEO_STREAM_CB_DONE;
375 /* set bo, stride and elevation */
376 num_bos = gst_tizen_memory_get_num_bos(memory);
377 for (i = 0 ; i < num_bos ; i++)
378 stream.bo[i] = gst_tizen_memory_get_bos(memory, i);
380 for (i = 0 ; i < ts_info.num_planes ; i++) {
381 stream.stride[i] = ts_info.planes[i].stride;
382 stream.elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
383 MMCAM_LOG_VERBOSE(" plane[%d] %dx%d", i, stream.stride[i], stream.elevation[i]);
386 stream.length_total = ts_info.size;
387 stream.internal_buffer = buffer;
389 if (!__mmcamcorder_set_stream_data_tbm(&stream, &ts_info))
390 goto _INVOKE_VIDEO_STREAM_CB_DONE;
392 stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
394 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE) ||
395 !__mmcamcorder_set_stream_data_normal(&stream, buffer, &map_info))
396 goto _INVOKE_VIDEO_STREAM_CB_DONE;
399 MMCAM_LOG_DEBUG("VideoStreamData : format[%d], resolution[%dx%d], stream_id[%d]",
400 stream.format, stream.width, stream.height, stream_id);
402 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
403 stream.extra_stream_id = stream_id;
405 /* invoke application callback */
407 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
408 if (hcamcorder->vstream_cb)
409 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
410 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
412 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
413 if (hcamcorder->vedecision_cb)
414 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
415 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
418 _INVOKE_VIDEO_STREAM_CB_DONE:
419 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
420 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
421 tbm_bo_unmap(stream.bo[i]);
425 gst_memory_unmap(memory, &map_info);
427 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format))
428 gst_memory_unref(memory);
434 int _mmcamcorder_create_preview_elements(MMHandleType handle)
436 int err = MM_ERROR_NONE;
438 int camera_rotate = 0;
442 int capture_width = 0;
443 int capture_height = 0;
444 int capture_jpg_quality = 100;
445 int video_stabilization = 0;
447 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
448 const char *videosrc_name = NULL;
449 const char *videosink_name = NULL;
450 const char *videoconvert_name = NULL;
451 const char *videodecoder_name = NULL;
452 const char *decoder_conf_name = NULL;
453 char videodecoder_name_final[32] = {'\0',};
454 char *err_name = NULL;
455 char *socket_path = NULL;
457 #ifdef _MMCAMCORDER_RM_SUPPORT
458 int decoder_index = 0;
459 #endif /* _MMCAMCORDER_RM_SUPPORT */
460 GstElement *sink_element = NULL;
461 GstCameraControl *control = NULL;
462 int sink_element_size = 0;
465 int extra_preview_enable = 0;
467 GList *element_list = NULL;
469 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
470 _MMCamcorderSubContext *sc = NULL;
471 type_element *VideosrcElement = NULL;
472 type_int_array *input_index = NULL;
474 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
476 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
477 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
478 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
482 /* Check existence */
483 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
484 if (sc->element[i].gst) {
485 if (((GObject *)sc->element[i].gst)->ref_count > 0)
486 gst_object_unref(sc->element[i].gst);
488 MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
492 /* Get video device index info */
493 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
494 CONFIGURE_CATEGORY_CTRL_CAMERA,
497 if (input_index == NULL) {
498 MMCAM_LOG_ERROR("Failed to get input_index");
499 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
502 err = mm_camcorder_get_attributes(handle, &err_name,
503 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
504 MMCAM_CAMERA_FPS, &fps,
505 MMCAM_CAMERA_ROTATION, &camera_rotate,
506 MMCAM_CAMERA_FLIP, &camera_flip,
507 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
508 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
509 MMCAM_CAPTURE_WIDTH, &capture_width,
510 MMCAM_CAPTURE_HEIGHT, &capture_height,
511 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
512 MMCAM_IMAGE_ENCODER, &codectype,
513 MMCAM_IMAGE_ENCODER_QUALITY, &capture_jpg_quality,
514 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
515 MMCAM_DISPLAY_SURFACE, &display_surface_type,
516 MMCAM_EXTRA_PREVIEW_ENABLE, &extra_preview_enable,
518 if (err != MM_ERROR_NONE) {
519 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
524 if (hcamcorder->support_user_buffer) {
525 err = mm_camcorder_get_attributes(handle, NULL,
526 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
528 if (err != MM_ERROR_NONE || fd_number < 1) {
529 MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
534 for (i = 0 ; i < fd_number ; i++)
535 MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
539 /* Get fourcc from picture format */
540 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
542 /* Get videosrc element and its name from configure */
543 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
544 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
547 _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
550 * Create child element
552 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
554 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
557 * This is for "tizencamerasrc" element only.
558 * The camera HAL library will be loaded when "hal-name" property is set.
559 * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
561 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
563 /* camera properties */
564 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
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);
569 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "extra-preview", extra_preview_enable);
570 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
572 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
574 /* set camera flip */
575 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
577 /* set video stabilization mode */
578 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
580 /* set anti handshake mode */
581 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
583 if (sc->is_modified_rate)
584 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
586 /* Set basic information of videosrc element */
587 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
589 /* Set video device index */
590 if (hcamcorder->is_network) {
591 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
593 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
594 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
596 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
600 /* set user buffer fd to videosrc element */
601 if (hcamcorder->support_user_buffer) {
602 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
603 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
604 MMCAM_LOG_ERROR("set user buffer fd failed");
605 goto pipeline_creation_error;
609 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
610 /* get recreate_decoder flag */
611 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
612 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
614 &hcamcorder->recreate_decoder);
617 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
618 _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
619 switch (sc->info_image->preview_format) {
620 case MM_PIXEL_FORMAT_ENCODED_H264:
621 decoder_conf_name = "VideodecoderElementH264";
623 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
624 decoder_conf_name = "VideodecoderElementMJPEG";
626 case MM_PIXEL_FORMAT_ENCODED_VP8:
627 decoder_conf_name = "VideodecoderElementVP8";
629 case MM_PIXEL_FORMAT_ENCODED_VP9:
630 decoder_conf_name = "VideodecoderElementVP9";
633 MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
634 goto pipeline_creation_error;
637 /* get video decoder element and name */
638 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
639 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
641 &sc->VideodecoderElement);
643 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
646 if (!videodecoder_name) {
647 MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
648 goto pipeline_creation_error;
651 #ifdef _MMCAMCORDER_RM_SUPPORT
652 MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
653 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
654 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
656 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
657 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
658 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
659 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
661 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
663 #endif /* _MMCAMCORDER_RM_SUPPORT */
664 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
665 #ifdef _MMCAMCORDER_RM_SUPPORT
667 #endif /* _MMCAMCORDER_RM_SUPPORT */
669 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
671 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
674 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
676 /* Get videosink name */
677 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
679 if (!videosink_name) {
680 MMCAM_LOG_ERROR("failed to get videosink name");
681 goto pipeline_creation_error;
684 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
686 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
688 if (display_surface_type == MM_DISPLAY_SURFACE_REMOTE) {
689 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "ipc_sink", element_list, err);
691 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
693 err = mm_camcorder_get_attributes(handle, &err_name,
694 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
696 if (err != MM_ERROR_NONE) {
697 MMCAM_LOG_WARNING("Get socket path failed 0x%x", err);
699 goto pipeline_creation_error;
702 g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
704 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
705 /* get video convert name */
706 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
708 if (videoconvert_name) {
709 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
710 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
712 MMCAM_LOG_ERROR("failed to get videoconvert element name");
715 /* check sink element in attribute */
716 mm_camcorder_get_attributes(handle, NULL,
717 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
722 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
724 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
726 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
728 /* reset attribute */
730 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
731 mm_attrs_set_data(attrs, attr_index, NULL, 0);
732 mm_attrs_commit(attrs, attr_index);
734 MMCAM_LOG_WARNING("attribute is NULL");
735 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
736 goto pipeline_creation_error;
739 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
741 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
744 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
745 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
746 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
747 goto pipeline_creation_error;
751 /* Set caps by rotation */
752 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
754 /* add elements to main pipeline */
755 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
756 MMCAM_LOG_ERROR("element_list add error.");
757 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
758 goto pipeline_creation_error;
762 if (!_mmcamcorder_link_elements(element_list)) {
763 MMCAM_LOG_ERROR("element link error.");
764 err = MM_ERROR_CAMCORDER_GST_LINK;
765 goto pipeline_creation_error;
769 g_list_free(element_list);
773 return MM_ERROR_NONE;
775 pipeline_creation_error:
776 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
777 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
778 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_QUE);
779 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS);
780 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_FILT);
781 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
782 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
783 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
784 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
787 g_list_free(element_list);
795 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
797 int err = MM_ERROR_NONE;
802 int a_enc = MM_AUDIO_CODEC_AMR;
803 int a_dev = MM_AUDIO_DEVICE_MIC;
805 char *err_name = NULL;
806 const char *audiosrc_name = NULL;
807 char *cat_name = NULL;
808 char *stream_type = NULL;
809 int stream_type_len = 0;
810 int stream_index = 0;
811 int buffer_interval = 0;
813 int replay_gain_enable = FALSE;
814 double replay_gain_ref_level = 0.0;
816 GstCaps *caps = NULL;
818 GList *element_list = NULL;
820 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
821 _MMCamcorderSubContext *sc = NULL;
822 _MMCamcorderGstElement *last_element = NULL;
823 type_element *AudiosrcElement = NULL;
825 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
827 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
828 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
829 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
833 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
834 if (err != MM_ERROR_NONE)
837 err = mm_camcorder_get_attributes(handle, &err_name,
838 MMCAM_AUDIO_DEVICE, &a_dev,
839 MMCAM_AUDIO_ENCODER, &a_enc,
840 MMCAM_AUDIO_ENCODER_BITRATE, &val,
841 MMCAM_AUDIO_SAMPLERATE, &rate,
842 MMCAM_AUDIO_FORMAT, &format,
843 MMCAM_AUDIO_CHANNEL, &channel,
844 MMCAM_AUDIO_VOLUME, &volume,
845 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
846 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
847 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
848 MMCAM_SOUND_STREAM_INDEX, &stream_index,
850 if (err != MM_ERROR_NONE) {
851 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
856 /* Check existence */
857 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
858 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
859 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
861 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
864 /* Create bin element */
865 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
867 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
868 cat_name = strdup("AudiomodemsrcElement");
870 /* MM_AUDIO_DEVICE_MIC or others */
871 cat_name = strdup("AudiosrcElement");
874 if (cat_name == NULL) {
875 MMCAM_LOG_ERROR("strdup failed.");
876 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
877 goto pipeline_creation_error;
880 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
881 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
884 _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
889 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
891 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
893 /* set sound stream info */
894 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
896 /* set audiosrc properties in ini configuration */
897 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
900 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
901 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
902 "AudioBufferInterval",
905 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
906 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
907 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
910 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
912 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
913 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
914 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
915 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
917 /* Set basic information */
918 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
920 const gchar* format_name = NULL;
922 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
925 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
926 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
928 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
929 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
932 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
934 format_name = "S16LE";
935 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
940 caps = gst_caps_new_simple("audio/x-raw",
941 "rate", G_TYPE_INT, rate,
942 "channels", G_TYPE_INT, channel,
943 "format", G_TYPE_STRING, format_name,
945 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
946 rate, channel, depth, volume);
948 /* what are the audio encoder which should get audio/x-raw-float? */
949 caps = gst_caps_new_simple("audio/x-raw",
950 "rate", G_TYPE_INT, rate,
951 "channels", G_TYPE_INT, channel,
952 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
954 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
955 rate, channel, BYTE_ORDER);
959 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
960 replay_gain_enable, replay_gain_ref_level);
962 if (replay_gain_enable) {
963 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
964 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
965 /* If num-tracks is not set, album gain and peak event is not come. */
966 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
970 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
971 gst_caps_unref(caps);
974 MMCAM_LOG_ERROR("create caps error");
975 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
976 goto pipeline_creation_error;
979 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
980 MMCAM_LOG_ERROR("element add error.");
981 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
982 goto pipeline_creation_error;
985 if (!_mmcamcorder_link_elements(element_list)) {
986 MMCAM_LOG_ERROR("element link error.");
987 err = MM_ERROR_CAMCORDER_GST_LINK;
988 goto pipeline_creation_error;
991 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
992 pad = gst_element_get_static_pad(last_element->gst, "src");
993 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
994 gst_object_unref(pad);
996 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
997 err = MM_ERROR_CAMCORDER_GST_LINK;
998 goto pipeline_creation_error;
1001 gst_object_unref(pad);
1005 g_list_free(element_list);
1006 element_list = NULL;
1009 return MM_ERROR_NONE;
1011 pipeline_creation_error:
1012 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1013 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1014 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1015 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1016 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1019 g_list_free(element_list);
1020 element_list = NULL;
1027 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1032 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1037 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1038 type, codec, bitrate);
1042 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1043 /* audio encoder bitrate setting */
1045 case MM_AUDIO_CODEC_AMR:
1046 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1047 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1048 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1050 case MM_AUDIO_CODEC_MP3:
1051 set_value = bitrate / 1000;
1052 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1053 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1055 case MM_AUDIO_CODEC_AAC:
1056 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1057 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1060 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1064 /* video encoder bitrate setting */
1065 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1066 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1073 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1075 int err = MM_ERROR_NONE;
1080 int encodebin_profile = 0;
1081 int auto_audio_convert = 0;
1082 int auto_audio_resample = 0;
1083 int auto_color_space = 0;
1084 int cap_format = MM_PIXEL_FORMAT_INVALID;
1085 const char *gst_element_venc_name = NULL;
1086 const char *gst_element_aenc_name = NULL;
1087 const char *gst_element_ienc_name = NULL;
1088 const char *gst_element_mux_name = NULL;
1089 const char *gst_element_rsink_name = NULL;
1090 const char *gst_element_vscale_name = NULL;
1091 const char *str_profile = NULL;
1092 const char *str_aac = NULL;
1093 const char *str_aar = NULL;
1094 const char *str_acs = NULL;
1095 char *err_name = NULL;
1096 const char *videoconvert_name = NULL;
1097 GstCaps *audio_caps = NULL;
1098 GstCaps *video_caps = NULL;
1099 GstCaps *videoscale_caps = NULL;
1101 GList *element_list = NULL;
1103 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1104 _MMCamcorderSubContext *sc = NULL;
1105 type_element *VideoencElement = NULL;
1106 type_element *AudioencElement = NULL;
1107 type_element *ImageencElement = NULL;
1108 type_element *MuxElement = NULL;
1109 type_element *RecordsinkElement = NULL;
1110 type_element *VideoscaleElement = NULL;
1112 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1114 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1115 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1116 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1118 MMCAM_LOG_INFO("start - profile : %d", profile);
1120 /* Check existence */
1121 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1122 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1123 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1125 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1128 /* Create bin element */
1129 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1131 /* Create child element */
1132 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1133 GstCaps *caps_from_pad = NULL;
1134 char *caps_str = NULL;
1136 /* create appsrc and capsfilter */
1137 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1139 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1141 /* set appsrc as live source */
1142 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1143 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1144 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1146 /* set capsfilter */
1147 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1148 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1149 MMCAM_LOG_INFO("get pad from videosrc_filter");
1150 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1152 MMCAM_LOG_INFO("get pad from videosrc_que");
1153 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1156 MMCAM_LOG_ERROR("get videosrc_que src pad failed");
1157 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1158 goto pipeline_creation_error;
1161 caps_from_pad = gst_pad_get_allowed_caps(pad);
1162 video_caps = gst_caps_copy(caps_from_pad);
1163 gst_caps_unref(caps_from_pad);
1164 caps_from_pad = NULL;
1165 gst_object_unref(pad);
1169 video_caps = gst_caps_fixate(video_caps);
1172 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1176 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1177 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1178 goto pipeline_creation_error;
1181 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1182 if (sc->info_video->use_videoscale) {
1183 gst_caps_set_simple(video_caps,
1184 "width", G_TYPE_INT, sc->info_video->preview_width,
1185 "height", G_TYPE_INT, sc->info_video->preview_height,
1187 videoscale_caps = gst_caps_copy(video_caps);
1189 gst_caps_set_simple(video_caps,
1190 "width", G_TYPE_INT, sc->info_video->video_width,
1191 "height", G_TYPE_INT, sc->info_video->video_height,
1196 caps_str = gst_caps_to_string(video_caps);
1198 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1203 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1205 gst_caps_unref(video_caps);
1209 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1210 sc->info_video->use_videoscale) {
1211 if (!videoscale_caps) {
1212 MMCAM_LOG_ERROR("no videoscale caps");
1213 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1214 goto pipeline_creation_error;
1217 gst_caps_set_simple(videoscale_caps,
1218 "width", G_TYPE_INT, sc->info_video->video_width,
1219 "height", G_TYPE_INT, sc->info_video->video_height,
1222 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1223 CONFIGURE_CATEGORY_MAIN_RECORD,
1224 "VideoscaleElement",
1225 &VideoscaleElement);
1227 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1228 MMCAM_LOG_ERROR("failed to get videoscale element name");
1229 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1230 goto pipeline_creation_error;
1233 caps_str = gst_caps_to_string(videoscale_caps);
1235 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1240 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
1241 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
1243 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
1245 gst_caps_unref(videoscale_caps);
1246 videoscale_caps = NULL;
1249 /* release element_list, they will be placed out of encodesink bin */
1251 g_list_free(element_list);
1252 element_list = NULL;
1255 /* connect signal for ready to push buffer */
1256 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1257 _MMCAMCORDER_HANDLER_VIDEOREC,
1259 _mmcamcorder_ready_to_encode_callback,
1263 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1264 "tizenencodebin", "encodesink_encbin", element_list, err);
1266 /* check element availability */
1267 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1268 err = mm_camcorder_get_attributes(handle, &err_name,
1269 MMCAM_CAPTURE_FORMAT, &cap_format,
1272 err = mm_camcorder_get_attributes(handle, &err_name,
1273 MMCAM_AUDIO_ENCODER, &audio_enc,
1274 MMCAM_AUDIO_CHANNEL, &channel,
1275 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1276 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1280 if (err != MM_ERROR_NONE) {
1282 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1283 SAFE_FREE(err_name);
1285 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1288 goto pipeline_creation_error;
1291 MMCAM_LOG_INFO("Profile[%d]", profile);
1293 /* Set information */
1294 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1295 str_profile = "VideoProfile";
1296 str_aac = "VideoAutoAudioConvert";
1297 str_aar = "VideoAutoAudioResample";
1298 str_acs = "VideoAutoColorSpace";
1299 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1300 str_profile = "AudioProfile";
1301 str_aac = "AudioAutoAudioConvert";
1302 str_aar = "AudioAutoAudioResample";
1303 str_acs = "AudioAutoColorSpace";
1304 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1305 str_profile = "ImageProfile";
1306 str_aac = "ImageAutoAudioConvert";
1307 str_aar = "ImageAutoAudioResample";
1308 str_acs = "ImageAutoColorSpace";
1311 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1312 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1313 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1314 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1316 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1317 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1319 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1320 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1321 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1322 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1323 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1325 /* get video convert element name */
1326 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1329 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1330 int use_venc_queue = 0;
1332 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1334 if (!VideoencElement) {
1335 MMCAM_LOG_ERROR("Fail to get type element");
1336 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1337 goto pipeline_creation_error;
1340 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1341 /* set dummy element */
1342 gst_element_venc_name = "identity";
1344 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1347 if (gst_element_venc_name) {
1348 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1350 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1351 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1353 MMCAM_LOG_ERROR("Fail to get video encoder name");
1354 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1355 goto pipeline_creation_error;
1358 /* set color space converting element */
1359 if (auto_color_space) {
1360 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1362 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1363 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1365 /* set colorspace plugin property setting */
1366 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1368 /* fourcc type was removed in GST 1.0 */
1369 if (hcamcorder->use_zero_copy_format) {
1370 if (strstr(gst_element_venc_name, "omx")) {
1371 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1374 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1375 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1377 gst_caps_unref(video_caps);
1380 MMCAM_LOG_WARNING("failed to create caps");
1383 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1388 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1389 CONFIGURE_CATEGORY_MAIN_RECORD,
1390 "UseVideoEncoderQueue",
1393 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1396 if (sc->audio_disable == FALSE &&
1397 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1398 int use_aenc_queue = 0;
1400 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1401 if (!AudioencElement) {
1402 MMCAM_LOG_ERROR("Fail to get type element");
1403 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1404 goto pipeline_creation_error;
1407 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1409 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1410 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1412 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1413 audio_caps = gst_caps_new_simple("audio/x-raw",
1414 "channels", G_TYPE_INT, 1,
1416 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1417 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1418 gst_caps_unref(audio_caps);
1422 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1423 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1424 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1425 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1426 gst_caps_unref(audio_caps);
1428 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1431 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1432 CONFIGURE_CATEGORY_MAIN_RECORD,
1433 "UseAudioEncoderQueue",
1435 if (use_aenc_queue) {
1436 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1437 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1438 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1442 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1443 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1444 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1445 if (!ImageencElement) {
1446 MMCAM_LOG_ERROR("Fail to get type element");
1447 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1448 goto pipeline_creation_error;
1451 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1453 /* raw format - set dummy element */
1454 gst_element_ienc_name = "identity";
1457 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1458 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1462 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1463 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1465 MMCAM_LOG_ERROR("Fail to get type element");
1466 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1467 goto pipeline_creation_error;
1470 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1472 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1473 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1475 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1479 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1481 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1482 CONFIGURE_CATEGORY_MAIN_RECORD,
1483 "RecordsinkElement",
1484 &RecordsinkElement);
1485 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1487 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1489 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1492 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1495 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1496 /* property setting in ini */
1497 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1499 /* bitrate setting */
1500 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1501 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1504 if (sc->audio_disable == FALSE &&
1505 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1506 /* property setting in ini */
1507 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1509 /* bitrate setting */
1510 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1511 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1514 MMCAM_LOG_INFO("Element creation complete");
1516 /* Add element to bin */
1517 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1518 MMCAM_LOG_ERROR("element add error.");
1519 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1520 goto pipeline_creation_error;
1523 MMCAM_LOG_INFO("Element add complete");
1525 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1526 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1527 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1528 gst_object_unref(pad);
1530 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1531 err = MM_ERROR_CAMCORDER_GST_LINK;
1532 goto pipeline_creation_error;
1534 gst_object_unref(pad);
1537 if (sc->audio_disable == FALSE) {
1538 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1539 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1540 gst_object_unref(pad);
1542 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1543 err = MM_ERROR_CAMCORDER_GST_LINK;
1544 goto pipeline_creation_error;
1546 gst_object_unref(pad);
1549 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1550 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1551 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1552 gst_object_unref(pad);
1554 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1555 err = MM_ERROR_CAMCORDER_GST_LINK;
1556 goto pipeline_creation_error;
1558 gst_object_unref(pad);
1562 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1563 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1564 gst_object_unref(pad);
1566 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1567 err = MM_ERROR_CAMCORDER_GST_LINK;
1568 goto pipeline_creation_error;
1570 gst_object_unref(pad);
1574 MMCAM_LOG_INFO("Get pad complete");
1576 /* Link internal element */
1577 if (!_mmcamcorder_link_elements(element_list)) {
1578 MMCAM_LOG_ERROR("element link error.");
1579 err = MM_ERROR_CAMCORDER_GST_LINK;
1580 goto pipeline_creation_error;
1584 g_list_free(element_list);
1586 MMCAM_LOG_INFO("done");
1588 return MM_ERROR_NONE;
1590 pipeline_creation_error:
1591 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1593 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1594 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1595 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1596 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1597 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
1598 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1599 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1600 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1601 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1602 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1603 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1606 g_list_free(element_list);
1608 if (videoscale_caps)
1609 gst_caps_unref(videoscale_caps);
1615 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1617 int err = MM_ERROR_NONE;
1619 GstPad *srcpad = NULL;
1622 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1623 _MMCamcorderSubContext *sc = NULL;
1625 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1627 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1628 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1629 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1633 /** Create gstreamer element **/
1635 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1638 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1639 if (err != MM_ERROR_NONE)
1640 goto pipeline_creation_error;
1642 /* Set data probe function */
1643 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1644 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1645 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1647 MMCAM_LOG_ERROR("there is no queue plugin");
1648 goto pipeline_creation_error;
1652 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1653 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1655 gst_object_unref(srcpad);
1658 MMCAM_LOG_ERROR("failed to get srcpad");
1659 goto pipeline_creation_error;
1662 /* set dataprobe for video recording if it does not support dual stream. */
1663 if (sc->info_video->record_dual_stream == FALSE) {
1664 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1665 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1667 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1669 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1670 __mmcamcorder_video_dataprobe_record, hcamcorder);
1671 gst_object_unref(srcpad);
1675 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1677 /* set sync handler */
1678 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1680 gst_object_unref(bus);
1683 return MM_ERROR_NONE;
1685 pipeline_creation_error:
1686 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1691 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1693 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1694 _MMCamcorderSubContext *sc = NULL;
1696 /*MMCAM_LOG_INFO("start");*/
1698 mmf_return_if_fail(hcamcorder);
1699 mmf_return_if_fail(hcamcorder->sub_context);
1700 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1703 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1704 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1705 MMCAM_LOG_WARNING("set push_encoding_buffer RUN");
1710 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1712 int err = MM_ERROR_NONE;
1717 int rect_height = 0;
1719 int rotation = MM_DISPLAY_ROTATION_NONE;
1720 int flip = MM_FLIP_NONE;
1721 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1722 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1723 int origin_size = 0;
1726 int do_scaling = FALSE;
1727 int *dp_handle = NULL;
1728 MMCamWindowInfo *window_info = NULL;
1730 char *err_name = NULL;
1731 const char *videosink_name = NULL;
1733 GstElement *vsink = NULL;
1735 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1736 _MMCamcorderSubContext *sc = NULL;
1740 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1742 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1743 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1744 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1745 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1747 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1749 /* Get video display information */
1750 err = mm_camcorder_get_attributes(handle, &err_name,
1751 MMCAM_DISPLAY_RECT_X, &rect_x,
1752 MMCAM_DISPLAY_RECT_Y, &rect_y,
1753 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1754 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1755 MMCAM_DISPLAY_ROTATION, &rotation,
1756 MMCAM_DISPLAY_FLIP, &flip,
1757 MMCAM_DISPLAY_VISIBLE, &visible,
1758 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1759 MMCAM_DISPLAY_MODE, &display_mode,
1760 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1761 MMCAM_DISPLAY_SCALE, &zoom_attr,
1762 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1764 if (err != MM_ERROR_NONE) {
1766 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1767 SAFE_FREE(err_name);
1769 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1775 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1777 if (!videosink_name) {
1778 MMCAM_LOG_ERROR("failed to get videosink name");
1779 return MM_ERROR_CAMCORDER_INTERNAL;
1782 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
1784 /* Set display handle */
1785 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1788 MMCAM_LOG_INFO("xid = %lu )", xid);
1789 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1791 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1792 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1794 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1795 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
1798 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1799 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1801 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
1802 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1804 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1806 window_info = (MMCamWindowInfo *)dp_handle;
1807 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
1808 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1810 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
1812 } else if (!strcmp(videosink_name, "directvideosink")) {
1813 #ifdef _MMCAMCORDER_RM_SUPPORT
1814 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1815 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
1816 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1817 #endif /* _MMCAMCORDER_RM_SUPPORT */
1819 window_info = (MMCamWindowInfo *)dp_handle;
1820 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1821 window_info->surface_id,
1822 window_info->rect.x,
1823 window_info->rect.y,
1824 window_info->rect.width,
1825 window_info->rect.height);
1826 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1827 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1828 window_info->rect.x,
1829 window_info->rect.y,
1830 window_info->rect.width,
1831 window_info->rect.height);
1833 MMCAM_LOG_WARNING("dp_handle is null");
1836 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
1839 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1840 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1843 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1844 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1846 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1849 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1851 switch (zoom_attr) {
1852 case MM_DISPLAY_SCALE_DEFAULT:
1855 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1858 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1862 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
1867 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1868 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1869 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1870 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1872 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1873 if (!strcmp(videosink_name, "tizenwlsink")) {
1874 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1875 rect_x, rect_y, rect_width, rect_height);
1878 "dst-roi-x", rect_x,
1879 "dst-roi-y", rect_y,
1880 "dst-roi-w", rect_width,
1881 "dst-roi-h", rect_height,
1887 return MM_ERROR_NONE;
1891 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1894 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1895 _MMCamcorderSubContext *sc = NULL;
1897 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1899 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1901 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1904 case _MMCamcorder_CMD_PREVIEW_START:
1905 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1907 case _MMCamcorder_CMD_CAPTURE:
1908 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1911 MMCAM_LOG_WARNING("unknown command : %d", cmd);
1912 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1915 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1916 category, "FrameStabilityCount", &sc->frame_stability_count);
1918 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
1919 cmd, sc->frame_stability_count);
1921 return MM_ERROR_NONE;
1924 /* Retreive device information and set them to attributes */
1925 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
1927 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1928 _MMCamcorderSubContext *sc = NULL;
1929 GstCameraControl *control = NULL;
1930 GstCameraControlExifInfo exif_info = {0,};
1932 mmf_return_val_if_fail(hcamcorder, FALSE);
1933 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1935 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
1937 if (sc && sc->element) {
1938 int err = MM_ERROR_NONE;
1939 char *err_name = NULL;
1940 double focal_len = 0.0;
1942 /* Video input device */
1943 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
1944 /* Exif related information */
1945 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1946 if (control != NULL) {
1947 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
1948 if (exif_info.focal_len_denominator != 0)
1949 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
1951 MMCAM_LOG_ERROR("Fail to get camera control interface!");
1956 /* Set values to attributes */
1957 err = mm_camcorder_set_attributes(handle, &err_name,
1958 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
1960 if (err != MM_ERROR_NONE) {
1961 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
1962 SAFE_FREE(err_name);
1966 MMCAM_LOG_WARNING("Sub context isn't exist.");
1973 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name)
1975 return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24);
1978 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
1980 gboolean ret = TRUE;
1981 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
1982 _MMCamcorderSubContext *sc = NULL;
1983 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
1984 GstSample *sample = NULL;
1985 GstCaps *caps = NULL;
1987 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
1988 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
1989 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
1991 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
1992 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
1994 if (sc->drop_vframe > 0) {
1995 if (sc->pass_first_vframe > 0) {
1996 sc->pass_first_vframe--;
1997 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2000 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2001 return GST_PAD_PROBE_DROP;
2003 } else if (sc->frame_stability_count > 0) {
2004 sc->frame_stability_count--;
2005 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2006 return GST_PAD_PROBE_DROP;
2009 if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
2010 _mmcamcorder_measure_fps(&sc->kpi);
2012 /* The first H.264 frame should not be skipped for vstream cb. */
2013 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2014 !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2015 MMCAM_LOG_WARNING("Not ready for stream callback");
2016 return GST_PAD_PROBE_OK;
2019 /* make sample with buffer and caps */
2020 caps = gst_pad_get_allowed_caps(pad);
2021 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2023 sample = gst_sample_new(buffer, caps, NULL, NULL);
2024 gst_caps_unref(caps);
2025 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2027 ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
2029 gst_sample_unref(sample);
2032 return GST_PAD_PROBE_OK;
2034 return GST_PAD_PROBE_DROP;
2038 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2040 gboolean ret = TRUE;
2041 GstSample *sample = NULL;
2042 GstCaps *caps = NULL;
2044 caps = gst_pad_get_allowed_caps(pad);
2045 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2047 sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
2048 gst_caps_unref(caps);
2049 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2051 ret = _mmcamcorder_video_push_buffer(u_data, sample);
2053 gst_sample_unref(sample);
2055 return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
2059 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2061 MMCamcorderMuxedStreamDataType stream;
2062 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2063 _MMCamcorderSubContext *sc = NULL;
2064 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2067 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2068 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2069 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2071 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2072 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2074 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2075 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2076 return GST_PAD_PROBE_OK;
2079 /* call application callback */
2080 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2082 if (hcamcorder->mstream_cb) {
2083 stream.data = (void *)mapinfo.data;
2084 stream.length = mapinfo.size;
2085 stream.offset = sc->muxed_stream_offset;
2086 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2089 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2091 /* calculate current offset */
2092 sc->muxed_stream_offset += mapinfo.size;
2094 gst_buffer_unmap(buffer, &mapinfo);
2096 return GST_PAD_PROBE_OK;
2100 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2102 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2103 mmf_camcorder_t *hcamcorder = NULL;
2104 _MMCamcorderSubContext *sc = NULL;
2105 GstObject *parent = NULL;
2107 switch (GST_EVENT_TYPE(event)) {
2108 case GST_EVENT_UNKNOWN:
2109 /* upstream events */
2111 case GST_EVENT_SEEK:
2112 case GST_EVENT_NAVIGATION:
2113 case GST_EVENT_LATENCY:
2114 /* downstream serialized events */
2115 case GST_EVENT_BUFFERSIZE:
2116 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2120 GstTagList *tag_list = NULL;
2121 _MMCamcorderReplayGain *replay_gain = NULL;
2123 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2125 hcamcorder = MMF_CAMCORDER(u_data);
2126 if (!hcamcorder || !hcamcorder->sub_context) {
2127 MMCAM_LOG_WARNING("NULL handle");
2131 replay_gain = &hcamcorder->sub_context->replay_gain;
2133 gst_event_parse_tag(event, &tag_list);
2135 MMCAM_LOG_WARNING("failed to get tag list");
2139 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2140 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2144 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2145 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2149 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2150 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2154 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2155 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2159 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2160 replay_gain->track_peak, replay_gain->track_gain,
2161 replay_gain->album_peak, replay_gain->album_gain);
2164 case GST_EVENT_SEGMENT:
2165 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2167 hcamcorder = MMF_CAMCORDER(u_data);
2169 MMCAM_LOG_WARNING("NULL handle");
2173 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2175 MMCAM_LOG_WARNING("NULL sub context");
2179 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2180 MMCAM_LOG_WARNING("no encoder sink");
2184 parent = gst_pad_get_parent(pad);
2186 MMCAM_LOG_WARNING("get parent failed");
2190 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2191 const GstSegment *segment;
2192 gst_event_parse_segment(event, &segment);
2193 if (segment->format == GST_FORMAT_BYTES) {
2194 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2195 sc->muxed_stream_offset, segment->start);
2197 sc->muxed_stream_offset = (unsigned long long)segment->start;
2201 gst_object_unref(parent);
2205 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2207 /* bidirectional events */
2208 case GST_EVENT_FLUSH_START:
2209 case GST_EVENT_FLUSH_STOP:
2210 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2213 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2217 return GST_PAD_PROBE_OK;
2221 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2223 int result = MM_CAMCORDER_MR475;
2226 result = MM_CAMCORDER_MR475; /*AMR475*/
2227 else if (bitrate < 5900)
2228 result = MM_CAMCORDER_MR515; /*AMR515*/
2229 else if (bitrate < 6700)
2230 result = MM_CAMCORDER_MR59; /*AMR59*/
2231 else if (bitrate < 7400)
2232 result = MM_CAMCORDER_MR67; /*AMR67*/
2233 else if (bitrate < 7950)
2234 result = MM_CAMCORDER_MR74; /*AMR74*/
2235 else if (bitrate < 10200)
2236 result = MM_CAMCORDER_MR795; /*AMR795*/
2237 else if (bitrate < 12200)
2238 result = MM_CAMCORDER_MR102; /*AMR102*/
2240 result = MM_CAMCORDER_MR122; /*AMR122*/
2246 int _mmcamcorder_get_eos_message(MMHandleType handle)
2249 int ret = MM_ERROR_NONE;
2251 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2252 _MMCamcorderSubContext *sc = NULL;
2254 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2255 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2256 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2258 MMCAM_LOG_INFO("START");
2260 _MMCAMCORDER_LOCK(handle);
2262 if (sc->bget_eos == FALSE) {
2263 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2264 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2265 MMCAM_LOG_INFO("EOS signal received");
2267 MMCAM_LOG_ERROR("EOS wait time out");
2269 if (hcamcorder->error_code == MM_ERROR_NONE)
2270 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2273 MMCAM_LOG_INFO("already got EOS");
2276 _MMCAMCORDER_UNLOCK(handle);
2278 if (hcamcorder->error_code == MM_ERROR_NONE) {
2279 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2280 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2281 if (sc->info_video->b_committing)
2282 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2284 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2285 if (sc->info_audio->b_committing)
2286 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2289 ret = hcamcorder->error_code;
2290 MMCAM_LOG_ERROR("error 0x%x", ret);
2293 MMCAM_LOG_INFO("END");
2299 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2302 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2304 mmf_return_if_fail(handle && remove_element);
2305 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2309 for (i = first_elem ; i <= last_elem ; i++) {
2310 remove_element[i].gst = NULL;
2311 remove_element[i].id = _MMCAMCORDER_NONE;
2318 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2320 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2322 /* Check compatibility between codec and file format */
2323 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2324 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2325 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2326 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2327 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2328 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2331 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2333 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2334 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2336 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2337 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2338 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2339 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2340 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2341 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2344 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2346 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2347 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2351 return MM_ERROR_NONE;
2355 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2357 int err = MM_ERROR_NONE;
2358 int audio_codec = MM_AUDIO_CODEC_INVALID;
2359 int file_format = MM_FILE_FORMAT_INVALID;
2361 char *err_name = NULL;
2363 err = mm_camcorder_get_attributes(handle, &err_name,
2364 MMCAM_AUDIO_ENCODER, &audio_codec,
2365 MMCAM_FILE_FORMAT, &file_format,
2367 if (err != MM_ERROR_NONE) {
2368 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2369 SAFE_FREE(err_name);
2373 /* Check compatibility between audio codec and file format */
2374 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2380 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2382 int err = MM_ERROR_NONE;
2383 int video_codec = MM_VIDEO_CODEC_INVALID;
2384 int file_format = MM_FILE_FORMAT_INVALID;
2386 char *err_name = NULL;
2388 err = mm_camcorder_get_attributes(handle, &err_name,
2389 MMCAM_VIDEO_ENCODER, &video_codec,
2390 MMCAM_FILE_FORMAT, &file_format,
2392 if (err != MM_ERROR_NONE) {
2393 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2394 SAFE_FREE(err_name);
2398 /* Check compatibility between video codec and file format */
2399 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2405 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2407 const char* videosink_name = NULL;
2409 mmf_camcorder_t *hcamcorder = NULL;
2410 _MMCamcorderSubContext *sc = NULL;
2412 hcamcorder = MMF_CAMCORDER(handle);
2413 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2415 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2416 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2417 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2419 if (sc->element[videosink_index].gst) {
2420 /* Get videosink name */
2421 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2422 if (videosink_name == NULL) {
2423 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2427 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2428 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2429 !strcmp(videosink_name, "directvideosink")) {
2430 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2431 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2433 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2438 MMCAM_LOG_ERROR("Videosink element is null");
2444 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2446 const char* videosink_name = NULL;
2448 mmf_camcorder_t *hcamcorder = NULL;
2449 _MMCamcorderSubContext *sc = NULL;
2451 hcamcorder = MMF_CAMCORDER(handle);
2452 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2454 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2455 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2456 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2458 if (sc->element[videosink_index].gst) {
2459 /* Get videosink name */
2460 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2461 if (videosink_name == NULL) {
2462 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2466 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2467 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2468 !strcmp(videosink_name, "directvideosink")) {
2469 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2470 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2472 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2477 MMCAM_LOG_ERROR("Videosink element is null");
2483 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2486 _MMCamcorderSubContext *sc = NULL;
2488 mmf_camcorder_t *hcamcorder = NULL;
2490 hcamcorder = MMF_CAMCORDER(handle);
2491 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2493 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2495 MMCAM_LOG_INFO("sub context is not initialized");
2499 mm_camcorder_get_attributes(handle, NULL,
2500 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2501 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2502 MMCAM_CAMERA_FPS, &fps,
2505 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2507 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2508 sc->info_video->preview_width, sc->info_video->preview_height,
2509 fps, videosrc_rotate);
2513 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2519 unsigned int caps_fourcc = 0;
2520 gboolean do_set_caps = FALSE;
2521 char fourcc_string[sizeof(fourcc) + 1];
2522 gchar *caps_str = NULL;
2523 #ifdef _MMCAMCORDER_PRODUCT_TV
2526 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
2527 #endif /* _MMCAMCORDER_PRODUCT_TV */
2529 GstCaps *caps = NULL;
2531 mmf_camcorder_t *hcamcorder = NULL;
2532 _MMCamcorderSubContext *sc = NULL;
2534 hcamcorder = MMF_CAMCORDER(handle);
2535 mmf_return_val_if_fail(hcamcorder, FALSE);
2537 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2539 if (!sc || !(sc->element)) {
2540 MMCAM_LOG_INFO("sub context is not initialized");
2544 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2545 MMCAM_LOG_ERROR("Video src is NULL!");
2549 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2550 MMCAM_LOG_ERROR("Video filter is NULL!");
2554 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2555 int capture_width = 0;
2556 int capture_height = 0;
2557 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2559 mm_camcorder_get_attributes(handle, NULL,
2560 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2561 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2562 MMCAM_CAPTURE_WIDTH, &capture_width,
2563 MMCAM_CAPTURE_HEIGHT, &capture_height,
2564 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2565 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2567 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2568 motion_rate, capture_width, capture_height, fps_auto,
2569 sc->info_video->video_width, sc->info_video->video_height);
2571 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2572 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2574 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2575 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2576 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2579 sc->info_video->fps = fps;
2582 /* Interleaved format does not support rotation */
2583 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2584 /* store videosrc rotation */
2585 sc->videosrc_rotate = rotate;
2587 /* Define width, height and rotate in caps */
2589 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2590 This will be applied when rotate is 0, 180 if front camera. */
2591 set_rotate = rotate * 90;
2593 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2594 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2597 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2598 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2605 set_height = height;
2608 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2611 set_height = height;
2613 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2616 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2617 if (caps && !gst_caps_is_any(caps)) {
2618 GstStructure *structure = NULL;
2620 structure = gst_caps_get_structure(caps, 0);
2622 const gchar *format_string = NULL;
2624 int caps_height = 0;
2626 int caps_rotate = 0;
2628 format_string = gst_structure_get_string(structure, "format");
2630 caps_fourcc = _mmcamcorder_convert_fourcc_string_to_value(format_string);
2632 gst_structure_get_int(structure, "width", &caps_width);
2633 gst_structure_get_int(structure, "height", &caps_height);
2634 gst_structure_get_int(structure, "fps", &caps_fps);
2635 gst_structure_get_int(structure, "rotate", &caps_rotate);
2637 #ifdef _MMCAMCORDER_PRODUCT_TV
2638 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2639 if (set_width == caps_width && set_height == caps_height &&
2640 set_rotate == caps_rotate && fps == caps_fps) {
2641 MMCAM_LOG_INFO("No need to replace caps.");
2643 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]",
2644 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2645 caps_width, caps_height, caps_fps, caps_rotate,
2646 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2647 set_width, set_height, fps, set_rotate);
2651 if (set_width == caps_width && set_height == caps_height &&
2652 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2653 MMCAM_LOG_INFO("No need to replace caps.");
2655 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]",
2656 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2657 caps_width, caps_height, caps_fps, caps_rotate,
2658 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2659 set_width, set_height, fps, set_rotate);
2663 #else /*_MMCAMCORDER_PRODUCT_TV */
2664 if (set_width == caps_width && set_height == caps_height &&
2665 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2666 MMCAM_LOG_INFO("No need to replace caps.");
2668 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]",
2669 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2670 caps_width, caps_height, caps_fps, caps_rotate,
2671 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2672 set_width, set_height, fps, set_rotate);
2675 #endif /*_MMCAMCORDER_PRODUCT_TV */
2677 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2681 MMCAM_LOG_INFO("No caps. set new one...");
2686 gst_caps_unref(caps);
2690 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2691 /* assume that it's camera capture mode */
2692 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2698 switch (sc->info_image->preview_format) {
2699 case MM_PIXEL_FORMAT_ENCODED_H264:
2700 #ifdef _MMCAMCORDER_PRODUCT_TV
2701 mm_camcorder_get_attributes(handle, NULL,
2702 MMCAM_DISPLAY_SURFACE, &display_surface_type,
2704 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
2705 __mmcamcorder_find_max_resolution(handle, &maxwidth, &maxheight) == false) {
2706 MMCAM_LOG_ERROR("can not find max resolution limitation");
2708 } else if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
2709 maxwidth = set_width;
2710 maxheight = set_height;
2712 #endif /* _MMCAMCORDER_PRODUCT_TV */
2713 caps = gst_caps_new_simple("video/x-h264",
2714 "width", G_TYPE_INT, set_width,
2715 "height", G_TYPE_INT, set_height,
2716 "framerate", GST_TYPE_FRACTION, fps, 1,
2717 "stream-format", G_TYPE_STRING, "byte-stream",
2718 #ifdef _MMCAMCORDER_PRODUCT_TV
2719 "maxwidth", G_TYPE_INT, maxwidth,
2720 "maxheight", G_TYPE_INT, maxheight,
2721 "alignment", G_TYPE_STRING, "au",
2722 #endif /* _MMCAMCORDER_PRODUCT_TV */
2725 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
2726 #ifdef _MMCAMCORDER_PRODUCT_TV
2727 caps = gst_caps_new_simple("video/x-jpeg",
2729 caps = gst_caps_new_simple("image/jpeg",
2731 "width", G_TYPE_INT, set_width,
2732 "height", G_TYPE_INT, set_height,
2733 "framerate", GST_TYPE_FRACTION, fps, 1,
2736 case MM_PIXEL_FORMAT_ENCODED_VP8:
2737 caps = gst_caps_new_simple("video/x-vp8",
2738 "width", G_TYPE_INT, set_width,
2739 "height", G_TYPE_INT, set_height,
2740 "framerate", GST_TYPE_FRACTION, fps, 1,
2743 case MM_PIXEL_FORMAT_ENCODED_VP9:
2744 caps = gst_caps_new_simple("video/x-vp9",
2745 "width", G_TYPE_INT, set_width,
2746 "height", G_TYPE_INT, set_height,
2747 "framerate", GST_TYPE_FRACTION, fps, 1,
2752 memcpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
2753 fourcc_string[sizeof(fourcc)] = '\0';
2754 caps = gst_caps_new_simple("video/x-raw",
2755 "format", G_TYPE_STRING, fourcc_string,
2756 "width", G_TYPE_INT, set_width,
2757 "height", G_TYPE_INT, set_height,
2758 "framerate", GST_TYPE_FRACTION, fps, 1,
2759 "rotate", G_TYPE_INT, set_rotate,
2765 MMCAM_LOG_ERROR("There are no caps");
2769 caps_str = gst_caps_to_string(caps);
2770 MMCAM_LOG_INFO("vidoesrc new caps set [%s]", caps_str);
2773 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2774 gst_caps_unref(caps);
2780 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2782 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2783 _MMCamcorderSubContext *sc = NULL;
2785 mmf_return_val_if_fail(hcamcorder, FALSE);
2787 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2791 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
2793 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2797 /* Interleaved format does not support FLIP */
2798 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2799 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2800 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2802 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
2804 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2805 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2807 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
2811 MMCAM_LOG_WARNING("element is NULL");
2819 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2821 GstCameraControl *control = NULL;
2822 _MMCamcorderSubContext *sc = NULL;
2823 GstElement *v_src = NULL;
2827 mmf_return_val_if_fail(handle, FALSE);
2829 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2833 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2836 MMCAM_LOG_WARNING("videosrc element is NULL");
2840 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2842 /* set anti-shake with camera control */
2843 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2844 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
2848 control = GST_CAMERA_CONTROL(v_src);
2849 if (gst_camera_control_set_ahs(control, set_value)) {
2850 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
2853 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
2860 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2862 _MMCamcorderSubContext *sc = NULL;
2863 GstElement *v_src = NULL;
2865 mmf_return_val_if_fail(handle, FALSE);
2867 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2871 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2873 MMCAM_LOG_WARNING("videosrc element is NULL");
2877 /* check property of videosrc element - support VDIS */
2878 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2879 int video_width = 0;
2880 int video_height = 0;
2882 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2883 MMCAM_LOG_INFO("ENABLE video stabilization");
2885 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2886 mm_camcorder_get_attributes(handle, NULL,
2887 MMCAM_VIDEO_WIDTH, &video_width,
2888 MMCAM_VIDEO_HEIGHT, &video_height,
2891 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2892 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
2893 video_width, video_height);
2895 g_object_set(G_OBJECT(v_src),
2896 "enable-vdis-mode", TRUE,
2899 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
2900 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2901 video_width, video_height);
2906 g_object_set(G_OBJECT(v_src),
2907 "enable-vdis-mode", FALSE,
2910 MMCAM_LOG_INFO("DISABLE video stabilization");
2912 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2913 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
2916 MMCAM_LOG_WARNING("no property for video stabilization");
2923 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2927 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2928 _MMCamcorderSubContext *sc = NULL;
2930 mmf_return_val_if_fail(hcamcorder, FALSE);
2932 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2936 mm_camcorder_get_attributes(handle, NULL,
2937 MMCAM_CAMERA_FPS, &fps,
2940 MMCAM_LOG_INFO("set %dx%d", width, height);
2942 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2946 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2948 _MMCamcorderSubContext *sc = NULL;
2950 if ((void *)handle == NULL) {
2951 MMCAM_LOG_WARNING("handle is NULL");
2955 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2957 MMCAM_LOG_WARNING("subcontext is NULL");
2961 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2962 MMCAM_LOG_WARNING("videosrc plugin is NULL");
2966 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
2968 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
2974 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
2976 _MMCamcorderSubContext *sc = NULL;
2978 if ((void *)handle == NULL) {
2979 MMCAM_LOG_WARNING("handle is NULL");
2983 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2985 MMCAM_LOG_WARNING("subcontext is NULL");
2989 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2990 MMCAM_LOG_WARNING("videosrc plugin is NULL");
2994 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
2996 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3002 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3004 GstStructure *props = NULL;
3005 char stream_props[64] = {'\0',};
3007 if (element == NULL || stream_type == NULL || stream_index < 0) {
3008 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3012 snprintf(stream_props, sizeof(stream_props) - 1,
3013 "props,media.role=%s, media.parent_id=%d",
3014 stream_type, stream_index);
3016 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3018 props = gst_structure_from_string(stream_props, NULL);
3020 MMCAM_LOG_ERROR("failed to create GstStructure");
3024 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3026 gst_structure_free(props);
3033 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3035 int ret = MM_ERROR_NONE;
3036 _MMCamcorderSubContext *sc = NULL;
3037 mmf_camcorder_t *hcamcorder = NULL;
3038 const char *videodecoder_name = NULL;
3039 char videodecoder_name_final[32] = {'\0',};
3040 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3041 #ifdef _MMCAMCORDER_RM_SUPPORT
3042 int decoder_index = 0;
3043 #endif /* _MMCAMCORDER_RM_SUPPORT */
3045 if ((void *)handle == NULL) {
3046 MMCAM_LOG_WARNING("handle is NULL");
3050 hcamcorder = MMF_CAMCORDER(handle);
3052 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3054 MMCAM_LOG_WARNING("subcontext is NULL");
3058 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3059 hcamcorder->recreate_decoder == FALSE) {
3060 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3061 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3065 mm_camcorder_get_attributes(handle, NULL,
3066 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3069 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3070 MMCAM_LOG_INFO("no need to control decoder element");
3074 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3075 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3076 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3080 MMCAM_LOG_INFO("start");
3082 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
3083 if (videodecoder_name == NULL) {
3084 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
3088 /* set state as NULL */
3089 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3090 if (ret != MM_ERROR_NONE) {
3091 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3095 /* remove decoder - pads will be unlinked automatically in remove function */
3096 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3097 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3098 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3102 /* check decoder element */
3103 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3104 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3105 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3106 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3109 #ifdef _MMCAMCORDER_RM_SUPPORT
3110 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3111 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3114 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
3115 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
3117 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3118 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
3120 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
3122 #endif /* _MMCAMCORDER_RM_SUPPORT */
3123 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
3124 #ifdef _MMCAMCORDER_RM_SUPPORT
3126 #endif /* _MMCAMCORDER_RM_SUPPORT */
3128 /* create decoder */
3129 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "videosrc_decode");
3130 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3131 MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
3135 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
3137 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3138 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3139 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3141 /* add to pipeline */
3142 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3143 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3144 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3145 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3150 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3151 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3152 MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
3154 MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
3158 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3159 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3160 MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
3162 MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
3166 /* set state READY */
3167 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3168 if (ret != MM_ERROR_NONE) {
3169 MMCAM_LOG_ERROR("failed to set READY to decoder");
3173 MMCAM_LOG_INFO("done");
3178 #ifdef _MMCAMCORDER_PRODUCT_TV
3179 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3181 _MMCamcorderSubContext *sc = NULL;
3182 mmf_camcorder_t *hcamcorder = NULL;
3184 const gchar *mime = NULL;
3186 GstCaps *decsink_caps = NULL;
3187 GstStructure *decsink_struct = NULL;
3189 mmf_return_val_if_fail(handle, false);
3190 mmf_return_val_if_fail(max_width, false);
3191 mmf_return_val_if_fail(max_height, false);
3193 hcamcorder = MMF_CAMCORDER(handle);
3194 mmf_return_val_if_fail(hcamcorder, false);
3196 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3198 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3200 MMCAM_LOG_ERROR("There are no decoder caps");
3204 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3205 if (!decsink_caps) {
3206 gst_object_unref(sinkpad);
3207 MMCAM_LOG_ERROR("There is no decoder sink caps");
3211 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3212 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3213 if (!decsink_struct) {
3214 MMCAM_LOG_ERROR("There are no structure from caps");
3215 gst_object_unref(decsink_caps);
3216 gst_object_unref(sinkpad);
3219 mime = gst_structure_get_name(decsink_struct);
3220 if (!strcmp(mime, "video/x-h264")) {
3221 MMCAM_LOG_INFO("h264 caps structure found");
3222 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3223 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3224 if (gst_structure_has_field(decsink_struct, "maxheight"))
3225 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3227 } else if (!strcmp(mime, "video/x-jpeg")) {
3228 MMCAM_LOG_INFO("mjpeg caps structure found");
3229 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3230 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3231 if (gst_structure_has_field(decsink_struct, "maxheight"))
3232 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3236 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3237 gst_object_unref(decsink_caps);
3238 gst_object_unref(sinkpad);
3240 if (*max_width <= 0 || *max_height <= 0)
3245 #endif /* _MMCAMCORDER_PRODUCT_TV */