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);
157 static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
158 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory);
159 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format);
160 static void __mmcamcorder_request_codec_config(GstElement *videosrc_element);
162 /*=======================================================================================
163 | FUNCTION DEFINITIONS |
164 =======================================================================================*/
165 static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
169 mmf_return_val_if_fail(buffer, FALSE);
170 mmf_return_val_if_fail(stream, FALSE);
171 mmf_return_val_if_fail(map_info, FALSE);
173 stream->length_total = map_info->size;
175 switch (stream->format) {
176 case MM_PIXEL_FORMAT_NV12: /* fall through */
177 case MM_PIXEL_FORMAT_NV21:
178 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
179 stream->data.yuv420sp.y = map_info->data;
180 stream->data.yuv420sp.length_y = stream->width * stream->height;
181 stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
182 stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
183 stream->stride[0] = stream->width;
184 stream->elevation[0] = stream->height;
185 stream->stride[1] = stream->width;
186 stream->elevation[1] = stream->height >> 1;
187 stream->num_planes = 2;
190 case MM_PIXEL_FORMAT_I420:
191 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
192 stream->data.yuv420p.y = map_info->data;
193 stream->data.yuv420p.length_y = stream->width * stream->height;
194 stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
195 stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
196 stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
197 stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
198 stream->stride[0] = stream->width;
199 stream->elevation[0] = stream->height;
200 stream->stride[1] = stream->stride[2] = stream->width >> 1;
201 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
202 stream->num_planes = 3;
205 case MM_PIXEL_FORMAT_422P:
206 stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
207 stream->data.yuv422p.y = map_info->data;
208 stream->data.yuv422p.length_y = stream->width * stream->height;
209 stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
210 stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
211 stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
212 stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
213 stream->stride[0] = stream->width;
214 stream->elevation[0] = stream->height;
215 stream->stride[1] = stream->stride[2] = stream->width;
216 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
217 stream->num_planes = 3;
220 case MM_PIXEL_FORMAT_YUYV: /* fall through */
221 case MM_PIXEL_FORMAT_UYVY: /* fall through */
222 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
223 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
224 stream->data.yuv422.yuv = map_info->data;
225 stream->data.yuv422.length_yuv = stream->length_total;
226 stream->stride[0] = stream->width << 1;
227 stream->elevation[0] = stream->height;
228 stream->num_planes = 1;
231 case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
232 case MM_PIXEL_FORMAT_ENCODED_MJPEG: /* fall through */
233 case MM_PIXEL_FORMAT_ENCODED_VP8: /* fall through */
234 case MM_PIXEL_FORMAT_ENCODED_VP9: /* fall through */
235 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
236 stream->data.encoded.data = map_info->data;
237 stream->data.encoded.length_data = stream->length_total;
238 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
239 stream->num_planes = 1;
242 case MM_PIXEL_FORMAT_INVZ:
243 stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
244 stream->data.depth.data = map_info->data;
245 stream->data.depth.length_data = stream->length_total;
246 stream->stride[0] = stream->width << 1;
247 stream->elevation[0] = stream->height;
248 stream->num_planes = 1;
251 case MM_PIXEL_FORMAT_RGBA: /* fall through */
252 case MM_PIXEL_FORMAT_ARGB:
253 stream->data_type = MM_CAM_STREAM_DATA_RGB;
254 stream->data.rgb.data = map_info->data;
255 stream->data.rgb.length_data = stream->length_total;
256 stream->stride[0] = stream->width << 2;
257 stream->elevation[0] = stream->height;
258 stream->num_planes = 1;
262 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
271 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory)
275 int tbm_ret = TBM_SURFACE_ERROR_NONE;
276 tbm_bo_handle bo_handle = {NULL, };
277 tbm_surface_info_s ts_info;
279 mmf_return_val_if_fail(stream, FALSE);
280 mmf_return_val_if_fail(buffer, FALSE);
281 mmf_return_val_if_fail(memory, FALSE);
283 if (_mmcamcorder_is_encoded_preview_pixel_format(stream->format)) {
284 stream->bo[0] = gst_tizen_memory_get_bos(memory, 0);
286 bo_handle = tbm_bo_get_handle(stream->bo[0], TBM_DEVICE_CPU);
287 if (!bo_handle.ptr) {
288 MMCAM_LOG_ERROR("tbm_bo_get_handle failed[bo:%p,memory:%p]", stream->bo[0], memory);
292 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
293 stream->num_planes = 1;
294 stream->stride[0] = stream->width;
295 stream->elevation[0] = stream->height;
296 stream->data.encoded.data = bo_handle.ptr;
297 stream->length_total = gst_memory_get_sizes(memory, NULL, NULL);
298 stream->data.encoded.length_data = stream->length_total;
299 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
301 MMCAM_LOG_VERBOSE("[ENCODED] length[%u], is_delta[%d]",
302 stream->data.encoded.length_data, stream->data.encoded.is_delta_frame);
307 memset(&ts_info, 0x0, sizeof(tbm_surface_info_s));
309 tbm_ret = tbm_surface_get_info((tbm_surface_h)gst_tizen_memory_get_surface(memory), &ts_info);
310 if (tbm_ret != TBM_SURFACE_ERROR_NONE) {
311 MMCAM_LOG_ERROR("get tbm surface info failed[0x%x]", tbm_ret);
315 stream->length_total = ts_info.size;
316 for (i = 0 ; i < ts_info.num_planes ; i++) {
317 stream->stride[i] = ts_info.planes[i].stride;
318 stream->elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
319 MMCAM_LOG_VERBOSE(" plane[%d] %dx%d", i, stream->stride[i], stream->elevation[i]);
322 num_bos = gst_tizen_memory_get_num_bos(memory);
323 for (i = 0 ; i < num_bos ; i++)
324 stream->bo[i] = gst_tizen_memory_get_bos(memory, i);
327 switch (stream->format) {
328 case MM_PIXEL_FORMAT_NV12: /* fall through */
329 case MM_PIXEL_FORMAT_NV21:
330 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
331 stream->num_planes = 2;
332 stream->data.yuv420sp.y = ts_info.planes[0].ptr;
333 stream->data.yuv420sp.length_y = ts_info.planes[0].size;
334 stream->data.yuv420sp.uv = ts_info.planes[1].ptr;
335 stream->data.yuv420sp.length_uv = ts_info.planes[1].size;
337 MMCAM_LOG_VERBOSE("[420SP] 0[%p,%u], 1[%p,%u]",
338 stream->data.yuv420sp.y, stream->data.yuv420sp.length_y,
339 stream->data.yuv420sp.uv, stream->data.yuv420sp.length_uv);
342 case MM_PIXEL_FORMAT_I420:
343 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
344 stream->num_planes = 3;
345 stream->data.yuv420p.y = ts_info.planes[0].ptr;
346 stream->data.yuv420p.length_y = ts_info.planes[0].size;
347 stream->data.yuv420p.u = ts_info.planes[1].ptr;
348 stream->data.yuv420p.length_u = ts_info.planes[1].size;
349 stream->data.yuv420p.v = ts_info.planes[2].ptr;
350 stream->data.yuv420p.length_v = ts_info.planes[2].size;
352 MMCAM_LOG_VERBOSE("[I420] 0[%p,%u], 1[%p,%u], 2[%p,%u]",
353 stream->data.yuv420p.y, stream->data.yuv420p.length_y,
354 stream->data.yuv420p.u, stream->data.yuv420p.length_u,
355 stream->data.yuv420p.v, stream->data.yuv420p.length_v);
358 case MM_PIXEL_FORMAT_YUYV:
359 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
360 stream->num_planes = 1;
361 stream->data.yuv422.yuv = ts_info.planes[0].ptr;
362 stream->data.yuv422.length_yuv = ts_info.planes[0].size;
364 MMCAM_LOG_VERBOSE("[YUYV] 0[%p,%u]",
365 stream->data.yuv422.yuv, stream->data.yuv422.length_yuv);
369 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
377 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format)
380 case MM_PIXEL_FORMAT_ENCODED_H264:
382 case MM_PIXEL_FORMAT_ENCODED_VP9:
385 MMCAM_LOG_WARNING("unsupported format[%d]", format);
391 static void __mmcamcorder_request_codec_config(GstElement *videosrc_element)
393 if (!videosrc_element || !G_TYPE_CHECK_INSTANCE(videosrc_element)) {
394 MMCAM_LOG_WARNING("invalid videosrc element[%p]", videosrc_element);
398 if (!g_signal_parse_name(_MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG,
399 G_TYPE_FROM_INSTANCE(videosrc_element), NULL, NULL, FALSE)) {
400 MMCAM_LOG_WARNING("no signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
404 MMCAM_LOG_INFO("emit signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
406 g_signal_emit_by_name(videosrc_element, _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
410 gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sample, gboolean is_preview, int stream_id)
413 gboolean ret_cb = TRUE;
414 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
415 _MMCamcorderSubContext *sc = NULL;
416 MMCamcorderVideoStreamDataType stream;
418 GstBuffer *buffer = NULL;
419 GstMemory *memory = NULL;
421 GstCaps *caps = NULL;
422 GstStructure *structure = NULL;
424 mmf_return_val_if_fail(hcamcorder, FALSE);
426 buffer = gst_sample_get_buffer(sample);
427 mmf_return_val_if_fail(buffer, FALSE);
428 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
430 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
431 mmf_return_val_if_fail(sc, FALSE);
433 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
435 caps = gst_sample_get_caps(sample);
436 mmf_return_val_if_fail(caps, FALSE);
438 structure = gst_caps_get_structure(caps, 0);
439 mmf_return_val_if_fail(structure, FALSE);
441 stream.format = _mmcamcorder_get_pixel_format(caps, TRUE);
442 gst_structure_get(structure,
443 "width", G_TYPE_INT, &stream.width,
444 "height", G_TYPE_INT, &stream.height,
447 memory = gst_buffer_peek_memory(buffer, 0);
449 MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
453 structure = gst_mini_object_get_qdata(GST_MINI_OBJECT_CAST(buffer), hcamcorder->buffer_quark);
454 if (structure && gst_structure_has_field(structure, "focus-state")) {
455 gst_structure_get(structure,
456 "focus-state", G_TYPE_INT, &stream.focus_state,
457 "facing-direction", G_TYPE_INT, &stream.facing_direction,
458 "flip", G_TYPE_INT, &stream.flip,
459 "rotation", G_TYPE_INT, &stream.rotation,
462 MMCAM_LOG_VERBOSE("structure[%p], [fs:%d,fd:%d,f:%d,r:%d]", structure,
463 stream.focus_state, stream.facing_direction, stream.flip, stream.rotation);
466 if (gst_is_tizen_memory(memory)) {
467 if (!__mmcamcorder_set_stream_data_zero_copy(&stream, buffer, memory))
468 goto _INVOKE_VIDEO_STREAM_CB_DONE;
470 memset(&map_info, 0x0, sizeof(GstMapInfo));
472 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE)) {
473 MMCAM_LOG_ERROR("map failed for memory[%p]", memory);
477 if (!__mmcamcorder_set_stream_data(&stream, buffer, &map_info))
478 goto _INVOKE_VIDEO_STREAM_CB_DONE;
481 MMCAM_LOG_DEBUG("VideoStreamData : format[%d], resolution[%dx%d], stream_id[%d]",
482 stream.format, stream.width, stream.height, stream_id);
484 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
485 stream.extra_stream_id = stream_id;
486 stream.internal_buffer = buffer;
488 /* invoke application callback */
490 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
491 if (hcamcorder->vstream_cb)
492 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
493 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
495 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
496 if (hcamcorder->vedecision_cb)
497 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
498 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
501 _INVOKE_VIDEO_STREAM_CB_DONE:
502 if (!gst_is_tizen_memory(memory))
503 gst_memory_unmap(memory, &map_info);
505 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
506 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
507 tbm_bo_unmap(stream.bo[i]);
514 int _mmcamcorder_create_preview_elements(MMHandleType handle)
516 int err = MM_ERROR_NONE;
518 int camera_rotate = 0;
522 int capture_width = 0;
523 int capture_height = 0;
524 int capture_quality = 0;
525 int video_stabilization = 0;
527 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
528 const char *videosrc_name = NULL;
529 const char *videosink_name = NULL;
530 const char *videoconvert_name = NULL;
531 const char *videodecoder_name = NULL;
532 const char *videoparse_name = NULL;
533 const char *decoder_conf_name = NULL;
534 char videodecoder_name_final[32] = {'\0',};
535 char *err_name = NULL;
536 #ifdef _MMCAMCORDER_RM_SUPPORT
537 int decoder_index = 0;
538 #endif /* _MMCAMCORDER_RM_SUPPORT */
539 GstElement *sink_element = NULL;
540 GstCameraControl *control = NULL;
541 int sink_element_size = 0;
544 int extra_preview_enable = 0;
546 GList *element_list = NULL;
548 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
549 _MMCamcorderSubContext *sc = NULL;
550 type_element *videosrc_element = NULL;
551 type_int_array *input_index = NULL;
553 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
555 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
556 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
557 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
561 /* Check existence */
562 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
563 if (sc->element[i].gst) {
564 if (((GObject *)sc->element[i].gst)->ref_count > 0)
565 gst_object_unref(sc->element[i].gst);
567 MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
571 /* Get video device index info */
572 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
573 CONFIGURE_CATEGORY_CTRL_CAMERA,
576 if (input_index == NULL) {
577 MMCAM_LOG_ERROR("Failed to get input_index");
578 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
581 err = mm_camcorder_get_attributes(handle, &err_name,
582 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
583 MMCAM_CAMERA_FPS, &fps,
584 MMCAM_CAMERA_ROTATION, &camera_rotate,
585 MMCAM_CAMERA_FLIP, &camera_flip,
586 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
587 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
588 MMCAM_CAPTURE_WIDTH, &capture_width,
589 MMCAM_CAPTURE_HEIGHT, &capture_height,
590 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
591 MMCAM_IMAGE_ENCODER, &codectype,
592 MMCAM_IMAGE_ENCODER_QUALITY, &capture_quality,
593 MMCAM_DISPLAY_SURFACE, &display_surface_type,
594 MMCAM_EXTRA_PREVIEW_ENABLE, &extra_preview_enable,
596 if (err != MM_ERROR_NONE) {
597 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
602 if (hcamcorder->support_user_buffer) {
603 err = mm_camcorder_get_attributes(handle, NULL,
604 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
606 if (err != MM_ERROR_NONE || fd_number < 1) {
607 MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
612 for (i = 0 ; i < fd_number ; i++)
613 MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
617 /* Get fourcc from picture format */
618 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
620 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
621 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
622 &videosrc_element, &videosrc_name);
625 * Create child element
627 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
629 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
632 * This is for "tizencamerasrc" element only.
633 * The camera HAL library will be loaded when "hal-name" property is set.
634 * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
636 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
638 /* camera properties */
639 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
640 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
641 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
642 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-quality", capture_quality);
643 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
644 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "extra-preview", extra_preview_enable);
645 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
647 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
649 /* set camera flip */
650 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
652 /* set video stabilization mode */
653 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
655 /* set anti handshake mode */
656 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
658 if (sc->is_modified_rate)
659 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
661 /* Set basic information of videosrc element */
662 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, videosrc_element);
664 /* Set video device index */
665 if (hcamcorder->is_network) {
666 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
668 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
669 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
671 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
675 /* set user buffer fd to videosrc element */
676 if (hcamcorder->support_user_buffer) {
677 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
678 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
679 MMCAM_LOG_ERROR("set user buffer fd failed");
680 goto pipeline_creation_error;
684 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
685 /* get recreate_decoder flag */
686 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
687 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
689 &hcamcorder->recreate_decoder);
692 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
693 _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
694 switch (sc->info_image->preview_format) {
695 case MM_PIXEL_FORMAT_ENCODED_H264:
696 decoder_conf_name = "VideodecoderElementH264";
698 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
699 decoder_conf_name = "VideodecoderElementMJPEG";
701 case MM_PIXEL_FORMAT_ENCODED_VP8:
702 decoder_conf_name = "VideodecoderElementVP8";
704 case MM_PIXEL_FORMAT_ENCODED_VP9:
705 decoder_conf_name = "VideodecoderElementVP9";
708 MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
709 goto pipeline_creation_error;
712 /* get video decoder element and name */
713 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
714 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
716 &sc->VideodecoderElement);
718 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
721 if (!videodecoder_name) {
722 MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
723 goto pipeline_creation_error;
726 #ifdef _MMCAMCORDER_RM_SUPPORT
727 MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
728 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
729 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
731 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
732 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
733 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
734 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
736 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
738 #endif /* _MMCAMCORDER_RM_SUPPORT */
739 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
740 #ifdef _MMCAMCORDER_RM_SUPPORT
742 #endif /* _MMCAMCORDER_RM_SUPPORT */
744 videoparse_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
746 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_PARSE, videoparse_name, "videosrc_parse", element_list, err);
748 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
750 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
753 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
755 /* Get videosink name */
756 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
758 if (!videosink_name) {
759 MMCAM_LOG_ERROR("failed to get videosink name");
760 goto pipeline_creation_error;
763 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
765 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
767 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
768 /* get video convert name */
769 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
771 if (videoconvert_name) {
772 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
773 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
775 MMCAM_LOG_ERROR("failed to get videoconvert element name");
778 /* check sink element in attribute */
779 mm_camcorder_get_attributes(handle, NULL,
780 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
785 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
787 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
789 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
791 /* reset attribute */
793 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
794 mm_attrs_set_data(attrs, attr_index, NULL, 0);
795 mm_attrs_commit(attrs, attr_index);
797 MMCAM_LOG_WARNING("attribute is NULL");
798 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
799 goto pipeline_creation_error;
802 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
804 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
807 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
808 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
809 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
810 goto pipeline_creation_error;
813 /* Set caps by rotation */
814 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
816 /* add elements to main pipeline */
817 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
818 MMCAM_LOG_ERROR("element_list add error.");
819 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
820 goto pipeline_creation_error;
824 if (!_mmcamcorder_link_elements(element_list)) {
825 MMCAM_LOG_ERROR("element link error.");
826 err = MM_ERROR_CAMCORDER_GST_LINK;
827 goto pipeline_creation_error;
831 g_list_free(element_list);
835 return MM_ERROR_NONE;
837 pipeline_creation_error:
838 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
839 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
840 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
841 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_FILT);
842 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_SINK);
843 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
844 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
845 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
848 g_list_free(element_list);
856 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
858 int err = MM_ERROR_NONE;
863 int a_enc = MM_AUDIO_CODEC_AMR;
864 int a_dev = MM_AUDIO_DEVICE_MIC;
866 char *err_name = NULL;
867 const char *audiosrc_name = NULL;
868 char *cat_name = NULL;
869 char *stream_type = NULL;
870 int stream_type_len = 0;
871 int stream_index = 0;
872 int buffer_interval = 0;
874 int replay_gain_enable = FALSE;
875 double replay_gain_ref_level = 0.0;
877 GstCaps *caps = NULL;
879 GList *element_list = NULL;
881 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
882 _MMCamcorderSubContext *sc = NULL;
883 _MMCamcorderGstElement *last_element = NULL;
884 type_element *audiosrc_element = NULL;
886 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
888 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
889 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
890 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
894 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
895 if (err != MM_ERROR_NONE)
898 err = mm_camcorder_get_attributes(handle, &err_name,
899 MMCAM_AUDIO_DEVICE, &a_dev,
900 MMCAM_AUDIO_ENCODER, &a_enc,
901 MMCAM_AUDIO_ENCODER_BITRATE, &val,
902 MMCAM_AUDIO_SAMPLERATE, &rate,
903 MMCAM_AUDIO_FORMAT, &format,
904 MMCAM_AUDIO_CHANNEL, &channel,
905 MMCAM_AUDIO_VOLUME, &volume,
906 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
907 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
908 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
909 MMCAM_SOUND_STREAM_INDEX, &stream_index,
911 if (err != MM_ERROR_NONE) {
912 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
917 /* Check existence */
918 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
919 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
920 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
922 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
925 /* Create bin element */
926 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
928 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
929 cat_name = strdup("AudiomodemsrcElement");
931 /* MM_AUDIO_DEVICE_MIC or others */
932 cat_name = strdup("AudiosrcElement");
935 if (cat_name == NULL) {
936 MMCAM_LOG_ERROR("strdup failed.");
937 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
938 goto pipeline_creation_error;
941 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
942 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, cat_name,
943 &audiosrc_element, &audiosrc_name);
948 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
950 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
952 /* set sound stream info */
953 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
955 /* set audiosrc properties in ini configuration */
956 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, audiosrc_element);
959 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
960 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
961 "AudioBufferInterval",
964 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
965 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
966 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
969 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
971 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
972 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
973 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
974 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
976 /* Set basic information */
977 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
979 const gchar* format_name = NULL;
981 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
984 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
985 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
987 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
988 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
991 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
993 format_name = "S16LE";
994 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
999 caps = gst_caps_new_simple("audio/x-raw",
1000 "rate", G_TYPE_INT, rate,
1001 "channels", G_TYPE_INT, channel,
1002 "format", G_TYPE_STRING, format_name,
1004 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
1005 rate, channel, depth, volume);
1007 /* what are the audio encoder which should get audio/x-raw-float? */
1008 caps = gst_caps_new_simple("audio/x-raw",
1009 "rate", G_TYPE_INT, rate,
1010 "channels", G_TYPE_INT, channel,
1011 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
1013 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
1014 rate, channel, BYTE_ORDER);
1018 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
1019 replay_gain_enable, replay_gain_ref_level);
1021 if (replay_gain_enable) {
1022 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
1023 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
1024 /* If num-tracks is not set, album gain and peak event is not come. */
1025 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
1029 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
1030 gst_caps_unref(caps);
1033 MMCAM_LOG_ERROR("create caps error");
1034 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1035 goto pipeline_creation_error;
1038 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
1039 MMCAM_LOG_ERROR("element add error.");
1040 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1041 goto pipeline_creation_error;
1044 if (!_mmcamcorder_link_elements(element_list)) {
1045 MMCAM_LOG_ERROR("element link error.");
1046 err = MM_ERROR_CAMCORDER_GST_LINK;
1047 goto pipeline_creation_error;
1050 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
1051 pad = gst_element_get_static_pad(last_element->gst, "src");
1052 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
1053 gst_object_unref(pad);
1055 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
1056 err = MM_ERROR_CAMCORDER_GST_LINK;
1057 goto pipeline_creation_error;
1060 gst_object_unref(pad);
1064 g_list_free(element_list);
1065 element_list = NULL;
1068 return MM_ERROR_NONE;
1070 pipeline_creation_error:
1071 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1072 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1073 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1074 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1075 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1078 g_list_free(element_list);
1079 element_list = NULL;
1086 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1091 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1096 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1097 type, codec, bitrate);
1101 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1102 /* audio encoder bitrate setting */
1104 case MM_AUDIO_CODEC_AMR:
1105 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1106 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1107 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1109 case MM_AUDIO_CODEC_MP3:
1110 set_value = bitrate / 1000;
1111 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1112 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1114 case MM_AUDIO_CODEC_AAC:
1115 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1116 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1119 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1123 /* video encoder bitrate setting */
1124 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1125 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1132 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1134 int err = MM_ERROR_NONE;
1139 int encodebin_profile = 0;
1140 int auto_audio_convert = 0;
1141 int auto_audio_resample = 0;
1142 int auto_color_space = 0;
1143 int cap_format = MM_PIXEL_FORMAT_INVALID;
1144 const char *gst_element_venc_name = NULL;
1145 const char *gst_element_aenc_name = NULL;
1146 const char *gst_element_ienc_name = NULL;
1147 const char *gst_element_mux_name = NULL;
1148 const char *gst_element_rsink_name = NULL;
1149 const char *gst_element_vscale_name = NULL;
1150 const char *str_profile = NULL;
1151 const char *str_aac = NULL;
1152 const char *str_aar = NULL;
1153 const char *str_acs = NULL;
1154 char *err_name = NULL;
1155 const char *videoconvert_name = NULL;
1156 GstCaps *audio_caps = NULL;
1157 GstCaps *video_caps = NULL;
1158 GstCaps *videoscale_caps = NULL;
1160 GList *element_list = NULL;
1162 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1163 _MMCamcorderSubContext *sc = NULL;
1164 type_element *VideoencElement = NULL;
1165 type_element *AudioencElement = NULL;
1166 type_element *ImageencElement = NULL;
1167 type_element *MuxElement = NULL;
1168 type_element *RecordsinkElement = NULL;
1169 type_element *VideoscaleElement = NULL;
1171 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1173 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1174 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1175 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1177 MMCAM_LOG_INFO("start - profile : %d", profile);
1179 /* Check existence */
1180 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1181 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1182 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1184 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1187 /* Create bin element */
1188 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1190 /* Create child element */
1191 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1192 GstCaps *caps_from_pad = NULL;
1193 char *caps_str = NULL;
1195 /* create appsrc and capsfilter */
1196 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1198 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1200 /* set appsrc as live source */
1201 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1202 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1203 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1205 /* set capsfilter */
1206 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1207 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1208 MMCAM_LOG_INFO("get pad from videosrc_filter");
1209 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1211 MMCAM_LOG_INFO("get pad from videosrc_que");
1212 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1215 MMCAM_LOG_ERROR("get videosrc_que src pad failed");
1216 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1217 goto pipeline_creation_error;
1220 caps_from_pad = gst_pad_get_allowed_caps(pad);
1221 video_caps = gst_caps_copy(caps_from_pad);
1222 gst_caps_unref(caps_from_pad);
1223 caps_from_pad = NULL;
1224 gst_object_unref(pad);
1228 video_caps = gst_caps_fixate(video_caps);
1231 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1235 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1236 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1237 goto pipeline_creation_error;
1240 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1241 if (sc->info_video->use_videoscale) {
1242 gst_caps_set_simple(video_caps,
1243 "width", G_TYPE_INT, sc->info_video->preview_width,
1244 "height", G_TYPE_INT, sc->info_video->preview_height,
1246 videoscale_caps = gst_caps_copy(video_caps);
1248 gst_caps_set_simple(video_caps,
1249 "width", G_TYPE_INT, sc->info_video->video_width,
1250 "height", G_TYPE_INT, sc->info_video->video_height,
1255 caps_str = gst_caps_to_string(video_caps);
1257 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1262 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1264 gst_caps_unref(video_caps);
1268 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1269 sc->info_video->use_videoscale) {
1270 if (!videoscale_caps) {
1271 MMCAM_LOG_ERROR("no videoscale caps");
1272 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1273 goto pipeline_creation_error;
1276 gst_caps_set_simple(videoscale_caps,
1277 "width", G_TYPE_INT, sc->info_video->video_width,
1278 "height", G_TYPE_INT, sc->info_video->video_height,
1281 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1282 CONFIGURE_CATEGORY_MAIN_RECORD,
1283 "VideoscaleElement",
1284 &VideoscaleElement);
1286 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1287 MMCAM_LOG_ERROR("failed to get videoscale element name");
1288 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1289 goto pipeline_creation_error;
1292 caps_str = gst_caps_to_string(videoscale_caps);
1294 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1299 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
1300 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
1302 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
1304 gst_caps_unref(videoscale_caps);
1305 videoscale_caps = NULL;
1308 /* release element_list, they will be placed out of encodesink bin */
1310 g_list_free(element_list);
1311 element_list = NULL;
1314 /* connect signal for ready to push buffer */
1315 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1316 _MMCAMCORDER_HANDLER_VIDEOREC,
1318 _mmcamcorder_ready_to_encode_callback,
1322 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1323 "tizenencodebin", "encodesink_encbin", element_list, err);
1325 /* check element availability */
1326 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1327 err = mm_camcorder_get_attributes(handle, &err_name,
1328 MMCAM_CAPTURE_FORMAT, &cap_format,
1331 err = mm_camcorder_get_attributes(handle, &err_name,
1332 MMCAM_AUDIO_ENCODER, &audio_enc,
1333 MMCAM_AUDIO_CHANNEL, &channel,
1334 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1335 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1339 if (err != MM_ERROR_NONE) {
1341 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1342 SAFE_FREE(err_name);
1344 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1347 goto pipeline_creation_error;
1350 MMCAM_LOG_INFO("Profile[%d]", profile);
1352 /* Set information */
1353 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1354 str_profile = "VideoProfile";
1355 str_aac = "VideoAutoAudioConvert";
1356 str_aar = "VideoAutoAudioResample";
1357 str_acs = "VideoAutoColorSpace";
1358 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1359 str_profile = "AudioProfile";
1360 str_aac = "AudioAutoAudioConvert";
1361 str_aar = "AudioAutoAudioResample";
1362 str_acs = "AudioAutoColorSpace";
1363 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1364 str_profile = "ImageProfile";
1365 str_aac = "ImageAutoAudioConvert";
1366 str_aar = "ImageAutoAudioResample";
1367 str_acs = "ImageAutoColorSpace";
1370 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1371 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1372 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1373 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1375 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1376 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1378 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1379 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1380 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1381 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1382 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1384 /* get video convert element name */
1385 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1388 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1389 int use_venc_queue = 0;
1391 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1393 if (!VideoencElement) {
1394 MMCAM_LOG_ERROR("Fail to get type element");
1395 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1396 goto pipeline_creation_error;
1399 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1400 /* set parse element */
1401 gst_element_venc_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
1402 if (!gst_element_venc_name)
1403 gst_element_venc_name = "identity";
1405 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1408 if (gst_element_venc_name) {
1409 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1411 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1412 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1414 MMCAM_LOG_ERROR("Fail to get video encoder name");
1415 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1416 goto pipeline_creation_error;
1419 /* set color space converting element */
1420 if (auto_color_space) {
1421 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1423 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1424 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1426 /* set colorspace plugin property setting */
1427 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1429 /* fourcc type was removed in GST 1.0 */
1430 if (hcamcorder->use_zero_copy_format) {
1431 if (strstr(gst_element_venc_name, "omx")) {
1432 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1435 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1436 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1438 gst_caps_unref(video_caps);
1441 MMCAM_LOG_WARNING("failed to create caps");
1444 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1449 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1450 CONFIGURE_CATEGORY_MAIN_RECORD,
1451 "UseVideoEncoderQueue",
1454 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1457 if (sc->audio_disable == FALSE &&
1458 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1459 int use_aenc_queue = 0;
1461 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1462 if (!AudioencElement) {
1463 MMCAM_LOG_ERROR("Fail to get type element");
1464 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1465 goto pipeline_creation_error;
1468 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1470 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1471 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1473 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1474 audio_caps = gst_caps_new_simple("audio/x-raw",
1475 "channels", G_TYPE_INT, 1,
1477 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1478 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1479 gst_caps_unref(audio_caps);
1483 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1484 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
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);
1489 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1492 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1493 CONFIGURE_CATEGORY_MAIN_RECORD,
1494 "UseAudioEncoderQueue",
1496 if (use_aenc_queue) {
1497 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1498 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1499 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1503 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1504 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1505 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1506 if (!ImageencElement) {
1507 MMCAM_LOG_ERROR("Fail to get type element");
1508 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1509 goto pipeline_creation_error;
1512 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1514 /* raw format - set dummy element */
1515 gst_element_ienc_name = "identity";
1518 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1519 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1523 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1524 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1526 MMCAM_LOG_ERROR("Fail to get type element");
1527 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1528 goto pipeline_creation_error;
1531 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1533 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1534 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1536 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1540 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1542 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1543 CONFIGURE_CATEGORY_MAIN_RECORD,
1544 "RecordsinkElement",
1545 &RecordsinkElement);
1546 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1548 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1550 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1553 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1556 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1557 /* property setting in ini */
1558 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1560 /* bitrate setting */
1561 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1562 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1565 if (sc->audio_disable == FALSE &&
1566 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1567 /* property setting in ini */
1568 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1570 /* bitrate setting */
1571 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1572 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1575 MMCAM_LOG_INFO("Element creation complete");
1577 /* Add element to bin */
1578 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1579 MMCAM_LOG_ERROR("element add error.");
1580 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1581 goto pipeline_creation_error;
1584 MMCAM_LOG_INFO("Element add complete");
1586 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1587 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1588 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1589 gst_object_unref(pad);
1591 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1592 err = MM_ERROR_CAMCORDER_GST_LINK;
1593 goto pipeline_creation_error;
1595 gst_object_unref(pad);
1598 if (sc->audio_disable == FALSE) {
1599 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1600 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1601 gst_object_unref(pad);
1603 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1604 err = MM_ERROR_CAMCORDER_GST_LINK;
1605 goto pipeline_creation_error;
1607 gst_object_unref(pad);
1610 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1611 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1612 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1613 gst_object_unref(pad);
1615 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1616 err = MM_ERROR_CAMCORDER_GST_LINK;
1617 goto pipeline_creation_error;
1619 gst_object_unref(pad);
1623 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1624 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1625 gst_object_unref(pad);
1627 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1628 err = MM_ERROR_CAMCORDER_GST_LINK;
1629 goto pipeline_creation_error;
1631 gst_object_unref(pad);
1635 MMCAM_LOG_INFO("Get pad complete");
1637 /* Link internal element */
1638 if (!_mmcamcorder_link_elements(element_list)) {
1639 MMCAM_LOG_ERROR("element link error.");
1640 err = MM_ERROR_CAMCORDER_GST_LINK;
1641 goto pipeline_creation_error;
1645 g_list_free(element_list);
1647 MMCAM_LOG_INFO("done");
1649 return MM_ERROR_NONE;
1651 pipeline_creation_error:
1652 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1654 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1655 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1656 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1657 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1658 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
1659 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1660 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1661 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1662 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1663 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1664 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1667 g_list_free(element_list);
1669 if (videoscale_caps)
1670 gst_caps_unref(videoscale_caps);
1676 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1678 int err = MM_ERROR_NONE;
1680 GstPad *srcpad = NULL;
1683 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1684 _MMCamcorderSubContext *sc = NULL;
1686 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1688 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1689 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1690 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1694 /** Create gstreamer element **/
1696 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1699 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1700 if (err != MM_ERROR_NONE)
1701 goto pipeline_creation_error;
1703 /* Set data probe function */
1704 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1705 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1706 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1708 MMCAM_LOG_ERROR("there is no queue plugin");
1709 goto pipeline_creation_error;
1713 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1714 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1716 gst_object_unref(srcpad);
1719 MMCAM_LOG_ERROR("failed to get srcpad");
1720 goto pipeline_creation_error;
1723 /* set dataprobe for video recording if it does not support dual stream. */
1724 if (sc->info_video->record_dual_stream == FALSE) {
1725 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1726 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1728 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1730 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1731 __mmcamcorder_video_dataprobe_record, hcamcorder);
1732 gst_object_unref(srcpad);
1736 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1738 /* set sync handler */
1739 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1741 gst_object_unref(bus);
1745 err = _mmcamcorder_initialize_capture_mode(handle);
1746 if (err != MM_ERROR_NONE) {
1747 MMCAM_LOG_ERROR("initialize capture mode[%d] failed", hcamcorder->capture_mode);
1748 goto pipeline_creation_error;
1751 /* extra preview mode */
1752 err = _mmcamcorder_initialize_extra_preview_mode(handle);
1753 if (err != MM_ERROR_NONE) {
1754 MMCAM_LOG_ERROR("initialize extra preview mode[%d] failed", hcamcorder->extra_preview.mode);
1755 goto pipeline_creation_error;
1758 return MM_ERROR_NONE;
1760 pipeline_creation_error:
1761 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1766 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1768 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1769 _MMCamcorderSubContext *sc = NULL;
1771 /*MMCAM_LOG_INFO("start");*/
1773 mmf_return_if_fail(hcamcorder);
1774 mmf_return_if_fail(hcamcorder->sub_context);
1775 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1778 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1779 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1780 __mmcamcorder_request_codec_config(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1781 MMCAM_LOG_WARNING("start to push buffer to encoding pipeline");
1786 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1788 int err = MM_ERROR_NONE;
1793 int rect_height = 0;
1795 int rotation = MM_DISPLAY_ROTATION_NONE;
1796 int flip = MM_FLIP_NONE;
1797 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1798 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1799 int origin_size = 0;
1802 int do_scaling = FALSE;
1803 int *dp_handle = NULL;
1804 MMCamWindowInfo *window_info = NULL;
1806 char *err_name = NULL;
1807 const char *videosink_name = NULL;
1809 GstElement *vsink = NULL;
1811 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1812 _MMCamcorderSubContext *sc = NULL;
1816 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1818 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1819 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1820 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1821 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1823 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1825 /* Get video display information */
1826 err = mm_camcorder_get_attributes(handle, &err_name,
1827 MMCAM_DISPLAY_RECT_X, &rect_x,
1828 MMCAM_DISPLAY_RECT_Y, &rect_y,
1829 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1830 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1831 MMCAM_DISPLAY_ROTATION, &rotation,
1832 MMCAM_DISPLAY_FLIP, &flip,
1833 MMCAM_DISPLAY_VISIBLE, &visible,
1834 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1835 MMCAM_DISPLAY_MODE, &display_mode,
1836 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1837 MMCAM_DISPLAY_SCALE, &zoom_attr,
1838 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1840 if (err != MM_ERROR_NONE) {
1842 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1843 SAFE_FREE(err_name);
1845 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1851 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1853 if (!videosink_name) {
1854 MMCAM_LOG_ERROR("failed to get videosink name");
1855 return MM_ERROR_CAMCORDER_INTERNAL;
1858 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
1860 /* Set display handle */
1861 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1864 MMCAM_LOG_INFO("xid = %lu )", xid);
1865 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1867 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1868 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1870 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1871 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
1874 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1875 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1877 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
1878 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1880 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1882 window_info = (MMCamWindowInfo *)dp_handle;
1883 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
1884 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1886 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
1888 } else if (!strcmp(videosink_name, "directvideosink")) {
1889 #ifdef _MMCAMCORDER_RM_SUPPORT
1890 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1891 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
1892 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1893 #endif /* _MMCAMCORDER_RM_SUPPORT */
1895 window_info = (MMCamWindowInfo *)dp_handle;
1896 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1897 window_info->surface_id,
1898 window_info->rect.x,
1899 window_info->rect.y,
1900 window_info->rect.width,
1901 window_info->rect.height);
1902 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1903 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1904 window_info->rect.x,
1905 window_info->rect.y,
1906 window_info->rect.width,
1907 window_info->rect.height);
1909 MMCAM_LOG_WARNING("dp_handle is null");
1912 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
1915 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1916 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1919 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1920 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1922 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1925 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1927 switch (zoom_attr) {
1928 case MM_DISPLAY_SCALE_DEFAULT:
1931 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1934 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1938 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
1943 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1944 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1945 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1946 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1948 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1949 if (!strcmp(videosink_name, "tizenwlsink")) {
1950 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1951 rect_x, rect_y, rect_width, rect_height);
1954 "dst-roi-x", rect_x,
1955 "dst-roi-y", rect_y,
1956 "dst-roi-w", rect_width,
1957 "dst-roi-h", rect_height,
1963 return MM_ERROR_NONE;
1967 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1970 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1971 _MMCamcorderSubContext *sc = NULL;
1973 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1975 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1977 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1980 case _MMCamcorder_CMD_PREVIEW_START:
1981 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1983 case _MMCamcorder_CMD_CAPTURE:
1984 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
1987 MMCAM_LOG_WARNING("unknown command : %d", cmd);
1988 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1991 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1992 category, "FrameStabilityCount", &sc->frame_stability_count);
1994 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
1995 cmd, sc->frame_stability_count);
1997 return MM_ERROR_NONE;
2000 /* Retreive device information and set them to attributes */
2001 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
2003 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2004 _MMCamcorderSubContext *sc = NULL;
2005 GstCameraControl *control = NULL;
2006 GstCameraControlExifInfo exif_info = {0,};
2008 mmf_return_val_if_fail(hcamcorder, FALSE);
2009 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2011 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
2013 if (sc && sc->element) {
2014 int err = MM_ERROR_NONE;
2015 char *err_name = NULL;
2016 double focal_len = 0.0;
2018 /* Video input device */
2019 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2020 /* Exif related information */
2021 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2022 if (control != NULL) {
2023 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
2024 if (exif_info.focal_len_denominator != 0)
2025 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
2027 MMCAM_LOG_ERROR("Fail to get camera control interface!");
2032 /* Set values to attributes */
2033 err = mm_camcorder_set_attributes(handle, &err_name,
2034 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
2036 if (err != MM_ERROR_NONE) {
2037 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
2038 SAFE_FREE(err_name);
2042 MMCAM_LOG_WARNING("Sub context isn't exist.");
2049 static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure)
2051 const gchar *format_string = NULL;
2054 MMCAM_LOG_WARNING("NULL structure");
2055 return GST_MAKE_FOURCC('N', 'U', 'L', 'L');
2058 if (gst_structure_has_name(structure, "video/x-h264"))
2059 return GST_MAKE_FOURCC('H', '2', '6', '4');
2061 if (gst_structure_has_name(structure, "video/x-h265"))
2062 return GST_MAKE_FOURCC('H', '2', '6', '5');
2064 if (gst_structure_has_name(structure, "video/x-vp8"))
2065 return GST_MAKE_FOURCC('V', 'P', '8', '0');
2067 if (gst_structure_has_name(structure, "video/x-vp9"))
2068 return GST_MAKE_FOURCC('V', 'P', '9', '0');
2070 if (gst_structure_has_name(structure, "video/x-jpeg") ||
2071 gst_structure_has_name(structure, "image/jpeg"))
2072 return GST_MAKE_FOURCC('M', 'J', 'P', 'G');
2074 format_string = gst_structure_get_string(structure, "format");
2077 return GST_STR_FOURCC(format_string);
2079 return GST_MAKE_FOURCC('N', 'O', 'N', 'E');
2082 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2084 gboolean ret = TRUE;
2085 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2086 _MMCamcorderSubContext *sc = NULL;
2087 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2088 GstSample *sample = NULL;
2089 GstCaps *caps = NULL;
2091 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
2092 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
2093 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
2095 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
2096 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
2098 if (sc->drop_vframe > 0) {
2099 if (sc->pass_first_vframe > 0) {
2100 sc->pass_first_vframe--;
2101 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2104 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2105 return GST_PAD_PROBE_DROP;
2107 } else if (sc->frame_stability_count > 0) {
2108 sc->frame_stability_count--;
2109 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2110 return GST_PAD_PROBE_DROP;
2113 if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
2114 _mmcamcorder_measure_fps(&sc->kpi);
2116 /* The first H.264 frame should not be skipped for vstream cb. */
2117 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2118 !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2119 MMCAM_LOG_WARNING("Not ready for stream callback");
2120 return GST_PAD_PROBE_OK;
2123 /* make sample with buffer and caps */
2124 caps = gst_pad_get_allowed_caps(pad);
2125 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2127 sample = gst_sample_new(buffer, caps, NULL, NULL);
2128 gst_caps_unref(caps);
2129 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2131 ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
2133 gst_sample_unref(sample);
2136 return GST_PAD_PROBE_OK;
2138 return GST_PAD_PROBE_DROP;
2142 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2144 gboolean ret = TRUE;
2145 GstSample *sample = NULL;
2146 GstCaps *caps = NULL;
2148 caps = gst_pad_get_allowed_caps(pad);
2149 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2151 sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
2152 gst_caps_unref(caps);
2153 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2155 ret = _mmcamcorder_video_push_buffer(u_data, sample);
2157 gst_sample_unref(sample);
2159 return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
2163 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2165 MMCamcorderMuxedStreamDataType stream;
2166 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2167 _MMCamcorderSubContext *sc = NULL;
2168 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2171 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2172 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2173 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2175 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2176 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2178 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2179 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2180 return GST_PAD_PROBE_OK;
2183 /* call application callback */
2184 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2186 if (hcamcorder->mstream_cb) {
2187 stream.data = (void *)mapinfo.data;
2188 stream.length = mapinfo.size;
2189 stream.offset = sc->muxed_stream_offset;
2190 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2193 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2195 /* calculate current offset */
2196 sc->muxed_stream_offset += mapinfo.size;
2198 gst_buffer_unmap(buffer, &mapinfo);
2200 return GST_PAD_PROBE_OK;
2204 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2206 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2207 mmf_camcorder_t *hcamcorder = NULL;
2208 _MMCamcorderSubContext *sc = NULL;
2209 GstObject *parent = NULL;
2211 switch (GST_EVENT_TYPE(event)) {
2212 case GST_EVENT_UNKNOWN:
2213 /* upstream events */
2215 case GST_EVENT_SEEK:
2216 case GST_EVENT_NAVIGATION:
2217 case GST_EVENT_LATENCY:
2218 /* downstream serialized events */
2219 case GST_EVENT_BUFFERSIZE:
2220 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2224 GstTagList *tag_list = NULL;
2225 _MMCamcorderReplayGain *replay_gain = NULL;
2227 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2229 hcamcorder = MMF_CAMCORDER(u_data);
2230 if (!hcamcorder || !hcamcorder->sub_context) {
2231 MMCAM_LOG_WARNING("NULL handle");
2235 replay_gain = &hcamcorder->sub_context->replay_gain;
2237 gst_event_parse_tag(event, &tag_list);
2239 MMCAM_LOG_WARNING("failed to get tag list");
2243 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2244 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2248 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2249 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2253 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2254 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2258 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2259 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2263 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2264 replay_gain->track_peak, replay_gain->track_gain,
2265 replay_gain->album_peak, replay_gain->album_gain);
2268 case GST_EVENT_SEGMENT:
2269 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2271 hcamcorder = MMF_CAMCORDER(u_data);
2273 MMCAM_LOG_WARNING("NULL handle");
2277 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2279 MMCAM_LOG_WARNING("NULL sub context");
2283 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2284 MMCAM_LOG_WARNING("no encoder sink");
2288 parent = gst_pad_get_parent(pad);
2290 MMCAM_LOG_WARNING("get parent failed");
2294 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2295 const GstSegment *segment;
2296 gst_event_parse_segment(event, &segment);
2297 if (segment->format == GST_FORMAT_BYTES) {
2298 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2299 sc->muxed_stream_offset, segment->start);
2301 sc->muxed_stream_offset = (unsigned long long)segment->start;
2305 gst_object_unref(parent);
2309 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2311 /* bidirectional events */
2312 case GST_EVENT_FLUSH_START:
2313 case GST_EVENT_FLUSH_STOP:
2314 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2317 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2321 return GST_PAD_PROBE_OK;
2325 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2327 int result = MM_CAMCORDER_MR475;
2330 result = MM_CAMCORDER_MR475; /*AMR475*/
2331 else if (bitrate < 5900)
2332 result = MM_CAMCORDER_MR515; /*AMR515*/
2333 else if (bitrate < 6700)
2334 result = MM_CAMCORDER_MR59; /*AMR59*/
2335 else if (bitrate < 7400)
2336 result = MM_CAMCORDER_MR67; /*AMR67*/
2337 else if (bitrate < 7950)
2338 result = MM_CAMCORDER_MR74; /*AMR74*/
2339 else if (bitrate < 10200)
2340 result = MM_CAMCORDER_MR795; /*AMR795*/
2341 else if (bitrate < 12200)
2342 result = MM_CAMCORDER_MR102; /*AMR102*/
2344 result = MM_CAMCORDER_MR122; /*AMR122*/
2350 int _mmcamcorder_get_eos_message(MMHandleType handle)
2353 int ret = MM_ERROR_NONE;
2355 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2356 _MMCamcorderSubContext *sc = NULL;
2358 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2359 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2360 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2362 MMCAM_LOG_INFO("START");
2364 _MMCAMCORDER_LOCK(handle);
2366 if (sc->bget_eos == FALSE) {
2367 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2368 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2369 MMCAM_LOG_INFO("EOS signal received");
2371 MMCAM_LOG_ERROR("EOS wait time out");
2373 if (hcamcorder->error_code == MM_ERROR_NONE)
2374 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2377 MMCAM_LOG_INFO("already got EOS");
2380 _MMCAMCORDER_UNLOCK(handle);
2382 if (hcamcorder->error_code == MM_ERROR_NONE) {
2383 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2384 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2385 if (sc->info_video->b_committing)
2386 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2388 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2389 if (sc->info_audio->b_committing)
2390 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2393 ret = hcamcorder->error_code;
2394 MMCAM_LOG_ERROR("error 0x%x", ret);
2397 MMCAM_LOG_INFO("END");
2403 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2406 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2408 mmf_return_if_fail(handle && remove_element);
2409 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2413 for (i = first_elem ; i <= last_elem ; i++) {
2414 remove_element[i].gst = NULL;
2415 remove_element[i].id = _MMCAMCORDER_NONE;
2422 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2424 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2426 /* Check compatibility between codec and file format */
2427 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2428 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2429 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2430 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2431 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2432 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2435 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2437 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2438 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2440 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2441 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2442 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2443 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2444 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2445 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2448 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2450 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2451 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2455 return MM_ERROR_NONE;
2459 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2461 int err = MM_ERROR_NONE;
2462 int audio_codec = MM_AUDIO_CODEC_INVALID;
2463 int file_format = MM_FILE_FORMAT_INVALID;
2465 char *err_name = NULL;
2467 err = mm_camcorder_get_attributes(handle, &err_name,
2468 MMCAM_AUDIO_ENCODER, &audio_codec,
2469 MMCAM_FILE_FORMAT, &file_format,
2471 if (err != MM_ERROR_NONE) {
2472 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2473 SAFE_FREE(err_name);
2477 /* Check compatibility between audio codec and file format */
2478 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2484 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2486 int err = MM_ERROR_NONE;
2487 int video_codec = MM_VIDEO_CODEC_INVALID;
2488 int file_format = MM_FILE_FORMAT_INVALID;
2490 char *err_name = NULL;
2492 err = mm_camcorder_get_attributes(handle, &err_name,
2493 MMCAM_VIDEO_ENCODER, &video_codec,
2494 MMCAM_FILE_FORMAT, &file_format,
2496 if (err != MM_ERROR_NONE) {
2497 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2498 SAFE_FREE(err_name);
2502 /* Check compatibility between video codec and file format */
2503 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2509 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2511 const char* videosink_name = NULL;
2513 mmf_camcorder_t *hcamcorder = NULL;
2514 _MMCamcorderSubContext *sc = NULL;
2516 hcamcorder = MMF_CAMCORDER(handle);
2517 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2519 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2520 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2521 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2523 if (sc->element[videosink_index].gst) {
2524 /* Get videosink name */
2525 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2526 if (videosink_name == NULL) {
2527 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2531 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2532 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2533 !strcmp(videosink_name, "directvideosink")) {
2534 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2535 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2537 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2542 MMCAM_LOG_ERROR("Videosink element is null");
2548 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2550 const char* videosink_name = NULL;
2552 mmf_camcorder_t *hcamcorder = NULL;
2553 _MMCamcorderSubContext *sc = NULL;
2555 hcamcorder = MMF_CAMCORDER(handle);
2556 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2558 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2559 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2560 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2562 if (sc->element[videosink_index].gst) {
2563 /* Get videosink name */
2564 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2565 if (videosink_name == NULL) {
2566 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2570 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2571 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2572 !strcmp(videosink_name, "directvideosink")) {
2573 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2574 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2576 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2581 MMCAM_LOG_ERROR("Videosink element is null");
2587 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2590 _MMCamcorderSubContext *sc = NULL;
2592 mmf_camcorder_t *hcamcorder = NULL;
2594 hcamcorder = MMF_CAMCORDER(handle);
2595 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2597 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2599 MMCAM_LOG_INFO("sub context is not initialized");
2603 mm_camcorder_get_attributes(handle, NULL,
2604 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2605 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2606 MMCAM_CAMERA_FPS, &fps,
2609 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2611 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2612 sc->info_video->preview_width, sc->info_video->preview_height,
2613 fps, videosrc_rotate);
2617 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2623 unsigned int caps_fourcc = 0;
2624 gboolean do_set_caps = FALSE;
2625 GstCaps *caps = NULL;
2627 mmf_camcorder_t *hcamcorder = NULL;
2628 _MMCamcorderSubContext *sc = NULL;
2630 hcamcorder = MMF_CAMCORDER(handle);
2631 mmf_return_val_if_fail(hcamcorder, FALSE);
2633 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2635 if (!sc || !(sc->element)) {
2636 MMCAM_LOG_INFO("sub context is not initialized");
2640 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2641 MMCAM_LOG_ERROR("Video src is NULL!");
2645 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2646 MMCAM_LOG_ERROR("Video filter is NULL!");
2650 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2651 int capture_width = 0;
2652 int capture_height = 0;
2653 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2655 mm_camcorder_get_attributes(handle, NULL,
2656 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2657 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2658 MMCAM_CAPTURE_WIDTH, &capture_width,
2659 MMCAM_CAPTURE_HEIGHT, &capture_height,
2660 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2661 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2663 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2664 motion_rate, capture_width, capture_height, fps_auto,
2665 sc->info_video->video_width, sc->info_video->video_height);
2667 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2668 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2670 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2671 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2672 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2675 sc->info_video->fps = fps;
2678 /* Interleaved format does not support rotation */
2679 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2680 /* store videosrc rotation */
2681 sc->videosrc_rotate = rotate;
2683 /* Define width, height and rotate in caps */
2685 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2686 This will be applied when rotate is 0, 180 if front camera. */
2687 set_rotate = rotate * 90;
2689 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2690 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2693 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2694 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2701 set_height = height;
2704 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2707 set_height = height;
2709 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2712 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2713 if (caps && !gst_caps_is_any(caps)) {
2714 GstStructure *structure = NULL;
2716 structure = gst_caps_get_structure(caps, 0);
2719 int caps_height = 0;
2722 int caps_rotate = 0;
2724 caps_fourcc = _mmcamcorder_get_structure_fourcc(structure);
2726 gst_structure_get(structure,
2727 "width", G_TYPE_INT, &caps_width,
2728 "height", G_TYPE_INT, &caps_height,
2729 "framerate", GST_TYPE_FRACTION, &caps_fps_n, &caps_fps_d,
2730 "rotate", G_TYPE_INT, &caps_rotate,
2733 #ifdef _MMCAMCORDER_PRODUCT_TV
2734 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2735 if (set_width == caps_width && set_height == caps_height &&
2736 set_rotate == caps_rotate && fps == caps_fps_n) {
2737 MMCAM_LOG_INFO("No need to replace caps.");
2739 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]",
2740 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2741 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2742 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2743 set_width, set_height, fps, set_rotate);
2747 if (set_width == caps_width && set_height == caps_height &&
2748 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2749 MMCAM_LOG_INFO("No need to replace caps.");
2751 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]",
2752 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2753 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2754 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2755 set_width, set_height, fps, set_rotate);
2759 #else /*_MMCAMCORDER_PRODUCT_TV */
2760 if (set_width == caps_width && set_height == caps_height &&
2761 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2762 MMCAM_LOG_INFO("No need to replace caps.");
2764 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]",
2765 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2766 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2767 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2768 set_width, set_height, fps, set_rotate);
2771 #endif /*_MMCAMCORDER_PRODUCT_TV */
2773 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2777 MMCAM_LOG_INFO("No caps. set new one...");
2782 gst_caps_unref(caps);
2786 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2787 /* assume that it's camera capture mode */
2788 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2794 caps = _mmcamcorder_get_video_caps(handle,
2795 sc->info_image->preview_format, set_width, set_height, fps, set_rotate);
2797 MMCAM_LOG_ERROR("There are no caps");
2801 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2802 gst_caps_unref(caps);
2808 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2810 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2811 _MMCamcorderSubContext *sc = NULL;
2813 mmf_return_val_if_fail(hcamcorder, FALSE);
2815 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2819 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
2821 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2825 /* Interleaved format does not support FLIP */
2826 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2827 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2828 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2830 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
2832 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2833 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2835 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
2839 MMCAM_LOG_WARNING("element is NULL");
2847 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2849 GstCameraControl *control = NULL;
2850 _MMCamcorderSubContext *sc = NULL;
2851 GstElement *v_src = NULL;
2855 mmf_return_val_if_fail(handle, FALSE);
2857 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2861 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2864 MMCAM_LOG_WARNING("videosrc element is NULL");
2868 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2870 /* set anti-shake with camera control */
2871 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2872 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
2876 control = GST_CAMERA_CONTROL(v_src);
2877 if (gst_camera_control_set_ahs(control, set_value)) {
2878 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
2881 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
2888 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2890 _MMCamcorderSubContext *sc = NULL;
2891 GstElement *v_src = NULL;
2893 mmf_return_val_if_fail(handle, FALSE);
2895 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2899 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2901 MMCAM_LOG_WARNING("videosrc element is NULL");
2905 /* check property of videosrc element - support VDIS */
2906 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2907 int video_width = 0;
2908 int video_height = 0;
2910 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2911 MMCAM_LOG_INFO("ENABLE video stabilization");
2913 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2914 mm_camcorder_get_attributes(handle, NULL,
2915 MMCAM_VIDEO_WIDTH, &video_width,
2916 MMCAM_VIDEO_HEIGHT, &video_height,
2919 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2920 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
2921 video_width, video_height);
2923 g_object_set(G_OBJECT(v_src),
2924 "enable-vdis-mode", TRUE,
2927 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
2928 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2929 video_width, video_height);
2934 g_object_set(G_OBJECT(v_src),
2935 "enable-vdis-mode", FALSE,
2938 MMCAM_LOG_INFO("DISABLE video stabilization");
2940 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2941 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
2944 MMCAM_LOG_WARNING("no property for video stabilization");
2951 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2955 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2956 _MMCamcorderSubContext *sc = NULL;
2958 mmf_return_val_if_fail(hcamcorder, FALSE);
2960 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2964 mm_camcorder_get_attributes(handle, NULL,
2965 MMCAM_CAMERA_FPS, &fps,
2968 MMCAM_LOG_INFO("set %dx%d", width, height);
2970 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2974 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2976 _MMCamcorderSubContext *sc = NULL;
2978 if ((void *)handle == NULL) {
2979 MMCAM_LOG_WARNING("handle is NULL");
2983 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2985 MMCAM_LOG_WARNING("subcontext is NULL");
2989 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
2990 MMCAM_LOG_WARNING("videosrc plugin is NULL");
2994 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
2996 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
3002 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
3004 _MMCamcorderSubContext *sc = NULL;
3006 if ((void *)handle == NULL) {
3007 MMCAM_LOG_WARNING("handle is NULL");
3011 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3013 MMCAM_LOG_WARNING("subcontext is NULL");
3017 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3018 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3022 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
3024 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3030 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3032 GstStructure *props = NULL;
3033 char stream_props[64] = {'\0',};
3035 if (element == NULL || stream_type == NULL || stream_index < 0) {
3036 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3040 snprintf(stream_props, sizeof(stream_props) - 1,
3041 "props,media.role=%s, media.parent_id=%d",
3042 stream_type, stream_index);
3044 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3046 props = gst_structure_from_string(stream_props, NULL);
3048 MMCAM_LOG_ERROR("failed to create GstStructure");
3052 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3054 gst_structure_free(props);
3061 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3063 int ret = MM_ERROR_NONE;
3064 _MMCamcorderSubContext *sc = NULL;
3065 mmf_camcorder_t *hcamcorder = NULL;
3066 const char *videodecoder_name = NULL;
3067 char videodecoder_name_final[32] = {'\0',};
3068 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3069 #ifdef _MMCAMCORDER_RM_SUPPORT
3070 int decoder_index = 0;
3071 #endif /* _MMCAMCORDER_RM_SUPPORT */
3073 if ((void *)handle == NULL) {
3074 MMCAM_LOG_WARNING("handle is NULL");
3078 hcamcorder = MMF_CAMCORDER(handle);
3080 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3082 MMCAM_LOG_WARNING("subcontext is NULL");
3086 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3087 hcamcorder->recreate_decoder == FALSE) {
3088 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3089 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3093 mm_camcorder_get_attributes(handle, NULL,
3094 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3097 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3098 MMCAM_LOG_INFO("no need to control decoder element");
3102 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3103 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3104 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3108 MMCAM_LOG_INFO("start");
3110 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
3111 if (videodecoder_name == NULL) {
3112 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
3116 /* set state as NULL */
3117 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3118 if (ret != MM_ERROR_NONE) {
3119 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3123 /* remove decoder - pads will be unlinked automatically in remove function */
3124 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3125 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3126 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3130 /* check decoder element */
3131 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3132 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3133 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3134 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3137 #ifdef _MMCAMCORDER_RM_SUPPORT
3138 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3139 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3142 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
3143 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
3145 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3146 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
3148 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
3150 #endif /* _MMCAMCORDER_RM_SUPPORT */
3151 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
3152 #ifdef _MMCAMCORDER_RM_SUPPORT
3154 #endif /* _MMCAMCORDER_RM_SUPPORT */
3156 /* create decoder */
3157 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "videosrc_decode");
3158 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3159 MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
3163 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
3165 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3166 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3167 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3169 /* add to pipeline */
3170 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3171 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3172 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3173 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3178 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3179 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3180 MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
3182 MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
3186 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3187 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3188 MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
3190 MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
3194 /* set state READY */
3195 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3196 if (ret != MM_ERROR_NONE) {
3197 MMCAM_LOG_ERROR("failed to set READY to decoder");
3201 MMCAM_LOG_INFO("done");
3206 #ifdef _MMCAMCORDER_PRODUCT_TV
3207 bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3209 _MMCamcorderSubContext *sc = NULL;
3210 mmf_camcorder_t *hcamcorder = NULL;
3212 const gchar *mime = NULL;
3214 GstCaps *decsink_caps = NULL;
3215 GstStructure *decsink_struct = NULL;
3217 mmf_return_val_if_fail(handle, false);
3218 mmf_return_val_if_fail(max_width, false);
3219 mmf_return_val_if_fail(max_height, false);
3221 hcamcorder = MMF_CAMCORDER(handle);
3222 mmf_return_val_if_fail(hcamcorder, false);
3224 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3226 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3228 MMCAM_LOG_ERROR("There are no decoder caps");
3232 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3233 if (!decsink_caps) {
3234 gst_object_unref(sinkpad);
3235 MMCAM_LOG_ERROR("There is no decoder sink caps");
3239 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3240 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3241 if (!decsink_struct) {
3242 MMCAM_LOG_ERROR("There are no structure from caps");
3243 gst_object_unref(decsink_caps);
3244 gst_object_unref(sinkpad);
3247 mime = gst_structure_get_name(decsink_struct);
3248 if (!strcmp(mime, "video/x-h264")) {
3249 MMCAM_LOG_INFO("h264 caps structure found");
3250 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3251 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3252 if (gst_structure_has_field(decsink_struct, "maxheight"))
3253 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3255 } else if (!strcmp(mime, "video/x-jpeg")) {
3256 MMCAM_LOG_INFO("mjpeg caps structure found");
3257 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3258 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3259 if (gst_structure_has_field(decsink_struct, "maxheight"))
3260 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3264 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3265 gst_object_unref(decsink_caps);
3266 gst_object_unref(sinkpad);
3268 if (*max_width <= 0 || *max_height <= 0)
3273 #endif /* _MMCAMCORDER_PRODUCT_TV */