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 *VideosrcElement = 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 /* Get videosrc element and its name from configure */
624 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
625 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
628 _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
631 * Create child element
633 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
635 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
638 * This is for "tizencamerasrc" element only.
639 * The camera HAL library will be loaded when "hal-name" property is set.
640 * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
642 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
644 /* camera properties */
645 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
646 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
647 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
648 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-quality", capture_quality);
649 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
650 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "extra-preview", extra_preview_enable);
651 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
653 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
655 /* set camera flip */
656 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
658 /* set video stabilization mode */
659 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
661 /* set anti handshake mode */
662 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
664 if (sc->is_modified_rate)
665 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
667 /* Set basic information of videosrc element */
668 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
670 /* Set video device index */
671 if (hcamcorder->is_network) {
672 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
674 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
675 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
677 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
681 /* set user buffer fd to videosrc element */
682 if (hcamcorder->support_user_buffer) {
683 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
684 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
685 MMCAM_LOG_ERROR("set user buffer fd failed");
686 goto pipeline_creation_error;
690 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
691 /* get recreate_decoder flag */
692 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
693 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
695 &hcamcorder->recreate_decoder);
698 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
699 _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
700 switch (sc->info_image->preview_format) {
701 case MM_PIXEL_FORMAT_ENCODED_H264:
702 decoder_conf_name = "VideodecoderElementH264";
704 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
705 decoder_conf_name = "VideodecoderElementMJPEG";
707 case MM_PIXEL_FORMAT_ENCODED_VP8:
708 decoder_conf_name = "VideodecoderElementVP8";
710 case MM_PIXEL_FORMAT_ENCODED_VP9:
711 decoder_conf_name = "VideodecoderElementVP9";
714 MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
715 goto pipeline_creation_error;
718 /* get video decoder element and name */
719 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
720 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
722 &sc->VideodecoderElement);
724 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
727 if (!videodecoder_name) {
728 MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
729 goto pipeline_creation_error;
732 #ifdef _MMCAMCORDER_RM_SUPPORT
733 MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
734 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
735 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
737 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
738 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
739 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
740 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
742 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
744 #endif /* _MMCAMCORDER_RM_SUPPORT */
745 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
746 #ifdef _MMCAMCORDER_RM_SUPPORT
748 #endif /* _MMCAMCORDER_RM_SUPPORT */
750 videoparse_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
752 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_PARSE, videoparse_name, "videosrc_parse", element_list, err);
754 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
756 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
759 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
761 /* Get videosink name */
762 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
764 if (!videosink_name) {
765 MMCAM_LOG_ERROR("failed to get videosink name");
766 goto pipeline_creation_error;
769 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
771 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
773 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
774 /* get video convert name */
775 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
777 if (videoconvert_name) {
778 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
779 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
781 MMCAM_LOG_ERROR("failed to get videoconvert element name");
784 /* check sink element in attribute */
785 mm_camcorder_get_attributes(handle, NULL,
786 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
791 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
793 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
795 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
797 /* reset attribute */
799 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
800 mm_attrs_set_data(attrs, attr_index, NULL, 0);
801 mm_attrs_commit(attrs, attr_index);
803 MMCAM_LOG_WARNING("attribute is NULL");
804 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
805 goto pipeline_creation_error;
808 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
810 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
813 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
814 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
815 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
816 goto pipeline_creation_error;
819 /* Set caps by rotation */
820 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
822 /* add elements to main pipeline */
823 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
824 MMCAM_LOG_ERROR("element_list add error.");
825 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
826 goto pipeline_creation_error;
830 if (!_mmcamcorder_link_elements(element_list)) {
831 MMCAM_LOG_ERROR("element link error.");
832 err = MM_ERROR_CAMCORDER_GST_LINK;
833 goto pipeline_creation_error;
837 g_list_free(element_list);
841 return MM_ERROR_NONE;
843 pipeline_creation_error:
844 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
845 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
846 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
847 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_FILT);
848 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_SINK);
849 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
850 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
851 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
854 g_list_free(element_list);
862 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
864 int err = MM_ERROR_NONE;
869 int a_enc = MM_AUDIO_CODEC_AMR;
870 int a_dev = MM_AUDIO_DEVICE_MIC;
872 char *err_name = NULL;
873 const char *audiosrc_name = NULL;
874 char *cat_name = NULL;
875 char *stream_type = NULL;
876 int stream_type_len = 0;
877 int stream_index = 0;
878 int buffer_interval = 0;
880 int replay_gain_enable = FALSE;
881 double replay_gain_ref_level = 0.0;
883 GstCaps *caps = NULL;
885 GList *element_list = NULL;
887 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
888 _MMCamcorderSubContext *sc = NULL;
889 _MMCamcorderGstElement *last_element = NULL;
890 type_element *AudiosrcElement = NULL;
892 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
894 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
895 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
896 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
900 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
901 if (err != MM_ERROR_NONE)
904 err = mm_camcorder_get_attributes(handle, &err_name,
905 MMCAM_AUDIO_DEVICE, &a_dev,
906 MMCAM_AUDIO_ENCODER, &a_enc,
907 MMCAM_AUDIO_ENCODER_BITRATE, &val,
908 MMCAM_AUDIO_SAMPLERATE, &rate,
909 MMCAM_AUDIO_FORMAT, &format,
910 MMCAM_AUDIO_CHANNEL, &channel,
911 MMCAM_AUDIO_VOLUME, &volume,
912 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
913 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
914 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
915 MMCAM_SOUND_STREAM_INDEX, &stream_index,
917 if (err != MM_ERROR_NONE) {
918 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
923 /* Check existence */
924 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
925 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
926 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
928 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
931 /* Create bin element */
932 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
934 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
935 cat_name = strdup("AudiomodemsrcElement");
937 /* MM_AUDIO_DEVICE_MIC or others */
938 cat_name = strdup("AudiosrcElement");
941 if (cat_name == NULL) {
942 MMCAM_LOG_ERROR("strdup failed.");
943 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
944 goto pipeline_creation_error;
947 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
948 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
951 _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
956 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
958 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
960 /* set sound stream info */
961 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
963 /* set audiosrc properties in ini configuration */
964 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
967 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
968 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
969 "AudioBufferInterval",
972 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
973 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
974 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
977 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
979 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
980 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
981 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
982 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
984 /* Set basic information */
985 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
987 const gchar* format_name = NULL;
989 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
992 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
993 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
995 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
996 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
999 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
1001 format_name = "S16LE";
1002 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
1007 caps = gst_caps_new_simple("audio/x-raw",
1008 "rate", G_TYPE_INT, rate,
1009 "channels", G_TYPE_INT, channel,
1010 "format", G_TYPE_STRING, format_name,
1012 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
1013 rate, channel, depth, volume);
1015 /* what are the audio encoder which should get audio/x-raw-float? */
1016 caps = gst_caps_new_simple("audio/x-raw",
1017 "rate", G_TYPE_INT, rate,
1018 "channels", G_TYPE_INT, channel,
1019 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
1021 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
1022 rate, channel, BYTE_ORDER);
1026 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
1027 replay_gain_enable, replay_gain_ref_level);
1029 if (replay_gain_enable) {
1030 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
1031 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
1032 /* If num-tracks is not set, album gain and peak event is not come. */
1033 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
1037 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
1038 gst_caps_unref(caps);
1041 MMCAM_LOG_ERROR("create caps error");
1042 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1043 goto pipeline_creation_error;
1046 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
1047 MMCAM_LOG_ERROR("element add error.");
1048 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1049 goto pipeline_creation_error;
1052 if (!_mmcamcorder_link_elements(element_list)) {
1053 MMCAM_LOG_ERROR("element link error.");
1054 err = MM_ERROR_CAMCORDER_GST_LINK;
1055 goto pipeline_creation_error;
1058 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
1059 pad = gst_element_get_static_pad(last_element->gst, "src");
1060 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
1061 gst_object_unref(pad);
1063 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
1064 err = MM_ERROR_CAMCORDER_GST_LINK;
1065 goto pipeline_creation_error;
1068 gst_object_unref(pad);
1072 g_list_free(element_list);
1073 element_list = NULL;
1076 return MM_ERROR_NONE;
1078 pipeline_creation_error:
1079 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1080 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1081 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1082 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1083 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1086 g_list_free(element_list);
1087 element_list = NULL;
1094 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1099 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1104 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1105 type, codec, bitrate);
1109 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1110 /* audio encoder bitrate setting */
1112 case MM_AUDIO_CODEC_AMR:
1113 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1114 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1115 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1117 case MM_AUDIO_CODEC_MP3:
1118 set_value = bitrate / 1000;
1119 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1120 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1122 case MM_AUDIO_CODEC_AAC:
1123 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1124 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1127 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1131 /* video encoder bitrate setting */
1132 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1133 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1140 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1142 int err = MM_ERROR_NONE;
1147 int encodebin_profile = 0;
1148 int auto_audio_convert = 0;
1149 int auto_audio_resample = 0;
1150 int auto_color_space = 0;
1151 int cap_format = MM_PIXEL_FORMAT_INVALID;
1152 const char *gst_element_venc_name = NULL;
1153 const char *gst_element_aenc_name = NULL;
1154 const char *gst_element_ienc_name = NULL;
1155 const char *gst_element_mux_name = NULL;
1156 const char *gst_element_rsink_name = NULL;
1157 const char *gst_element_vscale_name = NULL;
1158 const char *str_profile = NULL;
1159 const char *str_aac = NULL;
1160 const char *str_aar = NULL;
1161 const char *str_acs = NULL;
1162 char *err_name = NULL;
1163 const char *videoconvert_name = NULL;
1164 GstCaps *audio_caps = NULL;
1165 GstCaps *video_caps = NULL;
1166 GstCaps *videoscale_caps = NULL;
1168 GList *element_list = NULL;
1170 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1171 _MMCamcorderSubContext *sc = NULL;
1172 type_element *VideoencElement = NULL;
1173 type_element *AudioencElement = NULL;
1174 type_element *ImageencElement = NULL;
1175 type_element *MuxElement = NULL;
1176 type_element *RecordsinkElement = NULL;
1177 type_element *VideoscaleElement = NULL;
1179 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1181 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1182 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1183 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1185 MMCAM_LOG_INFO("start - profile : %d", profile);
1187 /* Check existence */
1188 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1189 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1190 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1192 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1195 /* Create bin element */
1196 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1198 /* Create child element */
1199 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1200 GstCaps *caps_from_pad = NULL;
1201 char *caps_str = NULL;
1203 /* create appsrc and capsfilter */
1204 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1206 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1208 /* set appsrc as live source */
1209 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1210 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1211 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1213 /* set capsfilter */
1214 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1215 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1216 MMCAM_LOG_INFO("get pad from videosrc_filter");
1217 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1219 MMCAM_LOG_INFO("get pad from videosrc_que");
1220 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1223 MMCAM_LOG_ERROR("get videosrc_que src pad failed");
1224 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1225 goto pipeline_creation_error;
1228 caps_from_pad = gst_pad_get_allowed_caps(pad);
1229 video_caps = gst_caps_copy(caps_from_pad);
1230 gst_caps_unref(caps_from_pad);
1231 caps_from_pad = NULL;
1232 gst_object_unref(pad);
1236 video_caps = gst_caps_fixate(video_caps);
1239 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1243 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1244 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1245 goto pipeline_creation_error;
1248 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1249 if (sc->info_video->use_videoscale) {
1250 gst_caps_set_simple(video_caps,
1251 "width", G_TYPE_INT, sc->info_video->preview_width,
1252 "height", G_TYPE_INT, sc->info_video->preview_height,
1254 videoscale_caps = gst_caps_copy(video_caps);
1256 gst_caps_set_simple(video_caps,
1257 "width", G_TYPE_INT, sc->info_video->video_width,
1258 "height", G_TYPE_INT, sc->info_video->video_height,
1263 caps_str = gst_caps_to_string(video_caps);
1265 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1270 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1272 gst_caps_unref(video_caps);
1276 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1277 sc->info_video->use_videoscale) {
1278 if (!videoscale_caps) {
1279 MMCAM_LOG_ERROR("no videoscale caps");
1280 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1281 goto pipeline_creation_error;
1284 gst_caps_set_simple(videoscale_caps,
1285 "width", G_TYPE_INT, sc->info_video->video_width,
1286 "height", G_TYPE_INT, sc->info_video->video_height,
1289 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1290 CONFIGURE_CATEGORY_MAIN_RECORD,
1291 "VideoscaleElement",
1292 &VideoscaleElement);
1294 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1295 MMCAM_LOG_ERROR("failed to get videoscale element name");
1296 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1297 goto pipeline_creation_error;
1300 caps_str = gst_caps_to_string(videoscale_caps);
1302 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1307 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
1308 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
1310 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
1312 gst_caps_unref(videoscale_caps);
1313 videoscale_caps = NULL;
1316 /* release element_list, they will be placed out of encodesink bin */
1318 g_list_free(element_list);
1319 element_list = NULL;
1322 /* connect signal for ready to push buffer */
1323 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1324 _MMCAMCORDER_HANDLER_VIDEOREC,
1326 _mmcamcorder_ready_to_encode_callback,
1330 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1331 "tizenencodebin", "encodesink_encbin", element_list, err);
1333 /* check element availability */
1334 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1335 err = mm_camcorder_get_attributes(handle, &err_name,
1336 MMCAM_CAPTURE_FORMAT, &cap_format,
1339 err = mm_camcorder_get_attributes(handle, &err_name,
1340 MMCAM_AUDIO_ENCODER, &audio_enc,
1341 MMCAM_AUDIO_CHANNEL, &channel,
1342 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1343 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1347 if (err != MM_ERROR_NONE) {
1349 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1350 SAFE_FREE(err_name);
1352 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1355 goto pipeline_creation_error;
1358 MMCAM_LOG_INFO("Profile[%d]", profile);
1360 /* Set information */
1361 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1362 str_profile = "VideoProfile";
1363 str_aac = "VideoAutoAudioConvert";
1364 str_aar = "VideoAutoAudioResample";
1365 str_acs = "VideoAutoColorSpace";
1366 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1367 str_profile = "AudioProfile";
1368 str_aac = "AudioAutoAudioConvert";
1369 str_aar = "AudioAutoAudioResample";
1370 str_acs = "AudioAutoColorSpace";
1371 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1372 str_profile = "ImageProfile";
1373 str_aac = "ImageAutoAudioConvert";
1374 str_aar = "ImageAutoAudioResample";
1375 str_acs = "ImageAutoColorSpace";
1378 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1379 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1380 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1381 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1383 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1384 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1386 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1387 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1388 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1389 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1390 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1392 /* get video convert element name */
1393 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1396 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1397 int use_venc_queue = 0;
1399 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1401 if (!VideoencElement) {
1402 MMCAM_LOG_ERROR("Fail to get type element");
1403 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1404 goto pipeline_creation_error;
1407 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1408 /* set parse element */
1409 gst_element_venc_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
1410 if (!gst_element_venc_name)
1411 gst_element_venc_name = "identity";
1413 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1416 if (gst_element_venc_name) {
1417 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1419 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1420 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1422 MMCAM_LOG_ERROR("Fail to get video encoder name");
1423 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1424 goto pipeline_creation_error;
1427 /* set color space converting element */
1428 if (auto_color_space) {
1429 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1431 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1432 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1434 /* set colorspace plugin property setting */
1435 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1437 /* fourcc type was removed in GST 1.0 */
1438 if (hcamcorder->use_zero_copy_format) {
1439 if (strstr(gst_element_venc_name, "omx")) {
1440 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1443 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1444 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1446 gst_caps_unref(video_caps);
1449 MMCAM_LOG_WARNING("failed to create caps");
1452 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1457 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1458 CONFIGURE_CATEGORY_MAIN_RECORD,
1459 "UseVideoEncoderQueue",
1462 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1465 if (sc->audio_disable == FALSE &&
1466 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1467 int use_aenc_queue = 0;
1469 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1470 if (!AudioencElement) {
1471 MMCAM_LOG_ERROR("Fail to get type element");
1472 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1473 goto pipeline_creation_error;
1476 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1478 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1479 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1481 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1482 audio_caps = gst_caps_new_simple("audio/x-raw",
1483 "channels", G_TYPE_INT, 1,
1485 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1486 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1487 gst_caps_unref(audio_caps);
1491 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1492 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1493 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1494 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1495 gst_caps_unref(audio_caps);
1497 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1500 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1501 CONFIGURE_CATEGORY_MAIN_RECORD,
1502 "UseAudioEncoderQueue",
1504 if (use_aenc_queue) {
1505 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1506 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1507 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1511 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1512 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1513 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1514 if (!ImageencElement) {
1515 MMCAM_LOG_ERROR("Fail to get type element");
1516 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1517 goto pipeline_creation_error;
1520 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1522 /* raw format - set dummy element */
1523 gst_element_ienc_name = "identity";
1526 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1527 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1531 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1532 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1534 MMCAM_LOG_ERROR("Fail to get type element");
1535 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1536 goto pipeline_creation_error;
1539 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1541 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1542 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1544 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1548 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1550 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1551 CONFIGURE_CATEGORY_MAIN_RECORD,
1552 "RecordsinkElement",
1553 &RecordsinkElement);
1554 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1556 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1558 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1561 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1564 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1565 /* property setting in ini */
1566 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1568 /* bitrate setting */
1569 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1570 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1573 if (sc->audio_disable == FALSE &&
1574 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1575 /* property setting in ini */
1576 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1578 /* bitrate setting */
1579 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1580 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1583 MMCAM_LOG_INFO("Element creation complete");
1585 /* Add element to bin */
1586 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1587 MMCAM_LOG_ERROR("element add error.");
1588 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1589 goto pipeline_creation_error;
1592 MMCAM_LOG_INFO("Element add complete");
1594 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1595 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1596 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1597 gst_object_unref(pad);
1599 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1600 err = MM_ERROR_CAMCORDER_GST_LINK;
1601 goto pipeline_creation_error;
1603 gst_object_unref(pad);
1606 if (sc->audio_disable == FALSE) {
1607 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1608 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1609 gst_object_unref(pad);
1611 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1612 err = MM_ERROR_CAMCORDER_GST_LINK;
1613 goto pipeline_creation_error;
1615 gst_object_unref(pad);
1618 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1619 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1620 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1621 gst_object_unref(pad);
1623 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1624 err = MM_ERROR_CAMCORDER_GST_LINK;
1625 goto pipeline_creation_error;
1627 gst_object_unref(pad);
1631 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1632 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1633 gst_object_unref(pad);
1635 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1636 err = MM_ERROR_CAMCORDER_GST_LINK;
1637 goto pipeline_creation_error;
1639 gst_object_unref(pad);
1643 MMCAM_LOG_INFO("Get pad complete");
1645 /* Link internal element */
1646 if (!_mmcamcorder_link_elements(element_list)) {
1647 MMCAM_LOG_ERROR("element link error.");
1648 err = MM_ERROR_CAMCORDER_GST_LINK;
1649 goto pipeline_creation_error;
1653 g_list_free(element_list);
1655 MMCAM_LOG_INFO("done");
1657 return MM_ERROR_NONE;
1659 pipeline_creation_error:
1660 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1662 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1663 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1664 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1665 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1666 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
1667 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1668 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1669 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1670 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1671 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1672 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1675 g_list_free(element_list);
1677 if (videoscale_caps)
1678 gst_caps_unref(videoscale_caps);
1684 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1686 int err = MM_ERROR_NONE;
1688 GstPad *srcpad = NULL;
1691 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1692 _MMCamcorderSubContext *sc = NULL;
1694 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1696 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1697 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1698 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1702 /** Create gstreamer element **/
1704 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1707 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1708 if (err != MM_ERROR_NONE)
1709 goto pipeline_creation_error;
1711 /* Set data probe function */
1712 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1713 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1714 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1716 MMCAM_LOG_ERROR("there is no queue plugin");
1717 goto pipeline_creation_error;
1721 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1722 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1724 gst_object_unref(srcpad);
1727 MMCAM_LOG_ERROR("failed to get srcpad");
1728 goto pipeline_creation_error;
1731 /* set dataprobe for video recording if it does not support dual stream. */
1732 if (sc->info_video->record_dual_stream == FALSE) {
1733 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1734 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1736 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1738 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1739 __mmcamcorder_video_dataprobe_record, hcamcorder);
1740 gst_object_unref(srcpad);
1744 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1746 /* set sync handler */
1747 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1749 gst_object_unref(bus);
1752 return MM_ERROR_NONE;
1754 pipeline_creation_error:
1755 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1760 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1762 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1763 _MMCamcorderSubContext *sc = NULL;
1765 /*MMCAM_LOG_INFO("start");*/
1767 mmf_return_if_fail(hcamcorder);
1768 mmf_return_if_fail(hcamcorder->sub_context);
1769 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1772 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1773 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1774 __mmcamcorder_request_codec_config(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1775 MMCAM_LOG_WARNING("start to push buffer to encoding pipeline");
1780 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1782 int err = MM_ERROR_NONE;
1787 int rect_height = 0;
1789 int rotation = MM_DISPLAY_ROTATION_NONE;
1790 int flip = MM_FLIP_NONE;
1791 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1792 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1793 int origin_size = 0;
1796 int do_scaling = FALSE;
1797 int *dp_handle = NULL;
1798 MMCamWindowInfo *window_info = NULL;
1800 char *err_name = NULL;
1801 const char *videosink_name = NULL;
1803 GstElement *vsink = NULL;
1805 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1806 _MMCamcorderSubContext *sc = NULL;
1810 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1812 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1813 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1814 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1815 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1817 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1819 /* Get video display information */
1820 err = mm_camcorder_get_attributes(handle, &err_name,
1821 MMCAM_DISPLAY_RECT_X, &rect_x,
1822 MMCAM_DISPLAY_RECT_Y, &rect_y,
1823 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1824 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1825 MMCAM_DISPLAY_ROTATION, &rotation,
1826 MMCAM_DISPLAY_FLIP, &flip,
1827 MMCAM_DISPLAY_VISIBLE, &visible,
1828 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1829 MMCAM_DISPLAY_MODE, &display_mode,
1830 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1831 MMCAM_DISPLAY_SCALE, &zoom_attr,
1832 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1834 if (err != MM_ERROR_NONE) {
1836 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1837 SAFE_FREE(err_name);
1839 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1845 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1847 if (!videosink_name) {
1848 MMCAM_LOG_ERROR("failed to get videosink name");
1849 return MM_ERROR_CAMCORDER_INTERNAL;
1852 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
1854 /* Set display handle */
1855 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1858 MMCAM_LOG_INFO("xid = %lu )", xid);
1859 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1861 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1862 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1864 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1865 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
1868 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1869 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1871 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
1872 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1874 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1876 window_info = (MMCamWindowInfo *)dp_handle;
1877 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
1878 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1880 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
1882 } else if (!strcmp(videosink_name, "directvideosink")) {
1883 #ifdef _MMCAMCORDER_RM_SUPPORT
1884 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1885 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
1886 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1887 #endif /* _MMCAMCORDER_RM_SUPPORT */
1889 window_info = (MMCamWindowInfo *)dp_handle;
1890 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1891 window_info->surface_id,
1892 window_info->rect.x,
1893 window_info->rect.y,
1894 window_info->rect.width,
1895 window_info->rect.height);
1896 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1897 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1898 window_info->rect.x,
1899 window_info->rect.y,
1900 window_info->rect.width,
1901 window_info->rect.height);
1903 MMCAM_LOG_WARNING("dp_handle is null");
1906 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
1909 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1910 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1913 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1914 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1916 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1919 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1921 switch (zoom_attr) {
1922 case MM_DISPLAY_SCALE_DEFAULT:
1925 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1928 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1932 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
1937 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1938 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1939 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1940 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1942 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1943 if (!strcmp(videosink_name, "tizenwlsink")) {
1944 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1945 rect_x, rect_y, rect_width, rect_height);
1948 "dst-roi-x", rect_x,
1949 "dst-roi-y", rect_y,
1950 "dst-roi-w", rect_width,
1951 "dst-roi-h", rect_height,
1957 return MM_ERROR_NONE;
1961 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1964 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1965 _MMCamcorderSubContext *sc = NULL;
1967 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1969 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1971 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1974 case _MMCamcorder_CMD_PREVIEW_START:
1975 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1977 case _MMCamcorder_CMD_CAPTURE:
1978 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1981 MMCAM_LOG_WARNING("unknown command : %d", cmd);
1982 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1985 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1986 category, "FrameStabilityCount", &sc->frame_stability_count);
1988 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
1989 cmd, sc->frame_stability_count);
1991 return MM_ERROR_NONE;
1994 /* Retreive device information and set them to attributes */
1995 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
1997 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1998 _MMCamcorderSubContext *sc = NULL;
1999 GstCameraControl *control = NULL;
2000 GstCameraControlExifInfo exif_info = {0,};
2002 mmf_return_val_if_fail(hcamcorder, FALSE);
2003 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2005 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
2007 if (sc && sc->element) {
2008 int err = MM_ERROR_NONE;
2009 char *err_name = NULL;
2010 double focal_len = 0.0;
2012 /* Video input device */
2013 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2014 /* Exif related information */
2015 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2016 if (control != NULL) {
2017 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
2018 if (exif_info.focal_len_denominator != 0)
2019 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
2021 MMCAM_LOG_ERROR("Fail to get camera control interface!");
2026 /* Set values to attributes */
2027 err = mm_camcorder_set_attributes(handle, &err_name,
2028 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
2030 if (err != MM_ERROR_NONE) {
2031 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
2032 SAFE_FREE(err_name);
2036 MMCAM_LOG_WARNING("Sub context isn't exist.");
2043 static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure)
2045 const gchar *format_string = NULL;
2048 MMCAM_LOG_WARNING("NULL structure");
2049 return GST_MAKE_FOURCC('N', 'U', 'L', 'L');
2052 if (gst_structure_has_name(structure, "video/x-h264"))
2053 return GST_MAKE_FOURCC('H', '2', '6', '4');
2055 if (gst_structure_has_name(structure, "video/x-h265"))
2056 return GST_MAKE_FOURCC('H', '2', '6', '5');
2058 if (gst_structure_has_name(structure, "video/x-vp8"))
2059 return GST_MAKE_FOURCC('V', 'P', '8', '0');
2061 if (gst_structure_has_name(structure, "video/x-vp9"))
2062 return GST_MAKE_FOURCC('V', 'P', '9', '0');
2064 if (gst_structure_has_name(structure, "video/x-jpeg") ||
2065 gst_structure_has_name(structure, "image/jpeg"))
2066 return GST_MAKE_FOURCC('M', 'J', 'P', 'G');
2068 format_string = gst_structure_get_string(structure, "format");
2071 return GST_STR_FOURCC(format_string);
2073 return GST_MAKE_FOURCC('N', 'O', 'N', 'E');
2076 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2078 gboolean ret = TRUE;
2079 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2080 _MMCamcorderSubContext *sc = NULL;
2081 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2082 GstSample *sample = NULL;
2083 GstCaps *caps = NULL;
2085 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
2086 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
2087 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
2089 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
2090 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
2092 if (sc->drop_vframe > 0) {
2093 if (sc->pass_first_vframe > 0) {
2094 sc->pass_first_vframe--;
2095 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2098 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2099 return GST_PAD_PROBE_DROP;
2101 } else if (sc->frame_stability_count > 0) {
2102 sc->frame_stability_count--;
2103 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2104 return GST_PAD_PROBE_DROP;
2107 if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
2108 _mmcamcorder_measure_fps(&sc->kpi);
2110 /* The first H.264 frame should not be skipped for vstream cb. */
2111 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2112 !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2113 MMCAM_LOG_WARNING("Not ready for stream callback");
2114 return GST_PAD_PROBE_OK;
2117 /* make sample with buffer and caps */
2118 caps = gst_pad_get_allowed_caps(pad);
2119 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2121 sample = gst_sample_new(buffer, caps, NULL, NULL);
2122 gst_caps_unref(caps);
2123 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2125 ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
2127 gst_sample_unref(sample);
2130 return GST_PAD_PROBE_OK;
2132 return GST_PAD_PROBE_DROP;
2136 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2138 gboolean ret = TRUE;
2139 GstSample *sample = NULL;
2140 GstCaps *caps = NULL;
2142 caps = gst_pad_get_allowed_caps(pad);
2143 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2145 sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
2146 gst_caps_unref(caps);
2147 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2149 ret = _mmcamcorder_video_push_buffer(u_data, sample);
2151 gst_sample_unref(sample);
2153 return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
2157 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2159 MMCamcorderMuxedStreamDataType stream;
2160 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2161 _MMCamcorderSubContext *sc = NULL;
2162 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2165 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2166 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2167 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2169 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2170 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2172 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2173 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2174 return GST_PAD_PROBE_OK;
2177 /* call application callback */
2178 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2180 if (hcamcorder->mstream_cb) {
2181 stream.data = (void *)mapinfo.data;
2182 stream.length = mapinfo.size;
2183 stream.offset = sc->muxed_stream_offset;
2184 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2187 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2189 /* calculate current offset */
2190 sc->muxed_stream_offset += mapinfo.size;
2192 gst_buffer_unmap(buffer, &mapinfo);
2194 return GST_PAD_PROBE_OK;
2198 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2200 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2201 mmf_camcorder_t *hcamcorder = NULL;
2202 _MMCamcorderSubContext *sc = NULL;
2203 GstObject *parent = NULL;
2205 switch (GST_EVENT_TYPE(event)) {
2206 case GST_EVENT_UNKNOWN:
2207 /* upstream events */
2209 case GST_EVENT_SEEK:
2210 case GST_EVENT_NAVIGATION:
2211 case GST_EVENT_LATENCY:
2212 /* downstream serialized events */
2213 case GST_EVENT_BUFFERSIZE:
2214 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2218 GstTagList *tag_list = NULL;
2219 _MMCamcorderReplayGain *replay_gain = NULL;
2221 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2223 hcamcorder = MMF_CAMCORDER(u_data);
2224 if (!hcamcorder || !hcamcorder->sub_context) {
2225 MMCAM_LOG_WARNING("NULL handle");
2229 replay_gain = &hcamcorder->sub_context->replay_gain;
2231 gst_event_parse_tag(event, &tag_list);
2233 MMCAM_LOG_WARNING("failed to get tag list");
2237 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2238 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2242 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2243 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2247 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2248 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2252 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2253 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2257 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2258 replay_gain->track_peak, replay_gain->track_gain,
2259 replay_gain->album_peak, replay_gain->album_gain);
2262 case GST_EVENT_SEGMENT:
2263 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2265 hcamcorder = MMF_CAMCORDER(u_data);
2267 MMCAM_LOG_WARNING("NULL handle");
2271 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2273 MMCAM_LOG_WARNING("NULL sub context");
2277 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2278 MMCAM_LOG_WARNING("no encoder sink");
2282 parent = gst_pad_get_parent(pad);
2284 MMCAM_LOG_WARNING("get parent failed");
2288 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2289 const GstSegment *segment;
2290 gst_event_parse_segment(event, &segment);
2291 if (segment->format == GST_FORMAT_BYTES) {
2292 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2293 sc->muxed_stream_offset, segment->start);
2295 sc->muxed_stream_offset = (unsigned long long)segment->start;
2299 gst_object_unref(parent);
2303 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2305 /* bidirectional events */
2306 case GST_EVENT_FLUSH_START:
2307 case GST_EVENT_FLUSH_STOP:
2308 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2311 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2315 return GST_PAD_PROBE_OK;
2319 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2321 int result = MM_CAMCORDER_MR475;
2324 result = MM_CAMCORDER_MR475; /*AMR475*/
2325 else if (bitrate < 5900)
2326 result = MM_CAMCORDER_MR515; /*AMR515*/
2327 else if (bitrate < 6700)
2328 result = MM_CAMCORDER_MR59; /*AMR59*/
2329 else if (bitrate < 7400)
2330 result = MM_CAMCORDER_MR67; /*AMR67*/
2331 else if (bitrate < 7950)
2332 result = MM_CAMCORDER_MR74; /*AMR74*/
2333 else if (bitrate < 10200)
2334 result = MM_CAMCORDER_MR795; /*AMR795*/
2335 else if (bitrate < 12200)
2336 result = MM_CAMCORDER_MR102; /*AMR102*/
2338 result = MM_CAMCORDER_MR122; /*AMR122*/
2344 int _mmcamcorder_get_eos_message(MMHandleType handle)
2347 int ret = MM_ERROR_NONE;
2349 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2350 _MMCamcorderSubContext *sc = NULL;
2352 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2353 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2354 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2356 MMCAM_LOG_INFO("START");
2358 _MMCAMCORDER_LOCK(handle);
2360 if (sc->bget_eos == FALSE) {
2361 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2362 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2363 MMCAM_LOG_INFO("EOS signal received");
2365 MMCAM_LOG_ERROR("EOS wait time out");
2367 if (hcamcorder->error_code == MM_ERROR_NONE)
2368 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2371 MMCAM_LOG_INFO("already got EOS");
2374 _MMCAMCORDER_UNLOCK(handle);
2376 if (hcamcorder->error_code == MM_ERROR_NONE) {
2377 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2378 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2379 if (sc->info_video->b_committing)
2380 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2382 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2383 if (sc->info_audio->b_committing)
2384 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2387 ret = hcamcorder->error_code;
2388 MMCAM_LOG_ERROR("error 0x%x", ret);
2391 MMCAM_LOG_INFO("END");
2397 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2400 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2402 mmf_return_if_fail(handle && remove_element);
2403 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2407 for (i = first_elem ; i <= last_elem ; i++) {
2408 remove_element[i].gst = NULL;
2409 remove_element[i].id = _MMCAMCORDER_NONE;
2416 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2418 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2420 /* Check compatibility between codec and file format */
2421 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2422 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2423 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2424 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2425 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2426 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2429 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2431 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2432 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2434 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2435 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2436 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2437 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2438 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2439 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2442 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2444 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2445 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2449 return MM_ERROR_NONE;
2453 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2455 int err = MM_ERROR_NONE;
2456 int audio_codec = MM_AUDIO_CODEC_INVALID;
2457 int file_format = MM_FILE_FORMAT_INVALID;
2459 char *err_name = NULL;
2461 err = mm_camcorder_get_attributes(handle, &err_name,
2462 MMCAM_AUDIO_ENCODER, &audio_codec,
2463 MMCAM_FILE_FORMAT, &file_format,
2465 if (err != MM_ERROR_NONE) {
2466 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2467 SAFE_FREE(err_name);
2471 /* Check compatibility between audio codec and file format */
2472 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2478 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2480 int err = MM_ERROR_NONE;
2481 int video_codec = MM_VIDEO_CODEC_INVALID;
2482 int file_format = MM_FILE_FORMAT_INVALID;
2484 char *err_name = NULL;
2486 err = mm_camcorder_get_attributes(handle, &err_name,
2487 MMCAM_VIDEO_ENCODER, &video_codec,
2488 MMCAM_FILE_FORMAT, &file_format,
2490 if (err != MM_ERROR_NONE) {
2491 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2492 SAFE_FREE(err_name);
2496 /* Check compatibility between video codec and file format */
2497 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2503 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2505 const char* videosink_name = NULL;
2507 mmf_camcorder_t *hcamcorder = NULL;
2508 _MMCamcorderSubContext *sc = NULL;
2510 hcamcorder = MMF_CAMCORDER(handle);
2511 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2513 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2514 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2515 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2517 if (sc->element[videosink_index].gst) {
2518 /* Get videosink name */
2519 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2520 if (videosink_name == NULL) {
2521 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2525 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2526 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2527 !strcmp(videosink_name, "directvideosink")) {
2528 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2529 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2531 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2536 MMCAM_LOG_ERROR("Videosink element is null");
2542 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2544 const char* videosink_name = NULL;
2546 mmf_camcorder_t *hcamcorder = NULL;
2547 _MMCamcorderSubContext *sc = NULL;
2549 hcamcorder = MMF_CAMCORDER(handle);
2550 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2552 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2553 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2554 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2556 if (sc->element[videosink_index].gst) {
2557 /* Get videosink name */
2558 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2559 if (videosink_name == NULL) {
2560 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2564 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2565 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2566 !strcmp(videosink_name, "directvideosink")) {
2567 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2568 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2570 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2575 MMCAM_LOG_ERROR("Videosink element is null");
2581 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2584 _MMCamcorderSubContext *sc = NULL;
2586 mmf_camcorder_t *hcamcorder = NULL;
2588 hcamcorder = MMF_CAMCORDER(handle);
2589 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2591 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2593 MMCAM_LOG_INFO("sub context is not initialized");
2597 mm_camcorder_get_attributes(handle, NULL,
2598 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2599 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2600 MMCAM_CAMERA_FPS, &fps,
2603 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2605 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2606 sc->info_video->preview_width, sc->info_video->preview_height,
2607 fps, videosrc_rotate);
2611 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2617 unsigned int caps_fourcc = 0;
2618 gboolean do_set_caps = FALSE;
2619 char fourcc_string[sizeof(fourcc) + 1];
2620 gchar *caps_str = NULL;
2621 #ifdef _MMCAMCORDER_PRODUCT_TV
2624 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
2625 #endif /* _MMCAMCORDER_PRODUCT_TV */
2627 GstCaps *caps = NULL;
2629 mmf_camcorder_t *hcamcorder = NULL;
2630 _MMCamcorderSubContext *sc = NULL;
2632 hcamcorder = MMF_CAMCORDER(handle);
2633 mmf_return_val_if_fail(hcamcorder, FALSE);
2635 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2637 if (!sc || !(sc->element)) {
2638 MMCAM_LOG_INFO("sub context is not initialized");
2642 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2643 MMCAM_LOG_ERROR("Video src is NULL!");
2647 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2648 MMCAM_LOG_ERROR("Video filter is NULL!");
2652 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2653 int capture_width = 0;
2654 int capture_height = 0;
2655 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2657 mm_camcorder_get_attributes(handle, NULL,
2658 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2659 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2660 MMCAM_CAPTURE_WIDTH, &capture_width,
2661 MMCAM_CAPTURE_HEIGHT, &capture_height,
2662 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2663 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2665 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2666 motion_rate, capture_width, capture_height, fps_auto,
2667 sc->info_video->video_width, sc->info_video->video_height);
2669 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2670 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2672 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2673 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2674 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2677 sc->info_video->fps = fps;
2680 /* Interleaved format does not support rotation */
2681 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2682 /* store videosrc rotation */
2683 sc->videosrc_rotate = rotate;
2685 /* Define width, height and rotate in caps */
2687 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2688 This will be applied when rotate is 0, 180 if front camera. */
2689 set_rotate = rotate * 90;
2691 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2692 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2695 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2696 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2703 set_height = height;
2706 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2709 set_height = height;
2711 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2714 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2715 if (caps && !gst_caps_is_any(caps)) {
2716 GstStructure *structure = NULL;
2718 structure = gst_caps_get_structure(caps, 0);
2721 int caps_height = 0;
2724 int caps_rotate = 0;
2726 caps_fourcc = _mmcamcorder_get_structure_fourcc(structure);
2728 gst_structure_get(structure,
2729 "width", G_TYPE_INT, &caps_width,
2730 "height", G_TYPE_INT, &caps_height,
2731 "framerate", GST_TYPE_FRACTION, &caps_fps_n, &caps_fps_d,
2732 "rotate", G_TYPE_INT, &caps_rotate,
2735 #ifdef _MMCAMCORDER_PRODUCT_TV
2736 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2737 if (set_width == caps_width && set_height == caps_height &&
2738 set_rotate == caps_rotate && fps == caps_fps_n) {
2739 MMCAM_LOG_INFO("No need to replace caps.");
2741 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]",
2742 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2743 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2744 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2745 set_width, set_height, fps, set_rotate);
2749 if (set_width == caps_width && set_height == caps_height &&
2750 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2751 MMCAM_LOG_INFO("No need to replace caps.");
2753 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]",
2754 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2755 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2756 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2757 set_width, set_height, fps, set_rotate);
2761 #else /*_MMCAMCORDER_PRODUCT_TV */
2762 if (set_width == caps_width && set_height == caps_height &&
2763 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2764 MMCAM_LOG_INFO("No need to replace caps.");
2766 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]",
2767 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2768 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2769 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2770 set_width, set_height, fps, set_rotate);
2773 #endif /*_MMCAMCORDER_PRODUCT_TV */
2775 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2779 MMCAM_LOG_INFO("No caps. set new one...");
2784 gst_caps_unref(caps);
2788 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2789 /* assume that it's camera capture mode */
2790 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2796 switch (sc->info_image->preview_format) {
2797 case MM_PIXEL_FORMAT_ENCODED_H264:
2798 #ifdef _MMCAMCORDER_PRODUCT_TV
2799 mm_camcorder_get_attributes(handle, NULL,
2800 MMCAM_DISPLAY_SURFACE, &display_surface_type,
2802 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
2803 __mmcamcorder_find_max_resolution(handle, &maxwidth, &maxheight) == false) {
2804 MMCAM_LOG_ERROR("can not find max resolution limitation");
2806 } else if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
2807 maxwidth = set_width;
2808 maxheight = set_height;
2810 #endif /* _MMCAMCORDER_PRODUCT_TV */
2811 caps = gst_caps_new_simple("video/x-h264",
2812 "width", G_TYPE_INT, set_width,
2813 "height", G_TYPE_INT, set_height,
2814 "framerate", GST_TYPE_FRACTION, fps, 1,
2815 "stream-format", G_TYPE_STRING, "byte-stream",
2816 #ifdef _MMCAMCORDER_PRODUCT_TV
2817 "maxwidth", G_TYPE_INT, maxwidth,
2818 "maxheight", G_TYPE_INT, maxheight,
2819 "alignment", G_TYPE_STRING, "au",
2820 #endif /* _MMCAMCORDER_PRODUCT_TV */
2823 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
2824 #ifdef _MMCAMCORDER_PRODUCT_TV
2825 caps = gst_caps_new_simple("video/x-jpeg",
2827 caps = gst_caps_new_simple("image/jpeg",
2829 "width", G_TYPE_INT, set_width,
2830 "height", G_TYPE_INT, set_height,
2831 "framerate", GST_TYPE_FRACTION, fps, 1,
2834 case MM_PIXEL_FORMAT_ENCODED_VP8:
2835 caps = gst_caps_new_simple("video/x-vp8",
2836 "width", G_TYPE_INT, set_width,
2837 "height", G_TYPE_INT, set_height,
2838 "framerate", GST_TYPE_FRACTION, fps, 1,
2841 case MM_PIXEL_FORMAT_ENCODED_VP9:
2842 caps = gst_caps_new_simple("video/x-vp9",
2843 "width", G_TYPE_INT, set_width,
2844 "height", G_TYPE_INT, set_height,
2845 "framerate", GST_TYPE_FRACTION, fps, 1,
2850 memcpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
2851 fourcc_string[sizeof(fourcc)] = '\0';
2852 caps = gst_caps_new_simple("video/x-raw",
2853 "format", G_TYPE_STRING, fourcc_string,
2854 "width", G_TYPE_INT, set_width,
2855 "height", G_TYPE_INT, set_height,
2856 "framerate", GST_TYPE_FRACTION, fps, 1,
2857 "rotate", G_TYPE_INT, set_rotate,
2863 MMCAM_LOG_ERROR("There are no caps");
2867 caps_str = gst_caps_to_string(caps);
2868 MMCAM_LOG_INFO("vidoesrc new caps set [%s]", caps_str);
2871 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2872 gst_caps_unref(caps);
2878 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2880 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2881 _MMCamcorderSubContext *sc = NULL;
2883 mmf_return_val_if_fail(hcamcorder, FALSE);
2885 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2889 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
2891 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2895 /* Interleaved format does not support FLIP */
2896 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2897 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2898 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2900 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
2902 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2903 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2905 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
2909 MMCAM_LOG_WARNING("element is NULL");
2917 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2919 GstCameraControl *control = NULL;
2920 _MMCamcorderSubContext *sc = NULL;
2921 GstElement *v_src = NULL;
2925 mmf_return_val_if_fail(handle, FALSE);
2927 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2931 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2934 MMCAM_LOG_WARNING("videosrc element is NULL");
2938 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2940 /* set anti-shake with camera control */
2941 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2942 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
2946 control = GST_CAMERA_CONTROL(v_src);
2947 if (gst_camera_control_set_ahs(control, set_value)) {
2948 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
2951 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
2958 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2960 _MMCamcorderSubContext *sc = NULL;
2961 GstElement *v_src = NULL;
2963 mmf_return_val_if_fail(handle, FALSE);
2965 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2969 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2971 MMCAM_LOG_WARNING("videosrc element is NULL");
2975 /* check property of videosrc element - support VDIS */
2976 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2977 int video_width = 0;
2978 int video_height = 0;
2980 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2981 MMCAM_LOG_INFO("ENABLE video stabilization");
2983 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2984 mm_camcorder_get_attributes(handle, NULL,
2985 MMCAM_VIDEO_WIDTH, &video_width,
2986 MMCAM_VIDEO_HEIGHT, &video_height,
2989 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2990 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
2991 video_width, video_height);
2993 g_object_set(G_OBJECT(v_src),
2994 "enable-vdis-mode", TRUE,
2997 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
2998 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2999 video_width, video_height);
3004 g_object_set(G_OBJECT(v_src),
3005 "enable-vdis-mode", FALSE,
3008 MMCAM_LOG_INFO("DISABLE video stabilization");
3010 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
3011 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
3014 MMCAM_LOG_WARNING("no property for video stabilization");
3021 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
3025 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3026 _MMCamcorderSubContext *sc = NULL;
3028 mmf_return_val_if_fail(hcamcorder, FALSE);
3030 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3034 mm_camcorder_get_attributes(handle, NULL,
3035 MMCAM_CAMERA_FPS, &fps,
3038 MMCAM_LOG_INFO("set %dx%d", width, height);
3040 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
3044 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
3046 _MMCamcorderSubContext *sc = NULL;
3048 if ((void *)handle == NULL) {
3049 MMCAM_LOG_WARNING("handle is NULL");
3053 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3055 MMCAM_LOG_WARNING("subcontext is NULL");
3059 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3060 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3064 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
3066 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
3072 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
3074 _MMCamcorderSubContext *sc = NULL;
3076 if ((void *)handle == NULL) {
3077 MMCAM_LOG_WARNING("handle is NULL");
3081 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3083 MMCAM_LOG_WARNING("subcontext is NULL");
3087 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3088 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3092 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
3094 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3100 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3102 GstStructure *props = NULL;
3103 char stream_props[64] = {'\0',};
3105 if (element == NULL || stream_type == NULL || stream_index < 0) {
3106 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3110 snprintf(stream_props, sizeof(stream_props) - 1,
3111 "props,media.role=%s, media.parent_id=%d",
3112 stream_type, stream_index);
3114 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3116 props = gst_structure_from_string(stream_props, NULL);
3118 MMCAM_LOG_ERROR("failed to create GstStructure");
3122 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3124 gst_structure_free(props);
3131 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3133 int ret = MM_ERROR_NONE;
3134 _MMCamcorderSubContext *sc = NULL;
3135 mmf_camcorder_t *hcamcorder = NULL;
3136 const char *videodecoder_name = NULL;
3137 char videodecoder_name_final[32] = {'\0',};
3138 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3139 #ifdef _MMCAMCORDER_RM_SUPPORT
3140 int decoder_index = 0;
3141 #endif /* _MMCAMCORDER_RM_SUPPORT */
3143 if ((void *)handle == NULL) {
3144 MMCAM_LOG_WARNING("handle is NULL");
3148 hcamcorder = MMF_CAMCORDER(handle);
3150 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3152 MMCAM_LOG_WARNING("subcontext is NULL");
3156 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3157 hcamcorder->recreate_decoder == FALSE) {
3158 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3159 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3163 mm_camcorder_get_attributes(handle, NULL,
3164 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3167 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3168 MMCAM_LOG_INFO("no need to control decoder element");
3172 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3173 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3174 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3178 MMCAM_LOG_INFO("start");
3180 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
3181 if (videodecoder_name == NULL) {
3182 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
3186 /* set state as NULL */
3187 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3188 if (ret != MM_ERROR_NONE) {
3189 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3193 /* remove decoder - pads will be unlinked automatically in remove function */
3194 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3195 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3196 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3200 /* check decoder element */
3201 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3202 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3203 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3204 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3207 #ifdef _MMCAMCORDER_RM_SUPPORT
3208 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3209 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3212 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
3213 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
3215 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3216 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
3218 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
3220 #endif /* _MMCAMCORDER_RM_SUPPORT */
3221 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
3222 #ifdef _MMCAMCORDER_RM_SUPPORT
3224 #endif /* _MMCAMCORDER_RM_SUPPORT */
3226 /* create decoder */
3227 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "videosrc_decode");
3228 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3229 MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
3233 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
3235 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3236 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3237 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3239 /* add to pipeline */
3240 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3241 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3242 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3243 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3248 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3249 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3250 MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
3252 MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
3256 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3257 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3258 MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
3260 MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
3264 /* set state READY */
3265 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3266 if (ret != MM_ERROR_NONE) {
3267 MMCAM_LOG_ERROR("failed to set READY to decoder");
3271 MMCAM_LOG_INFO("done");
3276 #ifdef _MMCAMCORDER_PRODUCT_TV
3277 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3279 _MMCamcorderSubContext *sc = NULL;
3280 mmf_camcorder_t *hcamcorder = NULL;
3282 const gchar *mime = NULL;
3284 GstCaps *decsink_caps = NULL;
3285 GstStructure *decsink_struct = NULL;
3287 mmf_return_val_if_fail(handle, false);
3288 mmf_return_val_if_fail(max_width, false);
3289 mmf_return_val_if_fail(max_height, false);
3291 hcamcorder = MMF_CAMCORDER(handle);
3292 mmf_return_val_if_fail(hcamcorder, false);
3294 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3296 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3298 MMCAM_LOG_ERROR("There are no decoder caps");
3302 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3303 if (!decsink_caps) {
3304 gst_object_unref(sinkpad);
3305 MMCAM_LOG_ERROR("There is no decoder sink caps");
3309 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3310 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3311 if (!decsink_struct) {
3312 MMCAM_LOG_ERROR("There are no structure from caps");
3313 gst_object_unref(decsink_caps);
3314 gst_object_unref(sinkpad);
3317 mime = gst_structure_get_name(decsink_struct);
3318 if (!strcmp(mime, "video/x-h264")) {
3319 MMCAM_LOG_INFO("h264 caps structure found");
3320 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3321 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3322 if (gst_structure_has_field(decsink_struct, "maxheight"))
3323 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3325 } else if (!strcmp(mime, "video/x-jpeg")) {
3326 MMCAM_LOG_INFO("mjpeg caps structure found");
3327 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3328 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3329 if (gst_structure_has_field(decsink_struct, "maxheight"))
3330 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3334 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3335 gst_object_unref(decsink_caps);
3336 gst_object_unref(sinkpad);
3338 if (*max_width <= 0 || *max_height <= 0)
3343 #endif /* _MMCAMCORDER_PRODUCT_TV */