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(structure,
341 "width", G_TYPE_INT, &stream.width,
342 "height", G_TYPE_INT, &stream.height,
344 stream.format = _mmcamcorder_get_pixel_format(caps);
346 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format)) {
347 memory = gst_buffer_get_all_memory(buffer);
348 stream.internal_buffer = buffer;
350 memory = gst_buffer_peek_memory(buffer, 0);
353 MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
357 structure = gst_mini_object_get_qdata(GST_MINI_OBJECT_CAST(buffer), hcamcorder->buffer_quark);
359 gst_structure_get(structure,
360 "focus-state", G_TYPE_INT, &stream.focus_state,
361 "facing-direction", G_TYPE_INT, &stream.facing_direction,
362 "flip", G_TYPE_INT, &stream.flip,
363 "rotation", G_TYPE_INT, &stream.rotation,
366 MMCAM_LOG_VERBOSE("structure[%p], [fs:%d,fd:%d,f:%d,r:%d]", structure,
367 stream.focus_state, stream.facing_direction, stream.flip, stream.rotation);
370 /* set zero-copy related information */
371 if (hcamcorder->use_zero_copy_format) {
372 t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
374 if (tbm_surface_get_info(t_surface, &ts_info) != TBM_SURFACE_ERROR_NONE) {
375 MMCAM_LOG_ERROR("failed to get tbm surface[%p] info", t_surface);
376 goto _INVOKE_VIDEO_STREAM_CB_DONE;
379 /* set bo, stride and elevation */
380 num_bos = gst_tizen_memory_get_num_bos(memory);
381 for (i = 0 ; i < num_bos ; i++)
382 stream.bo[i] = gst_tizen_memory_get_bos(memory, i);
384 for (i = 0 ; i < ts_info.num_planes ; i++) {
385 stream.stride[i] = ts_info.planes[i].stride;
386 stream.elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
387 MMCAM_LOG_VERBOSE(" plane[%d] %dx%d", i, stream.stride[i], stream.elevation[i]);
390 stream.length_total = ts_info.size;
391 stream.internal_buffer = buffer;
393 if (!__mmcamcorder_set_stream_data_tbm(&stream, &ts_info))
394 goto _INVOKE_VIDEO_STREAM_CB_DONE;
396 stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
398 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE) ||
399 !__mmcamcorder_set_stream_data_normal(&stream, buffer, &map_info))
400 goto _INVOKE_VIDEO_STREAM_CB_DONE;
403 MMCAM_LOG_DEBUG("VideoStreamData : format[%d], resolution[%dx%d], stream_id[%d]",
404 stream.format, stream.width, stream.height, stream_id);
406 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
407 stream.extra_stream_id = stream_id;
409 /* invoke application callback */
411 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
412 if (hcamcorder->vstream_cb)
413 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
414 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
416 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
417 if (hcamcorder->vedecision_cb)
418 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
419 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
422 _INVOKE_VIDEO_STREAM_CB_DONE:
423 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
424 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
425 tbm_bo_unmap(stream.bo[i]);
429 gst_memory_unmap(memory, &map_info);
431 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format))
432 gst_memory_unref(memory);
438 int _mmcamcorder_create_preview_elements(MMHandleType handle)
440 int err = MM_ERROR_NONE;
442 int camera_rotate = 0;
446 int capture_width = 0;
447 int capture_height = 0;
448 int capture_jpg_quality = 100;
449 int video_stabilization = 0;
451 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
452 const char *videosrc_name = NULL;
453 const char *videosink_name = NULL;
454 const char *videoconvert_name = NULL;
455 const char *videodecoder_name = NULL;
456 const char *decoder_conf_name = NULL;
457 char videodecoder_name_final[32] = {'\0',};
458 char *err_name = NULL;
459 char *socket_path = NULL;
461 #ifdef _MMCAMCORDER_RM_SUPPORT
462 int decoder_index = 0;
463 #endif /* _MMCAMCORDER_RM_SUPPORT */
464 GstElement *sink_element = NULL;
465 GstCameraControl *control = NULL;
466 int sink_element_size = 0;
469 int extra_preview_enable = 0;
471 GList *element_list = NULL;
473 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
474 _MMCamcorderSubContext *sc = NULL;
475 type_element *VideosrcElement = NULL;
476 type_int_array *input_index = NULL;
478 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
480 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
481 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
482 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
486 /* Check existence */
487 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
488 if (sc->element[i].gst) {
489 if (((GObject *)sc->element[i].gst)->ref_count > 0)
490 gst_object_unref(sc->element[i].gst);
492 MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
496 /* Get video device index info */
497 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
498 CONFIGURE_CATEGORY_CTRL_CAMERA,
501 if (input_index == NULL) {
502 MMCAM_LOG_ERROR("Failed to get input_index");
503 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
506 err = mm_camcorder_get_attributes(handle, &err_name,
507 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
508 MMCAM_CAMERA_FPS, &fps,
509 MMCAM_CAMERA_ROTATION, &camera_rotate,
510 MMCAM_CAMERA_FLIP, &camera_flip,
511 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
512 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
513 MMCAM_CAPTURE_WIDTH, &capture_width,
514 MMCAM_CAPTURE_HEIGHT, &capture_height,
515 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
516 MMCAM_IMAGE_ENCODER, &codectype,
517 MMCAM_IMAGE_ENCODER_QUALITY, &capture_jpg_quality,
518 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
519 MMCAM_DISPLAY_SURFACE, &display_surface_type,
520 MMCAM_EXTRA_PREVIEW_ENABLE, &extra_preview_enable,
522 if (err != MM_ERROR_NONE) {
523 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
528 if (hcamcorder->support_user_buffer) {
529 err = mm_camcorder_get_attributes(handle, NULL,
530 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
532 if (err != MM_ERROR_NONE || fd_number < 1) {
533 MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
538 for (i = 0 ; i < fd_number ; i++)
539 MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
543 /* Get fourcc from picture format */
544 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
546 /* Get videosrc element and its name from configure */
547 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
548 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
551 _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
554 * Create child element
556 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
558 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
561 * This is for "tizencamerasrc" element only.
562 * The camera HAL library will be loaded when "hal-name" property is set.
563 * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
565 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
567 /* camera properties */
568 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
569 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
570 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
571 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-jpg-quality", capture_jpg_quality);
572 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
573 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "extra-preview", extra_preview_enable);
574 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
576 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
578 /* set camera flip */
579 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
581 /* set video stabilization mode */
582 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
584 /* set anti handshake mode */
585 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
587 if (sc->is_modified_rate)
588 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
590 /* Set basic information of videosrc element */
591 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
593 /* Set video device index */
594 if (hcamcorder->is_network) {
595 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
597 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
598 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
600 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
604 /* set user buffer fd to videosrc element */
605 if (hcamcorder->support_user_buffer) {
606 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
607 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
608 MMCAM_LOG_ERROR("set user buffer fd failed");
609 goto pipeline_creation_error;
613 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
614 /* get recreate_decoder flag */
615 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
616 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
618 &hcamcorder->recreate_decoder);
621 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
622 _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
623 switch (sc->info_image->preview_format) {
624 case MM_PIXEL_FORMAT_ENCODED_H264:
625 decoder_conf_name = "VideodecoderElementH264";
627 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
628 decoder_conf_name = "VideodecoderElementMJPEG";
630 case MM_PIXEL_FORMAT_ENCODED_VP8:
631 decoder_conf_name = "VideodecoderElementVP8";
633 case MM_PIXEL_FORMAT_ENCODED_VP9:
634 decoder_conf_name = "VideodecoderElementVP9";
637 MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
638 goto pipeline_creation_error;
641 /* get video decoder element and name */
642 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
643 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
645 &sc->VideodecoderElement);
647 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
650 if (!videodecoder_name) {
651 MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
652 goto pipeline_creation_error;
655 #ifdef _MMCAMCORDER_RM_SUPPORT
656 MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
657 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
658 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
660 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
661 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
662 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
663 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
665 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
667 #endif /* _MMCAMCORDER_RM_SUPPORT */
668 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
669 #ifdef _MMCAMCORDER_RM_SUPPORT
671 #endif /* _MMCAMCORDER_RM_SUPPORT */
673 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
675 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
678 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
680 /* Get videosink name */
681 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
683 if (!videosink_name) {
684 MMCAM_LOG_ERROR("failed to get videosink name");
685 goto pipeline_creation_error;
688 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
690 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
692 if (display_surface_type == MM_DISPLAY_SURFACE_REMOTE) {
693 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "ipc_sink", element_list, err);
695 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
697 err = mm_camcorder_get_attributes(handle, &err_name,
698 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
700 if (err != MM_ERROR_NONE) {
701 MMCAM_LOG_WARNING("Get socket path failed 0x%x", err);
703 goto pipeline_creation_error;
706 g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
708 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
709 /* get video convert name */
710 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
712 if (videoconvert_name) {
713 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
714 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
716 MMCAM_LOG_ERROR("failed to get videoconvert element name");
719 /* check sink element in attribute */
720 mm_camcorder_get_attributes(handle, NULL,
721 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
726 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
728 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
730 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
732 /* reset attribute */
734 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
735 mm_attrs_set_data(attrs, attr_index, NULL, 0);
736 mm_attrs_commit(attrs, attr_index);
738 MMCAM_LOG_WARNING("attribute is NULL");
739 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
740 goto pipeline_creation_error;
743 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
745 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
748 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
749 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
750 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
751 goto pipeline_creation_error;
755 /* Set caps by rotation */
756 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
758 /* add elements to main pipeline */
759 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
760 MMCAM_LOG_ERROR("element_list add error.");
761 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
762 goto pipeline_creation_error;
766 if (!_mmcamcorder_link_elements(element_list)) {
767 MMCAM_LOG_ERROR("element link error.");
768 err = MM_ERROR_CAMCORDER_GST_LINK;
769 goto pipeline_creation_error;
773 g_list_free(element_list);
777 return MM_ERROR_NONE;
779 pipeline_creation_error:
780 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
781 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
782 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_QUE);
783 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS);
784 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_FILT);
785 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
786 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
787 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
788 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
791 g_list_free(element_list);
799 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
801 int err = MM_ERROR_NONE;
806 int a_enc = MM_AUDIO_CODEC_AMR;
807 int a_dev = MM_AUDIO_DEVICE_MIC;
809 char *err_name = NULL;
810 const char *audiosrc_name = NULL;
811 char *cat_name = NULL;
812 char *stream_type = NULL;
813 int stream_type_len = 0;
814 int stream_index = 0;
815 int buffer_interval = 0;
817 int replay_gain_enable = FALSE;
818 double replay_gain_ref_level = 0.0;
820 GstCaps *caps = NULL;
822 GList *element_list = NULL;
824 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
825 _MMCamcorderSubContext *sc = NULL;
826 _MMCamcorderGstElement *last_element = NULL;
827 type_element *AudiosrcElement = NULL;
829 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
831 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
832 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
833 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
837 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
838 if (err != MM_ERROR_NONE)
841 err = mm_camcorder_get_attributes(handle, &err_name,
842 MMCAM_AUDIO_DEVICE, &a_dev,
843 MMCAM_AUDIO_ENCODER, &a_enc,
844 MMCAM_AUDIO_ENCODER_BITRATE, &val,
845 MMCAM_AUDIO_SAMPLERATE, &rate,
846 MMCAM_AUDIO_FORMAT, &format,
847 MMCAM_AUDIO_CHANNEL, &channel,
848 MMCAM_AUDIO_VOLUME, &volume,
849 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
850 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
851 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
852 MMCAM_SOUND_STREAM_INDEX, &stream_index,
854 if (err != MM_ERROR_NONE) {
855 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
860 /* Check existence */
861 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
862 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
863 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
865 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
868 /* Create bin element */
869 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
871 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
872 cat_name = strdup("AudiomodemsrcElement");
874 /* MM_AUDIO_DEVICE_MIC or others */
875 cat_name = strdup("AudiosrcElement");
878 if (cat_name == NULL) {
879 MMCAM_LOG_ERROR("strdup failed.");
880 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
881 goto pipeline_creation_error;
884 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
885 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
888 _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
893 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
895 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
897 /* set sound stream info */
898 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
900 /* set audiosrc properties in ini configuration */
901 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
904 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
905 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
906 "AudioBufferInterval",
909 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
910 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
911 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
914 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
916 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
917 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
918 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
919 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
921 /* Set basic information */
922 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
924 const gchar* format_name = NULL;
926 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
929 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
930 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
932 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
933 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
936 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
938 format_name = "S16LE";
939 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
944 caps = gst_caps_new_simple("audio/x-raw",
945 "rate", G_TYPE_INT, rate,
946 "channels", G_TYPE_INT, channel,
947 "format", G_TYPE_STRING, format_name,
949 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
950 rate, channel, depth, volume);
952 /* what are the audio encoder which should get audio/x-raw-float? */
953 caps = gst_caps_new_simple("audio/x-raw",
954 "rate", G_TYPE_INT, rate,
955 "channels", G_TYPE_INT, channel,
956 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
958 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
959 rate, channel, BYTE_ORDER);
963 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
964 replay_gain_enable, replay_gain_ref_level);
966 if (replay_gain_enable) {
967 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
968 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
969 /* If num-tracks is not set, album gain and peak event is not come. */
970 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
974 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
975 gst_caps_unref(caps);
978 MMCAM_LOG_ERROR("create caps error");
979 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
980 goto pipeline_creation_error;
983 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
984 MMCAM_LOG_ERROR("element add error.");
985 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
986 goto pipeline_creation_error;
989 if (!_mmcamcorder_link_elements(element_list)) {
990 MMCAM_LOG_ERROR("element link error.");
991 err = MM_ERROR_CAMCORDER_GST_LINK;
992 goto pipeline_creation_error;
995 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
996 pad = gst_element_get_static_pad(last_element->gst, "src");
997 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
998 gst_object_unref(pad);
1000 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
1001 err = MM_ERROR_CAMCORDER_GST_LINK;
1002 goto pipeline_creation_error;
1005 gst_object_unref(pad);
1009 g_list_free(element_list);
1010 element_list = NULL;
1013 return MM_ERROR_NONE;
1015 pipeline_creation_error:
1016 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1017 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1018 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1019 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1020 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1023 g_list_free(element_list);
1024 element_list = NULL;
1031 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1036 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1041 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1042 type, codec, bitrate);
1046 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1047 /* audio encoder bitrate setting */
1049 case MM_AUDIO_CODEC_AMR:
1050 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1051 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1052 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1054 case MM_AUDIO_CODEC_MP3:
1055 set_value = bitrate / 1000;
1056 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1057 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1059 case MM_AUDIO_CODEC_AAC:
1060 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1061 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1064 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1068 /* video encoder bitrate setting */
1069 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1070 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1077 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1079 int err = MM_ERROR_NONE;
1084 int encodebin_profile = 0;
1085 int auto_audio_convert = 0;
1086 int auto_audio_resample = 0;
1087 int auto_color_space = 0;
1088 int cap_format = MM_PIXEL_FORMAT_INVALID;
1089 const char *gst_element_venc_name = NULL;
1090 const char *gst_element_aenc_name = NULL;
1091 const char *gst_element_ienc_name = NULL;
1092 const char *gst_element_mux_name = NULL;
1093 const char *gst_element_rsink_name = NULL;
1094 const char *gst_element_vscale_name = NULL;
1095 const char *str_profile = NULL;
1096 const char *str_aac = NULL;
1097 const char *str_aar = NULL;
1098 const char *str_acs = NULL;
1099 char *err_name = NULL;
1100 const char *videoconvert_name = NULL;
1101 GstCaps *audio_caps = NULL;
1102 GstCaps *video_caps = NULL;
1103 GstCaps *videoscale_caps = NULL;
1105 GList *element_list = NULL;
1107 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1108 _MMCamcorderSubContext *sc = NULL;
1109 type_element *VideoencElement = NULL;
1110 type_element *AudioencElement = NULL;
1111 type_element *ImageencElement = NULL;
1112 type_element *MuxElement = NULL;
1113 type_element *RecordsinkElement = NULL;
1114 type_element *VideoscaleElement = NULL;
1116 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1118 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1119 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1120 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1122 MMCAM_LOG_INFO("start - profile : %d", profile);
1124 /* Check existence */
1125 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1126 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1127 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1129 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1132 /* Create bin element */
1133 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1135 /* Create child element */
1136 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1137 GstCaps *caps_from_pad = NULL;
1138 char *caps_str = NULL;
1140 /* create appsrc and capsfilter */
1141 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1143 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1145 /* set appsrc as live source */
1146 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1147 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1148 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1150 /* set capsfilter */
1151 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1152 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1153 MMCAM_LOG_INFO("get pad from videosrc_filter");
1154 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1156 MMCAM_LOG_INFO("get pad from videosrc_que");
1157 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1160 MMCAM_LOG_ERROR("get videosrc_que src pad failed");
1161 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1162 goto pipeline_creation_error;
1165 caps_from_pad = gst_pad_get_allowed_caps(pad);
1166 video_caps = gst_caps_copy(caps_from_pad);
1167 gst_caps_unref(caps_from_pad);
1168 caps_from_pad = NULL;
1169 gst_object_unref(pad);
1173 video_caps = gst_caps_fixate(video_caps);
1176 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1180 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1181 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1182 goto pipeline_creation_error;
1185 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1186 if (sc->info_video->use_videoscale) {
1187 gst_caps_set_simple(video_caps,
1188 "width", G_TYPE_INT, sc->info_video->preview_width,
1189 "height", G_TYPE_INT, sc->info_video->preview_height,
1191 videoscale_caps = gst_caps_copy(video_caps);
1193 gst_caps_set_simple(video_caps,
1194 "width", G_TYPE_INT, sc->info_video->video_width,
1195 "height", G_TYPE_INT, sc->info_video->video_height,
1200 caps_str = gst_caps_to_string(video_caps);
1202 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1207 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1209 gst_caps_unref(video_caps);
1213 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1214 sc->info_video->use_videoscale) {
1215 if (!videoscale_caps) {
1216 MMCAM_LOG_ERROR("no videoscale caps");
1217 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1218 goto pipeline_creation_error;
1221 gst_caps_set_simple(videoscale_caps,
1222 "width", G_TYPE_INT, sc->info_video->video_width,
1223 "height", G_TYPE_INT, sc->info_video->video_height,
1226 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1227 CONFIGURE_CATEGORY_MAIN_RECORD,
1228 "VideoscaleElement",
1229 &VideoscaleElement);
1231 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1232 MMCAM_LOG_ERROR("failed to get videoscale element name");
1233 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1234 goto pipeline_creation_error;
1237 caps_str = gst_caps_to_string(videoscale_caps);
1239 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1244 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
1245 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
1247 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
1249 gst_caps_unref(videoscale_caps);
1250 videoscale_caps = NULL;
1253 /* release element_list, they will be placed out of encodesink bin */
1255 g_list_free(element_list);
1256 element_list = NULL;
1259 /* connect signal for ready to push buffer */
1260 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1261 _MMCAMCORDER_HANDLER_VIDEOREC,
1263 _mmcamcorder_ready_to_encode_callback,
1267 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1268 "tizenencodebin", "encodesink_encbin", element_list, err);
1270 /* check element availability */
1271 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1272 err = mm_camcorder_get_attributes(handle, &err_name,
1273 MMCAM_CAPTURE_FORMAT, &cap_format,
1276 err = mm_camcorder_get_attributes(handle, &err_name,
1277 MMCAM_AUDIO_ENCODER, &audio_enc,
1278 MMCAM_AUDIO_CHANNEL, &channel,
1279 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1280 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1284 if (err != MM_ERROR_NONE) {
1286 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1287 SAFE_FREE(err_name);
1289 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1292 goto pipeline_creation_error;
1295 MMCAM_LOG_INFO("Profile[%d]", profile);
1297 /* Set information */
1298 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1299 str_profile = "VideoProfile";
1300 str_aac = "VideoAutoAudioConvert";
1301 str_aar = "VideoAutoAudioResample";
1302 str_acs = "VideoAutoColorSpace";
1303 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1304 str_profile = "AudioProfile";
1305 str_aac = "AudioAutoAudioConvert";
1306 str_aar = "AudioAutoAudioResample";
1307 str_acs = "AudioAutoColorSpace";
1308 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1309 str_profile = "ImageProfile";
1310 str_aac = "ImageAutoAudioConvert";
1311 str_aar = "ImageAutoAudioResample";
1312 str_acs = "ImageAutoColorSpace";
1315 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1316 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1317 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1318 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1320 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1321 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1323 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1324 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1325 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1326 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1327 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1329 /* get video convert element name */
1330 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1333 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1334 int use_venc_queue = 0;
1336 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1338 if (!VideoencElement) {
1339 MMCAM_LOG_ERROR("Fail to get type element");
1340 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1341 goto pipeline_creation_error;
1344 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1345 /* set dummy element */
1346 gst_element_venc_name = "identity";
1348 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1351 if (gst_element_venc_name) {
1352 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1354 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1355 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1357 MMCAM_LOG_ERROR("Fail to get video encoder name");
1358 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1359 goto pipeline_creation_error;
1362 /* set color space converting element */
1363 if (auto_color_space) {
1364 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1366 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1367 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1369 /* set colorspace plugin property setting */
1370 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1372 /* fourcc type was removed in GST 1.0 */
1373 if (hcamcorder->use_zero_copy_format) {
1374 if (strstr(gst_element_venc_name, "omx")) {
1375 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1378 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1379 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1381 gst_caps_unref(video_caps);
1384 MMCAM_LOG_WARNING("failed to create caps");
1387 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1392 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1393 CONFIGURE_CATEGORY_MAIN_RECORD,
1394 "UseVideoEncoderQueue",
1397 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1400 if (sc->audio_disable == FALSE &&
1401 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1402 int use_aenc_queue = 0;
1404 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1405 if (!AudioencElement) {
1406 MMCAM_LOG_ERROR("Fail to get type element");
1407 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1408 goto pipeline_creation_error;
1411 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1413 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1414 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1416 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1417 audio_caps = gst_caps_new_simple("audio/x-raw",
1418 "channels", G_TYPE_INT, 1,
1420 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1421 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1422 gst_caps_unref(audio_caps);
1426 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1427 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1428 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1429 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1430 gst_caps_unref(audio_caps);
1432 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1435 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1436 CONFIGURE_CATEGORY_MAIN_RECORD,
1437 "UseAudioEncoderQueue",
1439 if (use_aenc_queue) {
1440 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1441 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1442 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1446 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1447 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1448 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1449 if (!ImageencElement) {
1450 MMCAM_LOG_ERROR("Fail to get type element");
1451 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1452 goto pipeline_creation_error;
1455 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1457 /* raw format - set dummy element */
1458 gst_element_ienc_name = "identity";
1461 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1462 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1466 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1467 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1469 MMCAM_LOG_ERROR("Fail to get type element");
1470 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1471 goto pipeline_creation_error;
1474 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1476 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1477 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1479 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1483 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1485 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1486 CONFIGURE_CATEGORY_MAIN_RECORD,
1487 "RecordsinkElement",
1488 &RecordsinkElement);
1489 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1491 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1493 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1496 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1499 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1500 /* property setting in ini */
1501 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1503 /* bitrate setting */
1504 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1505 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1508 if (sc->audio_disable == FALSE &&
1509 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1510 /* property setting in ini */
1511 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1513 /* bitrate setting */
1514 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1515 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1518 MMCAM_LOG_INFO("Element creation complete");
1520 /* Add element to bin */
1521 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1522 MMCAM_LOG_ERROR("element add error.");
1523 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1524 goto pipeline_creation_error;
1527 MMCAM_LOG_INFO("Element add complete");
1529 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1530 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1531 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1532 gst_object_unref(pad);
1534 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1535 err = MM_ERROR_CAMCORDER_GST_LINK;
1536 goto pipeline_creation_error;
1538 gst_object_unref(pad);
1541 if (sc->audio_disable == FALSE) {
1542 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1543 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1544 gst_object_unref(pad);
1546 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1547 err = MM_ERROR_CAMCORDER_GST_LINK;
1548 goto pipeline_creation_error;
1550 gst_object_unref(pad);
1553 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1554 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1555 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1556 gst_object_unref(pad);
1558 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1559 err = MM_ERROR_CAMCORDER_GST_LINK;
1560 goto pipeline_creation_error;
1562 gst_object_unref(pad);
1566 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1567 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1568 gst_object_unref(pad);
1570 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1571 err = MM_ERROR_CAMCORDER_GST_LINK;
1572 goto pipeline_creation_error;
1574 gst_object_unref(pad);
1578 MMCAM_LOG_INFO("Get pad complete");
1580 /* Link internal element */
1581 if (!_mmcamcorder_link_elements(element_list)) {
1582 MMCAM_LOG_ERROR("element link error.");
1583 err = MM_ERROR_CAMCORDER_GST_LINK;
1584 goto pipeline_creation_error;
1588 g_list_free(element_list);
1590 MMCAM_LOG_INFO("done");
1592 return MM_ERROR_NONE;
1594 pipeline_creation_error:
1595 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1597 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1598 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1599 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1600 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1601 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
1602 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1603 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1604 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1605 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1606 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1607 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1610 g_list_free(element_list);
1612 if (videoscale_caps)
1613 gst_caps_unref(videoscale_caps);
1619 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1621 int err = MM_ERROR_NONE;
1623 GstPad *srcpad = NULL;
1626 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1627 _MMCamcorderSubContext *sc = NULL;
1629 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1631 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1632 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1633 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1637 /** Create gstreamer element **/
1639 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1642 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1643 if (err != MM_ERROR_NONE)
1644 goto pipeline_creation_error;
1646 /* Set data probe function */
1647 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1648 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1649 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1651 MMCAM_LOG_ERROR("there is no queue plugin");
1652 goto pipeline_creation_error;
1656 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1657 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1659 gst_object_unref(srcpad);
1662 MMCAM_LOG_ERROR("failed to get srcpad");
1663 goto pipeline_creation_error;
1666 /* set dataprobe for video recording if it does not support dual stream. */
1667 if (sc->info_video->record_dual_stream == FALSE) {
1668 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1669 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1671 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1673 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1674 __mmcamcorder_video_dataprobe_record, hcamcorder);
1675 gst_object_unref(srcpad);
1679 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1681 /* set sync handler */
1682 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1684 gst_object_unref(bus);
1687 return MM_ERROR_NONE;
1689 pipeline_creation_error:
1690 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1695 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1697 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1698 _MMCamcorderSubContext *sc = NULL;
1700 /*MMCAM_LOG_INFO("start");*/
1702 mmf_return_if_fail(hcamcorder);
1703 mmf_return_if_fail(hcamcorder->sub_context);
1704 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1707 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1708 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1709 MMCAM_LOG_WARNING("set push_encoding_buffer RUN");
1714 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1716 int err = MM_ERROR_NONE;
1721 int rect_height = 0;
1723 int rotation = MM_DISPLAY_ROTATION_NONE;
1724 int flip = MM_FLIP_NONE;
1725 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1726 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1727 int origin_size = 0;
1730 int do_scaling = FALSE;
1731 int *dp_handle = NULL;
1732 MMCamWindowInfo *window_info = NULL;
1734 char *err_name = NULL;
1735 const char *videosink_name = NULL;
1737 GstElement *vsink = NULL;
1739 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1740 _MMCamcorderSubContext *sc = NULL;
1744 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1746 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1747 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1748 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1749 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1751 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1753 /* Get video display information */
1754 err = mm_camcorder_get_attributes(handle, &err_name,
1755 MMCAM_DISPLAY_RECT_X, &rect_x,
1756 MMCAM_DISPLAY_RECT_Y, &rect_y,
1757 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1758 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1759 MMCAM_DISPLAY_ROTATION, &rotation,
1760 MMCAM_DISPLAY_FLIP, &flip,
1761 MMCAM_DISPLAY_VISIBLE, &visible,
1762 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1763 MMCAM_DISPLAY_MODE, &display_mode,
1764 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1765 MMCAM_DISPLAY_SCALE, &zoom_attr,
1766 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1768 if (err != MM_ERROR_NONE) {
1770 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1771 SAFE_FREE(err_name);
1773 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1779 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1781 if (!videosink_name) {
1782 MMCAM_LOG_ERROR("failed to get videosink name");
1783 return MM_ERROR_CAMCORDER_INTERNAL;
1786 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
1788 /* Set display handle */
1789 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1792 MMCAM_LOG_INFO("xid = %lu )", xid);
1793 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1795 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1796 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1798 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1799 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
1802 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1803 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1805 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
1806 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1808 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1810 window_info = (MMCamWindowInfo *)dp_handle;
1811 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
1812 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1814 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
1816 } else if (!strcmp(videosink_name, "directvideosink")) {
1817 #ifdef _MMCAMCORDER_RM_SUPPORT
1818 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1819 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
1820 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1821 #endif /* _MMCAMCORDER_RM_SUPPORT */
1823 window_info = (MMCamWindowInfo *)dp_handle;
1824 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1825 window_info->surface_id,
1826 window_info->rect.x,
1827 window_info->rect.y,
1828 window_info->rect.width,
1829 window_info->rect.height);
1830 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1831 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1832 window_info->rect.x,
1833 window_info->rect.y,
1834 window_info->rect.width,
1835 window_info->rect.height);
1837 MMCAM_LOG_WARNING("dp_handle is null");
1840 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
1843 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1844 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1847 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1848 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1850 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1853 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1855 switch (zoom_attr) {
1856 case MM_DISPLAY_SCALE_DEFAULT:
1859 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1862 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1866 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
1871 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1872 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1873 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1874 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1876 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1877 if (!strcmp(videosink_name, "tizenwlsink")) {
1878 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1879 rect_x, rect_y, rect_width, rect_height);
1882 "dst-roi-x", rect_x,
1883 "dst-roi-y", rect_y,
1884 "dst-roi-w", rect_width,
1885 "dst-roi-h", rect_height,
1891 return MM_ERROR_NONE;
1895 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1898 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1899 _MMCamcorderSubContext *sc = NULL;
1901 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1903 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1905 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1908 case _MMCamcorder_CMD_PREVIEW_START:
1909 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1911 case _MMCamcorder_CMD_CAPTURE:
1912 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1915 MMCAM_LOG_WARNING("unknown command : %d", cmd);
1916 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1919 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1920 category, "FrameStabilityCount", &sc->frame_stability_count);
1922 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
1923 cmd, sc->frame_stability_count);
1925 return MM_ERROR_NONE;
1928 /* Retreive device information and set them to attributes */
1929 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
1931 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1932 _MMCamcorderSubContext *sc = NULL;
1933 GstCameraControl *control = NULL;
1934 GstCameraControlExifInfo exif_info = {0,};
1936 mmf_return_val_if_fail(hcamcorder, FALSE);
1937 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1939 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
1941 if (sc && sc->element) {
1942 int err = MM_ERROR_NONE;
1943 char *err_name = NULL;
1944 double focal_len = 0.0;
1946 /* Video input device */
1947 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
1948 /* Exif related information */
1949 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1950 if (control != NULL) {
1951 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
1952 if (exif_info.focal_len_denominator != 0)
1953 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
1955 MMCAM_LOG_ERROR("Fail to get camera control interface!");
1960 /* Set values to attributes */
1961 err = mm_camcorder_set_attributes(handle, &err_name,
1962 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
1964 if (err != MM_ERROR_NONE) {
1965 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
1966 SAFE_FREE(err_name);
1970 MMCAM_LOG_WARNING("Sub context isn't exist.");
1977 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name)
1979 return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24);
1982 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
1984 gboolean ret = TRUE;
1985 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
1986 _MMCamcorderSubContext *sc = NULL;
1987 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
1988 GstSample *sample = NULL;
1989 GstCaps *caps = NULL;
1991 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
1992 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
1993 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
1995 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
1996 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
1998 if (sc->drop_vframe > 0) {
1999 if (sc->pass_first_vframe > 0) {
2000 sc->pass_first_vframe--;
2001 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2004 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2005 return GST_PAD_PROBE_DROP;
2007 } else if (sc->frame_stability_count > 0) {
2008 sc->frame_stability_count--;
2009 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2010 return GST_PAD_PROBE_DROP;
2013 if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
2014 _mmcamcorder_measure_fps(&sc->kpi);
2016 /* The first H.264 frame should not be skipped for vstream cb. */
2017 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2018 !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2019 MMCAM_LOG_WARNING("Not ready for stream callback");
2020 return GST_PAD_PROBE_OK;
2023 /* make sample with buffer and caps */
2024 caps = gst_pad_get_allowed_caps(pad);
2025 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2027 sample = gst_sample_new(buffer, caps, NULL, NULL);
2028 gst_caps_unref(caps);
2029 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2031 ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
2033 gst_sample_unref(sample);
2036 return GST_PAD_PROBE_OK;
2038 return GST_PAD_PROBE_DROP;
2042 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2044 gboolean ret = TRUE;
2045 GstSample *sample = NULL;
2046 GstCaps *caps = NULL;
2048 caps = gst_pad_get_allowed_caps(pad);
2049 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2051 sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
2052 gst_caps_unref(caps);
2053 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2055 ret = _mmcamcorder_video_push_buffer(u_data, sample);
2057 gst_sample_unref(sample);
2059 return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
2063 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2065 MMCamcorderMuxedStreamDataType stream;
2066 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2067 _MMCamcorderSubContext *sc = NULL;
2068 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2071 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2072 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2073 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2075 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2076 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2078 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2079 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2080 return GST_PAD_PROBE_OK;
2083 /* call application callback */
2084 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2086 if (hcamcorder->mstream_cb) {
2087 stream.data = (void *)mapinfo.data;
2088 stream.length = mapinfo.size;
2089 stream.offset = sc->muxed_stream_offset;
2090 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2093 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2095 /* calculate current offset */
2096 sc->muxed_stream_offset += mapinfo.size;
2098 gst_buffer_unmap(buffer, &mapinfo);
2100 return GST_PAD_PROBE_OK;
2104 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2106 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2107 mmf_camcorder_t *hcamcorder = NULL;
2108 _MMCamcorderSubContext *sc = NULL;
2109 GstObject *parent = NULL;
2111 switch (GST_EVENT_TYPE(event)) {
2112 case GST_EVENT_UNKNOWN:
2113 /* upstream events */
2115 case GST_EVENT_SEEK:
2116 case GST_EVENT_NAVIGATION:
2117 case GST_EVENT_LATENCY:
2118 /* downstream serialized events */
2119 case GST_EVENT_BUFFERSIZE:
2120 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2124 GstTagList *tag_list = NULL;
2125 _MMCamcorderReplayGain *replay_gain = NULL;
2127 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2129 hcamcorder = MMF_CAMCORDER(u_data);
2130 if (!hcamcorder || !hcamcorder->sub_context) {
2131 MMCAM_LOG_WARNING("NULL handle");
2135 replay_gain = &hcamcorder->sub_context->replay_gain;
2137 gst_event_parse_tag(event, &tag_list);
2139 MMCAM_LOG_WARNING("failed to get tag list");
2143 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2144 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2148 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2149 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2153 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2154 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2158 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2159 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2163 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2164 replay_gain->track_peak, replay_gain->track_gain,
2165 replay_gain->album_peak, replay_gain->album_gain);
2168 case GST_EVENT_SEGMENT:
2169 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2171 hcamcorder = MMF_CAMCORDER(u_data);
2173 MMCAM_LOG_WARNING("NULL handle");
2177 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2179 MMCAM_LOG_WARNING("NULL sub context");
2183 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2184 MMCAM_LOG_WARNING("no encoder sink");
2188 parent = gst_pad_get_parent(pad);
2190 MMCAM_LOG_WARNING("get parent failed");
2194 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2195 const GstSegment *segment;
2196 gst_event_parse_segment(event, &segment);
2197 if (segment->format == GST_FORMAT_BYTES) {
2198 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2199 sc->muxed_stream_offset, segment->start);
2201 sc->muxed_stream_offset = (unsigned long long)segment->start;
2205 gst_object_unref(parent);
2209 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2211 /* bidirectional events */
2212 case GST_EVENT_FLUSH_START:
2213 case GST_EVENT_FLUSH_STOP:
2214 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2217 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2221 return GST_PAD_PROBE_OK;
2225 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2227 int result = MM_CAMCORDER_MR475;
2230 result = MM_CAMCORDER_MR475; /*AMR475*/
2231 else if (bitrate < 5900)
2232 result = MM_CAMCORDER_MR515; /*AMR515*/
2233 else if (bitrate < 6700)
2234 result = MM_CAMCORDER_MR59; /*AMR59*/
2235 else if (bitrate < 7400)
2236 result = MM_CAMCORDER_MR67; /*AMR67*/
2237 else if (bitrate < 7950)
2238 result = MM_CAMCORDER_MR74; /*AMR74*/
2239 else if (bitrate < 10200)
2240 result = MM_CAMCORDER_MR795; /*AMR795*/
2241 else if (bitrate < 12200)
2242 result = MM_CAMCORDER_MR102; /*AMR102*/
2244 result = MM_CAMCORDER_MR122; /*AMR122*/
2250 int _mmcamcorder_get_eos_message(MMHandleType handle)
2253 int ret = MM_ERROR_NONE;
2255 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2256 _MMCamcorderSubContext *sc = NULL;
2258 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2259 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2260 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2262 MMCAM_LOG_INFO("START");
2264 _MMCAMCORDER_LOCK(handle);
2266 if (sc->bget_eos == FALSE) {
2267 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2268 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2269 MMCAM_LOG_INFO("EOS signal received");
2271 MMCAM_LOG_ERROR("EOS wait time out");
2273 if (hcamcorder->error_code == MM_ERROR_NONE)
2274 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2277 MMCAM_LOG_INFO("already got EOS");
2280 _MMCAMCORDER_UNLOCK(handle);
2282 if (hcamcorder->error_code == MM_ERROR_NONE) {
2283 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2284 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2285 if (sc->info_video->b_committing)
2286 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2288 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2289 if (sc->info_audio->b_committing)
2290 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2293 ret = hcamcorder->error_code;
2294 MMCAM_LOG_ERROR("error 0x%x", ret);
2297 MMCAM_LOG_INFO("END");
2303 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2306 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2308 mmf_return_if_fail(handle && remove_element);
2309 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2313 for (i = first_elem ; i <= last_elem ; i++) {
2314 remove_element[i].gst = NULL;
2315 remove_element[i].id = _MMCAMCORDER_NONE;
2322 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2324 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2326 /* Check compatibility between codec and file format */
2327 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2328 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2329 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2330 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2331 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2332 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2335 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2337 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2338 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2340 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2341 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2342 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2343 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2344 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2345 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2348 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2350 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2351 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2355 return MM_ERROR_NONE;
2359 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2361 int err = MM_ERROR_NONE;
2362 int audio_codec = MM_AUDIO_CODEC_INVALID;
2363 int file_format = MM_FILE_FORMAT_INVALID;
2365 char *err_name = NULL;
2367 err = mm_camcorder_get_attributes(handle, &err_name,
2368 MMCAM_AUDIO_ENCODER, &audio_codec,
2369 MMCAM_FILE_FORMAT, &file_format,
2371 if (err != MM_ERROR_NONE) {
2372 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2373 SAFE_FREE(err_name);
2377 /* Check compatibility between audio codec and file format */
2378 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2384 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2386 int err = MM_ERROR_NONE;
2387 int video_codec = MM_VIDEO_CODEC_INVALID;
2388 int file_format = MM_FILE_FORMAT_INVALID;
2390 char *err_name = NULL;
2392 err = mm_camcorder_get_attributes(handle, &err_name,
2393 MMCAM_VIDEO_ENCODER, &video_codec,
2394 MMCAM_FILE_FORMAT, &file_format,
2396 if (err != MM_ERROR_NONE) {
2397 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2398 SAFE_FREE(err_name);
2402 /* Check compatibility between video codec and file format */
2403 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2409 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2411 const char* videosink_name = NULL;
2413 mmf_camcorder_t *hcamcorder = NULL;
2414 _MMCamcorderSubContext *sc = NULL;
2416 hcamcorder = MMF_CAMCORDER(handle);
2417 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2419 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2420 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2421 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2423 if (sc->element[videosink_index].gst) {
2424 /* Get videosink name */
2425 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2426 if (videosink_name == NULL) {
2427 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2431 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2432 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2433 !strcmp(videosink_name, "directvideosink")) {
2434 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2435 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2437 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2442 MMCAM_LOG_ERROR("Videosink element is null");
2448 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2450 const char* videosink_name = NULL;
2452 mmf_camcorder_t *hcamcorder = NULL;
2453 _MMCamcorderSubContext *sc = NULL;
2455 hcamcorder = MMF_CAMCORDER(handle);
2456 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2458 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2459 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2460 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2462 if (sc->element[videosink_index].gst) {
2463 /* Get videosink name */
2464 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2465 if (videosink_name == NULL) {
2466 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2470 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2471 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2472 !strcmp(videosink_name, "directvideosink")) {
2473 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2474 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2476 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2481 MMCAM_LOG_ERROR("Videosink element is null");
2487 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2490 _MMCamcorderSubContext *sc = NULL;
2492 mmf_camcorder_t *hcamcorder = NULL;
2494 hcamcorder = MMF_CAMCORDER(handle);
2495 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2497 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2499 MMCAM_LOG_INFO("sub context is not initialized");
2503 mm_camcorder_get_attributes(handle, NULL,
2504 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2505 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2506 MMCAM_CAMERA_FPS, &fps,
2509 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2511 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2512 sc->info_video->preview_width, sc->info_video->preview_height,
2513 fps, videosrc_rotate);
2517 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2523 unsigned int caps_fourcc = 0;
2524 gboolean do_set_caps = FALSE;
2525 char fourcc_string[sizeof(fourcc) + 1];
2526 gchar *caps_str = NULL;
2527 #ifdef _MMCAMCORDER_PRODUCT_TV
2530 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
2531 #endif /* _MMCAMCORDER_PRODUCT_TV */
2533 GstCaps *caps = NULL;
2535 mmf_camcorder_t *hcamcorder = NULL;
2536 _MMCamcorderSubContext *sc = NULL;
2538 hcamcorder = MMF_CAMCORDER(handle);
2539 mmf_return_val_if_fail(hcamcorder, FALSE);
2541 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2543 if (!sc || !(sc->element)) {
2544 MMCAM_LOG_INFO("sub context is not initialized");
2548 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2549 MMCAM_LOG_ERROR("Video src is NULL!");
2553 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2554 MMCAM_LOG_ERROR("Video filter is NULL!");
2558 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2559 int capture_width = 0;
2560 int capture_height = 0;
2561 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2563 mm_camcorder_get_attributes(handle, NULL,
2564 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2565 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2566 MMCAM_CAPTURE_WIDTH, &capture_width,
2567 MMCAM_CAPTURE_HEIGHT, &capture_height,
2568 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2569 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2571 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2572 motion_rate, capture_width, capture_height, fps_auto,
2573 sc->info_video->video_width, sc->info_video->video_height);
2575 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2576 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2578 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2579 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2580 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2583 sc->info_video->fps = fps;
2586 /* Interleaved format does not support rotation */
2587 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2588 /* store videosrc rotation */
2589 sc->videosrc_rotate = rotate;
2591 /* Define width, height and rotate in caps */
2593 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2594 This will be applied when rotate is 0, 180 if front camera. */
2595 set_rotate = rotate * 90;
2597 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2598 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2601 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2602 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2609 set_height = height;
2612 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2615 set_height = height;
2617 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2620 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2621 if (caps && !gst_caps_is_any(caps)) {
2622 GstStructure *structure = NULL;
2624 structure = gst_caps_get_structure(caps, 0);
2626 const gchar *format_string = NULL;
2628 int caps_height = 0;
2630 int caps_rotate = 0;
2632 format_string = gst_structure_get_string(structure, "format");
2634 caps_fourcc = _mmcamcorder_convert_fourcc_string_to_value(format_string);
2636 gst_structure_get(structure,
2637 "width", G_TYPE_INT, &caps_width,
2638 "height", G_TYPE_INT, &caps_height,
2639 "fps", G_TYPE_INT, &caps_fps,
2640 "rotate", G_TYPE_INT, &caps_rotate,
2643 #ifdef _MMCAMCORDER_PRODUCT_TV
2644 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2645 if (set_width == caps_width && set_height == caps_height &&
2646 set_rotate == caps_rotate && fps == caps_fps) {
2647 MMCAM_LOG_INFO("No need to replace caps.");
2649 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]",
2650 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2651 caps_width, caps_height, caps_fps, caps_rotate,
2652 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2653 set_width, set_height, fps, set_rotate);
2657 if (set_width == caps_width && set_height == caps_height &&
2658 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2659 MMCAM_LOG_INFO("No need to replace caps.");
2661 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]",
2662 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2663 caps_width, caps_height, caps_fps, caps_rotate,
2664 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2665 set_width, set_height, fps, set_rotate);
2669 #else /*_MMCAMCORDER_PRODUCT_TV */
2670 if (set_width == caps_width && set_height == caps_height &&
2671 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2672 MMCAM_LOG_INFO("No need to replace caps.");
2674 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]",
2675 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2676 caps_width, caps_height, caps_fps, caps_rotate,
2677 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2678 set_width, set_height, fps, set_rotate);
2681 #endif /*_MMCAMCORDER_PRODUCT_TV */
2683 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2687 MMCAM_LOG_INFO("No caps. set new one...");
2692 gst_caps_unref(caps);
2696 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2697 /* assume that it's camera capture mode */
2698 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2704 switch (sc->info_image->preview_format) {
2705 case MM_PIXEL_FORMAT_ENCODED_H264:
2706 #ifdef _MMCAMCORDER_PRODUCT_TV
2707 mm_camcorder_get_attributes(handle, NULL,
2708 MMCAM_DISPLAY_SURFACE, &display_surface_type,
2710 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
2711 __mmcamcorder_find_max_resolution(handle, &maxwidth, &maxheight) == false) {
2712 MMCAM_LOG_ERROR("can not find max resolution limitation");
2714 } else if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
2715 maxwidth = set_width;
2716 maxheight = set_height;
2718 #endif /* _MMCAMCORDER_PRODUCT_TV */
2719 caps = gst_caps_new_simple("video/x-h264",
2720 "width", G_TYPE_INT, set_width,
2721 "height", G_TYPE_INT, set_height,
2722 "framerate", GST_TYPE_FRACTION, fps, 1,
2723 "stream-format", G_TYPE_STRING, "byte-stream",
2724 #ifdef _MMCAMCORDER_PRODUCT_TV
2725 "maxwidth", G_TYPE_INT, maxwidth,
2726 "maxheight", G_TYPE_INT, maxheight,
2727 "alignment", G_TYPE_STRING, "au",
2728 #endif /* _MMCAMCORDER_PRODUCT_TV */
2731 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
2732 #ifdef _MMCAMCORDER_PRODUCT_TV
2733 caps = gst_caps_new_simple("video/x-jpeg",
2735 caps = gst_caps_new_simple("image/jpeg",
2737 "width", G_TYPE_INT, set_width,
2738 "height", G_TYPE_INT, set_height,
2739 "framerate", GST_TYPE_FRACTION, fps, 1,
2742 case MM_PIXEL_FORMAT_ENCODED_VP8:
2743 caps = gst_caps_new_simple("video/x-vp8",
2744 "width", G_TYPE_INT, set_width,
2745 "height", G_TYPE_INT, set_height,
2746 "framerate", GST_TYPE_FRACTION, fps, 1,
2749 case MM_PIXEL_FORMAT_ENCODED_VP9:
2750 caps = gst_caps_new_simple("video/x-vp9",
2751 "width", G_TYPE_INT, set_width,
2752 "height", G_TYPE_INT, set_height,
2753 "framerate", GST_TYPE_FRACTION, fps, 1,
2758 memcpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
2759 fourcc_string[sizeof(fourcc)] = '\0';
2760 caps = gst_caps_new_simple("video/x-raw",
2761 "format", G_TYPE_STRING, fourcc_string,
2762 "width", G_TYPE_INT, set_width,
2763 "height", G_TYPE_INT, set_height,
2764 "framerate", GST_TYPE_FRACTION, fps, 1,
2765 "rotate", G_TYPE_INT, set_rotate,
2771 MMCAM_LOG_ERROR("There are no caps");
2775 caps_str = gst_caps_to_string(caps);
2776 MMCAM_LOG_INFO("vidoesrc new caps set [%s]", caps_str);
2779 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2780 gst_caps_unref(caps);
2786 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2788 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2789 _MMCamcorderSubContext *sc = NULL;
2791 mmf_return_val_if_fail(hcamcorder, FALSE);
2793 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2797 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
2799 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2803 /* Interleaved format does not support FLIP */
2804 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2805 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2806 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2808 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
2810 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2811 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2813 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
2817 MMCAM_LOG_WARNING("element is NULL");
2825 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2827 GstCameraControl *control = NULL;
2828 _MMCamcorderSubContext *sc = NULL;
2829 GstElement *v_src = NULL;
2833 mmf_return_val_if_fail(handle, FALSE);
2835 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2839 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2842 MMCAM_LOG_WARNING("videosrc element is NULL");
2846 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2848 /* set anti-shake with camera control */
2849 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2850 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
2854 control = GST_CAMERA_CONTROL(v_src);
2855 if (gst_camera_control_set_ahs(control, set_value)) {
2856 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
2859 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
2866 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2868 _MMCamcorderSubContext *sc = NULL;
2869 GstElement *v_src = NULL;
2871 mmf_return_val_if_fail(handle, FALSE);
2873 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2877 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2879 MMCAM_LOG_WARNING("videosrc element is NULL");
2883 /* check property of videosrc element - support VDIS */
2884 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2885 int video_width = 0;
2886 int video_height = 0;
2888 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2889 MMCAM_LOG_INFO("ENABLE video stabilization");
2891 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2892 mm_camcorder_get_attributes(handle, NULL,
2893 MMCAM_VIDEO_WIDTH, &video_width,
2894 MMCAM_VIDEO_HEIGHT, &video_height,
2897 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2898 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
2899 video_width, video_height);
2901 g_object_set(G_OBJECT(v_src),
2902 "enable-vdis-mode", TRUE,
2905 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
2906 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2907 video_width, video_height);
2912 g_object_set(G_OBJECT(v_src),
2913 "enable-vdis-mode", FALSE,
2916 MMCAM_LOG_INFO("DISABLE video stabilization");
2918 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2919 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
2922 MMCAM_LOG_WARNING("no property for video stabilization");
2929 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2933 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2934 _MMCamcorderSubContext *sc = NULL;
2936 mmf_return_val_if_fail(hcamcorder, FALSE);
2938 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2942 mm_camcorder_get_attributes(handle, NULL,
2943 MMCAM_CAMERA_FPS, &fps,
2946 MMCAM_LOG_INFO("set %dx%d", width, height);
2948 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2952 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2954 _MMCamcorderSubContext *sc = NULL;
2956 if ((void *)handle == NULL) {
2957 MMCAM_LOG_WARNING("handle is NULL");
2961 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2963 MMCAM_LOG_WARNING("subcontext is NULL");
2967 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2968 MMCAM_LOG_WARNING("videosrc plugin is NULL");
2972 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
2974 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
2980 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
2982 _MMCamcorderSubContext *sc = NULL;
2984 if ((void *)handle == NULL) {
2985 MMCAM_LOG_WARNING("handle is NULL");
2989 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2991 MMCAM_LOG_WARNING("subcontext is NULL");
2995 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2996 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3000 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
3002 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3008 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3010 GstStructure *props = NULL;
3011 char stream_props[64] = {'\0',};
3013 if (element == NULL || stream_type == NULL || stream_index < 0) {
3014 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3018 snprintf(stream_props, sizeof(stream_props) - 1,
3019 "props,media.role=%s, media.parent_id=%d",
3020 stream_type, stream_index);
3022 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3024 props = gst_structure_from_string(stream_props, NULL);
3026 MMCAM_LOG_ERROR("failed to create GstStructure");
3030 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3032 gst_structure_free(props);
3039 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3041 int ret = MM_ERROR_NONE;
3042 _MMCamcorderSubContext *sc = NULL;
3043 mmf_camcorder_t *hcamcorder = NULL;
3044 const char *videodecoder_name = NULL;
3045 char videodecoder_name_final[32] = {'\0',};
3046 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3047 #ifdef _MMCAMCORDER_RM_SUPPORT
3048 int decoder_index = 0;
3049 #endif /* _MMCAMCORDER_RM_SUPPORT */
3051 if ((void *)handle == NULL) {
3052 MMCAM_LOG_WARNING("handle is NULL");
3056 hcamcorder = MMF_CAMCORDER(handle);
3058 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3060 MMCAM_LOG_WARNING("subcontext is NULL");
3064 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3065 hcamcorder->recreate_decoder == FALSE) {
3066 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3067 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3071 mm_camcorder_get_attributes(handle, NULL,
3072 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3075 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3076 MMCAM_LOG_INFO("no need to control decoder element");
3080 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3081 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3082 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3086 MMCAM_LOG_INFO("start");
3088 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
3089 if (videodecoder_name == NULL) {
3090 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
3094 /* set state as NULL */
3095 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3096 if (ret != MM_ERROR_NONE) {
3097 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3101 /* remove decoder - pads will be unlinked automatically in remove function */
3102 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3103 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3104 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3108 /* check decoder element */
3109 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3110 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3111 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3112 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3115 #ifdef _MMCAMCORDER_RM_SUPPORT
3116 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3117 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3120 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
3121 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
3123 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3124 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
3126 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
3128 #endif /* _MMCAMCORDER_RM_SUPPORT */
3129 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
3130 #ifdef _MMCAMCORDER_RM_SUPPORT
3132 #endif /* _MMCAMCORDER_RM_SUPPORT */
3134 /* create decoder */
3135 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "videosrc_decode");
3136 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3137 MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
3141 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
3143 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3144 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3145 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3147 /* add to pipeline */
3148 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3149 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3150 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3151 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3156 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3157 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3158 MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
3160 MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
3164 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3165 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3166 MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
3168 MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
3172 /* set state READY */
3173 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3174 if (ret != MM_ERROR_NONE) {
3175 MMCAM_LOG_ERROR("failed to set READY to decoder");
3179 MMCAM_LOG_INFO("done");
3184 #ifdef _MMCAMCORDER_PRODUCT_TV
3185 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3187 _MMCamcorderSubContext *sc = NULL;
3188 mmf_camcorder_t *hcamcorder = NULL;
3190 const gchar *mime = NULL;
3192 GstCaps *decsink_caps = NULL;
3193 GstStructure *decsink_struct = NULL;
3195 mmf_return_val_if_fail(handle, false);
3196 mmf_return_val_if_fail(max_width, false);
3197 mmf_return_val_if_fail(max_height, false);
3199 hcamcorder = MMF_CAMCORDER(handle);
3200 mmf_return_val_if_fail(hcamcorder, false);
3202 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3204 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3206 MMCAM_LOG_ERROR("There are no decoder caps");
3210 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3211 if (!decsink_caps) {
3212 gst_object_unref(sinkpad);
3213 MMCAM_LOG_ERROR("There is no decoder sink caps");
3217 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3218 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3219 if (!decsink_struct) {
3220 MMCAM_LOG_ERROR("There are no structure from caps");
3221 gst_object_unref(decsink_caps);
3222 gst_object_unref(sinkpad);
3225 mime = gst_structure_get_name(decsink_struct);
3226 if (!strcmp(mime, "video/x-h264")) {
3227 MMCAM_LOG_INFO("h264 caps structure found");
3228 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3229 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3230 if (gst_structure_has_field(decsink_struct, "maxheight"))
3231 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3233 } else if (!strcmp(mime, "video/x-jpeg")) {
3234 MMCAM_LOG_INFO("mjpeg caps structure found");
3235 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3236 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3237 if (gst_structure_has_field(decsink_struct, "maxheight"))
3238 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3242 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3243 gst_object_unref(decsink_caps);
3244 gst_object_unref(sinkpad);
3246 if (*max_width <= 0 || *max_height <= 0)
3251 #endif /* _MMCAMCORDER_PRODUCT_TV */