4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
25 #include <gst/allocators/gsttizenmemory.h>
26 #include <gst/audio/audio-format.h>
27 #include <gst/video/videooverlay.h>
28 #include <gst/video/cameracontrol.h>
32 #include <tbm_bufmgr.h>
33 #include <tbm_surface.h>
34 #include <tbm_surface_internal.h>
36 #include "mm_camcorder_internal.h"
37 #include "mm_camcorder_gstcommon.h"
39 /*-----------------------------------------------------------------------
40 | GLOBAL VARIABLE DEFINITIONS for internal |
41 -----------------------------------------------------------------------*/
42 /* Table for compatibility between audio codec and file format */
43 gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
44 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
45 /*AMR*/ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
46 /*G723.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
47 /*MP3*/ { 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
48 /*OGG*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
49 /*AAC*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
50 /*WMA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 /*MMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
52 /*ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
53 /*WAVE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
54 /*WAVE_NEW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
55 /*MIDI*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
56 /*IMELODY*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
57 /*MXMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
58 /*MPA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
59 /*MP2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
60 /*G711*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
61 /*G722*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
62 /*G722.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
63 /*G722.2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
64 /*G723*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
65 /*G726*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
66 /*G728*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
67 /*G729*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
68 /*G729A*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
69 /*G729.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
70 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
71 /*AAC_LC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
72 /*AAC_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
73 /*AAC_SRS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
74 /*AAC_LTP*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
75 /*AAC_HE_V1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
76 /*AAC_HE_V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
77 /*AC3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
78 /*ALAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
79 /*ATRAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
80 /*SPEEX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
81 /*VORBIS*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
82 /*AIFF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
83 /*AU*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
84 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
85 /*PCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 /*ALAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 /*MULAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
88 /*MS_ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
91 /* Table for compatibility between video codec and file format */
92 gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
93 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
94 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
95 /*H263*/ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
96 /*H264*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
97 /*H26L*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
98 /*MPEG4*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
99 /*MPEG1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
100 /*WMV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
101 /*DIVX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
102 /*XVID*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
103 /*H261*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
104 /*H262*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
105 /*H263V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
106 /*H263V3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
107 /*MJPEG*/ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
108 /*MPEG2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
109 /*MPEG4_SIMPLE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
110 /*MPEG4_ADV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
111 /*MPEG4_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
112 /*MPEG4_CORE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
113 /*MPEG4_ACE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
114 /*MPEG4_ARTS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
115 /*MPEG4_AVC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
116 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
117 /*VC1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
118 /*AVS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
119 /*CINEPAK*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
120 /*INDEO*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
121 /*THEORA*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
125 /*-----------------------------------------------------------------------
126 | LOCAL VARIABLE DEFINITIONS for internal |
127 -----------------------------------------------------------------------*/
128 #define USE_AUDIO_CLOCK_TUNE
129 #define _MMCAMCORDER_WAIT_EOS_TIME 60.0 /* sec */
130 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM 6
131 #define _MMCAMCORDER_NANOSEC_PER_1SEC 1000000000
132 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC 1000
135 /*-----------------------------------------------------------------------
136 | LOCAL FUNCTION PROTOTYPES: |
137 -----------------------------------------------------------------------*/
138 /* STATIC INTERNAL FUNCTION */
140 * These are video data probing functions.
141 * If there are pads which set probe callback by gst_pad_add_probe(),
142 * the functions will be called when data stream pass through the pad.
144 * @param[in] pad probing pad which calls this function.
145 * @param[in] buffer buffer which contains stream data.
146 * @param[in] u_data user data.
147 * @return Refer #GstPadProbeReturn in gstpad.h
149 * @see __mmcamcorder_create_preview_pipeline()
151 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
152 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
154 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
155 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name);
156 #ifdef _MMCAMCORDER_PRODUCT_TV
157 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height);
158 #endif /* _MMCAMCORDER_PRODUCT_TV */
160 static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info);
161 static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
163 /*=======================================================================================
164 | FUNCTION DEFINITIONS |
165 =======================================================================================*/
166 static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
168 mmf_return_val_if_fail(buffer, FALSE);
169 mmf_return_val_if_fail(map_info, FALSE);
170 mmf_return_val_if_fail(stream, FALSE);
172 switch (stream->format) {
173 case MM_PIXEL_FORMAT_NV12: /* fall through */
174 case MM_PIXEL_FORMAT_NV21:
175 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
176 stream->data.yuv420sp.y = map_info->data;
177 stream->data.yuv420sp.length_y = stream->width * stream->height;
178 stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
179 stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
180 stream->stride[0] = stream->width;
181 stream->elevation[0] = stream->height;
182 stream->stride[1] = stream->width;
183 stream->elevation[1] = stream->height >> 1;
184 stream->num_planes = 2;
187 case MM_PIXEL_FORMAT_I420:
188 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
189 stream->data.yuv420p.y = map_info->data;
190 stream->data.yuv420p.length_y = stream->width * stream->height;
191 stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
192 stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
193 stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
194 stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
195 stream->stride[0] = stream->width;
196 stream->elevation[0] = stream->height;
197 stream->stride[1] = stream->stride[2] = stream->width >> 1;
198 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
199 stream->num_planes = 3;
202 case MM_PIXEL_FORMAT_422P:
203 stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
204 stream->data.yuv422p.y = map_info->data;
205 stream->data.yuv422p.length_y = stream->width * stream->height;
206 stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
207 stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
208 stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
209 stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
210 stream->stride[0] = stream->width;
211 stream->elevation[0] = stream->height;
212 stream->stride[1] = stream->stride[2] = stream->width;
213 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
214 stream->num_planes = 3;
217 case MM_PIXEL_FORMAT_YUYV: /* fall through */
218 case MM_PIXEL_FORMAT_UYVY: /* fall through */
219 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
220 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
221 stream->data.yuv422.yuv = map_info->data;
222 stream->data.yuv422.length_yuv = stream->length_total;
223 stream->stride[0] = stream->width << 1;
224 stream->elevation[0] = stream->height;
225 stream->num_planes = 1;
228 case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
229 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
230 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
231 stream->data.encoded.data = map_info->data;
232 stream->data.encoded.length_data = stream->length_total;
233 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
234 stream->num_planes = 1;
237 case MM_PIXEL_FORMAT_INVZ:
238 stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
239 stream->data.depth.data = map_info->data;
240 stream->data.depth.length_data = stream->length_total;
241 stream->stride[0] = stream->width << 1;
242 stream->elevation[0] = stream->height;
243 stream->num_planes = 1;
246 case MM_PIXEL_FORMAT_RGBA: /* fall through */
247 case MM_PIXEL_FORMAT_ARGB:
248 stream->data_type = MM_CAM_STREAM_DATA_RGB;
249 stream->data.rgb.data = map_info->data;
250 stream->data.rgb.length_data = stream->length_total;
251 stream->stride[0] = stream->width << 2;
252 stream->elevation[0] = stream->height;
253 stream->num_planes = 1;
257 _mmcam_dbg_err("unsupported format[%d]", stream->format);
265 static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info)
267 mmf_return_val_if_fail(ts_info, FALSE);
268 mmf_return_val_if_fail(stream, FALSE);
270 switch (stream->format) {
271 case MM_PIXEL_FORMAT_NV12: /* fall through */
272 case MM_PIXEL_FORMAT_NV21:
273 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
274 stream->num_planes = 2;
275 stream->data.yuv420sp.y = ts_info->planes[0].ptr;
276 stream->data.yuv420sp.length_y = ts_info->planes[0].size;
277 stream->data.yuv420sp.uv = ts_info->planes[1].ptr;
278 stream->data.yuv420sp.length_uv = ts_info->planes[1].size;
281 case MM_PIXEL_FORMAT_I420:
282 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
283 stream->num_planes = 3;
284 stream->data.yuv420p.y = ts_info->planes[0].ptr;
285 stream->data.yuv420p.length_y = ts_info->planes[0].size;
286 stream->data.yuv420p.u = ts_info->planes[1].ptr;
287 stream->data.yuv420p.length_u = ts_info->planes[1].size;
288 stream->data.yuv420p.v = ts_info->planes[2].ptr;
289 stream->data.yuv420p.length_v = ts_info->planes[2].size;
293 _mmcam_dbg_err("unsupported format[%d]", stream->format);
301 gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstBuffer *buffer, gboolean is_preview)
305 gboolean ret_cb = TRUE;
306 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
307 _MMCamcorderSubContext *sc = NULL;
308 MMCamcorderVideoStreamDataType stream;
310 tbm_surface_h t_surface = NULL;
311 tbm_surface_info_s ts_info;
313 GstMemory *memory = NULL;
316 mmf_return_val_if_fail(hcamcorder, FALSE);
317 mmf_return_val_if_fail(buffer, FALSE);
318 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
320 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
321 mmf_return_val_if_fail(sc, FALSE);
323 /* clear data structure */
324 memset(&map_info, 0x0, sizeof(GstMapInfo));
325 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
327 stream.format = sc->info_image->preview_format;
330 stream.width = sc->info_video->preview_width;
331 stream.height = sc->info_video->preview_height;
333 /* video recording buffer */
334 stream.width = sc->info_video->video_width;
335 stream.height = sc->info_video->video_height;
339 _mmcam_dbg_log("VideoStreamData : resolution[%dx%d], format[%d]",
340 stream.width, stream.height, stream.format);
343 /* set size and timestamp */
344 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format))
345 memory = gst_buffer_get_all_memory(buffer);
347 memory = gst_buffer_peek_memory(buffer, 0);
349 _mmcam_dbg_err("GstMemory get failed from buffer %p", buffer);
353 /* set zero-copy related information */
354 if (hcamcorder->use_zero_copy_format) {
355 t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
357 if (tbm_surface_get_info(t_surface, &ts_info) != TBM_SURFACE_ERROR_NONE) {
358 _mmcam_dbg_err("failed to get tbm surface[%p] info", t_surface);
359 goto _INVOKE_VIDEO_STREAM_CB_DONE;
362 /* set bo, stride and elevation */
363 num_bos = gst_tizen_memory_get_num_bos(memory);
364 for (i = 0 ; i < num_bos ; i++)
365 stream.bo[i] = gst_tizen_memory_get_bos(memory, i);
367 for (i = 0 ; i < ts_info.num_planes ; i++) {
368 stream.stride[i] = ts_info.planes[i].stride;
369 stream.elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
370 /*_mmcam_dbg_log("[%d] %dx%d", i, stream.stride[i], stream.elevation[i]);*/
373 stream.length_total = ts_info.size;
374 stream.internal_buffer = buffer;
376 if (!__mmcamcorder_set_stream_data_tbm(&stream, &ts_info))
377 goto _INVOKE_VIDEO_STREAM_CB_DONE;
379 stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
381 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE) ||
382 !__mmcamcorder_set_stream_data_normal(&stream, buffer, &map_info))
383 goto _INVOKE_VIDEO_STREAM_CB_DONE;
386 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
388 /* invoke application callback */
390 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
391 if (hcamcorder->vstream_cb)
392 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
393 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
395 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
396 if (hcamcorder->vedecision_cb)
397 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
398 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
401 _INVOKE_VIDEO_STREAM_CB_DONE:
402 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
403 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
404 tbm_bo_unmap(stream.bo[i]);
408 gst_memory_unmap(memory, &map_info);
410 if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format))
411 gst_memory_unref(memory);
417 int _mmcamcorder_create_preview_elements(MMHandleType handle)
419 int err = MM_ERROR_NONE;
421 int camera_rotate = 0;
425 int capture_width = 0;
426 int capture_height = 0;
427 int capture_jpg_quality = 100;
428 int video_stabilization = 0;
430 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
431 const char *videosrc_name = NULL;
432 const char *videosink_name = NULL;
433 const char *videoconvert_name = NULL;
434 char *err_name = NULL;
435 char *socket_path = NULL;
437 #ifdef _MMCAMCORDER_RM_SUPPORT
438 int decoder_index = 0;
439 char decoder_name[20] = {'\0',};
440 #endif /* _MMCAMCORDER_RM_SUPPORT */
441 GstElement *sink_element = NULL;
442 GstCameraControl *control = NULL;
443 int sink_element_size = 0;
447 GList *element_list = NULL;
449 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
450 _MMCamcorderSubContext *sc = NULL;
451 type_element *VideosrcElement = NULL;
452 type_int_array *input_index = NULL;
454 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
456 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
457 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
458 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
462 /* Check existence */
463 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
464 if (sc->element[i].gst) {
465 if (((GObject *)sc->element[i].gst)->ref_count > 0)
466 gst_object_unref(sc->element[i].gst);
468 _mmcam_dbg_log("element[index:%d] is Already existed.", i);
472 /* Get video device index info */
473 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
474 CONFIGURE_CATEGORY_CTRL_CAMERA,
477 if (input_index == NULL) {
478 _mmcam_dbg_err("Failed to get input_index");
479 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
482 err = mm_camcorder_get_attributes(handle, &err_name,
483 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
484 MMCAM_CAMERA_FPS, &fps,
485 MMCAM_CAMERA_ROTATION, &camera_rotate,
486 MMCAM_CAMERA_FLIP, &camera_flip,
487 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
488 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
489 MMCAM_CAPTURE_WIDTH, &capture_width,
490 MMCAM_CAPTURE_HEIGHT, &capture_height,
491 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
492 MMCAM_IMAGE_ENCODER, &codectype,
493 MMCAM_IMAGE_ENCODER_QUALITY, &capture_jpg_quality,
494 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
495 MMCAM_DISPLAY_SURFACE, &display_surface_type,
497 if (err != MM_ERROR_NONE) {
498 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
503 if (hcamcorder->support_user_buffer) {
504 err = mm_camcorder_get_attributes(handle, NULL,
505 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
507 if (err != MM_ERROR_NONE || fd_number < 1) {
508 _mmcam_dbg_err("get user buffer fd failed 0x%x, number %d", err, fd_number);
513 for (i = 0 ; i < fd_number ; i++)
514 _mmcam_dbg_log("fds[%d] %d", i, fds[i]);
518 /* Get fourcc from picture format */
519 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
521 /* Get videosrc element and its name from configure */
522 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
523 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
526 _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
529 * Create child element
531 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
533 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
535 /* init high-speed-fps */
536 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
538 /* set capture size, quality and flip setting which were set before mm_camcorder_realize */
539 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
540 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
541 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-jpg-quality", capture_jpg_quality);
542 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
544 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
546 /* set camera flip */
547 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
549 /* set video stabilization mode */
550 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
552 /* set anti handshake mode */
553 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
555 if (sc->is_modified_rate)
556 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
558 /* Set basic infomation of videosrc element */
559 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
561 /* Set video device index */
562 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
563 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
565 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
568 /* set user buffer fd to videosrc element */
569 if (hcamcorder->support_user_buffer) {
570 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
571 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
572 _mmcam_dbg_err("set user buffer fd failed");
573 goto pipeline_creation_error;
577 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
578 /* get recreate_decoder flag */
579 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
580 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
582 &hcamcorder->recreate_decoder);
585 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
586 int preview_bitrate = 0;
587 int gop_interval = 0;
588 mm_camcorder_get_attributes(handle, NULL,
589 MMCAM_ENCODED_PREVIEW_BITRATE, &preview_bitrate,
590 MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
593 /* set encoded preview bitrate */
594 if (!_mmcamcorder_set_encoded_preview_bitrate(handle, preview_bitrate))
595 _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_bitrate failed");
597 /* set encoded preview iframe interval */
598 if (!_mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval))
599 _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_gop_interval failed");
602 if (display_surface_type != MM_DISPLAY_SURFACE_NULL) {
603 const char *videodecoder_name = NULL;
604 /* case of decoder element */
605 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
606 /* get video decoder element and name for H.264 format */
607 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
608 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
609 "VideodecoderElementH264",
610 &sc->VideodecoderElementH264);
611 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264,
613 if (videodecoder_name) {
614 #ifdef _MMCAMCORDER_RM_SUPPORT
615 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
618 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
619 _mmcam_dbg_log("encoded preview decoder_name [%s], video decoder element [%s]",
620 decoder_name, videodecoder_name);
621 /* create decoder element */
622 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
623 #else /* _MMCAMCORDER_RM_SUPPORT */
624 _mmcam_dbg_log("video decoder element [%s]", videodecoder_name);
625 /* create decoder element */
626 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name, "videosrc_decode", element_list, err);
627 #endif /* _MMCAMCORDER_RM_SUPPORT */
628 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
630 _mmcam_dbg_err("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
631 goto pipeline_creation_error;
633 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
634 #ifdef _MMCAMCORDER_RM_SUPPORT
635 /* get video decoder element and name for MJPEG format */
636 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
637 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
638 "VideodecoderElementH264",
639 &sc->VideodecoderElementH264);
640 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264,
642 if (videodecoder_name) {
643 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
644 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_uhd_mjpegdec");
646 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_mjpegdec");
647 _mmcam_dbg_log("encoded preview decoder_name [%s], video decoder element [%s]",
648 decoder_name, videodecoder_name);
649 /* create decoder element */
650 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
651 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
653 _mmcam_dbg_err("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
654 goto pipeline_creation_error;
656 #else /* _MMCAMCORDER_RM_SUPPORT */
657 _mmcam_dbg_log("video decoder element [jpegdec]");
658 /* create decoder element */
659 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, "jpegdec", "videosrc_decode", element_list, err);
660 #endif /* _MMCAMCORDER_RM_SUPPORT */
664 _mmcam_dbg_log("Current mode[%d]", hcamcorder->type);
666 /* Get videosink name */
667 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
669 if (!videosink_name) {
670 _mmcam_dbg_err("failed to get videosink name");
671 goto pipeline_creation_error;
674 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
676 _mmcam_dbg_log("videosink_name: %s", videosink_name);
678 if (display_surface_type == MM_DISPLAY_SURFACE_REMOTE) {
679 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "ipc_sink", element_list, err);
681 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
683 err = mm_camcorder_get_attributes(handle, &err_name,
684 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
686 if (err != MM_ERROR_NONE) {
687 _mmcam_dbg_warn("Get socket path failed 0x%x", err);
689 goto pipeline_creation_error;
692 g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
694 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
695 /* get video convert name */
696 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
698 if (videoconvert_name) {
699 _mmcam_dbg_log("videoconvert element name : %s", videoconvert_name);
700 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
702 _mmcam_dbg_err("failed to get videoconvert element name");
705 /* check sink element in attribute */
706 mm_camcorder_get_attributes(handle, NULL,
707 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
712 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
714 _mmcam_dbg_log("reuse sink element %p in attribute", sink_element);
716 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
718 /* reset attribute */
720 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
721 mm_attrs_set_data(attrs, attr_index, NULL, 0);
722 mm_attrs_commit(attrs, attr_index);
724 _mmcam_dbg_warn("attribute is NULL");
725 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
726 goto pipeline_creation_error;
729 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
731 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
734 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
735 _mmcam_dbg_err("_mmcamcorder_videosink_window_set error");
736 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
737 goto pipeline_creation_error;
741 /* Set caps by rotation */
742 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
744 /* add elements to main pipeline */
745 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
746 _mmcam_dbg_err("element_list add error.");
747 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
748 goto pipeline_creation_error;
752 if (!_mmcamcorder_link_elements(element_list)) {
753 _mmcam_dbg_err("element link error.");
754 err = MM_ERROR_CAMCORDER_GST_LINK;
755 goto pipeline_creation_error;
759 g_list_free(element_list);
763 return MM_ERROR_NONE;
765 pipeline_creation_error:
766 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
767 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
768 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_QUE);
769 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS);
770 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_FILT);
771 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
772 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
773 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
774 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
777 g_list_free(element_list);
785 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
787 int err = MM_ERROR_NONE;
792 int a_enc = MM_AUDIO_CODEC_AMR;
793 int a_dev = MM_AUDIO_DEVICE_MIC;
795 char *err_name = NULL;
796 const char *audiosrc_name = NULL;
797 char *cat_name = NULL;
798 char *stream_type = NULL;
799 int stream_type_len = 0;
800 int stream_index = 0;
801 int buffer_interval = 0;
803 int replay_gain_enable = FALSE;
804 double replay_gain_ref_level = 0.0;
806 GstCaps *caps = NULL;
808 GList *element_list = NULL;
810 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
811 _MMCamcorderSubContext *sc = NULL;
812 _MMCamcorderGstElement *last_element = NULL;
813 type_element *AudiosrcElement = NULL;
815 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
817 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
818 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
819 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
823 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
824 if (err != MM_ERROR_NONE)
827 err = mm_camcorder_get_attributes(handle, &err_name,
828 MMCAM_AUDIO_DEVICE, &a_dev,
829 MMCAM_AUDIO_ENCODER, &a_enc,
830 MMCAM_AUDIO_ENCODER_BITRATE, &val,
831 MMCAM_AUDIO_SAMPLERATE, &rate,
832 MMCAM_AUDIO_FORMAT, &format,
833 MMCAM_AUDIO_CHANNEL, &channel,
834 MMCAM_AUDIO_VOLUME, &volume,
835 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
836 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
837 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
838 MMCAM_SOUND_STREAM_INDEX, &stream_index,
840 if (err != MM_ERROR_NONE) {
841 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
846 /* Check existence */
847 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
848 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
849 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
851 _mmcam_dbg_log("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
854 /* Create bin element */
855 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
857 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
858 cat_name = strdup("AudiomodemsrcElement");
860 /* MM_AUDIO_DEVICE_MIC or others */
861 cat_name = strdup("AudiosrcElement");
864 if (cat_name == NULL) {
865 _mmcam_dbg_err("strdup failed.");
866 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
867 goto pipeline_creation_error;
870 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
871 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
874 _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
879 _mmcam_dbg_log("Audio src name : %s", audiosrc_name);
881 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
883 /* set sound stream info */
884 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
886 /* set audiosrc properties in ini configuration */
887 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
890 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
891 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
892 "AudioBufferInterval",
895 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
896 _mmcam_dbg_log("set audiosrc block size %d", blocksize);
897 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
900 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
902 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
903 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
904 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
905 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
907 /* Set basic infomation */
908 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
910 const gchar* format_name = NULL;
912 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
915 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
916 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
918 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
919 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
922 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
924 format_name = "S16LE";
925 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
930 caps = gst_caps_new_simple("audio/x-raw",
931 "rate", G_TYPE_INT, rate,
932 "channels", G_TYPE_INT, channel,
933 "format", G_TYPE_STRING, format_name,
935 _mmcam_dbg_log("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
936 rate, channel, depth, volume);
938 /* what are the audio encoder which should get audio/x-raw-float? */
939 caps = gst_caps_new_simple("audio/x-raw",
940 "rate", G_TYPE_INT, rate,
941 "channels", G_TYPE_INT, channel,
942 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
944 _mmcam_dbg_log("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
945 rate, channel, BYTE_ORDER);
949 _mmcam_dbg_log("Replay gain - enable : %d, reference level : %lf",
950 replay_gain_enable, replay_gain_ref_level);
952 if (replay_gain_enable) {
953 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
954 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
955 /* If num-tracks is not set, album gain and peak event is not come. */
956 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
960 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
961 gst_caps_unref(caps);
964 _mmcam_dbg_err("create caps error");
965 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
966 goto pipeline_creation_error;
969 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
970 _mmcam_dbg_err("element add error.");
971 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
972 goto pipeline_creation_error;
975 if (!_mmcamcorder_link_elements(element_list)) {
976 _mmcam_dbg_err("element link error.");
977 err = MM_ERROR_CAMCORDER_GST_LINK;
978 goto pipeline_creation_error;
981 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
982 pad = gst_element_get_static_pad(last_element->gst, "src");
983 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
984 gst_object_unref(pad);
986 _mmcam_dbg_err("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
987 err = MM_ERROR_CAMCORDER_GST_LINK;
988 goto pipeline_creation_error;
991 gst_object_unref(pad);
995 g_list_free(element_list);
999 return MM_ERROR_NONE;
1001 pipeline_creation_error:
1002 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1003 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1004 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1005 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1006 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1009 g_list_free(element_list);
1010 element_list = NULL;
1017 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1022 _mmcam_dbg_warn("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1027 _mmcam_dbg_warn("[type %d, codec %d] too small bitrate[%d], use default",
1028 type, codec, bitrate);
1032 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1033 /* audio encoder bitrate setting */
1035 case MM_AUDIO_CODEC_AMR:
1036 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1037 _mmcam_dbg_log("Set AMR encoder mode [%d]", set_value);
1038 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1040 case MM_AUDIO_CODEC_MP3:
1041 set_value = bitrate / 1000;
1042 _mmcam_dbg_log("Set MP3 encoder bitrate [%d] kbps", set_value);
1043 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1045 case MM_AUDIO_CODEC_AAC:
1046 _mmcam_dbg_log("Set AAC encoder bitrate [%d] bps", bitrate);
1047 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1050 _mmcam_dbg_warn("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1054 /* video encoder bitrate setting */
1055 _mmcam_dbg_log("Set video encoder bitrate %d", bitrate);
1056 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1063 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1065 int err = MM_ERROR_NONE;
1070 int encodebin_profile = 0;
1071 int auto_audio_convert = 0;
1072 int auto_audio_resample = 0;
1073 int auto_color_space = 0;
1074 int cap_format = MM_PIXEL_FORMAT_INVALID;
1075 const char *gst_element_venc_name = NULL;
1076 const char *gst_element_aenc_name = NULL;
1077 const char *gst_element_ienc_name = NULL;
1078 const char *gst_element_mux_name = NULL;
1079 const char *gst_element_rsink_name = NULL;
1080 const char *str_profile = NULL;
1081 const char *str_aac = NULL;
1082 const char *str_aar = NULL;
1083 const char *str_acs = NULL;
1084 char *err_name = NULL;
1085 const char *videoconvert_name = NULL;
1086 GstCaps *audio_caps = NULL;
1087 GstCaps *video_caps = NULL;
1089 GList *element_list = NULL;
1091 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1092 _MMCamcorderSubContext *sc = NULL;
1093 type_element *VideoencElement = NULL;
1094 type_element *AudioencElement = NULL;
1095 type_element *ImageencElement = NULL;
1096 type_element *MuxElement = NULL;
1097 type_element *RecordsinkElement = NULL;
1099 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1101 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1102 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1103 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1105 _mmcam_dbg_log("start - profile : %d", profile);
1107 /* Check existence */
1108 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1109 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1110 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1112 _mmcam_dbg_log("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1115 /* Create bin element */
1116 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1118 /* Create child element */
1119 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1120 GstCaps *caps_from_pad = NULL;
1122 /* create appsrc and capsfilter */
1123 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1125 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1127 /* release element_list, they will be placed out of encodesink bin */
1129 g_list_free(element_list);
1130 element_list = NULL;
1133 /* set appsrc as live source */
1134 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1135 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1136 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1138 /* set capsfilter */
1139 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1140 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1141 _mmcam_dbg_log("get pad from videosrc_filter");
1142 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1144 _mmcam_dbg_log("get pad from videosrc_que");
1145 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1148 _mmcam_dbg_err("get videosrc_que src pad failed");
1149 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1150 goto pipeline_creation_error;
1153 caps_from_pad = gst_pad_get_allowed_caps(pad);
1154 video_caps = gst_caps_copy(caps_from_pad);
1155 gst_caps_unref(caps_from_pad);
1156 caps_from_pad = NULL;
1157 gst_object_unref(pad);
1161 video_caps = gst_caps_fixate(video_caps);
1164 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1168 char *caps_str = NULL;
1170 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1171 gst_caps_set_simple(video_caps,
1172 "width", G_TYPE_INT, sc->info_video->video_width,
1173 "height", G_TYPE_INT, sc->info_video->video_height,
1177 caps_str = gst_caps_to_string(video_caps);
1178 _mmcam_dbg_log("encodebin caps [%s]", caps_str);
1182 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1183 gst_caps_unref(video_caps);
1186 _mmcam_dbg_err("create recording pipeline caps failed");
1187 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1188 goto pipeline_creation_error;
1191 /* connect signal for ready to push buffer */
1192 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1193 _MMCAMCORDER_HANDLER_VIDEOREC,
1195 _mmcamcorder_ready_to_encode_callback,
1199 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN, "encodebin", "encodesink_encbin", element_list, err);
1201 /* check element availability */
1202 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1203 err = mm_camcorder_get_attributes(handle, &err_name,
1204 MMCAM_CAPTURE_FORMAT, &cap_format,
1207 err = mm_camcorder_get_attributes(handle, &err_name,
1208 MMCAM_AUDIO_ENCODER, &audio_enc,
1209 MMCAM_AUDIO_CHANNEL, &channel,
1210 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1211 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1215 if (err != MM_ERROR_NONE) {
1217 _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
1218 SAFE_FREE(err_name);
1220 _mmcam_dbg_err("failed to get attributes [0x%x]", err);
1223 goto pipeline_creation_error;
1226 _mmcam_dbg_log("Profile[%d]", profile);
1228 /* Set information */
1229 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1230 str_profile = "VideoProfile";
1231 str_aac = "VideoAutoAudioConvert";
1232 str_aar = "VideoAutoAudioResample";
1233 str_acs = "VideoAutoColorSpace";
1234 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1235 str_profile = "AudioProfile";
1236 str_aac = "AudioAutoAudioConvert";
1237 str_aar = "AudioAutoAudioResample";
1238 str_acs = "AudioAutoColorSpace";
1239 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1240 str_profile = "ImageProfile";
1241 str_aac = "ImageAutoAudioConvert";
1242 str_aar = "ImageAutoAudioResample";
1243 str_acs = "ImageAutoColorSpace";
1246 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1247 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1248 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1249 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1251 _mmcam_dbg_log("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1252 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1254 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1255 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1256 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1257 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1258 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1260 /* get video convert element name */
1261 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1264 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1265 int use_venc_queue = 0;
1267 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1269 if (!VideoencElement) {
1270 _mmcam_dbg_err("Fail to get type element");
1271 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1272 goto pipeline_creation_error;
1275 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1276 /* set dummy element */
1277 gst_element_venc_name = "identity";
1279 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1282 if (gst_element_venc_name) {
1283 _mmcam_dbg_log("video encoder name [%s]", gst_element_venc_name);
1285 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1286 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1288 _mmcam_dbg_err("Fail to get video encoder name");
1289 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1290 goto pipeline_creation_error;
1293 /* set color space converting element */
1294 if (auto_color_space) {
1295 _mmcam_dbg_log("set video convert element [%s]", videoconvert_name);
1297 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1298 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1300 /* set colorspace plugin property setting */
1301 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1303 /* fourcc type was removed in GST 1.0 */
1304 if (hcamcorder->use_zero_copy_format) {
1305 if (strstr(gst_element_venc_name, "omx")) {
1306 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1309 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1310 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1312 gst_caps_unref(video_caps);
1315 _mmcam_dbg_warn("failed to create caps");
1318 _mmcam_dbg_log("current video codec is not openmax but [%s]", gst_element_venc_name);
1323 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1324 CONFIGURE_CATEGORY_MAIN_RECORD,
1325 "UseVideoEncoderQueue",
1328 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1331 if (sc->audio_disable == FALSE &&
1332 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1333 int use_aenc_queue = 0;
1335 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1336 if (!AudioencElement) {
1337 _mmcam_dbg_err("Fail to get type element");
1338 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1339 goto pipeline_creation_error;
1342 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1344 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1345 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1347 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1348 audio_caps = gst_caps_new_simple("audio/x-raw",
1349 "channels", G_TYPE_INT, 1,
1351 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1352 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1353 gst_caps_unref(audio_caps);
1357 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1358 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1359 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1360 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1361 gst_caps_unref(audio_caps);
1363 _mmcam_dbg_log("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1366 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1367 CONFIGURE_CATEGORY_MAIN_RECORD,
1368 "UseAudioEncoderQueue",
1370 if (use_aenc_queue) {
1371 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1372 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1373 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1377 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1378 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1379 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1380 if (!ImageencElement) {
1381 _mmcam_dbg_err("Fail to get type element");
1382 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1383 goto pipeline_creation_error;
1386 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1388 /* raw format - set dummy element */
1389 gst_element_ienc_name = "identity";
1392 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1393 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1397 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1398 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1400 _mmcam_dbg_err("Fail to get type element");
1401 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1402 goto pipeline_creation_error;
1405 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1407 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1408 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1410 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1414 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1416 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1417 CONFIGURE_CATEGORY_MAIN_RECORD,
1418 "RecordsinkElement",
1419 &RecordsinkElement);
1420 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1422 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1424 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1427 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1430 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1431 /* property setting in ini */
1432 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1434 /* bitrate setting */
1435 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1436 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1439 if (sc->audio_disable == FALSE &&
1440 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1441 /* property setting in ini */
1442 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1444 /* bitrate setting */
1445 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1446 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1449 _mmcam_dbg_log("Element creation complete");
1451 /* Add element to bin */
1452 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1453 _mmcam_dbg_err("element add error.");
1454 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1455 goto pipeline_creation_error;
1458 _mmcam_dbg_log("Element add complete");
1460 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1461 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1462 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1463 gst_object_unref(pad);
1465 _mmcam_dbg_err("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1466 err = MM_ERROR_CAMCORDER_GST_LINK;
1467 goto pipeline_creation_error;
1469 gst_object_unref(pad);
1472 if (sc->audio_disable == FALSE) {
1473 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1474 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1475 gst_object_unref(pad);
1477 _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1478 err = MM_ERROR_CAMCORDER_GST_LINK;
1479 goto pipeline_creation_error;
1481 gst_object_unref(pad);
1484 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1485 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1486 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1487 gst_object_unref(pad);
1489 _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1490 err = MM_ERROR_CAMCORDER_GST_LINK;
1491 goto pipeline_creation_error;
1493 gst_object_unref(pad);
1497 pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1498 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1499 gst_object_unref(pad);
1501 _mmcam_dbg_err("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1502 err = MM_ERROR_CAMCORDER_GST_LINK;
1503 goto pipeline_creation_error;
1505 gst_object_unref(pad);
1509 _mmcam_dbg_log("Get pad complete");
1511 /* Link internal element */
1512 if (!_mmcamcorder_link_elements(element_list)) {
1513 _mmcam_dbg_err("element link error.");
1514 err = MM_ERROR_CAMCORDER_GST_LINK;
1515 goto pipeline_creation_error;
1519 g_list_free(element_list);
1520 element_list = NULL;
1523 _mmcam_dbg_log("done");
1525 return MM_ERROR_NONE;
1527 pipeline_creation_error:
1528 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1530 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1531 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1532 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1533 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1534 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1535 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1536 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1537 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1538 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1541 g_list_free(element_list);
1542 element_list = NULL;
1549 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1551 int err = MM_ERROR_NONE;
1553 GstPad *srcpad = NULL;
1556 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1557 _MMCamcorderSubContext *sc = NULL;
1559 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1561 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1562 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1563 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1567 /** Create gstreamer element **/
1569 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1572 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1573 if (err != MM_ERROR_NONE)
1574 goto pipeline_creation_error;
1576 /* Set data probe function */
1577 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1578 _mmcam_dbg_log("add video dataprobe to videosrc queue");
1579 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1581 _mmcam_dbg_err("there is no queue plugin");
1582 goto pipeline_creation_error;
1586 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1587 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1589 gst_object_unref(srcpad);
1592 _mmcam_dbg_err("failed to get srcpad");
1593 goto pipeline_creation_error;
1596 /* set dataprobe for video recording if it does not support dual stream. */
1597 if (sc->info_video->record_dual_stream == FALSE) {
1598 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1599 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1601 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1603 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1604 __mmcamcorder_video_dataprobe_record, hcamcorder);
1605 gst_object_unref(srcpad);
1609 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1611 /* Register pipeline message callback */
1612 hcamcorder->pipeline_cb_event_id = gst_bus_add_watch(bus, _mmcamcorder_pipeline_cb_message, (gpointer)hcamcorder);
1614 /* set sync handler */
1615 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1617 gst_object_unref(bus);
1620 return MM_ERROR_NONE;
1622 pipeline_creation_error:
1623 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1628 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1630 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1631 _MMCamcorderSubContext *sc = NULL;
1633 /*_mmcam_dbg_log("start");*/
1635 mmf_return_if_fail(hcamcorder);
1636 mmf_return_if_fail(hcamcorder->sub_context);
1637 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1640 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1641 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1642 _mmcam_dbg_warn("set push_encoding_buffer RUN");
1647 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1649 int err = MM_ERROR_NONE;
1654 int rect_height = 0;
1656 int rotation = MM_DISPLAY_ROTATION_NONE;
1657 int flip = MM_FLIP_NONE;
1658 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1659 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1660 int origin_size = 0;
1663 int do_scaling = FALSE;
1664 #ifdef _MMCAMCORDER_RM_SUPPORT
1665 int display_scaler = 0;
1666 #endif /* _MMCAMCORDER_RM_SUPPORT */
1667 int *dp_handle = NULL;
1668 MMCamWindowInfo *window_info = NULL;
1670 char *err_name = NULL;
1671 const char *videosink_name = NULL;
1673 GstElement *vsink = NULL;
1675 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1676 _MMCamcorderSubContext *sc = NULL;
1680 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1682 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1683 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1684 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1685 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1687 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1689 /* Get video display information */
1690 err = mm_camcorder_get_attributes(handle, &err_name,
1691 MMCAM_DISPLAY_RECT_X, &rect_x,
1692 MMCAM_DISPLAY_RECT_Y, &rect_y,
1693 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1694 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1695 MMCAM_DISPLAY_ROTATION, &rotation,
1696 MMCAM_DISPLAY_FLIP, &flip,
1697 MMCAM_DISPLAY_VISIBLE, &visible,
1698 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1699 MMCAM_DISPLAY_MODE, &display_mode,
1700 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1701 MMCAM_DISPLAY_SCALE, &zoom_attr,
1702 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1704 if (err != MM_ERROR_NONE) {
1706 _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
1707 SAFE_FREE(err_name);
1709 _mmcam_dbg_err("failed to get attributes [0x%x]", err);
1715 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1717 if (!videosink_name) {
1718 _mmcam_dbg_err("failed to get videosink name");
1719 return MM_ERROR_CAMCORDER_INTERNAL;
1722 _mmcam_dbg_log("(dp_handle=%p, size=%d)", dp_handle, size);
1724 /* Set display handle */
1725 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1728 _mmcam_dbg_log("xid = %lu )", xid);
1729 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1731 _mmcam_dbg_warn("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1732 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1734 #ifdef _MMCAMCORDER_RM_SUPPORT
1735 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
1738 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", display_scaler);
1739 #endif /* _MMCAMCORDER_RM_SUPPORT */
1740 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1741 _mmcam_dbg_log("videosink : %s, handle : %p", videosink_name, dp_handle);
1744 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1745 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1747 _mmcam_dbg_err("display handle(eavs object) is NULL");
1748 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1750 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1752 window_info = (MMCamWindowInfo *)dp_handle;
1753 _mmcam_dbg_log("wayland global surface id : %d", window_info->surface_id);
1754 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1756 _mmcam_dbg_warn("Handle is NULL. skip setting.");
1758 } else if (!strcmp(videosink_name, "directvideosink")) {
1760 window_info = (MMCamWindowInfo *)dp_handle;
1761 _mmcam_dbg_log("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1762 window_info->surface_id,
1763 window_info->rect.x,
1764 window_info->rect.y,
1765 window_info->rect.width,
1766 window_info->rect.height);
1767 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1768 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1769 window_info->rect.x,
1770 window_info->rect.y,
1771 window_info->rect.width,
1772 window_info->rect.height);
1774 _mmcam_dbg_warn("dp_handle is null");
1776 #ifdef _MMCAMCORDER_RM_SUPPORT
1777 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
1779 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", display_scaler);
1780 #endif /* _MMCAMCORDER_RM_SUPPORT */
1782 _mmcam_dbg_warn("Who are you?? (Videosink: %s)", videosink_name);
1785 _mmcam_dbg_log("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1786 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1789 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1790 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1792 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1795 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1797 switch (zoom_attr) {
1798 case MM_DISPLAY_SCALE_DEFAULT:
1801 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1804 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1808 _mmcam_dbg_warn("Unsupported zoom value. set as default.");
1813 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1814 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1815 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1816 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1818 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1819 if (!strcmp(videosink_name, "tizenwlsink")) {
1820 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1821 rect_x, rect_y, rect_width, rect_height);
1824 "dst-roi-x", rect_x,
1825 "dst-roi-y", rect_y,
1826 "dst-roi-w", rect_width,
1827 "dst-roi-h", rect_height,
1833 return MM_ERROR_NONE;
1837 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1840 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1841 _MMCamcorderSubContext *sc = NULL;
1843 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1845 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1847 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1850 case _MMCamcorder_CMD_PREVIEW_START:
1851 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1853 case _MMCamcorder_CMD_CAPTURE:
1854 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1857 _mmcam_dbg_warn("unknown command : %d", cmd);
1858 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1861 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1862 category, "FrameStabilityCount", &sc->frame_stability_count);
1864 _mmcam_dbg_log("[cmd %d] frame stability count : %d",
1865 cmd, sc->frame_stability_count);
1867 return MM_ERROR_NONE;
1870 /* Retreive device information and set them to attributes */
1871 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
1873 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1874 _MMCamcorderSubContext *sc = NULL;
1875 GstCameraControl *control = NULL;
1876 GstCameraControlExifInfo exif_info = {0,};
1878 mmf_return_val_if_fail(hcamcorder, FALSE);
1879 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1881 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
1883 if (sc && sc->element) {
1884 int err = MM_ERROR_NONE;
1885 char *err_name = NULL;
1886 double focal_len = 0.0;
1888 /* Video input device */
1889 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
1890 /* Exif related information */
1891 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1892 if (control != NULL) {
1893 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
1894 if (exif_info.focal_len_denominator != 0)
1895 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
1897 _mmcam_dbg_err("Fail to get camera control interface!");
1902 /* Set values to attributes */
1903 err = mm_camcorder_set_attributes(handle, &err_name,
1904 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
1906 if (err != MM_ERROR_NONE) {
1907 _mmcam_dbg_err("Set attributes error(%s:%x)!", err_name, err);
1908 SAFE_FREE(err_name);
1912 _mmcam_dbg_warn("Sub context isn't exist.");
1919 static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name)
1921 return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24);
1924 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
1926 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
1927 _MMCamcorderSubContext *sc = NULL;
1928 _MMCamcorderKPIMeasure *kpi = NULL;
1929 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
1931 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
1932 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
1933 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
1935 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
1936 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
1938 if (sc->drop_vframe > 0) {
1939 if (sc->pass_first_vframe > 0) {
1940 sc->pass_first_vframe--;
1941 _mmcam_dbg_log("Pass video frame by pass_first_vframe");
1944 _mmcam_dbg_log("Drop video frame by drop_vframe");
1945 return GST_PAD_PROBE_DROP;
1947 } else if (sc->frame_stability_count > 0) {
1948 sc->frame_stability_count--;
1949 _mmcam_dbg_log("Drop video frame by frame_stability_count");
1950 return GST_PAD_PROBE_DROP;
1953 if (hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE) {
1955 int frame_count = 0;
1956 struct timeval current_video_time;
1959 if (kpi->init_video_time.tv_sec == kpi->last_video_time.tv_sec &&
1960 kpi->init_video_time.tv_usec == kpi->last_video_time.tv_usec &&
1961 kpi->init_video_time.tv_usec == 0) {
1963 _mmcam_dbg_log("START to measure FPS");
1965 gettimeofday(&(kpi->init_video_time), NULL);
1968 frame_count = ++(kpi->video_framecount);
1970 gettimeofday(¤t_video_time, NULL);
1971 diff_sec = current_video_time.tv_sec - kpi->last_video_time.tv_sec;
1972 if (diff_sec != 0) {
1973 kpi->current_fps = (frame_count - kpi->last_framecount) / diff_sec;
1974 if ((current_video_time.tv_sec - kpi->init_video_time.tv_sec) != 0) {
1975 int framecount = kpi->video_framecount;
1976 int elased_sec = current_video_time.tv_sec - kpi->init_video_time.tv_sec;
1977 kpi->average_fps = framecount / elased_sec;
1980 kpi->last_framecount = frame_count;
1981 kpi->last_video_time.tv_sec = current_video_time.tv_sec;
1982 kpi->last_video_time.tv_usec = current_video_time.tv_usec;
1984 _mmcam_dbg_log("current fps(%d), average(%d)", kpi->current_fps, kpi->average_fps);
1989 /* The first H.264 frame should not be skipped for vstream cb. */
1990 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
1991 sc->info_image->preview_format != MM_PIXEL_FORMAT_ENCODED_H264) {
1992 _mmcam_dbg_warn("Not ready for stream callback");
1993 return GST_PAD_PROBE_OK;
1996 if (_mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, buffer, TRUE))
1997 return GST_PAD_PROBE_OK;
1999 return GST_PAD_PROBE_DROP;
2003 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2005 if (_mmcamcorder_video_push_buffer(u_data, GST_PAD_PROBE_INFO_BUFFER(info)))
2006 return GST_PAD_PROBE_OK;
2008 return GST_PAD_PROBE_DROP;
2012 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2014 MMCamcorderMuxedStreamDataType stream;
2015 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2016 _MMCamcorderSubContext *sc = NULL;
2017 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2020 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2021 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2022 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2024 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2025 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2027 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2028 _mmcam_dbg_warn("map failed : buffer %p", buffer);
2029 return GST_PAD_PROBE_OK;
2032 /* call application callback */
2033 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2035 if (hcamcorder->mstream_cb) {
2036 stream.data = (void *)mapinfo.data;
2037 stream.length = mapinfo.size;
2038 stream.offset = sc->muxed_stream_offset;
2039 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2042 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2044 /* calculate current offset */
2045 sc->muxed_stream_offset += mapinfo.size;
2047 gst_buffer_unmap(buffer, &mapinfo);
2049 return GST_PAD_PROBE_OK;
2053 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2055 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2056 mmf_camcorder_t *hcamcorder = NULL;
2057 _MMCamcorderSubContext *sc = NULL;
2058 GstObject *parent = NULL;
2060 switch (GST_EVENT_TYPE(event)) {
2061 case GST_EVENT_UNKNOWN:
2062 /* upstream events */
2064 case GST_EVENT_SEEK:
2065 case GST_EVENT_NAVIGATION:
2066 case GST_EVENT_LATENCY:
2067 /* downstream serialized events */
2068 case GST_EVENT_BUFFERSIZE:
2069 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2073 GstTagList *tag_list = NULL;
2074 _MMCamcorderReplayGain *replay_gain = NULL;
2076 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2078 hcamcorder = MMF_CAMCORDER(u_data);
2079 if (!hcamcorder || !hcamcorder->sub_context) {
2080 _mmcam_dbg_warn("NULL handle");
2084 replay_gain = &hcamcorder->sub_context->replay_gain;
2086 gst_event_parse_tag(event, &tag_list);
2088 _mmcam_dbg_warn("failed to get tag list");
2092 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2093 _mmcam_dbg_warn("failed to get GST_TAG_TRACK_PEAK");
2097 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2098 _mmcam_dbg_warn("failed to get GST_TAG_TRACK_GAIN");
2102 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2103 _mmcam_dbg_warn("failed to get GST_TAG_ALBUM_PEAK");
2107 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2108 _mmcam_dbg_warn("failed to get GST_TAG_ALBUM_PEAK");
2112 _mmcam_dbg_log("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2113 replay_gain->track_peak, replay_gain->track_gain,
2114 replay_gain->album_peak, replay_gain->album_gain);
2117 case GST_EVENT_SEGMENT:
2118 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2120 hcamcorder = MMF_CAMCORDER(u_data);
2122 _mmcam_dbg_warn("NULL handle");
2126 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2128 _mmcam_dbg_warn("NULL sub context");
2132 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2133 _mmcam_dbg_warn("no encoder sink");
2137 parent = gst_pad_get_parent(pad);
2139 _mmcam_dbg_warn("get parent failed");
2143 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2144 const GstSegment *segment;
2145 gst_event_parse_segment(event, &segment);
2146 if (segment->format == GST_FORMAT_BYTES) {
2147 _mmcam_dbg_log("change current offset %llu -> %"G_GUINT64_FORMAT,
2148 sc->muxed_stream_offset, segment->start);
2150 sc->muxed_stream_offset = (unsigned long long)segment->start;
2154 gst_object_unref(parent);
2158 _mmcam_dbg_warn("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2160 /* bidirectional events */
2161 case GST_EVENT_FLUSH_START:
2162 case GST_EVENT_FLUSH_STOP:
2163 _mmcam_dbg_err("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2166 _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2170 return GST_PAD_PROBE_OK;
2174 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2176 int result = MM_CAMCORDER_MR475;
2179 result = MM_CAMCORDER_MR475; /*AMR475*/
2180 else if (bitrate < 5900)
2181 result = MM_CAMCORDER_MR515; /*AMR515*/
2182 else if (bitrate < 6700)
2183 result = MM_CAMCORDER_MR59; /*AMR59*/
2184 else if (bitrate < 7400)
2185 result = MM_CAMCORDER_MR67; /*AMR67*/
2186 else if (bitrate < 7950)
2187 result = MM_CAMCORDER_MR74; /*AMR74*/
2188 else if (bitrate < 10200)
2189 result = MM_CAMCORDER_MR795; /*AMR795*/
2190 else if (bitrate < 12200)
2191 result = MM_CAMCORDER_MR102; /*AMR102*/
2193 result = MM_CAMCORDER_MR122; /*AMR122*/
2199 int _mmcamcorder_get_eos_message(MMHandleType handle)
2202 int ret = MM_ERROR_NONE;
2204 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2205 _MMCamcorderSubContext *sc = NULL;
2207 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2208 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2209 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2211 _mmcam_dbg_log("START");
2213 _MMCAMCORDER_LOCK(handle);
2215 if (sc->bget_eos == FALSE) {
2216 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2217 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2218 _mmcam_dbg_log("EOS signal received");
2220 _mmcam_dbg_err("EOS wait time out");
2222 if (hcamcorder->error_code == MM_ERROR_NONE)
2223 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2226 _mmcam_dbg_log("already got EOS");
2229 _MMCAMCORDER_UNLOCK(handle);
2231 if (hcamcorder->error_code == MM_ERROR_NONE) {
2232 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2233 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2234 if (sc->info_video->b_commiting)
2235 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2237 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2238 if (sc->info_audio->b_commiting)
2239 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2242 ret = hcamcorder->error_code;
2243 _mmcam_dbg_err("error 0x%x", ret);
2246 _mmcam_dbg_log("END");
2252 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2255 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2257 mmf_return_if_fail(handle && remove_element);
2258 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2262 for (i = first_elem ; i <= last_elem ; i++) {
2263 remove_element[i].gst = NULL;
2264 remove_element[i].id = _MMCAMCORDER_NONE;
2271 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2273 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2275 /* Check compatibility between codec and file format */
2276 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2277 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2278 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2279 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2280 _mmcam_dbg_err("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2281 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2284 _mmcam_dbg_log("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2286 _mmcam_dbg_err("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2287 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2289 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2290 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2291 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2292 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2293 _mmcam_dbg_err("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2294 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2297 _mmcam_dbg_log("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2299 _mmcam_dbg_err("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2300 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2304 return MM_ERROR_NONE;
2308 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2310 int err = MM_ERROR_NONE;
2311 int audio_codec = MM_AUDIO_CODEC_INVALID;
2312 int file_format = MM_FILE_FORMAT_INVALID;
2314 char *err_name = NULL;
2316 err = mm_camcorder_get_attributes(handle, &err_name,
2317 MMCAM_AUDIO_ENCODER, &audio_codec,
2318 MMCAM_FILE_FORMAT, &file_format,
2320 if (err != MM_ERROR_NONE) {
2321 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
2322 SAFE_FREE(err_name);
2326 /* Check compatibility between audio codec and file format */
2327 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2333 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2335 int err = MM_ERROR_NONE;
2336 int video_codec = MM_VIDEO_CODEC_INVALID;
2337 int file_format = MM_FILE_FORMAT_INVALID;
2339 char *err_name = NULL;
2341 err = mm_camcorder_get_attributes(handle, &err_name,
2342 MMCAM_VIDEO_ENCODER, &video_codec,
2343 MMCAM_FILE_FORMAT, &file_format,
2345 if (err != MM_ERROR_NONE) {
2346 _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
2347 SAFE_FREE(err_name);
2351 /* Check compatibility between video codec and file format */
2352 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2358 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2360 const char* videosink_name = NULL;
2362 mmf_camcorder_t *hcamcorder = NULL;
2363 _MMCamcorderSubContext *sc = NULL;
2365 hcamcorder = MMF_CAMCORDER(handle);
2366 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2368 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2369 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2370 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2372 if (sc->element[videosink_index].gst) {
2373 /* Get videosink name */
2374 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2375 if (videosink_name == NULL) {
2376 _mmcam_dbg_err("Please check videosink element in configuration file");
2380 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2381 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2382 !strcmp(videosink_name, "directvideosink")) {
2383 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2384 _mmcam_dbg_log("Set display-rotate [%d] done.", display_rotate);
2386 _mmcam_dbg_warn("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2391 _mmcam_dbg_err("Videosink element is null");
2397 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2399 const char* videosink_name = NULL;
2401 mmf_camcorder_t *hcamcorder = NULL;
2402 _MMCamcorderSubContext *sc = NULL;
2404 hcamcorder = MMF_CAMCORDER(handle);
2405 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2407 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2408 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2409 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2411 if (sc->element[videosink_index].gst) {
2412 /* Get videosink name */
2413 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2414 if (videosink_name == NULL) {
2415 _mmcam_dbg_err("Please check videosink element in configuration file");
2419 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2420 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2421 !strcmp(videosink_name, "directvideosink")) {
2422 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2423 _mmcam_dbg_log("Set display flip [%d] done.", display_flip);
2425 _mmcam_dbg_warn("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2430 _mmcam_dbg_err("Videosink element is null");
2436 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2439 _MMCamcorderSubContext *sc = NULL;
2441 mmf_camcorder_t *hcamcorder = NULL;
2443 hcamcorder = MMF_CAMCORDER(handle);
2444 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2446 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2448 _mmcam_dbg_log("sub context is not initailized");
2452 mm_camcorder_get_attributes(handle, NULL,
2453 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2454 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2455 MMCAM_CAMERA_FPS, &fps,
2458 _mmcam_dbg_log("set rotate %d", videosrc_rotate);
2460 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2461 sc->info_video->preview_width, sc->info_video->preview_height,
2462 fps, videosrc_rotate);
2466 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2472 unsigned int caps_fourcc = 0;
2473 gboolean do_set_caps = FALSE;
2475 GstCaps *caps = NULL;
2477 mmf_camcorder_t *hcamcorder = NULL;
2478 _MMCamcorderSubContext *sc = NULL;
2480 hcamcorder = MMF_CAMCORDER(handle);
2481 mmf_return_val_if_fail(hcamcorder, FALSE);
2483 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2485 if (!sc || !(sc->element)) {
2486 _mmcam_dbg_log("sub context is not initialized");
2490 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2491 _mmcam_dbg_err("Video src is NULL!");
2495 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2496 _mmcam_dbg_err("Video filter is NULL!");
2500 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2501 int capture_width = 0;
2502 int capture_height = 0;
2503 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2505 mm_camcorder_get_attributes(handle, NULL,
2506 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2507 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2508 MMCAM_CAPTURE_WIDTH, &capture_width,
2509 MMCAM_CAPTURE_HEIGHT, &capture_height,
2510 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2511 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2513 _mmcam_dbg_log("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2514 motion_rate, capture_width, capture_height, fps_auto,
2515 sc->info_video->video_width, sc->info_video->video_height);
2517 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2518 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2520 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2521 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2522 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2525 sc->info_video->fps = fps;
2528 /* Interleaved format does not support rotation */
2529 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2530 /* store videosrc rotation */
2531 sc->videosrc_rotate = rotate;
2533 /* Define width, height and rotate in caps */
2535 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2536 This will be applied when rotate is 0, 180 if front camera. */
2537 set_rotate = rotate * 90;
2539 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2540 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2543 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2544 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2551 set_height = height;
2554 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2557 set_height = height;
2559 _mmcam_dbg_warn("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2562 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2563 if (caps && !gst_caps_is_any(caps)) {
2564 GstStructure *structure = NULL;
2566 structure = gst_caps_get_structure(caps, 0);
2568 const gchar *format_string = NULL;
2570 int caps_height = 0;
2572 int caps_rotate = 0;
2574 format_string = gst_structure_get_string(structure, "format");
2576 caps_fourcc = _mmcamcorder_convert_fourcc_string_to_value(format_string);
2578 gst_structure_get_int(structure, "width", &caps_width);
2579 gst_structure_get_int(structure, "height", &caps_height);
2580 gst_structure_get_int(structure, "fps", &caps_fps);
2581 gst_structure_get_int(structure, "rotate", &caps_rotate);
2583 #ifdef _MMCAMCORDER_PRODUCT_TV
2584 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2585 if (set_width == caps_width && set_height == caps_height &&
2586 set_rotate == caps_rotate && fps == caps_fps) {
2587 _mmcam_dbg_log("No need to replace caps.");
2589 _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2590 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2591 caps_width, caps_height, caps_fps, caps_rotate,
2592 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2593 set_width, set_height, fps, set_rotate);
2597 if (set_width == caps_width && set_height == caps_height &&
2598 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2599 _mmcam_dbg_log("No need to replace caps.");
2601 _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2602 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2603 caps_width, caps_height, caps_fps, caps_rotate,
2604 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2605 set_width, set_height, fps, set_rotate);
2609 #else /*_MMCAMCORDER_PRODUCT_TV */
2610 if (set_width == caps_width && set_height == caps_height &&
2611 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
2612 _mmcam_dbg_log("No need to replace caps.");
2614 _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2615 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2616 caps_width, caps_height, caps_fps, caps_rotate,
2617 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2618 set_width, set_height, fps, set_rotate);
2621 #endif /*_MMCAMCORDER_PRODUCT_TV */
2623 _mmcam_dbg_log("can not get structure of caps. set new one...");
2627 _mmcam_dbg_log("No caps. set new one...");
2632 gst_caps_unref(caps);
2637 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
2638 #ifdef _MMCAMCORDER_PRODUCT_TV
2641 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
2642 mm_camcorder_get_attributes(handle, NULL,
2643 MMCAM_DISPLAY_SURFACE, &display_surface_type,
2646 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
2647 __mmcamcorder_find_max_resolution(handle, &maxwidth, &maxheight) == false) {
2648 _mmcam_dbg_err("can not find max resolution limitation");
2650 } else if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
2651 maxwidth = set_width;
2652 maxheight = set_height;
2654 #endif /* _MMCAMCORDER_PRODUCT_TV */
2655 caps = gst_caps_new_simple("video/x-h264",
2656 "width", G_TYPE_INT, set_width,
2657 "height", G_TYPE_INT, set_height,
2658 "framerate", GST_TYPE_FRACTION, fps, 1,
2659 "stream-format", G_TYPE_STRING, "byte-stream",
2660 #ifdef _MMCAMCORDER_PRODUCT_TV
2661 "maxwidth", G_TYPE_INT, maxwidth,
2662 "maxheight", G_TYPE_INT, maxheight,
2663 "alignment", G_TYPE_STRING, "au",
2664 #endif /* _MMCAMCORDER_PRODUCT_TV */
2666 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG){
2667 #ifdef _MMCAMCORDER_PRODUCT_TV
2668 caps = gst_caps_new_simple("video/x-jpeg",
2670 caps = gst_caps_new_simple("image/jpeg",
2672 "width", G_TYPE_INT, set_width,
2673 "height", G_TYPE_INT, set_height,
2674 "framerate", GST_TYPE_FRACTION, fps, 1,
2677 char fourcc_string[sizeof(fourcc)+1];
2678 memcpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
2679 fourcc_string[sizeof(fourcc)] = '\0';
2680 caps = gst_caps_new_simple("video/x-raw",
2681 "format", G_TYPE_STRING, fourcc_string,
2682 "width", G_TYPE_INT, set_width,
2683 "height", G_TYPE_INT, set_height,
2684 "framerate", GST_TYPE_FRACTION, fps, 1,
2685 "rotate", G_TYPE_INT, set_rotate,
2690 gchar *caps_str = gst_caps_to_string(caps);
2693 _mmcam_dbg_log("vidoesrc new caps set [%s]", caps_str);
2697 _mmcam_dbg_warn("caps string failed");
2700 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2701 gst_caps_unref(caps);
2704 _mmcam_dbg_err("There are no caps");
2708 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2709 /* assume that it's camera capture mode */
2710 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2717 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2719 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2720 _MMCamcorderSubContext *sc = NULL;
2722 mmf_return_val_if_fail(hcamcorder, FALSE);
2724 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2728 _mmcam_dbg_log("Set FLIP %d", videosrc_flip);
2730 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2734 /* Interleaved format does not support FLIP */
2735 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2736 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2737 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2739 _mmcam_dbg_log("videosrc flip H:%d, V:%d", hflip, vflip);
2741 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2742 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2744 _mmcam_dbg_warn("ITLV format does not support FLIP. Ignore FLIP[%d]",
2748 _mmcam_dbg_warn("element is NULL");
2756 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2758 GstCameraControl *control = NULL;
2759 _MMCamcorderSubContext *sc = NULL;
2760 GstElement *v_src = NULL;
2764 mmf_return_val_if_fail(handle, FALSE);
2766 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2770 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2773 _mmcam_dbg_warn("videosrc element is NULL");
2777 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2779 /* set anti-shake with camera control */
2780 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2781 _mmcam_dbg_warn("Can't cast Video source into camera control.");
2785 control = GST_CAMERA_CONTROL(v_src);
2786 if (gst_camera_control_set_ahs(control, set_value)) {
2787 _mmcam_dbg_log("Succeed in operating anti-handshake. value[%d]", set_value);
2790 _mmcam_dbg_warn("Failed to operate anti-handshake. value[%d]", set_value);
2797 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2799 _MMCamcorderSubContext *sc = NULL;
2800 GstElement *v_src = NULL;
2802 mmf_return_val_if_fail(handle, FALSE);
2804 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2808 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2810 _mmcam_dbg_warn("videosrc element is NULL");
2814 /* check property of videosrc element - support VDIS */
2815 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2816 int video_width = 0;
2817 int video_height = 0;
2819 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2820 _mmcam_dbg_log("ENABLE video stabilization");
2822 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2823 mm_camcorder_get_attributes(handle, NULL,
2824 MMCAM_VIDEO_WIDTH, &video_width,
2825 MMCAM_VIDEO_HEIGHT, &video_height,
2828 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2829 _mmcam_dbg_log("NV12, video size %dx%d, ENABLE video stabilization",
2830 video_width, video_height);
2832 g_object_set(G_OBJECT(v_src),
2833 "enable-vdis-mode", TRUE,
2836 _mmcam_dbg_warn("invalid preview format %c%c%c%c or video size %dx%d",
2837 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2838 video_width, video_height);
2843 g_object_set(G_OBJECT(v_src),
2844 "enable-vdis-mode", FALSE,
2847 _mmcam_dbg_log("DISABLE video stabilization");
2849 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2850 _mmcam_dbg_err("no property for video stabilization, so can not set ON");
2853 _mmcam_dbg_warn("no property for video stabilization");
2860 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2864 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2865 _MMCamcorderSubContext *sc = NULL;
2867 mmf_return_val_if_fail(hcamcorder, FALSE);
2869 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2873 mm_camcorder_get_attributes(handle, NULL,
2874 MMCAM_CAMERA_FPS, &fps,
2877 _mmcam_dbg_log("set %dx%d", width, height);
2879 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2883 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2885 _MMCamcorderSubContext *sc = NULL;
2887 if ((void *)handle == NULL) {
2888 _mmcam_dbg_warn("handle is NULL");
2892 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2894 _mmcam_dbg_warn("subcontext is NULL");
2898 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2899 _mmcam_dbg_warn("videosrc plugin is NULL");
2903 _mmcam_dbg_log("set encoded preview bitrate : %d bps", bitrate);
2905 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
2911 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
2913 _MMCamcorderSubContext *sc = NULL;
2915 if ((void *)handle == NULL) {
2916 _mmcam_dbg_warn("handle is NULL");
2920 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2922 _mmcam_dbg_warn("subcontext is NULL");
2926 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2927 _mmcam_dbg_warn("videosrc plugin is NULL");
2931 _mmcam_dbg_log("set encoded preview GOP interval : %d ms", gop_interval);
2933 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
2939 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
2941 GstStructure *props = NULL;
2942 char stream_props[64] = {'\0',};
2944 if (element == NULL || stream_type == NULL || stream_index < 0) {
2945 _mmcam_dbg_err("invalid argument %p %p %d", element, stream_type, stream_index);
2949 snprintf(stream_props, sizeof(stream_props) - 1,
2950 "props,media.role=%s, media.parent_id=%d",
2951 stream_type, stream_index);
2953 _mmcam_dbg_warn("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
2955 props = gst_structure_from_string(stream_props, NULL);
2957 _mmcam_dbg_err("failed to create GstStructure");
2961 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
2963 gst_structure_free(props);
2970 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
2972 int ret = MM_ERROR_NONE;
2973 _MMCamcorderSubContext *sc = NULL;
2974 mmf_camcorder_t *hcamcorder = NULL;
2975 const char *videodecoder_name = NULL;
2976 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
2977 #ifdef _MMCAMCORDER_RM_SUPPORT
2978 char decoder_name[20] = {'\0',};
2979 int decoder_index = 0;
2980 #endif /* _MMCAMCORDER_RM_SUPPORT */
2982 if ((void *)handle == NULL) {
2983 _mmcam_dbg_warn("handle is NULL");
2987 hcamcorder = MMF_CAMCORDER(handle);
2989 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2991 _mmcam_dbg_warn("subcontext is NULL");
2995 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
2996 hcamcorder->recreate_decoder == FALSE) {
2997 _mmcam_dbg_log("skip this fuction - format %d, recreate decoder %d",
2998 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3002 mm_camcorder_get_attributes(handle, NULL,
3003 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3006 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3007 _mmcam_dbg_log("no need to control decoder element");
3011 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3012 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3013 _mmcam_dbg_warn("main pipeline or decoder plugin is NULL");
3017 _mmcam_dbg_log("start");
3019 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
3020 if (videodecoder_name == NULL) {
3021 _mmcam_dbg_err("failed to get decoder element name from %p", sc->VideodecoderElementH264);
3025 /* set state as NULL */
3026 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3027 if (ret != MM_ERROR_NONE) {
3028 _mmcam_dbg_err("failed to set NULL to decoder");
3032 /* remove decoder - pads will be unlinked automatically in remove function */
3033 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3034 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3035 _mmcam_dbg_err("failed to remove decoder from pipeline");
3039 /* check decoder element */
3040 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3041 _mmcam_dbg_log("decoder[%p] is still alive - ref count %d",
3042 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3043 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3046 #ifdef _MMCAMCORDER_RM_SUPPORT
3047 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3048 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3051 snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
3052 _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
3055 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3056 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_uhd_mjpegdec");
3058 snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_mjpegdec");
3059 _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
3062 /* create decoder */
3063 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(decoder_name, "videosrc_decode");
3064 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3065 _mmcam_dbg_err("Decoder[%s] creation fail", decoder_name);
3068 #else /* _MMCAMCORDER_RM_SUPPORT */
3069 /* create new decoder */
3070 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name, "videosrc_decode");
3071 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3072 _mmcam_dbg_err("Decoder [%s] creation fail", videodecoder_name);
3075 #endif /* _MMCAMCORDER_RM_SUPPORT */
3076 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
3078 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3079 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3080 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3082 /* add to pipeline */
3083 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3084 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3085 _mmcam_dbg_err("failed to add decoder to pipeline");
3086 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3091 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3092 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3093 _mmcam_dbg_log("Link videosrc_queue to decoder OK");
3095 _mmcam_dbg_err("Link videosrc_queue to decoder FAILED");
3099 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3100 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3101 _mmcam_dbg_log("Link decoder to videosink_queue OK");
3103 _mmcam_dbg_err("Link decoder to videosink_queue FAILED");
3107 /* set state READY */
3108 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3109 if (ret != MM_ERROR_NONE) {
3110 _mmcam_dbg_err("failed to set READY to decoder");
3114 _mmcam_dbg_log("done");
3119 #ifdef _MMCAMCORDER_PRODUCT_TV
3120 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3122 _MMCamcorderSubContext *sc = NULL;
3123 mmf_camcorder_t *hcamcorder = NULL;
3125 const gchar *mime = NULL;
3127 GstCaps *decsink_caps = NULL;
3128 GstStructure *decsink_struct = NULL;
3130 mmf_return_val_if_fail(handle, false);
3131 mmf_return_val_if_fail(max_width, false);
3132 mmf_return_val_if_fail(max_height, false);
3134 hcamcorder = MMF_CAMCORDER(handle);
3135 mmf_return_val_if_fail(hcamcorder, false);
3137 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3139 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3141 _mmcam_dbg_err("There are no decoder caps");
3145 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3146 if (!decsink_caps) {
3147 gst_object_unref(sinkpad);
3148 _mmcam_dbg_err("There is no decoder sink caps");
3152 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3153 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3154 if (!decsink_struct) {
3155 _mmcam_dbg_err("There are no structure from caps");
3156 gst_object_unref(decsink_caps);
3157 gst_object_unref(sinkpad);
3160 mime = gst_structure_get_name(decsink_struct);
3161 if (!strcmp(mime, "video/x-h264")) {
3162 _mmcam_dbg_log("h264 caps structure found");
3163 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3164 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3165 if (gst_structure_has_field(decsink_struct, "maxheight"))
3166 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3168 } else if (!strcmp(mime, "video/x-jpeg")) {
3169 _mmcam_dbg_log("mjpeg caps structure found");
3170 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3171 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3172 if (gst_structure_has_field(decsink_struct, "maxheight"))
3173 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3177 _mmcam_dbg_log("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3178 gst_object_unref(decsink_caps);
3179 gst_object_unref(sinkpad);
3181 if (*max_width <= 0 || *max_height <= 0)
3186 #endif /* _MMCAMCORDER_PRODUCT_TV */