4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
25 #include <gst/allocators/gsttizenmemory.h>
26 #include <gst/audio/audio-format.h>
27 #include <gst/video/videooverlay.h>
31 #include <tbm_bufmgr.h>
32 #include <tbm_surface.h>
33 #include <tbm_surface_internal.h>
35 #include "mm_camcorder_internal.h"
36 #include "mm_camcorder_gstcommon.h"
38 /*-----------------------------------------------------------------------
39 | GLOBAL VARIABLE DEFINITIONS for internal |
40 -----------------------------------------------------------------------*/
41 /* Table for compatibility between audio codec and file format */
42 static gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
43 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
44 /*AMR*/ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
45 /*G723.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
46 /*MP3*/ { 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
47 /*OGG*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
48 /*AAC*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
49 /*WMA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
50 /*MMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 /*ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
52 /*WAVE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
53 /*WAVE_NEW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
54 /*MIDI*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
55 /*IMELODY*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
56 /*MXMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
57 /*MPA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
58 /*MP2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
59 /*G711*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
60 /*G722*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
61 /*G722.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
62 /*G722.2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
63 /*G723*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
64 /*G726*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
65 /*G728*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
66 /*G729*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
67 /*G729A*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
68 /*G729.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
69 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
70 /*AAC_LC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
71 /*AAC_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
72 /*AAC_SRS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
73 /*AAC_LTP*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
74 /*AAC_HE_V1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
75 /*AAC_HE_V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
76 /*AC3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
77 /*ALAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
78 /*ATRAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
79 /*SPEEX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
80 /*VORBIS*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
81 /*AIFF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
82 /*AU*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
83 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
84 /*PCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
85 /*ALAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 /*MULAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 /*MS_ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
90 /* Table for compatibility between video codec and file format */
91 static gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
92 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
93 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
94 /*H263*/ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
95 /*H264*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
96 /*H26L*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
97 /*MPEG4*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
98 /*MPEG1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
99 /*WMV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
100 /*DIVX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
101 /*XVID*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
102 /*H261*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
103 /*H262*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
104 /*H263V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
105 /*H263V3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
106 /*MJPEG*/ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
107 /*MPEG2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
108 /*MPEG4_SIMPLE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
109 /*MPEG4_ADV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
110 /*MPEG4_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
111 /*MPEG4_CORE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
112 /*MPEG4_ACE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
113 /*MPEG4_ARTS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
114 /*MPEG4_AVC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
115 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
116 /*VC1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
117 /*AVS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
118 /*CINEPAK*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
119 /*INDEO*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
120 /*THEORA*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
124 /*-----------------------------------------------------------------------
125 | LOCAL VARIABLE DEFINITIONS for internal |
126 -----------------------------------------------------------------------*/
127 #define USE_AUDIO_CLOCK_TUNE
128 #define _MMCAMCORDER_WAIT_EOS_TIME 60.0 /* sec */
129 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM 6
130 #define _MMCAMCORDER_NANOSEC_PER_1SEC 1000000000
131 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC 1000
132 #define _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG "request-codec-config"
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_get_structure_fourcc(const GstStructure *structure);
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(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
161 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory);
162 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format);
163 static void __mmcamcorder_request_codec_config(GstElement *videosrc_element);
165 /*=======================================================================================
166 | FUNCTION DEFINITIONS |
167 =======================================================================================*/
168 static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
172 mmf_return_val_if_fail(buffer, FALSE);
173 mmf_return_val_if_fail(stream, FALSE);
174 mmf_return_val_if_fail(map_info, FALSE);
176 stream->length_total = map_info->size;
178 switch (stream->format) {
179 case MM_PIXEL_FORMAT_NV12: /* fall through */
180 case MM_PIXEL_FORMAT_NV21:
181 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
182 stream->data.yuv420sp.y = map_info->data;
183 stream->data.yuv420sp.length_y = stream->width * stream->height;
184 stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
185 stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
186 stream->stride[0] = stream->width;
187 stream->elevation[0] = stream->height;
188 stream->stride[1] = stream->width;
189 stream->elevation[1] = stream->height >> 1;
190 stream->num_planes = 2;
193 case MM_PIXEL_FORMAT_I420:
194 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
195 stream->data.yuv420p.y = map_info->data;
196 stream->data.yuv420p.length_y = stream->width * stream->height;
197 stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
198 stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
199 stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
200 stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
201 stream->stride[0] = stream->width;
202 stream->elevation[0] = stream->height;
203 stream->stride[1] = stream->stride[2] = stream->width >> 1;
204 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
205 stream->num_planes = 3;
208 case MM_PIXEL_FORMAT_422P:
209 stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
210 stream->data.yuv422p.y = map_info->data;
211 stream->data.yuv422p.length_y = stream->width * stream->height;
212 stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
213 stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
214 stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
215 stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
216 stream->stride[0] = stream->width;
217 stream->elevation[0] = stream->height;
218 stream->stride[1] = stream->stride[2] = stream->width;
219 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
220 stream->num_planes = 3;
223 case MM_PIXEL_FORMAT_YUYV: /* fall through */
224 case MM_PIXEL_FORMAT_UYVY: /* fall through */
225 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
226 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
227 stream->data.yuv422.yuv = map_info->data;
228 stream->data.yuv422.length_yuv = stream->length_total;
229 stream->stride[0] = stream->width << 1;
230 stream->elevation[0] = stream->height;
231 stream->num_planes = 1;
234 case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
235 case MM_PIXEL_FORMAT_ENCODED_MJPEG: /* fall through */
236 case MM_PIXEL_FORMAT_ENCODED_VP8: /* fall through */
237 case MM_PIXEL_FORMAT_ENCODED_VP9: /* fall through */
238 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
239 stream->data.encoded.data = map_info->data;
240 stream->data.encoded.length_data = stream->length_total;
241 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
242 stream->num_planes = 1;
245 case MM_PIXEL_FORMAT_INVZ:
246 stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
247 stream->data.depth.data = map_info->data;
248 stream->data.depth.length_data = stream->length_total;
249 stream->stride[0] = stream->width << 1;
250 stream->elevation[0] = stream->height;
251 stream->num_planes = 1;
254 case MM_PIXEL_FORMAT_RGBA: /* fall through */
255 case MM_PIXEL_FORMAT_ARGB:
256 stream->data_type = MM_CAM_STREAM_DATA_RGB;
257 stream->data.rgb.data = map_info->data;
258 stream->data.rgb.length_data = stream->length_total;
259 stream->stride[0] = stream->width << 2;
260 stream->elevation[0] = stream->height;
261 stream->num_planes = 1;
265 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
274 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory)
278 int tbm_ret = TBM_SURFACE_ERROR_NONE;
279 tbm_bo_handle bo_handle = {NULL, };
280 tbm_surface_info_s ts_info;
282 mmf_return_val_if_fail(stream, FALSE);
283 mmf_return_val_if_fail(buffer, FALSE);
284 mmf_return_val_if_fail(memory, FALSE);
286 if (_mmcamcorder_is_encoded_preview_pixel_format(stream->format)) {
287 stream->bo[0] = gst_tizen_memory_get_bos(memory, 0);
289 bo_handle = tbm_bo_get_handle(stream->bo[0], TBM_DEVICE_CPU);
290 if (!bo_handle.ptr) {
291 MMCAM_LOG_ERROR("tbm_bo_get_handle failed[bo:%p,memory:%p]", stream->bo[0], memory);
295 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
296 stream->num_planes = 1;
297 stream->stride[0] = stream->width;
298 stream->elevation[0] = stream->height;
299 stream->data.encoded.data = bo_handle.ptr;
300 stream->length_total = gst_memory_get_sizes(memory, NULL, NULL);
301 stream->data.encoded.length_data = stream->length_total;
302 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
304 MMCAM_LOG_VERBOSE("[ENCODED] length[%u], is_delta[%d]",
305 stream->data.encoded.length_data, stream->data.encoded.is_delta_frame);
310 memset(&ts_info, 0x0, sizeof(tbm_surface_info_s));
312 tbm_ret = tbm_surface_get_info((tbm_surface_h)gst_tizen_memory_get_surface(memory), &ts_info);
313 if (tbm_ret != TBM_SURFACE_ERROR_NONE) {
314 MMCAM_LOG_ERROR("get tbm surface info failed[0x%x]", tbm_ret);
318 stream->length_total = ts_info.size;
319 for (i = 0 ; i < ts_info.num_planes ; i++) {
320 stream->stride[i] = ts_info.planes[i].stride;
321 stream->elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
322 MMCAM_LOG_VERBOSE(" plane[%d] %dx%d", i, stream->stride[i], stream->elevation[i]);
325 num_bos = gst_tizen_memory_get_num_bos(memory);
326 for (i = 0 ; i < num_bos ; i++)
327 stream->bo[i] = gst_tizen_memory_get_bos(memory, i);
330 switch (stream->format) {
331 case MM_PIXEL_FORMAT_NV12: /* fall through */
332 case MM_PIXEL_FORMAT_NV21:
333 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
334 stream->num_planes = 2;
335 stream->data.yuv420sp.y = ts_info.planes[0].ptr;
336 stream->data.yuv420sp.length_y = ts_info.planes[0].size;
337 stream->data.yuv420sp.uv = ts_info.planes[1].ptr;
338 stream->data.yuv420sp.length_uv = ts_info.planes[1].size;
340 MMCAM_LOG_VERBOSE("[420SP] 0[%p,%u], 1[%p,%u]",
341 stream->data.yuv420sp.y, stream->data.yuv420sp.length_y,
342 stream->data.yuv420sp.uv, stream->data.yuv420sp.length_uv);
345 case MM_PIXEL_FORMAT_I420:
346 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
347 stream->num_planes = 3;
348 stream->data.yuv420p.y = ts_info.planes[0].ptr;
349 stream->data.yuv420p.length_y = ts_info.planes[0].size;
350 stream->data.yuv420p.u = ts_info.planes[1].ptr;
351 stream->data.yuv420p.length_u = ts_info.planes[1].size;
352 stream->data.yuv420p.v = ts_info.planes[2].ptr;
353 stream->data.yuv420p.length_v = ts_info.planes[2].size;
355 MMCAM_LOG_VERBOSE("[I420] 0[%p,%u], 1[%p,%u], 2[%p,%u]",
356 stream->data.yuv420p.y, stream->data.yuv420p.length_y,
357 stream->data.yuv420p.u, stream->data.yuv420p.length_u,
358 stream->data.yuv420p.v, stream->data.yuv420p.length_v);
361 case MM_PIXEL_FORMAT_YUYV:
362 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
363 stream->num_planes = 1;
364 stream->data.yuv422.yuv = ts_info.planes[0].ptr;
365 stream->data.yuv422.length_yuv = ts_info.planes[0].size;
367 MMCAM_LOG_VERBOSE("[YUYV] 0[%p,%u]",
368 stream->data.yuv422.yuv, stream->data.yuv422.length_yuv);
372 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
380 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format)
383 case MM_PIXEL_FORMAT_ENCODED_H264:
385 case MM_PIXEL_FORMAT_ENCODED_VP9:
388 MMCAM_LOG_WARNING("unsupported format[%d]", format);
394 static void __mmcamcorder_request_codec_config(GstElement *videosrc_element)
396 if (!videosrc_element || !G_TYPE_CHECK_INSTANCE(videosrc_element)) {
397 MMCAM_LOG_WARNING("invalid videosrc element[%p]", videosrc_element);
401 if (!g_signal_parse_name(_MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG,
402 G_TYPE_FROM_INSTANCE(videosrc_element), NULL, NULL, FALSE)) {
403 MMCAM_LOG_WARNING("no signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
407 MMCAM_LOG_INFO("emit signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
409 g_signal_emit_by_name(videosrc_element, _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
413 gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sample, gboolean is_preview, int stream_id)
416 gboolean ret_cb = TRUE;
417 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
418 _MMCamcorderSubContext *sc = NULL;
419 MMCamcorderVideoStreamDataType stream;
421 GstBuffer *buffer = NULL;
422 GstMemory *memory = NULL;
424 GstCaps *caps = NULL;
425 GstStructure *structure = NULL;
427 mmf_return_val_if_fail(hcamcorder, FALSE);
429 buffer = gst_sample_get_buffer(sample);
430 mmf_return_val_if_fail(buffer, FALSE);
431 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
433 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
434 mmf_return_val_if_fail(sc, FALSE);
436 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
438 caps = gst_sample_get_caps(sample);
439 mmf_return_val_if_fail(caps, FALSE);
441 structure = gst_caps_get_structure(caps, 0);
442 mmf_return_val_if_fail(structure, FALSE);
444 stream.format = _mmcamcorder_get_pixel_format(caps, TRUE);
445 gst_structure_get(structure,
446 "width", G_TYPE_INT, &stream.width,
447 "height", G_TYPE_INT, &stream.height,
450 memory = gst_buffer_peek_memory(buffer, 0);
452 MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
456 structure = gst_mini_object_get_qdata(GST_MINI_OBJECT_CAST(buffer), hcamcorder->buffer_quark);
457 if (structure && gst_structure_has_field(structure, "focus-state")) {
458 gst_structure_get(structure,
459 "focus-state", G_TYPE_INT, &stream.focus_state,
460 "facing-direction", G_TYPE_INT, &stream.facing_direction,
461 "flip", G_TYPE_INT, &stream.flip,
462 "rotation", G_TYPE_INT, &stream.rotation,
465 MMCAM_LOG_VERBOSE("structure[%p], [fs:%d,fd:%d,f:%d,r:%d]", structure,
466 stream.focus_state, stream.facing_direction, stream.flip, stream.rotation);
469 if (gst_is_tizen_memory(memory)) {
470 if (!__mmcamcorder_set_stream_data_zero_copy(&stream, buffer, memory))
471 goto _INVOKE_VIDEO_STREAM_CB_DONE;
473 memset(&map_info, 0x0, sizeof(GstMapInfo));
475 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE)) {
476 MMCAM_LOG_ERROR("map failed for memory[%p]", memory);
480 if (!__mmcamcorder_set_stream_data(&stream, buffer, &map_info))
481 goto _INVOKE_VIDEO_STREAM_CB_DONE;
484 MMCAM_LOG_DEBUG("VideoStreamData : format[%d], resolution[%dx%d], stream_id[%d]",
485 stream.format, stream.width, stream.height, stream_id);
487 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
488 stream.extra_stream_id = stream_id;
489 stream.internal_buffer = buffer;
491 /* invoke application callback */
493 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
494 if (hcamcorder->vstream_cb)
495 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
496 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
498 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
499 if (hcamcorder->vedecision_cb)
500 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
501 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
504 _INVOKE_VIDEO_STREAM_CB_DONE:
505 if (!gst_is_tizen_memory(memory))
506 gst_memory_unmap(memory, &map_info);
508 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
509 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
510 tbm_bo_unmap(stream.bo[i]);
517 int _mmcamcorder_create_preview_elements(MMHandleType handle)
519 int err = MM_ERROR_NONE;
521 int camera_rotate = 0;
525 int capture_width = 0;
526 int capture_height = 0;
527 int capture_quality = 0;
528 int video_stabilization = 0;
530 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
531 const char *videosrc_name = NULL;
532 const char *videosink_name = NULL;
533 const char *videoconvert_name = NULL;
534 const char *videodecoder_name = NULL;
535 const char *videoparse_name = NULL;
536 const char *decoder_conf_name = NULL;
537 char videodecoder_name_final[32] = {'\0',};
538 char *err_name = NULL;
539 #ifdef _MMCAMCORDER_RM_SUPPORT
540 int decoder_index = 0;
541 #endif /* _MMCAMCORDER_RM_SUPPORT */
542 GstElement *sink_element = NULL;
543 GstCameraControl *control = NULL;
544 int sink_element_size = 0;
547 int extra_preview_enable = 0;
549 GList *element_list = NULL;
551 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
552 _MMCamcorderSubContext *sc = NULL;
553 type_element *videosrc_element = NULL;
554 type_int_array *input_index = NULL;
556 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
558 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
559 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
560 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
564 /* Check existence */
565 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
566 if (sc->element[i].gst) {
567 if (((GObject *)sc->element[i].gst)->ref_count > 0)
568 gst_object_unref(sc->element[i].gst);
570 MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
574 /* Get video device index info */
575 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
576 CONFIGURE_CATEGORY_CTRL_CAMERA,
579 if (input_index == NULL) {
580 MMCAM_LOG_ERROR("Failed to get input_index");
581 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
584 err = mm_camcorder_get_attributes(handle, &err_name,
585 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
586 MMCAM_CAMERA_FPS, &fps,
587 MMCAM_CAMERA_ROTATION, &camera_rotate,
588 MMCAM_CAMERA_FLIP, &camera_flip,
589 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
590 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
591 MMCAM_CAPTURE_WIDTH, &capture_width,
592 MMCAM_CAPTURE_HEIGHT, &capture_height,
593 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
594 MMCAM_IMAGE_ENCODER, &codectype,
595 MMCAM_IMAGE_ENCODER_QUALITY, &capture_quality,
596 MMCAM_DISPLAY_SURFACE, &display_surface_type,
597 MMCAM_EXTRA_PREVIEW_ENABLE, &extra_preview_enable,
599 if (err != MM_ERROR_NONE) {
600 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
605 if (hcamcorder->support_user_buffer) {
606 err = mm_camcorder_get_attributes(handle, NULL,
607 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
609 if (err != MM_ERROR_NONE || fd_number < 1) {
610 MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
615 for (i = 0 ; i < fd_number ; i++)
616 MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
620 /* Get fourcc from picture format */
621 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
623 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
624 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
625 &videosrc_element, &videosrc_name);
628 * Create child element
630 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
632 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
635 * This is for "tizencamerasrc" element only.
636 * The camera HAL library will be loaded when "hal-name" property is set.
637 * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
639 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
641 /* camera properties */
642 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
643 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
644 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
645 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-quality", capture_quality);
646 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
647 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "extra-preview", extra_preview_enable);
648 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
650 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
652 /* set camera flip */
653 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
655 /* set video stabilization mode */
656 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
658 /* set anti handshake mode */
659 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
661 if (sc->is_modified_rate)
662 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
664 /* Set basic information of videosrc element */
665 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, videosrc_element);
667 /* Set video device index */
668 if (hcamcorder->is_network) {
669 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
671 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
672 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
674 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
678 /* set user buffer fd to videosrc element */
679 if (hcamcorder->support_user_buffer) {
680 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
681 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
682 MMCAM_LOG_ERROR("set user buffer fd failed");
683 goto pipeline_creation_error;
687 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
688 /* get recreate_decoder flag */
689 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
690 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
692 &hcamcorder->recreate_decoder);
695 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
696 _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
697 switch (sc->info_image->preview_format) {
698 case MM_PIXEL_FORMAT_ENCODED_H264:
699 decoder_conf_name = "VideodecoderElementH264";
701 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
702 decoder_conf_name = "VideodecoderElementMJPEG";
704 case MM_PIXEL_FORMAT_ENCODED_VP8:
705 decoder_conf_name = "VideodecoderElementVP8";
707 case MM_PIXEL_FORMAT_ENCODED_VP9:
708 decoder_conf_name = "VideodecoderElementVP9";
711 MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
712 goto pipeline_creation_error;
715 /* get video decoder element and name */
716 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
717 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
719 &sc->VideodecoderElement);
721 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
724 if (!videodecoder_name) {
725 MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
726 goto pipeline_creation_error;
729 #ifdef _MMCAMCORDER_RM_SUPPORT
730 MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
731 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
732 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
734 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
735 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
736 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
737 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
739 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
741 #endif /* _MMCAMCORDER_RM_SUPPORT */
742 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
743 #ifdef _MMCAMCORDER_RM_SUPPORT
745 #endif /* _MMCAMCORDER_RM_SUPPORT */
747 videoparse_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
749 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_PARSE, videoparse_name, "videosrc_parse", element_list, err);
751 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
753 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
756 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
758 /* Get videosink name */
759 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
761 if (!videosink_name) {
762 MMCAM_LOG_ERROR("failed to get videosink name");
763 goto pipeline_creation_error;
766 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
768 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
770 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
771 /* get video convert name */
772 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
774 if (videoconvert_name) {
775 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
776 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
778 MMCAM_LOG_ERROR("failed to get videoconvert element name");
781 /* check sink element in attribute */
782 mm_camcorder_get_attributes(handle, NULL,
783 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
788 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
790 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
792 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
794 /* reset attribute */
796 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
797 mm_attrs_set_data(attrs, attr_index, NULL, 0);
798 mm_attrs_commit(attrs, attr_index);
800 MMCAM_LOG_WARNING("attribute is NULL");
801 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
802 goto pipeline_creation_error;
805 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
807 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
810 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
811 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
812 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
813 goto pipeline_creation_error;
816 /* Set caps by rotation */
817 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
819 /* add elements to main pipeline */
820 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
821 MMCAM_LOG_ERROR("element_list add error.");
822 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
823 goto pipeline_creation_error;
827 if (!_mmcamcorder_link_elements(element_list)) {
828 MMCAM_LOG_ERROR("element link error.");
829 err = MM_ERROR_CAMCORDER_GST_LINK;
830 goto pipeline_creation_error;
834 g_list_free(element_list);
838 return MM_ERROR_NONE;
840 pipeline_creation_error:
841 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
842 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
843 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
844 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_FILT);
845 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_SINK);
846 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
847 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
848 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
851 g_list_free(element_list);
859 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
861 int err = MM_ERROR_NONE;
866 int a_enc = MM_AUDIO_CODEC_AMR;
867 int a_dev = MM_AUDIO_DEVICE_MIC;
869 char *err_name = NULL;
870 const char *audiosrc_name = NULL;
871 char *cat_name = NULL;
872 char *stream_type = NULL;
873 int stream_type_len = 0;
874 int stream_index = 0;
875 int buffer_interval = 0;
877 int replay_gain_enable = FALSE;
878 double replay_gain_ref_level = 0.0;
880 GstCaps *caps = NULL;
882 GList *element_list = NULL;
884 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
885 _MMCamcorderSubContext *sc = NULL;
886 _MMCamcorderGstElement *last_element = NULL;
887 type_element *audiosrc_element = NULL;
889 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
891 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
892 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
893 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
897 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
898 if (err != MM_ERROR_NONE)
901 err = mm_camcorder_get_attributes(handle, &err_name,
902 MMCAM_AUDIO_DEVICE, &a_dev,
903 MMCAM_AUDIO_ENCODER, &a_enc,
904 MMCAM_AUDIO_ENCODER_BITRATE, &val,
905 MMCAM_AUDIO_SAMPLERATE, &rate,
906 MMCAM_AUDIO_FORMAT, &format,
907 MMCAM_AUDIO_CHANNEL, &channel,
908 MMCAM_AUDIO_VOLUME, &volume,
909 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
910 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
911 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
912 MMCAM_SOUND_STREAM_INDEX, &stream_index,
914 if (err != MM_ERROR_NONE) {
915 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
920 /* Check existence */
921 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
922 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
923 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
925 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
928 /* Create bin element */
929 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
931 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
932 cat_name = strdup("AudiomodemsrcElement");
934 /* MM_AUDIO_DEVICE_MIC or others */
935 cat_name = strdup("AudiosrcElement");
938 if (cat_name == NULL) {
939 MMCAM_LOG_ERROR("strdup failed.");
940 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
941 goto pipeline_creation_error;
944 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
945 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, cat_name,
946 &audiosrc_element, &audiosrc_name);
951 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
953 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
955 /* set sound stream info */
956 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
958 /* set audiosrc properties in ini configuration */
959 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, audiosrc_element);
962 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
963 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
964 "AudioBufferInterval",
967 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
968 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
969 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
972 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
974 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
975 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
976 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
977 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
979 /* Set basic information */
980 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
982 const gchar* format_name = NULL;
984 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
987 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
988 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
990 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
991 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
994 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
996 format_name = "S16LE";
997 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
1002 caps = gst_caps_new_simple("audio/x-raw",
1003 "rate", G_TYPE_INT, rate,
1004 "channels", G_TYPE_INT, channel,
1005 "format", G_TYPE_STRING, format_name,
1007 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
1008 rate, channel, depth, volume);
1010 /* what are the audio encoder which should get audio/x-raw-float? */
1011 caps = gst_caps_new_simple("audio/x-raw",
1012 "rate", G_TYPE_INT, rate,
1013 "channels", G_TYPE_INT, channel,
1014 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
1016 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
1017 rate, channel, BYTE_ORDER);
1021 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
1022 replay_gain_enable, replay_gain_ref_level);
1024 if (replay_gain_enable) {
1025 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
1026 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
1027 /* If num-tracks is not set, album gain and peak event is not come. */
1028 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
1032 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
1033 gst_caps_unref(caps);
1036 MMCAM_LOG_ERROR("create caps error");
1037 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1038 goto pipeline_creation_error;
1041 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
1042 MMCAM_LOG_ERROR("element add error.");
1043 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1044 goto pipeline_creation_error;
1047 if (!_mmcamcorder_link_elements(element_list)) {
1048 MMCAM_LOG_ERROR("element link error.");
1049 err = MM_ERROR_CAMCORDER_GST_LINK;
1050 goto pipeline_creation_error;
1053 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
1054 pad = gst_element_get_static_pad(last_element->gst, "src");
1055 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
1056 gst_object_unref(pad);
1058 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
1059 err = MM_ERROR_CAMCORDER_GST_LINK;
1060 goto pipeline_creation_error;
1063 gst_object_unref(pad);
1067 g_list_free(element_list);
1068 element_list = NULL;
1071 return MM_ERROR_NONE;
1073 pipeline_creation_error:
1074 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1075 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1076 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1077 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1078 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1081 g_list_free(element_list);
1082 element_list = NULL;
1089 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1094 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1099 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1100 type, codec, bitrate);
1104 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1105 /* audio encoder bitrate setting */
1107 case MM_AUDIO_CODEC_AMR:
1108 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1109 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1110 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1112 case MM_AUDIO_CODEC_MP3:
1113 set_value = bitrate / 1000;
1114 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1115 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1117 case MM_AUDIO_CODEC_AAC:
1118 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1119 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1122 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1126 /* video encoder bitrate setting */
1127 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1128 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1135 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1137 int err = MM_ERROR_NONE;
1142 int encodebin_profile = 0;
1143 int auto_audio_convert = 0;
1144 int auto_audio_resample = 0;
1145 int auto_color_space = 0;
1146 int cap_format = MM_PIXEL_FORMAT_INVALID;
1147 const char *gst_element_venc_name = NULL;
1148 const char *gst_element_aenc_name = NULL;
1149 const char *gst_element_ienc_name = NULL;
1150 const char *gst_element_mux_name = NULL;
1151 const char *gst_element_rsink_name = NULL;
1152 const char *gst_element_vscale_name = NULL;
1153 const char *str_profile = NULL;
1154 const char *str_aac = NULL;
1155 const char *str_aar = NULL;
1156 const char *str_acs = NULL;
1157 char *err_name = NULL;
1158 const char *videoconvert_name = NULL;
1159 GstCaps *audio_caps = NULL;
1160 GstCaps *video_caps = NULL;
1161 GstCaps *videoscale_caps = NULL;
1163 GList *element_list = NULL;
1165 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1166 _MMCamcorderSubContext *sc = NULL;
1167 type_element *VideoencElement = NULL;
1168 type_element *AudioencElement = NULL;
1169 type_element *ImageencElement = NULL;
1170 type_element *MuxElement = NULL;
1171 type_element *RecordsinkElement = NULL;
1172 type_element *VideoscaleElement = NULL;
1174 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1176 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1177 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1178 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1180 MMCAM_LOG_INFO("start - profile : %d", profile);
1182 /* Check existence */
1183 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1184 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1185 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1187 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1190 /* Create bin element */
1191 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1193 /* Create child element */
1194 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1195 GstCaps *caps_from_pad = NULL;
1196 char *caps_str = NULL;
1198 /* create appsrc and capsfilter */
1199 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1201 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1203 /* set appsrc as live source */
1204 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1205 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1206 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1208 /* set capsfilter */
1209 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1210 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1211 MMCAM_LOG_INFO("get pad from videosrc_filter");
1212 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1214 MMCAM_LOG_INFO("get pad from videosrc_que");
1215 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1218 MMCAM_LOG_ERROR("get videosrc_que src pad failed");
1219 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1220 goto pipeline_creation_error;
1223 caps_from_pad = gst_pad_get_allowed_caps(pad);
1224 video_caps = gst_caps_copy(caps_from_pad);
1225 gst_caps_unref(caps_from_pad);
1226 caps_from_pad = NULL;
1227 gst_object_unref(pad);
1231 video_caps = gst_caps_fixate(video_caps);
1234 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1238 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1239 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1240 goto pipeline_creation_error;
1243 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1244 if (sc->info_video->use_videoscale) {
1245 gst_caps_set_simple(video_caps,
1246 "width", G_TYPE_INT, sc->info_video->preview_width,
1247 "height", G_TYPE_INT, sc->info_video->preview_height,
1249 videoscale_caps = gst_caps_copy(video_caps);
1251 gst_caps_set_simple(video_caps,
1252 "width", G_TYPE_INT, sc->info_video->video_width,
1253 "height", G_TYPE_INT, sc->info_video->video_height,
1258 caps_str = gst_caps_to_string(video_caps);
1260 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1265 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1267 gst_caps_unref(video_caps);
1271 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1272 sc->info_video->use_videoscale) {
1273 if (!videoscale_caps) {
1274 MMCAM_LOG_ERROR("no videoscale caps");
1275 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1276 goto pipeline_creation_error;
1279 gst_caps_set_simple(videoscale_caps,
1280 "width", G_TYPE_INT, sc->info_video->video_width,
1281 "height", G_TYPE_INT, sc->info_video->video_height,
1284 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1285 CONFIGURE_CATEGORY_MAIN_RECORD,
1286 "VideoscaleElement",
1287 &VideoscaleElement);
1289 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1290 MMCAM_LOG_ERROR("failed to get videoscale element name");
1291 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1292 goto pipeline_creation_error;
1295 caps_str = gst_caps_to_string(videoscale_caps);
1297 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1302 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
1303 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
1305 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
1307 gst_caps_unref(videoscale_caps);
1308 videoscale_caps = NULL;
1311 /* release element_list, they will be placed out of encodesink bin */
1313 g_list_free(element_list);
1314 element_list = NULL;
1317 /* connect signal for ready to push buffer */
1318 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1319 _MMCAMCORDER_HANDLER_VIDEOREC,
1321 _mmcamcorder_ready_to_encode_callback,
1325 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1326 "tizenencodebin", "encodesink_encbin", element_list, err);
1328 /* check element availability */
1329 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1330 err = mm_camcorder_get_attributes(handle, &err_name,
1331 MMCAM_CAPTURE_FORMAT, &cap_format,
1334 err = mm_camcorder_get_attributes(handle, &err_name,
1335 MMCAM_AUDIO_ENCODER, &audio_enc,
1336 MMCAM_AUDIO_CHANNEL, &channel,
1337 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1338 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1342 if (err != MM_ERROR_NONE) {
1344 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1345 SAFE_FREE(err_name);
1347 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1350 goto pipeline_creation_error;
1353 MMCAM_LOG_INFO("Profile[%d]", profile);
1355 /* Set information */
1356 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1357 str_profile = "VideoProfile";
1358 str_aac = "VideoAutoAudioConvert";
1359 str_aar = "VideoAutoAudioResample";
1360 str_acs = "VideoAutoColorSpace";
1361 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1362 str_profile = "AudioProfile";
1363 str_aac = "AudioAutoAudioConvert";
1364 str_aar = "AudioAutoAudioResample";
1365 str_acs = "AudioAutoColorSpace";
1366 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1367 str_profile = "ImageProfile";
1368 str_aac = "ImageAutoAudioConvert";
1369 str_aar = "ImageAutoAudioResample";
1370 str_acs = "ImageAutoColorSpace";
1373 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1374 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1375 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1376 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1378 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1379 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1381 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1382 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1383 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1384 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1385 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1387 /* get video convert element name */
1388 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1391 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1392 int use_venc_queue = 0;
1394 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1396 if (!VideoencElement) {
1397 MMCAM_LOG_ERROR("Fail to get type element");
1398 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1399 goto pipeline_creation_error;
1402 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1403 /* set parse element */
1404 gst_element_venc_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
1405 if (!gst_element_venc_name)
1406 gst_element_venc_name = "identity";
1408 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1411 if (gst_element_venc_name) {
1412 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1414 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1415 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1417 MMCAM_LOG_ERROR("Fail to get video encoder name");
1418 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1419 goto pipeline_creation_error;
1422 /* set color space converting element */
1423 if (auto_color_space) {
1424 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1426 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1427 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1429 /* set colorspace plugin property setting */
1430 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1432 /* fourcc type was removed in GST 1.0 */
1433 if (hcamcorder->use_zero_copy_format) {
1434 if (strstr(gst_element_venc_name, "omx")) {
1435 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1438 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1439 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1441 gst_caps_unref(video_caps);
1444 MMCAM_LOG_WARNING("failed to create caps");
1447 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1452 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1453 CONFIGURE_CATEGORY_MAIN_RECORD,
1454 "UseVideoEncoderQueue",
1457 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1460 if (sc->audio_disable == FALSE &&
1461 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1462 int use_aenc_queue = 0;
1464 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1465 if (!AudioencElement) {
1466 MMCAM_LOG_ERROR("Fail to get type element");
1467 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1468 goto pipeline_creation_error;
1471 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1473 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1474 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1476 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1477 audio_caps = gst_caps_new_simple("audio/x-raw",
1478 "channels", G_TYPE_INT, 1,
1480 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1481 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1482 gst_caps_unref(audio_caps);
1486 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1487 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1488 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1489 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1490 gst_caps_unref(audio_caps);
1492 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1495 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1496 CONFIGURE_CATEGORY_MAIN_RECORD,
1497 "UseAudioEncoderQueue",
1499 if (use_aenc_queue) {
1500 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1501 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1502 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1506 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1507 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1508 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1509 if (!ImageencElement) {
1510 MMCAM_LOG_ERROR("Fail to get type element");
1511 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1512 goto pipeline_creation_error;
1515 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1517 /* raw format - set dummy element */
1518 gst_element_ienc_name = "identity";
1521 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1522 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1526 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1527 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1529 MMCAM_LOG_ERROR("Fail to get type element");
1530 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1531 goto pipeline_creation_error;
1534 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1536 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1537 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1539 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1543 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1545 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1546 CONFIGURE_CATEGORY_MAIN_RECORD,
1547 "RecordsinkElement",
1548 &RecordsinkElement);
1549 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1551 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1553 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1556 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1559 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1560 /* property setting in ini */
1561 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1563 /* bitrate setting */
1564 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1565 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1568 if (sc->audio_disable == FALSE &&
1569 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1570 /* property setting in ini */
1571 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1573 /* bitrate setting */
1574 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1575 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1578 MMCAM_LOG_INFO("Element creation complete");
1580 /* Add element to bin */
1581 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1582 MMCAM_LOG_ERROR("element add error.");
1583 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1584 goto pipeline_creation_error;
1587 MMCAM_LOG_INFO("Element add complete");
1589 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1590 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1591 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1592 gst_object_unref(pad);
1594 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1595 err = MM_ERROR_CAMCORDER_GST_LINK;
1596 goto pipeline_creation_error;
1598 gst_object_unref(pad);
1601 if (sc->audio_disable == FALSE) {
1602 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1603 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1604 gst_object_unref(pad);
1606 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1607 err = MM_ERROR_CAMCORDER_GST_LINK;
1608 goto pipeline_creation_error;
1610 gst_object_unref(pad);
1613 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1614 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1615 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1616 gst_object_unref(pad);
1618 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1619 err = MM_ERROR_CAMCORDER_GST_LINK;
1620 goto pipeline_creation_error;
1622 gst_object_unref(pad);
1626 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1627 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1628 gst_object_unref(pad);
1630 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1631 err = MM_ERROR_CAMCORDER_GST_LINK;
1632 goto pipeline_creation_error;
1634 gst_object_unref(pad);
1638 MMCAM_LOG_INFO("Get pad complete");
1640 /* Link internal element */
1641 if (!_mmcamcorder_link_elements(element_list)) {
1642 MMCAM_LOG_ERROR("element link error.");
1643 err = MM_ERROR_CAMCORDER_GST_LINK;
1644 goto pipeline_creation_error;
1648 g_list_free(element_list);
1650 MMCAM_LOG_INFO("done");
1652 return MM_ERROR_NONE;
1654 pipeline_creation_error:
1655 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1657 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1658 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1659 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1660 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1661 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
1662 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1663 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1664 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1665 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1666 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1667 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1670 g_list_free(element_list);
1672 if (videoscale_caps)
1673 gst_caps_unref(videoscale_caps);
1679 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1681 int err = MM_ERROR_NONE;
1683 GstPad *srcpad = NULL;
1686 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1687 _MMCamcorderSubContext *sc = NULL;
1689 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1691 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1692 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1693 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1697 /** Create gstreamer element **/
1699 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1702 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1703 if (err != MM_ERROR_NONE)
1704 goto pipeline_creation_error;
1706 /* Set data probe function */
1707 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1708 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1709 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1711 MMCAM_LOG_ERROR("there is no queue plugin");
1712 goto pipeline_creation_error;
1716 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1717 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1719 gst_object_unref(srcpad);
1722 MMCAM_LOG_ERROR("failed to get srcpad");
1723 goto pipeline_creation_error;
1726 /* set dataprobe for video recording if it does not support dual stream. */
1727 if (sc->info_video->record_dual_stream == FALSE) {
1728 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1729 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1731 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1733 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1734 __mmcamcorder_video_dataprobe_record, hcamcorder);
1735 gst_object_unref(srcpad);
1739 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1741 /* set sync handler */
1742 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1744 gst_object_unref(bus);
1748 err = _mmcamcorder_initialize_capture_mode(handle);
1749 if (err != MM_ERROR_NONE) {
1750 MMCAM_LOG_ERROR("initialize capture mode[%d] failed", hcamcorder->capture_mode);
1751 goto pipeline_creation_error;
1754 /* extra preview mode */
1755 err = _mmcamcorder_initialize_extra_preview_mode(handle);
1756 if (err != MM_ERROR_NONE) {
1757 MMCAM_LOG_ERROR("initialize extra preview mode[%d] failed", hcamcorder->extra_preview.mode);
1758 goto pipeline_creation_error;
1761 return MM_ERROR_NONE;
1763 pipeline_creation_error:
1764 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1769 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1771 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1772 _MMCamcorderSubContext *sc = NULL;
1774 /*MMCAM_LOG_INFO("start");*/
1776 mmf_return_if_fail(hcamcorder);
1777 mmf_return_if_fail(hcamcorder->sub_context);
1778 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1781 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1782 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1783 __mmcamcorder_request_codec_config(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1784 MMCAM_LOG_WARNING("start to push buffer to encoding pipeline");
1789 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1791 int err = MM_ERROR_NONE;
1796 int rect_height = 0;
1798 int rotation = MM_DISPLAY_ROTATION_NONE;
1799 int flip = MM_FLIP_NONE;
1800 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1801 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1802 int origin_size = 0;
1805 int do_scaling = FALSE;
1806 int *dp_handle = NULL;
1807 MMCamWindowInfo *window_info = NULL;
1809 char *err_name = NULL;
1810 const char *videosink_name = NULL;
1812 GstElement *vsink = NULL;
1814 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1815 _MMCamcorderSubContext *sc = NULL;
1819 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1821 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1822 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1823 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1824 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1826 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1828 /* Get video display information */
1829 err = mm_camcorder_get_attributes(handle, &err_name,
1830 MMCAM_DISPLAY_RECT_X, &rect_x,
1831 MMCAM_DISPLAY_RECT_Y, &rect_y,
1832 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1833 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1834 MMCAM_DISPLAY_ROTATION, &rotation,
1835 MMCAM_DISPLAY_FLIP, &flip,
1836 MMCAM_DISPLAY_VISIBLE, &visible,
1837 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1838 MMCAM_DISPLAY_MODE, &display_mode,
1839 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1840 MMCAM_DISPLAY_SCALE, &zoom_attr,
1841 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1843 if (err != MM_ERROR_NONE) {
1845 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1846 SAFE_FREE(err_name);
1848 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1854 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1856 if (!videosink_name) {
1857 MMCAM_LOG_ERROR("failed to get videosink name");
1858 return MM_ERROR_CAMCORDER_INTERNAL;
1861 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
1863 /* Set display handle */
1864 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1867 MMCAM_LOG_INFO("xid = %lu )", xid);
1868 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1870 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1871 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1873 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1874 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
1877 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1878 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1880 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
1881 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1883 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1885 window_info = (MMCamWindowInfo *)dp_handle;
1886 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
1887 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1889 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
1891 } else if (!strcmp(videosink_name, "directvideosink")) {
1892 #ifdef _MMCAMCORDER_RM_SUPPORT
1893 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1894 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
1895 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1896 #endif /* _MMCAMCORDER_RM_SUPPORT */
1898 window_info = (MMCamWindowInfo *)dp_handle;
1899 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1900 window_info->surface_id,
1901 window_info->rect.x,
1902 window_info->rect.y,
1903 window_info->rect.width,
1904 window_info->rect.height);
1905 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1906 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1907 window_info->rect.x,
1908 window_info->rect.y,
1909 window_info->rect.width,
1910 window_info->rect.height);
1912 MMCAM_LOG_WARNING("dp_handle is null");
1915 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
1918 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1919 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1922 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1923 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1925 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1928 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1930 switch (zoom_attr) {
1931 case MM_DISPLAY_SCALE_DEFAULT:
1934 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1937 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1941 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
1946 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1947 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1948 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1949 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1951 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1952 if (!strcmp(videosink_name, "tizenwlsink")) {
1953 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1954 rect_x, rect_y, rect_width, rect_height);
1957 "dst-roi-x", rect_x,
1958 "dst-roi-y", rect_y,
1959 "dst-roi-w", rect_width,
1960 "dst-roi-h", rect_height,
1966 return MM_ERROR_NONE;
1970 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1973 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1974 _MMCamcorderSubContext *sc = NULL;
1976 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1978 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1980 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1983 case _MMCamcorder_CMD_PREVIEW_START:
1984 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1986 case _MMCamcorder_CMD_CAPTURE:
1987 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1990 MMCAM_LOG_WARNING("unknown command : %d", cmd);
1991 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1994 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1995 category, "FrameStabilityCount", &sc->frame_stability_count);
1997 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
1998 cmd, sc->frame_stability_count);
2000 return MM_ERROR_NONE;
2003 /* Retreive device information and set them to attributes */
2004 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
2006 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2007 _MMCamcorderSubContext *sc = NULL;
2008 GstCameraControl *control = NULL;
2009 GstCameraControlExifInfo exif_info = {0,};
2011 mmf_return_val_if_fail(hcamcorder, FALSE);
2012 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2014 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
2016 if (sc && sc->element) {
2017 int err = MM_ERROR_NONE;
2018 char *err_name = NULL;
2019 double focal_len = 0.0;
2021 /* Video input device */
2022 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2023 /* Exif related information */
2024 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2025 if (control != NULL) {
2026 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
2027 if (exif_info.focal_len_denominator != 0)
2028 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
2030 MMCAM_LOG_ERROR("Fail to get camera control interface!");
2035 /* Set values to attributes */
2036 err = mm_camcorder_set_attributes(handle, &err_name,
2037 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
2039 if (err != MM_ERROR_NONE) {
2040 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
2041 SAFE_FREE(err_name);
2045 MMCAM_LOG_WARNING("Sub context isn't exist.");
2052 static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure)
2054 const gchar *format_string = NULL;
2057 MMCAM_LOG_WARNING("NULL structure");
2058 return GST_MAKE_FOURCC('N', 'U', 'L', 'L');
2061 if (gst_structure_has_name(structure, "video/x-h264"))
2062 return GST_MAKE_FOURCC('H', '2', '6', '4');
2064 if (gst_structure_has_name(structure, "video/x-h265"))
2065 return GST_MAKE_FOURCC('H', '2', '6', '5');
2067 if (gst_structure_has_name(structure, "video/x-vp8"))
2068 return GST_MAKE_FOURCC('V', 'P', '8', '0');
2070 if (gst_structure_has_name(structure, "video/x-vp9"))
2071 return GST_MAKE_FOURCC('V', 'P', '9', '0');
2073 if (gst_structure_has_name(structure, "video/x-jpeg") ||
2074 gst_structure_has_name(structure, "image/jpeg"))
2075 return GST_MAKE_FOURCC('M', 'J', 'P', 'G');
2077 format_string = gst_structure_get_string(structure, "format");
2080 return GST_STR_FOURCC(format_string);
2082 return GST_MAKE_FOURCC('N', 'O', 'N', 'E');
2085 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2087 gboolean ret = TRUE;
2088 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2089 _MMCamcorderSubContext *sc = NULL;
2090 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2091 GstSample *sample = NULL;
2092 GstCaps *caps = NULL;
2094 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
2095 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
2096 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
2098 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
2099 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
2101 if (sc->drop_vframe > 0) {
2102 if (sc->pass_first_vframe > 0) {
2103 sc->pass_first_vframe--;
2104 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2107 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2108 return GST_PAD_PROBE_DROP;
2110 } else if (sc->frame_stability_count > 0) {
2111 sc->frame_stability_count--;
2112 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2113 return GST_PAD_PROBE_DROP;
2116 if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
2117 _mmcamcorder_measure_fps(&sc->kpi);
2119 /* The first H.264 frame should not be skipped for vstream cb. */
2120 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2121 !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2122 MMCAM_LOG_WARNING("Not ready for stream callback");
2123 return GST_PAD_PROBE_OK;
2126 /* make sample with buffer and caps */
2127 caps = gst_pad_get_allowed_caps(pad);
2128 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2130 sample = gst_sample_new(buffer, caps, NULL, NULL);
2131 gst_caps_unref(caps);
2132 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2134 ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
2136 gst_sample_unref(sample);
2139 return GST_PAD_PROBE_OK;
2141 return GST_PAD_PROBE_DROP;
2145 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2147 gboolean ret = TRUE;
2148 GstSample *sample = NULL;
2149 GstCaps *caps = NULL;
2151 caps = gst_pad_get_allowed_caps(pad);
2152 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2154 sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
2155 gst_caps_unref(caps);
2156 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2158 ret = _mmcamcorder_video_push_buffer(u_data, sample);
2160 gst_sample_unref(sample);
2162 return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
2166 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2168 MMCamcorderMuxedStreamDataType stream;
2169 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2170 _MMCamcorderSubContext *sc = NULL;
2171 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2174 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2175 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2176 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2178 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2179 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2181 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2182 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2183 return GST_PAD_PROBE_OK;
2186 /* call application callback */
2187 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2189 if (hcamcorder->mstream_cb) {
2190 stream.data = (void *)mapinfo.data;
2191 stream.length = mapinfo.size;
2192 stream.offset = sc->muxed_stream_offset;
2193 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2196 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2198 /* calculate current offset */
2199 sc->muxed_stream_offset += mapinfo.size;
2201 gst_buffer_unmap(buffer, &mapinfo);
2203 return GST_PAD_PROBE_OK;
2207 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2209 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2210 mmf_camcorder_t *hcamcorder = NULL;
2211 _MMCamcorderSubContext *sc = NULL;
2212 GstObject *parent = NULL;
2214 switch (GST_EVENT_TYPE(event)) {
2215 case GST_EVENT_UNKNOWN:
2216 /* upstream events */
2218 case GST_EVENT_SEEK:
2219 case GST_EVENT_NAVIGATION:
2220 case GST_EVENT_LATENCY:
2221 /* downstream serialized events */
2222 case GST_EVENT_BUFFERSIZE:
2223 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2227 GstTagList *tag_list = NULL;
2228 _MMCamcorderReplayGain *replay_gain = NULL;
2230 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2232 hcamcorder = MMF_CAMCORDER(u_data);
2233 if (!hcamcorder || !hcamcorder->sub_context) {
2234 MMCAM_LOG_WARNING("NULL handle");
2238 replay_gain = &hcamcorder->sub_context->replay_gain;
2240 gst_event_parse_tag(event, &tag_list);
2242 MMCAM_LOG_WARNING("failed to get tag list");
2246 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2247 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2251 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2252 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2256 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2257 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2261 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2262 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2266 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2267 replay_gain->track_peak, replay_gain->track_gain,
2268 replay_gain->album_peak, replay_gain->album_gain);
2271 case GST_EVENT_SEGMENT:
2272 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2274 hcamcorder = MMF_CAMCORDER(u_data);
2276 MMCAM_LOG_WARNING("NULL handle");
2280 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2282 MMCAM_LOG_WARNING("NULL sub context");
2286 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2287 MMCAM_LOG_WARNING("no encoder sink");
2291 parent = gst_pad_get_parent(pad);
2293 MMCAM_LOG_WARNING("get parent failed");
2297 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2298 const GstSegment *segment;
2299 gst_event_parse_segment(event, &segment);
2300 if (segment->format == GST_FORMAT_BYTES) {
2301 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2302 sc->muxed_stream_offset, segment->start);
2304 sc->muxed_stream_offset = (unsigned long long)segment->start;
2308 gst_object_unref(parent);
2312 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2314 /* bidirectional events */
2315 case GST_EVENT_FLUSH_START:
2316 case GST_EVENT_FLUSH_STOP:
2317 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2320 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2324 return GST_PAD_PROBE_OK;
2328 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2330 int result = MM_CAMCORDER_MR475;
2333 result = MM_CAMCORDER_MR475; /*AMR475*/
2334 else if (bitrate < 5900)
2335 result = MM_CAMCORDER_MR515; /*AMR515*/
2336 else if (bitrate < 6700)
2337 result = MM_CAMCORDER_MR59; /*AMR59*/
2338 else if (bitrate < 7400)
2339 result = MM_CAMCORDER_MR67; /*AMR67*/
2340 else if (bitrate < 7950)
2341 result = MM_CAMCORDER_MR74; /*AMR74*/
2342 else if (bitrate < 10200)
2343 result = MM_CAMCORDER_MR795; /*AMR795*/
2344 else if (bitrate < 12200)
2345 result = MM_CAMCORDER_MR102; /*AMR102*/
2347 result = MM_CAMCORDER_MR122; /*AMR122*/
2353 int _mmcamcorder_get_eos_message(MMHandleType handle)
2356 int ret = MM_ERROR_NONE;
2358 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2359 _MMCamcorderSubContext *sc = NULL;
2361 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2362 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2363 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2365 MMCAM_LOG_INFO("START");
2367 _MMCAMCORDER_LOCK(handle);
2369 if (sc->bget_eos == FALSE) {
2370 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2371 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2372 MMCAM_LOG_INFO("EOS signal received");
2374 MMCAM_LOG_ERROR("EOS wait time out");
2376 if (hcamcorder->error_code == MM_ERROR_NONE)
2377 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2380 MMCAM_LOG_INFO("already got EOS");
2383 _MMCAMCORDER_UNLOCK(handle);
2385 if (hcamcorder->error_code == MM_ERROR_NONE) {
2386 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2387 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2388 if (sc->info_video->b_committing)
2389 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2391 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2392 if (sc->info_audio->b_committing)
2393 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2396 ret = hcamcorder->error_code;
2397 MMCAM_LOG_ERROR("error 0x%x", ret);
2400 MMCAM_LOG_INFO("END");
2406 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2409 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2411 mmf_return_if_fail(handle && remove_element);
2412 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2416 for (i = first_elem ; i <= last_elem ; i++) {
2417 remove_element[i].gst = NULL;
2418 remove_element[i].id = _MMCAMCORDER_NONE;
2425 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2427 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2429 /* Check compatibility between codec and file format */
2430 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2431 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2432 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2433 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2434 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2435 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2438 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2440 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2441 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2443 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2444 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2445 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2446 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2447 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2448 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2451 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2453 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2454 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2458 return MM_ERROR_NONE;
2462 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2464 int err = MM_ERROR_NONE;
2465 int audio_codec = MM_AUDIO_CODEC_INVALID;
2466 int file_format = MM_FILE_FORMAT_INVALID;
2468 char *err_name = NULL;
2470 err = mm_camcorder_get_attributes(handle, &err_name,
2471 MMCAM_AUDIO_ENCODER, &audio_codec,
2472 MMCAM_FILE_FORMAT, &file_format,
2474 if (err != MM_ERROR_NONE) {
2475 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2476 SAFE_FREE(err_name);
2480 /* Check compatibility between audio codec and file format */
2481 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2487 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2489 int err = MM_ERROR_NONE;
2490 int video_codec = MM_VIDEO_CODEC_INVALID;
2491 int file_format = MM_FILE_FORMAT_INVALID;
2493 char *err_name = NULL;
2495 err = mm_camcorder_get_attributes(handle, &err_name,
2496 MMCAM_VIDEO_ENCODER, &video_codec,
2497 MMCAM_FILE_FORMAT, &file_format,
2499 if (err != MM_ERROR_NONE) {
2500 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2501 SAFE_FREE(err_name);
2505 /* Check compatibility between video codec and file format */
2506 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2512 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2514 const char* videosink_name = NULL;
2516 mmf_camcorder_t *hcamcorder = NULL;
2517 _MMCamcorderSubContext *sc = NULL;
2519 hcamcorder = MMF_CAMCORDER(handle);
2520 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2522 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2523 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2524 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2526 if (sc->element[videosink_index].gst) {
2527 /* Get videosink name */
2528 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2529 if (videosink_name == NULL) {
2530 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2534 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2535 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2536 !strcmp(videosink_name, "directvideosink")) {
2537 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2538 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2540 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2545 MMCAM_LOG_ERROR("Videosink element is null");
2551 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2553 const char* videosink_name = NULL;
2555 mmf_camcorder_t *hcamcorder = NULL;
2556 _MMCamcorderSubContext *sc = NULL;
2558 hcamcorder = MMF_CAMCORDER(handle);
2559 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2561 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2562 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2563 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2565 if (sc->element[videosink_index].gst) {
2566 /* Get videosink name */
2567 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2568 if (videosink_name == NULL) {
2569 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2573 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2574 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2575 !strcmp(videosink_name, "directvideosink")) {
2576 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2577 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2579 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2584 MMCAM_LOG_ERROR("Videosink element is null");
2590 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2593 _MMCamcorderSubContext *sc = NULL;
2595 mmf_camcorder_t *hcamcorder = NULL;
2597 hcamcorder = MMF_CAMCORDER(handle);
2598 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2600 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2602 MMCAM_LOG_INFO("sub context is not initialized");
2606 mm_camcorder_get_attributes(handle, NULL,
2607 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2608 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2609 MMCAM_CAMERA_FPS, &fps,
2612 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2614 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2615 sc->info_video->preview_width, sc->info_video->preview_height,
2616 fps, videosrc_rotate);
2620 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2626 unsigned int caps_fourcc = 0;
2627 gboolean do_set_caps = FALSE;
2628 GstCaps *caps = NULL;
2630 mmf_camcorder_t *hcamcorder = NULL;
2631 _MMCamcorderSubContext *sc = NULL;
2633 hcamcorder = MMF_CAMCORDER(handle);
2634 mmf_return_val_if_fail(hcamcorder, FALSE);
2636 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2638 if (!sc || !(sc->element)) {
2639 MMCAM_LOG_INFO("sub context is not initialized");
2643 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2644 MMCAM_LOG_ERROR("Video src is NULL!");
2648 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2649 MMCAM_LOG_ERROR("Video filter is NULL!");
2653 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2654 int capture_width = 0;
2655 int capture_height = 0;
2656 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2658 mm_camcorder_get_attributes(handle, NULL,
2659 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2660 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2661 MMCAM_CAPTURE_WIDTH, &capture_width,
2662 MMCAM_CAPTURE_HEIGHT, &capture_height,
2663 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2664 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2666 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2667 motion_rate, capture_width, capture_height, fps_auto,
2668 sc->info_video->video_width, sc->info_video->video_height);
2670 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2671 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2673 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2674 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2675 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2678 sc->info_video->fps = fps;
2681 /* Interleaved format does not support rotation */
2682 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2683 /* store videosrc rotation */
2684 sc->videosrc_rotate = rotate;
2686 /* Define width, height and rotate in caps */
2688 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2689 This will be applied when rotate is 0, 180 if front camera. */
2690 set_rotate = rotate * 90;
2692 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2693 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2696 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2697 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2704 set_height = height;
2707 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2710 set_height = height;
2712 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2715 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2716 if (caps && !gst_caps_is_any(caps)) {
2717 GstStructure *structure = NULL;
2719 structure = gst_caps_get_structure(caps, 0);
2722 int caps_height = 0;
2725 int caps_rotate = 0;
2727 caps_fourcc = _mmcamcorder_get_structure_fourcc(structure);
2729 gst_structure_get(structure,
2730 "width", G_TYPE_INT, &caps_width,
2731 "height", G_TYPE_INT, &caps_height,
2732 "framerate", GST_TYPE_FRACTION, &caps_fps_n, &caps_fps_d,
2733 "rotate", G_TYPE_INT, &caps_rotate,
2736 #ifdef _MMCAMCORDER_PRODUCT_TV
2737 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2738 if (set_width == caps_width && set_height == caps_height &&
2739 set_rotate == caps_rotate && fps == caps_fps_n) {
2740 MMCAM_LOG_INFO("No need to replace caps.");
2742 MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d/%d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2743 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2744 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2745 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2746 set_width, set_height, fps, set_rotate);
2750 if (set_width == caps_width && set_height == caps_height &&
2751 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2752 MMCAM_LOG_INFO("No need to replace caps.");
2754 MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d/%d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2755 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2756 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2757 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2758 set_width, set_height, fps, set_rotate);
2762 #else /*_MMCAMCORDER_PRODUCT_TV */
2763 if (set_width == caps_width && set_height == caps_height &&
2764 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2765 MMCAM_LOG_INFO("No need to replace caps.");
2767 MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d/%d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2768 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2769 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2770 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2771 set_width, set_height, fps, set_rotate);
2774 #endif /*_MMCAMCORDER_PRODUCT_TV */
2776 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2780 MMCAM_LOG_INFO("No caps. set new one...");
2785 gst_caps_unref(caps);
2789 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2790 /* assume that it's camera capture mode */
2791 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2797 caps = _mmcamcorder_get_video_caps(handle,
2798 sc->info_image->preview_format, set_width, set_height, fps, set_rotate);
2800 MMCAM_LOG_ERROR("There are no caps");
2804 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2805 gst_caps_unref(caps);
2811 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2813 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2814 _MMCamcorderSubContext *sc = NULL;
2816 mmf_return_val_if_fail(hcamcorder, FALSE);
2818 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2822 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
2824 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2828 /* Interleaved format does not support FLIP */
2829 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2830 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2831 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2833 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
2835 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2836 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2838 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
2842 MMCAM_LOG_WARNING("element is NULL");
2850 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2852 GstCameraControl *control = NULL;
2853 _MMCamcorderSubContext *sc = NULL;
2854 GstElement *v_src = NULL;
2858 mmf_return_val_if_fail(handle, FALSE);
2860 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2864 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2867 MMCAM_LOG_WARNING("videosrc element is NULL");
2871 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2873 /* set anti-shake with camera control */
2874 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2875 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
2879 control = GST_CAMERA_CONTROL(v_src);
2880 if (gst_camera_control_set_ahs(control, set_value)) {
2881 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
2884 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
2891 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2893 _MMCamcorderSubContext *sc = NULL;
2894 GstElement *v_src = NULL;
2896 mmf_return_val_if_fail(handle, FALSE);
2898 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2902 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2904 MMCAM_LOG_WARNING("videosrc element is NULL");
2908 /* check property of videosrc element - support VDIS */
2909 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2910 int video_width = 0;
2911 int video_height = 0;
2913 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2914 MMCAM_LOG_INFO("ENABLE video stabilization");
2916 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2917 mm_camcorder_get_attributes(handle, NULL,
2918 MMCAM_VIDEO_WIDTH, &video_width,
2919 MMCAM_VIDEO_HEIGHT, &video_height,
2922 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2923 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
2924 video_width, video_height);
2926 g_object_set(G_OBJECT(v_src),
2927 "enable-vdis-mode", TRUE,
2930 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
2931 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2932 video_width, video_height);
2937 g_object_set(G_OBJECT(v_src),
2938 "enable-vdis-mode", FALSE,
2941 MMCAM_LOG_INFO("DISABLE video stabilization");
2943 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2944 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
2947 MMCAM_LOG_WARNING("no property for video stabilization");
2954 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2958 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2959 _MMCamcorderSubContext *sc = NULL;
2961 mmf_return_val_if_fail(hcamcorder, FALSE);
2963 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2967 mm_camcorder_get_attributes(handle, NULL,
2968 MMCAM_CAMERA_FPS, &fps,
2971 MMCAM_LOG_INFO("set %dx%d", width, height);
2973 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2977 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2979 _MMCamcorderSubContext *sc = NULL;
2981 if ((void *)handle == NULL) {
2982 MMCAM_LOG_WARNING("handle is NULL");
2986 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2988 MMCAM_LOG_WARNING("subcontext is NULL");
2992 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2993 MMCAM_LOG_WARNING("videosrc plugin is NULL");
2997 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
2999 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
3005 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
3007 _MMCamcorderSubContext *sc = NULL;
3009 if ((void *)handle == NULL) {
3010 MMCAM_LOG_WARNING("handle is NULL");
3014 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3016 MMCAM_LOG_WARNING("subcontext is NULL");
3020 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3021 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3025 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
3027 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3033 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3035 GstStructure *props = NULL;
3036 char stream_props[64] = {'\0',};
3038 if (element == NULL || stream_type == NULL || stream_index < 0) {
3039 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3043 snprintf(stream_props, sizeof(stream_props) - 1,
3044 "props,media.role=%s, media.parent_id=%d",
3045 stream_type, stream_index);
3047 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3049 props = gst_structure_from_string(stream_props, NULL);
3051 MMCAM_LOG_ERROR("failed to create GstStructure");
3055 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3057 gst_structure_free(props);
3064 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3066 int ret = MM_ERROR_NONE;
3067 _MMCamcorderSubContext *sc = NULL;
3068 mmf_camcorder_t *hcamcorder = NULL;
3069 const char *videodecoder_name = NULL;
3070 char videodecoder_name_final[32] = {'\0',};
3071 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3072 #ifdef _MMCAMCORDER_RM_SUPPORT
3073 int decoder_index = 0;
3074 #endif /* _MMCAMCORDER_RM_SUPPORT */
3076 if ((void *)handle == NULL) {
3077 MMCAM_LOG_WARNING("handle is NULL");
3081 hcamcorder = MMF_CAMCORDER(handle);
3083 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3085 MMCAM_LOG_WARNING("subcontext is NULL");
3089 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3090 hcamcorder->recreate_decoder == FALSE) {
3091 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3092 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3096 mm_camcorder_get_attributes(handle, NULL,
3097 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3100 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3101 MMCAM_LOG_INFO("no need to control decoder element");
3105 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3106 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3107 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3111 MMCAM_LOG_INFO("start");
3113 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
3114 if (videodecoder_name == NULL) {
3115 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
3119 /* set state as NULL */
3120 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3121 if (ret != MM_ERROR_NONE) {
3122 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3126 /* remove decoder - pads will be unlinked automatically in remove function */
3127 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3128 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3129 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3133 /* check decoder element */
3134 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3135 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3136 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3137 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3140 #ifdef _MMCAMCORDER_RM_SUPPORT
3141 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3142 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3145 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
3146 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
3148 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3149 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
3151 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
3153 #endif /* _MMCAMCORDER_RM_SUPPORT */
3154 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
3155 #ifdef _MMCAMCORDER_RM_SUPPORT
3157 #endif /* _MMCAMCORDER_RM_SUPPORT */
3159 /* create decoder */
3160 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "videosrc_decode");
3161 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3162 MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
3166 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
3168 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3169 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3170 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3172 /* add to pipeline */
3173 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3174 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3175 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3176 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3181 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3182 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3183 MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
3185 MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
3189 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3190 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3191 MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
3193 MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
3197 /* set state READY */
3198 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3199 if (ret != MM_ERROR_NONE) {
3200 MMCAM_LOG_ERROR("failed to set READY to decoder");
3204 MMCAM_LOG_INFO("done");
3209 #ifdef _MMCAMCORDER_PRODUCT_TV
3210 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3212 _MMCamcorderSubContext *sc = NULL;
3213 mmf_camcorder_t *hcamcorder = NULL;
3215 const gchar *mime = NULL;
3217 GstCaps *decsink_caps = NULL;
3218 GstStructure *decsink_struct = NULL;
3220 mmf_return_val_if_fail(handle, false);
3221 mmf_return_val_if_fail(max_width, false);
3222 mmf_return_val_if_fail(max_height, false);
3224 hcamcorder = MMF_CAMCORDER(handle);
3225 mmf_return_val_if_fail(hcamcorder, false);
3227 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3229 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3231 MMCAM_LOG_ERROR("There are no decoder caps");
3235 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3236 if (!decsink_caps) {
3237 gst_object_unref(sinkpad);
3238 MMCAM_LOG_ERROR("There is no decoder sink caps");
3242 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3243 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3244 if (!decsink_struct) {
3245 MMCAM_LOG_ERROR("There are no structure from caps");
3246 gst_object_unref(decsink_caps);
3247 gst_object_unref(sinkpad);
3250 mime = gst_structure_get_name(decsink_struct);
3251 if (!strcmp(mime, "video/x-h264")) {
3252 MMCAM_LOG_INFO("h264 caps structure found");
3253 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3254 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3255 if (gst_structure_has_field(decsink_struct, "maxheight"))
3256 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3258 } else if (!strcmp(mime, "video/x-jpeg")) {
3259 MMCAM_LOG_INFO("mjpeg caps structure found");
3260 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3261 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3262 if (gst_structure_has_field(decsink_struct, "maxheight"))
3263 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3267 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3268 gst_object_unref(decsink_caps);
3269 gst_object_unref(sinkpad);
3271 if (*max_width <= 0 || *max_height <= 0)
3276 #endif /* _MMCAMCORDER_PRODUCT_TV */