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"
133 #define _MMCAMCORDER_CROP_ARRAY_LENGTH 4
134 #define META_TIMESTAMP_FIELD_LENGTH 7
137 /*-----------------------------------------------------------------------
138 | LOCAL FUNCTION PROTOTYPES: |
139 -----------------------------------------------------------------------*/
140 /* STATIC INTERNAL FUNCTION */
142 * These are video data probing functions.
143 * If there are pads which set probe callback by gst_pad_add_probe(),
144 * the functions will be called when data stream pass through the pad.
146 * @param[in] pad probing pad which calls this function.
147 * @param[in] buffer buffer which contains stream data.
148 * @param[in] u_data user data.
149 * @return Refer #GstPadProbeReturn in gstpad.h
151 * @see __mmcamcorder_create_preview_pipeline()
154 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
155 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview2(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
156 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
158 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
159 static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure);
161 static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
162 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory);
163 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format);
164 static gboolean __mmcamcorder_frame_meta_foreach_func(GQuark field_id, const GValue *value, gpointer user_data);
166 /*=======================================================================================
167 | FUNCTION DEFINITIONS |
168 =======================================================================================*/
169 static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
173 mmf_return_val_if_fail(buffer, FALSE);
174 mmf_return_val_if_fail(stream, FALSE);
175 mmf_return_val_if_fail(map_info, FALSE);
177 stream->length_total = map_info->size;
179 switch (stream->format) {
180 case MM_PIXEL_FORMAT_NV12: /* fall through */
181 case MM_PIXEL_FORMAT_NV21:
182 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
183 stream->data.yuv420sp.y = map_info->data;
184 stream->data.yuv420sp.length_y = stream->width * stream->height;
185 stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
186 stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
187 stream->stride[0] = stream->width;
188 stream->elevation[0] = stream->height;
189 stream->stride[1] = stream->width;
190 stream->elevation[1] = stream->height >> 1;
191 stream->num_planes = 2;
194 case MM_PIXEL_FORMAT_I420:
195 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
196 stream->data.yuv420p.y = map_info->data;
197 stream->data.yuv420p.length_y = stream->width * stream->height;
198 stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
199 stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
200 stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
201 stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
202 stream->stride[0] = stream->width;
203 stream->elevation[0] = stream->height;
204 stream->stride[1] = stream->stride[2] = stream->width >> 1;
205 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
206 stream->num_planes = 3;
209 case MM_PIXEL_FORMAT_422P:
210 stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
211 stream->data.yuv422p.y = map_info->data;
212 stream->data.yuv422p.length_y = stream->width * stream->height;
213 stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
214 stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
215 stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
216 stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
217 stream->stride[0] = stream->width;
218 stream->elevation[0] = stream->height;
219 stream->stride[1] = stream->stride[2] = stream->width;
220 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
221 stream->num_planes = 3;
224 case MM_PIXEL_FORMAT_YUYV: /* fall through */
225 case MM_PIXEL_FORMAT_UYVY: /* fall through */
226 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
227 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
228 stream->data.yuv422.yuv = map_info->data;
229 stream->data.yuv422.length_yuv = stream->length_total;
230 stream->stride[0] = stream->width << 1;
231 stream->elevation[0] = stream->height;
232 stream->num_planes = 1;
235 case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
236 case MM_PIXEL_FORMAT_ENCODED_MJPEG: /* fall through */
237 case MM_PIXEL_FORMAT_ENCODED_VP8: /* fall through */
238 case MM_PIXEL_FORMAT_ENCODED_VP9: /* fall through */
239 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
240 stream->data.encoded.data = map_info->data;
241 stream->data.encoded.length_data = stream->length_total;
242 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
243 stream->data.encoded.is_header_included = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_HEADER);
244 stream->num_planes = 1;
247 case MM_PIXEL_FORMAT_INVZ:
248 stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
249 stream->data.depth.data = map_info->data;
250 stream->data.depth.length_data = stream->length_total;
251 stream->stride[0] = stream->width << 1;
252 stream->elevation[0] = stream->height;
253 stream->num_planes = 1;
256 case MM_PIXEL_FORMAT_RGBA: /* fall through */
257 case MM_PIXEL_FORMAT_ARGB:
258 stream->data_type = MM_CAM_STREAM_DATA_RGB;
259 stream->data.rgb.data = map_info->data;
260 stream->data.rgb.length_data = stream->length_total;
261 stream->stride[0] = stream->width << 2;
262 stream->elevation[0] = stream->height;
263 stream->num_planes = 1;
267 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
276 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory)
280 int tbm_ret = TBM_SURFACE_ERROR_NONE;
281 tbm_bo_handle bo_handle = {NULL, };
282 tbm_surface_info_s ts_info;
284 mmf_return_val_if_fail(stream, FALSE);
285 mmf_return_val_if_fail(buffer, FALSE);
286 mmf_return_val_if_fail(memory, FALSE);
288 if (_mmcamcorder_is_encoded_preview_pixel_format(stream->format)) {
289 stream->bo[0] = gst_tizen_memory_get_bos(memory, 0);
291 bo_handle = tbm_bo_get_handle(stream->bo[0], TBM_DEVICE_CPU);
292 if (!bo_handle.ptr) {
293 MMCAM_LOG_ERROR("tbm_bo_get_handle failed[bo:%p,memory:%p]", stream->bo[0], memory);
297 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
298 stream->num_planes = 1;
299 stream->stride[0] = stream->width;
300 stream->elevation[0] = stream->height;
301 stream->data.encoded.data = bo_handle.ptr;
302 stream->length_total = gst_memory_get_sizes(memory, NULL, NULL);
303 stream->data.encoded.length_data = stream->length_total;
304 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
305 stream->data.encoded.is_header_included = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_HEADER);
307 MMCAM_LOG_VERBOSE("[ENCODED] length[%u], is_delta[%d], is_header_included[%d]",
308 stream->data.encoded.length_data,
309 stream->data.encoded.is_delta_frame,
310 stream->data.encoded.is_header_included);
315 memset(&ts_info, 0x0, sizeof(tbm_surface_info_s));
317 tbm_ret = tbm_surface_get_info((tbm_surface_h)gst_tizen_memory_get_surface(memory), &ts_info);
318 if (tbm_ret != TBM_SURFACE_ERROR_NONE) {
319 MMCAM_LOG_ERROR("get tbm surface info failed[0x%x]", tbm_ret);
323 stream->length_total = ts_info.size;
324 for (i = 0 ; i < ts_info.num_planes ; i++) {
325 stream->stride[i] = ts_info.planes[i].stride;
326 stream->elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
327 MMCAM_LOG_VERBOSE(" plane[%d] %dx%d", i, stream->stride[i], stream->elevation[i]);
330 num_bos = gst_tizen_memory_get_num_bos(memory);
331 for (i = 0 ; i < num_bos ; i++)
332 stream->bo[i] = gst_tizen_memory_get_bos(memory, i);
335 switch (stream->format) {
336 case MM_PIXEL_FORMAT_NV12: /* fall through */
337 case MM_PIXEL_FORMAT_NV21:
338 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
339 stream->num_planes = 2;
340 stream->data.yuv420sp.y = ts_info.planes[0].ptr;
341 stream->data.yuv420sp.length_y = ts_info.planes[0].size;
342 stream->data.yuv420sp.uv = ts_info.planes[1].ptr;
343 stream->data.yuv420sp.length_uv = ts_info.planes[1].size;
345 MMCAM_LOG_VERBOSE("[420SP] 0[%p,%u], 1[%p,%u]",
346 stream->data.yuv420sp.y, stream->data.yuv420sp.length_y,
347 stream->data.yuv420sp.uv, stream->data.yuv420sp.length_uv);
350 case MM_PIXEL_FORMAT_I420:
351 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
352 stream->num_planes = 3;
353 stream->data.yuv420p.y = ts_info.planes[0].ptr;
354 stream->data.yuv420p.length_y = ts_info.planes[0].size;
355 stream->data.yuv420p.u = ts_info.planes[1].ptr;
356 stream->data.yuv420p.length_u = ts_info.planes[1].size;
357 stream->data.yuv420p.v = ts_info.planes[2].ptr;
358 stream->data.yuv420p.length_v = ts_info.planes[2].size;
360 MMCAM_LOG_VERBOSE("[I420] 0[%p,%u], 1[%p,%u], 2[%p,%u]",
361 stream->data.yuv420p.y, stream->data.yuv420p.length_y,
362 stream->data.yuv420p.u, stream->data.yuv420p.length_u,
363 stream->data.yuv420p.v, stream->data.yuv420p.length_v);
366 case MM_PIXEL_FORMAT_YUYV:
367 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
368 stream->num_planes = 1;
369 stream->data.yuv422.yuv = ts_info.planes[0].ptr;
370 stream->data.yuv422.length_yuv = ts_info.planes[0].size;
372 MMCAM_LOG_VERBOSE("[YUYV] 0[%p,%u]",
373 stream->data.yuv422.yuv, stream->data.yuv422.length_yuv);
377 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
385 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format)
388 case MM_PIXEL_FORMAT_ENCODED_H264:
390 case MM_PIXEL_FORMAT_ENCODED_VP9:
393 MMCAM_LOG_WARNING("unsupported format[%d]", format);
399 static gboolean __mmcamcorder_frame_meta_foreach_func(GQuark field_id, const GValue *value, gpointer user_data)
401 MMCamcorderVideoStreamDataType *stream = (MMCamcorderVideoStreamDataType *)user_data;
402 MMCamcorderFrameMeta *frame_meta = NULL;
403 const char *field_name = g_quark_to_string(field_id);
404 guint64 field_value = g_value_get_uint64(value);
406 if (!stream || !field_name) {
407 MMCAM_LOG_WARNING("invalid ptr[%p, %p]", stream, field_name);
411 frame_meta = &stream->frame_meta;
413 if (!strncmp("ts_soe", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
414 frame_meta->ts_soe = field_value;
415 MMCAM_LOG_VERBOSE("[TS] SOE -> %llu", frame_meta->ts_soe);
416 } else if (!strncmp("ts_eoe", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
417 frame_meta->ts_eoe = field_value;
418 MMCAM_LOG_VERBOSE("[TS] EOE -> %llu", frame_meta->ts_eoe);
419 } else if (!strncmp("ts_sof", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
420 frame_meta->ts_sof = field_value;
421 MMCAM_LOG_VERBOSE("[TS] SOF -> %llu", frame_meta->ts_sof);
422 } else if (!strncmp("ts_eof", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
423 frame_meta->ts_eof = field_value;
424 MMCAM_LOG_VERBOSE("[TS] EOF -> %llu", frame_meta->ts_eof);
425 } else if (!strncmp("ts_hal", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
426 frame_meta->ts_hal = field_value;
427 MMCAM_LOG_VERBOSE("[TS] HAL -> %llu", frame_meta->ts_hal);
428 } else if (!strncmp("ts_qmf", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
429 frame_meta->ts_qmf = field_value;
430 MMCAM_LOG_VERBOSE("[TS] QMF -> %llu", frame_meta->ts_qmf);
431 } else if (!strncmp("ts_gst", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
432 frame_meta->ts_gst = field_value;
433 MMCAM_LOG_VERBOSE("[TS] GST -> %llu", frame_meta->ts_gst);
434 } else if (!strncmp("td_exp", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
435 frame_meta->td_exp = field_value;
436 MMCAM_LOG_VERBOSE("[TD] EXP -> %llu", frame_meta->td_exp);
437 } else if (!strncmp("ts_aux", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
438 frame_meta->ts_aux = field_value;
439 MMCAM_LOG_VERBOSE("[TS] AUX -> %llu", frame_meta->ts_aux);
440 } else if (!strncmp("td_aux", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
441 frame_meta->td_aux = field_value;
442 MMCAM_LOG_VERBOSE("[TD] AUX -> %llu", frame_meta->td_aux);
443 } else if (!strncmp("seqnum", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
444 frame_meta->seqnum = field_value;
445 MMCAM_LOG_VERBOSE("SEQNUM -> %llu", frame_meta->seqnum);
446 } else if (!strncmp("flags", field_name, META_TIMESTAMP_FIELD_LENGTH)) {
447 frame_meta->flags = field_value;
448 MMCAM_LOG_VERBOSE("FLAGS -> %llu", frame_meta->flags);
455 int _mmcamcorder_request_codec_config(GstElement *videosrc_element)
457 if (!videosrc_element || !G_TYPE_CHECK_INSTANCE(videosrc_element)) {
458 MMCAM_LOG_WARNING("invalid videosrc element[%p]", videosrc_element);
459 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
462 if (!g_signal_parse_name(_MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG,
463 G_TYPE_FROM_INSTANCE(videosrc_element), NULL, NULL, FALSE)) {
464 MMCAM_LOG_WARNING("no signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
465 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
468 MMCAM_LOG_INFO("emit signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
470 g_signal_emit_by_name(videosrc_element, _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
472 return MM_ERROR_NONE;
476 gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sample, gboolean is_preview, int stream_id)
479 gboolean ret_cb = TRUE;
480 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
481 _MMCamcorderSubContext *sc = NULL;
482 MMCamcorderVideoStreamDataType stream;
484 GstBuffer *buffer = NULL;
485 GstMemory *memory = NULL;
487 GstCaps *caps = NULL;
488 GstStructure *structure = NULL;
489 GstProtectionMeta *p_meta = NULL;
491 mmf_return_val_if_fail(hcamcorder, FALSE);
493 buffer = gst_sample_get_buffer(sample);
494 mmf_return_val_if_fail(buffer, FALSE);
495 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
497 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
498 mmf_return_val_if_fail(sc, FALSE);
500 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
502 caps = gst_sample_get_caps(sample);
503 mmf_return_val_if_fail(caps, FALSE);
505 structure = gst_caps_get_structure(caps, 0);
506 mmf_return_val_if_fail(structure, FALSE);
508 stream.format = _mmcamcorder_get_pixel_format(caps, TRUE);
509 gst_structure_get(structure,
510 "width", G_TYPE_INT, &stream.width,
511 "height", G_TYPE_INT, &stream.height,
514 memory = gst_buffer_peek_memory(buffer, 0);
516 MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
520 structure = gst_mini_object_get_qdata(GST_MINI_OBJECT_CAST(buffer), hcamcorder->buffer_quark);
521 if (structure && gst_structure_has_field(structure, "focus-state")) {
522 gst_structure_get(structure,
523 "focus-state", G_TYPE_INT, &stream.focus_state,
524 "facing-direction", G_TYPE_INT, &stream.facing_direction,
525 "flip", G_TYPE_INT, &stream.flip,
526 "rotation", G_TYPE_INT, &stream.rotation,
527 "status-ae", G_TYPE_INT, &stream.status_ae,
528 "status-awb", G_TYPE_INT, &stream.status_awb,
531 MMCAM_LOG_VERBOSE("structure[%p], [fs:%d,fd:%d,f:%d,r:%d,ae:%d,awb:%d]", structure,
532 stream.focus_state, stream.facing_direction,
533 stream.flip, stream.rotation,
534 stream.status_ae, stream.status_awb);
537 if (gst_is_tizen_memory(memory)) {
538 if (!__mmcamcorder_set_stream_data_zero_copy(&stream, buffer, memory))
539 goto _INVOKE_VIDEO_STREAM_CB_DONE;
541 memset(&map_info, 0x0, sizeof(GstMapInfo));
543 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE)) {
544 MMCAM_LOG_ERROR("map failed for memory[%p]", memory);
548 if (!__mmcamcorder_set_stream_data(&stream, buffer, &map_info))
549 goto _INVOKE_VIDEO_STREAM_CB_DONE;
552 p_meta = gst_buffer_get_protection_meta(buffer);
554 gst_structure_foreach(p_meta->info, __mmcamcorder_frame_meta_foreach_func, &stream);
556 MMCAM_LOG_DEBUG("VideoStreamData : format[%d], resolution[%dx%d], stream_id[%d]",
557 stream.format, stream.width, stream.height, stream_id);
559 stream.timestamp_nsec = GST_BUFFER_PTS(buffer);
560 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
561 stream.extra_stream_id = stream_id;
562 stream.internal_buffer = buffer;
564 /* invoke application callback */
566 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
567 if (hcamcorder->vstream_cb)
568 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
569 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
571 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
572 if (hcamcorder->vedecision_cb)
573 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
574 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
577 _INVOKE_VIDEO_STREAM_CB_DONE:
578 if (!gst_is_tizen_memory(memory))
579 gst_memory_unmap(memory, &map_info);
581 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
582 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
583 tbm_bo_unmap(stream.bo[i]);
590 static gboolean __mmcamcorder_add_videofilter_element(mmf_camcorder_t *hcamcorder,
591 GList *element_list, const char *conf_prefix,
592 const char *filter_nick, _MMCAMCORDER_PREVIEW_PIPELINE_ELELMENT filter_index,
593 const char *queue_nick, _MMCAMCORDER_PREVIEW_PIPELINE_ELELMENT queue_index)
596 int err = MM_ERROR_NONE;
597 int videofilt_crop_rect[_MMCAMCORDER_CROP_ARRAY_LENGTH] = {0, };
598 char conf_name_element[CONFIGURE_FIELD_NAME_LENGTH] = {'\0',};
599 char conf_name_crop[_MMCAMCORDER_CROP_ARRAY_LENGTH][CONFIGURE_FIELD_NAME_LENGTH] = {{'\0',}, };
600 const char *conf_postfix_crop[_MMCAMCORDER_CROP_ARRAY_LENGTH] = {
607 _MMCamcorderSubContext *sc = NULL;
608 type_element *videofilt_element = NULL;
609 const char *videofilt_name = NULL;
611 mmf_return_val_if_fail(hcamcorder, FALSE);
612 mmf_return_val_if_fail(element_list, FALSE);
613 mmf_return_val_if_fail(filter_nick && filter_index > _MMCAMCORDER_NONE, FALSE);
615 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
616 mmf_return_val_if_fail(sc, FALSE);
618 snprintf(conf_name_element, sizeof(conf_name_element), "%sElement", conf_prefix);
620 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
621 hcamcorder->conf_ctrl, CONFIGURE_CATEGORY_CTRL_CAMERA, conf_name_element,
622 &videofilt_element, &videofilt_name);
624 if (!videofilt_element || !videofilt_name) {
625 MMCAM_LOG_INFO("No configure for %s", conf_name_element);
629 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, filter_index, videofilt_name, filter_nick, element_list, err);
630 _mmcamcorder_conf_set_value_element_property(sc->element[filter_index].gst, videofilt_element);
632 for (i = 0 ; i < _MMCAMCORDER_CROP_ARRAY_LENGTH ; i++) {
633 snprintf(conf_name_crop[i], sizeof(conf_name_crop[i]), "%s%s", conf_prefix, conf_postfix_crop[i]);
634 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
635 CONFIGURE_CATEGORY_CTRL_CAMERA,
636 conf_name_crop[i], &videofilt_crop_rect[i]);
639 if (videofilt_crop_rect[0] >= 0 && videofilt_crop_rect[1] >= 0 &&
640 videofilt_crop_rect[2] > 0 && videofilt_crop_rect[3] > 0) {
641 _mmcamcorder_set_property_array_int(sc->element[filter_index].gst,
642 "crop", videofilt_crop_rect, _MMCAMCORDER_CROP_ARRAY_LENGTH);
645 MMCAM_LOG_INFO("queue_nick[%p], queue_index[%d]", queue_nick, queue_index);
647 if (queue_nick && queue_index > _MMCAMCORDER_NONE)
648 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, queue_index, "queue", queue_nick, element_list, err);
652 pipeline_creation_error:
653 MMCAM_LOG_ERROR("failed[0x%x]", err);
658 int _mmcamcorder_create_preview_elements(MMHandleType handle)
660 int err = MM_ERROR_NONE;
662 int camera_rotate = 0;
666 int capture_width = 0;
667 int capture_height = 0;
668 int capture_quality = 0;
669 int video_stabilization = 0;
671 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
672 const char *videosrc_name = NULL;
673 const char *videosink_name = NULL;
674 const char *videoconvert_name = NULL;
675 const char *videodecoder_name = NULL;
676 const char *videoparse_name = NULL;
677 const char *decoder_conf_name = NULL;
678 char videodecoder_name_final[32] = {'\0',};
679 char *err_name = NULL;
680 #ifdef _MMCAMCORDER_RM_SUPPORT
681 int decoder_index = 0;
682 #endif /* _MMCAMCORDER_RM_SUPPORT */
683 GstElement *sink_element = NULL;
684 GstCameraControl *control = NULL;
685 int sink_element_size = 0;
688 int extra_preview_enable = 0;
690 GList *element_list = NULL;
692 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
693 _MMCamcorderSubContext *sc = NULL;
694 type_element *videosrc_element = NULL;
695 type_int_array *input_index = NULL;
697 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
699 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
700 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
701 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
705 /* Check existence */
706 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
707 if (sc->element[i].gst) {
708 if (((GObject *)sc->element[i].gst)->ref_count > 0)
709 gst_object_unref(sc->element[i].gst);
711 MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
715 /* Get video device index info */
716 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
717 CONFIGURE_CATEGORY_CTRL_CAMERA,
720 if (input_index == NULL) {
721 MMCAM_LOG_ERROR("Failed to get input_index");
722 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
725 err = mm_camcorder_get_attributes(handle, &err_name,
726 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
727 MMCAM_CAMERA_FPS, &fps,
728 MMCAM_CAMERA_ROTATION, &camera_rotate,
729 MMCAM_CAMERA_FLIP, &camera_flip,
730 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
731 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
732 MMCAM_CAPTURE_WIDTH, &capture_width,
733 MMCAM_CAPTURE_HEIGHT, &capture_height,
734 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
735 MMCAM_IMAGE_ENCODER, &codectype,
736 MMCAM_IMAGE_ENCODER_QUALITY, &capture_quality,
737 MMCAM_DISPLAY_SURFACE, &display_surface_type,
738 MMCAM_EXTRA_PREVIEW_ENABLE, &extra_preview_enable,
740 if (err != MM_ERROR_NONE) {
741 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
746 if (hcamcorder->support_user_buffer) {
747 err = mm_camcorder_get_attributes(handle, NULL,
748 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
750 if (err != MM_ERROR_NONE || fd_number < 1) {
751 MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
756 for (i = 0 ; i < fd_number ; i++)
757 MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
761 /* Get fourcc from picture format */
762 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
764 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
765 hcamcorder->conf_ctrl, CONFIGURE_CATEGORY_CTRL_CAMERA, "AltVideosrcElement",
766 &videosrc_element, &videosrc_name);
768 /* Skip getting "VideosrcElement" if alternative element exists. */
769 if (videosrc_name == NULL) {
770 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
771 hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
772 &videosrc_element, &videosrc_name);
776 * Create child element
778 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "vsrc_s", element_list, err);
780 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_CAPS, "capsfilter", "vsrc_c", element_list, err);
783 * This is for "tizencamerasrc" element only.
784 * The camera HAL library will be loaded when "hal-name" property is set.
785 * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
787 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
789 /* camera properties */
790 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
791 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
792 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
793 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-quality", capture_quality);
794 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
795 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
797 /* set camera flip */
798 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
800 /* set video stabilization mode */
801 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
803 /* set anti handshake mode */
804 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
806 if (sc->is_modified_rate)
807 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
809 /* Set basic information of videosrc element */
810 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, videosrc_element);
812 /* Set video device index */
813 if (hcamcorder->is_network) {
814 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
816 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
817 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
819 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
823 /* set user buffer fd to videosrc element */
824 if (hcamcorder->support_user_buffer) {
825 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
826 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
827 MMCAM_LOG_ERROR("set user buffer fd failed");
828 goto pipeline_creation_error;
832 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
833 /* get recreate_decoder flag */
834 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
835 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
837 &hcamcorder->recreate_decoder);
840 if (!__mmcamcorder_add_videofilter_element(hcamcorder, element_list, "VideoFilter",
841 "vsrc_f", _MMCAMCORDER_VIDEOSRC_FILT, NULL, _MMCAMCORDER_NONE)) {
842 MMCAM_LOG_ERROR("add videofilter failed for VideoFilterElement");
843 goto pipeline_creation_error;
846 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "vsrc_q", element_list, err);
848 if (!__mmcamcorder_add_videofilter_element(hcamcorder, element_list, "VideoFilter2",
849 "vsrc_f2", _MMCAMCORDER_VIDEOSRC_FILT2, "vsrc_q2", _MMCAMCORDER_VIDEOSRC_QUE2)) {
850 MMCAM_LOG_ERROR("add videofilter failed for VideoFilter2Element");
851 goto pipeline_creation_error;
854 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
855 _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
856 switch (sc->info_image->preview_format) {
857 case MM_PIXEL_FORMAT_ENCODED_H264:
858 decoder_conf_name = "VideodecoderElementH264";
860 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
861 decoder_conf_name = "VideodecoderElementMJPEG";
863 case MM_PIXEL_FORMAT_ENCODED_VP8:
864 decoder_conf_name = "VideodecoderElementVP8";
866 case MM_PIXEL_FORMAT_ENCODED_VP9:
867 decoder_conf_name = "VideodecoderElementVP9";
870 MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
871 goto pipeline_creation_error;
874 /* get video decoder element and name */
875 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
876 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
878 &sc->VideodecoderElement);
880 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
883 if (!videodecoder_name) {
884 MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
885 goto pipeline_creation_error;
888 #ifdef _MMCAMCORDER_RM_SUPPORT
889 MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
890 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
891 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
893 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
894 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
895 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
896 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
898 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
900 #endif /* _MMCAMCORDER_RM_SUPPORT */
901 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
902 #ifdef _MMCAMCORDER_RM_SUPPORT
904 #endif /* _MMCAMCORDER_RM_SUPPORT */
906 videoparse_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
908 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_PARSE, videoparse_name, "vsrc_p", element_list, err);
910 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "vsrc_d", element_list, err);
912 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
915 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
917 /* Get videosink name */
918 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
920 if (!videosink_name) {
921 MMCAM_LOG_ERROR("failed to get videosink name");
922 goto pipeline_creation_error;
925 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "vsink_q", element_list, err);
927 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
929 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
930 /* get video convert name */
931 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
933 if (videoconvert_name) {
934 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
935 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "vsink_c", element_list, err);
937 MMCAM_LOG_ERROR("failed to get videoconvert element name");
940 /* check sink element in attribute */
941 mm_camcorder_get_attributes(handle, NULL,
942 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
947 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
949 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
951 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
953 /* reset attribute */
955 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
956 mm_attrs_set_data(attrs, attr_index, NULL, 0);
957 mm_attrs_commit(attrs, attr_index);
959 MMCAM_LOG_WARNING("attribute is NULL");
960 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
961 goto pipeline_creation_error;
964 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "vsink_s", element_list, err);
966 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
969 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
970 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
971 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
972 goto pipeline_creation_error;
975 /* Set caps by rotation */
976 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
978 /* add elements to main pipeline */
979 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
980 MMCAM_LOG_ERROR("element_list add error.");
981 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
982 goto pipeline_creation_error;
986 if (!_mmcamcorder_link_elements(element_list)) {
987 MMCAM_LOG_ERROR("element link error.");
988 err = MM_ERROR_CAMCORDER_GST_LINK;
989 goto pipeline_creation_error;
993 g_list_free(element_list);
996 if (extra_preview_enable)
997 _mmcamcorder_initialize_extra_preview_mode(handle);
999 return MM_ERROR_NONE;
1001 pipeline_creation_error:
1002 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
1003 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAPS);
1004 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
1005 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
1006 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT2);
1007 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE2);
1008 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_CAPS);
1009 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_SINK);
1010 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
1011 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
1012 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
1015 g_list_free(element_list);
1021 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
1023 int err = MM_ERROR_NONE;
1028 int a_enc = MM_AUDIO_CODEC_AMR;
1029 int a_dev = MM_AUDIO_DEVICE_MIC;
1030 double volume = 0.0;
1031 char *err_name = NULL;
1032 const char *audiosrc_name = NULL;
1033 char *cat_name = NULL;
1034 char *stream_type = NULL;
1035 int stream_type_len = 0;
1036 int stream_index = 0;
1037 int buffer_interval = 0;
1039 int replay_gain_enable = FALSE;
1040 double replay_gain_ref_level = 0.0;
1042 GstCaps *caps = NULL;
1044 GList *element_list = NULL;
1046 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1047 _MMCamcorderSubContext *sc = NULL;
1048 _MMCamcorderGstElement *last_element = NULL;
1049 type_element *audiosrc_element = NULL;
1051 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1053 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1054 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1055 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1059 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
1060 if (err != MM_ERROR_NONE)
1063 err = mm_camcorder_get_attributes(handle, &err_name,
1064 MMCAM_AUDIO_DEVICE, &a_dev,
1065 MMCAM_AUDIO_ENCODER, &a_enc,
1066 MMCAM_AUDIO_ENCODER_BITRATE, &val,
1067 MMCAM_AUDIO_SAMPLERATE, &rate,
1068 MMCAM_AUDIO_FORMAT, &format,
1069 MMCAM_AUDIO_CHANNEL, &channel,
1070 MMCAM_AUDIO_VOLUME, &volume,
1071 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
1072 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
1073 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
1074 MMCAM_SOUND_STREAM_INDEX, &stream_index,
1076 if (err != MM_ERROR_NONE) {
1077 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
1078 SAFE_FREE(err_name);
1082 /* Check existence */
1083 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
1084 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
1085 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
1087 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
1090 /* Create bin element */
1091 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
1093 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
1094 cat_name = strdup("AudiomodemsrcElement");
1096 /* MM_AUDIO_DEVICE_MIC or others */
1097 cat_name = strdup("AudiosrcElement");
1100 if (cat_name == NULL) {
1101 MMCAM_LOG_ERROR("strdup failed.");
1102 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
1103 goto pipeline_creation_error;
1106 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
1107 hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, cat_name,
1108 &audiosrc_element, &audiosrc_name);
1112 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
1114 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "asrc_s", element_list, err);
1116 /* set sound stream info */
1117 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
1119 /* set audiosrc properties in ini configuration */
1120 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, audiosrc_element);
1122 /* set block size */
1123 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
1124 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
1125 "AudioBufferInterval",
1128 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
1129 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
1130 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
1133 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_CAPS, "capsfilter", "asrc_c", element_list, err);
1135 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "asrc_q", element_list, err);
1136 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
1137 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
1138 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
1140 /* Set basic information */
1141 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
1143 const gchar* format_name = NULL;
1145 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "asrc_v", element_list, err);
1147 if (volume == 0.0) {
1148 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
1149 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
1151 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
1152 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
1155 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
1157 format_name = "S16LE";
1158 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
1163 caps = gst_caps_new_simple("audio/x-raw",
1164 "rate", G_TYPE_INT, rate,
1165 "channels", G_TYPE_INT, channel,
1166 "format", G_TYPE_STRING, format_name,
1168 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
1169 rate, channel, depth, volume);
1171 /* what are the audio encoder which should get audio/x-raw-float? */
1172 caps = gst_caps_new_simple("audio/x-raw",
1173 "rate", G_TYPE_INT, rate,
1174 "channels", G_TYPE_INT, channel,
1175 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
1177 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
1178 rate, channel, BYTE_ORDER);
1182 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
1183 replay_gain_enable, replay_gain_ref_level);
1185 if (replay_gain_enable) {
1186 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "asrc_r", element_list, err);
1187 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
1188 /* If num-tracks is not set, album gain and peak event is not come. */
1189 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
1193 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_CAPS].gst), "caps", caps);
1194 gst_caps_unref(caps);
1196 MMCAM_LOG_ERROR("create caps error");
1197 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1198 goto pipeline_creation_error;
1201 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
1202 MMCAM_LOG_ERROR("element add error.");
1203 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1204 goto pipeline_creation_error;
1207 if (!_mmcamcorder_link_elements(element_list)) {
1208 MMCAM_LOG_ERROR("element link error.");
1209 err = MM_ERROR_CAMCORDER_GST_LINK;
1210 goto pipeline_creation_error;
1213 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
1214 pad = gst_element_get_static_pad(last_element->gst, "src");
1215 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
1216 gst_object_unref(pad);
1217 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
1218 err = MM_ERROR_CAMCORDER_GST_LINK;
1219 goto pipeline_creation_error;
1222 gst_object_unref(pad);
1225 g_list_free(element_list);
1227 return MM_ERROR_NONE;
1229 pipeline_creation_error:
1230 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1231 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_CAPS);
1232 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1233 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1234 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1237 g_list_free(element_list);
1243 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1248 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1253 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1254 type, codec, bitrate);
1258 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1259 /* audio encoder bitrate setting */
1261 case MM_AUDIO_CODEC_AMR:
1262 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1263 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1264 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1266 case MM_AUDIO_CODEC_MP3:
1267 set_value = bitrate / 1000;
1268 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1269 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1271 case MM_AUDIO_CODEC_AAC:
1272 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1273 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1276 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1280 /* video encoder bitrate setting */
1281 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1282 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1289 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1291 int err = MM_ERROR_NONE;
1296 int encodebin_profile = 0;
1297 int auto_audio_convert = 0;
1298 int auto_audio_resample = 0;
1299 int auto_color_space = 0;
1300 int cap_format = MM_PIXEL_FORMAT_INVALID;
1301 const char *gst_element_venc_name = NULL;
1302 const char *gst_element_aenc_name = NULL;
1303 const char *gst_element_ienc_name = NULL;
1304 const char *gst_element_mux_name = NULL;
1305 const char *gst_element_rsink_name = NULL;
1306 const char *gst_element_vscale_name = NULL;
1307 const char *str_profile = NULL;
1308 const char *str_aac = NULL;
1309 const char *str_aar = NULL;
1310 const char *str_acs = NULL;
1311 char *err_name = NULL;
1312 const char *videoconvert_name = NULL;
1313 GstCaps *audio_caps = NULL;
1314 GstCaps *video_caps = NULL;
1315 GstCaps *videoscale_caps = NULL;
1317 GList *element_list = NULL;
1319 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1320 _MMCamcorderSubContext *sc = NULL;
1321 type_element *VideoencElement = NULL;
1322 type_element *AudioencElement = NULL;
1323 type_element *ImageencElement = NULL;
1324 type_element *MuxElement = NULL;
1325 type_element *RecordsinkElement = NULL;
1326 type_element *VideoscaleElement = NULL;
1328 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1330 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1331 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1332 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1334 MMCAM_LOG_INFO("start - profile : %d", profile);
1336 /* Check existence */
1337 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1338 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1339 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1341 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1344 /* Create bin element */
1345 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1347 /* Create child element */
1348 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1349 GstCaps *caps_from_pad = NULL;
1350 char *caps_str = NULL;
1352 /* create appsrc and capsfilter */
1353 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "esink_s", element_list, err);
1355 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_CAPS, "capsfilter", "esink_c", element_list, err);
1357 /* set appsrc as live source */
1358 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1359 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1360 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1362 /* set capsfilter */
1363 if (sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
1364 MMCAM_LOG_INFO("get pad from vsrc_f");
1365 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1366 caps_from_pad = gst_pad_get_current_caps(pad);
1367 } else if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1368 MMCAM_LOG_INFO("get pad from vsrc_c");
1369 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_CAPS].gst, "src");
1370 caps_from_pad = gst_pad_get_allowed_caps(pad);
1372 MMCAM_LOG_INFO("get pad from vsrc_q");
1373 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1374 caps_from_pad = gst_pad_get_allowed_caps(pad);
1377 gst_object_unref(pad);
1379 if (!caps_from_pad) {
1380 MMCAM_LOG_ERROR("get caps failed");
1381 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1382 goto pipeline_creation_error;
1385 video_caps = gst_caps_fixate(gst_caps_copy(caps_from_pad));
1387 gst_caps_unref(caps_from_pad);
1390 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1391 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1392 goto pipeline_creation_error;
1395 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1396 if (sc->info_video->use_videoscale) {
1397 gst_caps_set_simple(video_caps,
1398 "width", G_TYPE_INT, sc->info_video->preview_width,
1399 "height", G_TYPE_INT, sc->info_video->preview_height,
1401 videoscale_caps = gst_caps_copy(video_caps);
1403 gst_caps_set_simple(video_caps,
1404 "width", G_TYPE_INT, sc->info_video->video_width,
1405 "height", G_TYPE_INT, sc->info_video->video_height,
1410 caps_str = gst_caps_to_string(video_caps);
1412 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1416 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_CAPS].gst, "caps", video_caps);
1418 gst_caps_unref(video_caps);
1421 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1422 sc->info_video->use_videoscale) {
1423 if (!videoscale_caps) {
1424 MMCAM_LOG_ERROR("no videoscale caps");
1425 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1426 goto pipeline_creation_error;
1429 gst_caps_set_simple(videoscale_caps,
1430 "width", G_TYPE_INT, sc->info_video->video_width,
1431 "height", G_TYPE_INT, sc->info_video->video_height,
1434 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1435 CONFIGURE_CATEGORY_MAIN_RECORD,
1436 "VideoscaleElement",
1437 &VideoscaleElement);
1439 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1440 MMCAM_LOG_ERROR("failed to get videoscale element name");
1441 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1442 goto pipeline_creation_error;
1445 caps_str = gst_caps_to_string(videoscale_caps);
1447 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1451 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "esink_vs", element_list, err);
1452 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_CAPS, "capsfilter", "esink_vs_c", element_list, err);
1454 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_CAPS].gst), "caps", videoscale_caps);
1456 gst_caps_unref(videoscale_caps);
1457 videoscale_caps = NULL;
1460 /* release element_list, they will be placed out of encodesink bin */
1462 g_list_free(element_list);
1463 element_list = NULL;
1466 /* connect signal for ready to push buffer */
1467 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1468 _MMCAMCORDER_HANDLER_VIDEOREC,
1470 _mmcamcorder_ready_to_encode_callback,
1474 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1475 "tizenencodebin", "esink_e", element_list, err);
1477 /* check element availability */
1478 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1479 err = mm_camcorder_get_attributes(handle, &err_name,
1480 MMCAM_CAPTURE_FORMAT, &cap_format,
1483 err = mm_camcorder_get_attributes(handle, &err_name,
1484 MMCAM_AUDIO_ENCODER, &audio_enc,
1485 MMCAM_AUDIO_CHANNEL, &channel,
1486 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1487 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1491 if (err != MM_ERROR_NONE) {
1493 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1494 SAFE_FREE(err_name);
1496 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1499 goto pipeline_creation_error;
1502 MMCAM_LOG_INFO("Profile[%d]", profile);
1504 /* Set information */
1505 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1506 str_profile = "VideoProfile";
1507 str_aac = "VideoAutoAudioConvert";
1508 str_aar = "VideoAutoAudioResample";
1509 str_acs = "VideoAutoColorSpace";
1510 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1511 str_profile = "AudioProfile";
1512 str_aac = "AudioAutoAudioConvert";
1513 str_aar = "AudioAutoAudioResample";
1514 str_acs = "AudioAutoColorSpace";
1515 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1516 str_profile = "ImageProfile";
1517 str_aac = "ImageAutoAudioConvert";
1518 str_aar = "ImageAutoAudioResample";
1519 str_acs = "ImageAutoColorSpace";
1522 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1523 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1524 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1525 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1527 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1528 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1530 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1531 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1532 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1533 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1534 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1536 /* get video convert element name */
1537 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1540 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1541 int use_venc_queue = 0;
1543 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1545 if (!VideoencElement) {
1546 MMCAM_LOG_ERROR("Fail to get type element");
1547 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1548 goto pipeline_creation_error;
1551 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1552 /* set parse element */
1553 gst_element_venc_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
1554 if (!gst_element_venc_name)
1555 gst_element_venc_name = "identity";
1557 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1560 if (gst_element_venc_name) {
1561 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1563 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1564 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1566 MMCAM_LOG_ERROR("Fail to get video encoder name");
1567 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1568 goto pipeline_creation_error;
1571 /* set color space converting element */
1572 if (auto_color_space) {
1573 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1575 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1576 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1578 /* set colorspace plugin property setting */
1579 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1581 /* fourcc type was removed in GST 1.0 */
1582 if (hcamcorder->use_zero_copy_format) {
1583 if (strstr(gst_element_venc_name, "omx")) {
1584 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1587 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1588 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1589 gst_caps_unref(video_caps);
1591 MMCAM_LOG_WARNING("failed to create caps");
1594 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1599 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1600 CONFIGURE_CATEGORY_MAIN_RECORD,
1601 "UseVideoEncoderQueue",
1604 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1607 if (sc->audio_disable == FALSE &&
1608 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1609 int use_aenc_queue = 0;
1611 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1612 if (!AudioencElement) {
1613 MMCAM_LOG_ERROR("Fail to get type element");
1614 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1615 goto pipeline_creation_error;
1618 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1620 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1621 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1623 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1624 audio_caps = gst_caps_new_simple("audio/x-raw",
1625 "channels", G_TYPE_INT, 1,
1627 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1628 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1629 gst_caps_unref(audio_caps);
1632 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1633 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1634 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1635 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1636 gst_caps_unref(audio_caps);
1637 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1640 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1641 CONFIGURE_CATEGORY_MAIN_RECORD,
1642 "UseAudioEncoderQueue",
1644 if (use_aenc_queue) {
1645 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1646 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1647 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1651 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1652 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1653 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1654 if (!ImageencElement) {
1655 MMCAM_LOG_ERROR("Fail to get type element");
1656 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1657 goto pipeline_creation_error;
1660 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1662 /* raw format - set dummy element */
1663 gst_element_ienc_name = "identity";
1666 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1667 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1671 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1672 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1674 MMCAM_LOG_ERROR("Fail to get type element");
1675 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1676 goto pipeline_creation_error;
1679 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1681 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1682 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1684 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1688 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1690 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1691 CONFIGURE_CATEGORY_MAIN_RECORD,
1692 "RecordsinkElement",
1693 &RecordsinkElement);
1694 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1696 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1698 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1701 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1704 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1705 /* property setting in ini */
1706 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1708 /* bitrate setting */
1709 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1710 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1713 if (sc->audio_disable == FALSE &&
1714 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1715 /* property setting in ini */
1716 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1718 /* bitrate setting */
1719 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1720 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1723 MMCAM_LOG_INFO("Element creation complete");
1725 /* Add element to bin */
1726 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1727 MMCAM_LOG_ERROR("element add error.");
1728 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1729 goto pipeline_creation_error;
1732 MMCAM_LOG_INFO("Element add complete");
1734 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1735 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1736 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1737 gst_object_unref(pad);
1738 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1739 err = MM_ERROR_CAMCORDER_GST_LINK;
1740 goto pipeline_creation_error;
1742 gst_object_unref(pad);
1744 if (sc->audio_disable == FALSE) {
1745 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1746 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1747 gst_object_unref(pad);
1748 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1749 err = MM_ERROR_CAMCORDER_GST_LINK;
1750 goto pipeline_creation_error;
1752 gst_object_unref(pad);
1754 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1755 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1756 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1757 gst_object_unref(pad);
1758 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1759 err = MM_ERROR_CAMCORDER_GST_LINK;
1760 goto pipeline_creation_error;
1762 gst_object_unref(pad);
1765 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1766 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1767 gst_object_unref(pad);
1768 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1769 err = MM_ERROR_CAMCORDER_GST_LINK;
1770 goto pipeline_creation_error;
1772 gst_object_unref(pad);
1775 MMCAM_LOG_INFO("Get pad complete");
1777 /* Link internal element */
1778 if (!_mmcamcorder_link_elements(element_list)) {
1779 MMCAM_LOG_ERROR("element link error.");
1780 err = MM_ERROR_CAMCORDER_GST_LINK;
1781 goto pipeline_creation_error;
1785 g_list_free(element_list);
1787 MMCAM_LOG_INFO("done");
1789 return MM_ERROR_NONE;
1791 pipeline_creation_error:
1792 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1794 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1795 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1796 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_CAPS);
1797 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1798 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_CAPS);
1799 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1800 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1801 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1802 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1803 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1804 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1807 g_list_free(element_list);
1809 if (videoscale_caps)
1810 gst_caps_unref(videoscale_caps);
1816 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1818 int err = MM_ERROR_NONE;
1820 GstPad *srcpad = NULL;
1823 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1824 _MMCamcorderSubContext *sc = NULL;
1826 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1828 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1829 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1830 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1834 /** Create gstreamer element **/
1836 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1839 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1840 if (err != MM_ERROR_NONE)
1841 goto pipeline_creation_error;
1843 /* Set data probe function */
1844 if (!sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1845 MMCAM_LOG_ERROR("there is no queue plugin");
1846 goto pipeline_creation_error;
1849 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1850 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1852 MMCAM_LOG_ERROR("failed to get srcpad");
1853 goto pipeline_creation_error;
1856 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1857 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1859 gst_object_unref(srcpad);
1861 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE2].gst) {
1862 MMCAM_LOG_INFO("add video dataprobe2 to videosrc queue2");
1863 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE2].gst, "src");
1865 MMCAM_LOG_ERROR("failed to get srcpad");
1866 goto pipeline_creation_error;
1869 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1870 __mmcamcorder_video_dataprobe_preview2, hcamcorder);
1872 gst_object_unref(srcpad);
1875 /* set dataprobe for video recording if it does not support dual stream. */
1876 if (sc->info_video->record_dual_stream == FALSE) {
1877 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1878 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1880 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1882 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1883 __mmcamcorder_video_dataprobe_record, hcamcorder);
1884 gst_object_unref(srcpad);
1887 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1889 /* set sync handler */
1890 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1892 gst_object_unref(bus);
1895 err = _mmcamcorder_initialize_capture_mode(handle);
1896 if (err != MM_ERROR_NONE) {
1897 MMCAM_LOG_ERROR("initialize capture mode[%d] failed", hcamcorder->capture_mode);
1898 goto pipeline_creation_error;
1901 return MM_ERROR_NONE;
1903 pipeline_creation_error:
1904 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1909 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1911 int ret = MM_ERROR_NONE;
1912 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1913 _MMCamcorderSubContext *sc = NULL;
1915 /*MMCAM_LOG_INFO("start");*/
1917 mmf_return_if_fail(hcamcorder);
1918 mmf_return_if_fail(hcamcorder->sub_context);
1919 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1922 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1923 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1924 ret = _mmcamcorder_request_codec_config(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1925 MMCAM_LOG_WARNING("Push buffer to encoding pipeline[request codec config:0x%x]", ret);
1930 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1932 int err = MM_ERROR_NONE;
1937 int rect_height = 0;
1939 int rotation = MM_DISPLAY_ROTATION_NONE;
1940 int flip = MM_FLIP_NONE;
1941 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1942 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1943 int origin_size = 0;
1946 int do_scaling = FALSE;
1947 int *dp_handle = NULL;
1948 MMCamWindowInfo *window_info = NULL;
1950 char *err_name = NULL;
1951 const char *videosink_name = NULL;
1953 GstElement *vsink = NULL;
1955 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1956 _MMCamcorderSubContext *sc = NULL;
1960 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1962 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1963 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1964 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1965 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1967 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1969 /* Get video display information */
1970 err = mm_camcorder_get_attributes(handle, &err_name,
1971 MMCAM_DISPLAY_RECT_X, &rect_x,
1972 MMCAM_DISPLAY_RECT_Y, &rect_y,
1973 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1974 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1975 MMCAM_DISPLAY_ROTATION, &rotation,
1976 MMCAM_DISPLAY_FLIP, &flip,
1977 MMCAM_DISPLAY_VISIBLE, &visible,
1978 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1979 MMCAM_DISPLAY_MODE, &display_mode,
1980 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1981 MMCAM_DISPLAY_SCALE, &zoom_attr,
1982 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1984 if (err != MM_ERROR_NONE) {
1986 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1987 SAFE_FREE(err_name);
1989 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1995 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1997 if (!videosink_name) {
1998 MMCAM_LOG_ERROR("failed to get videosink name");
1999 return MM_ERROR_CAMCORDER_INTERNAL;
2002 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
2004 /* Set display handle */
2005 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
2008 MMCAM_LOG_INFO("xid = %lu )", xid);
2009 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
2011 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
2012 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
2014 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
2015 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
2018 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
2019 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
2021 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
2022 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
2024 } else if (!strcmp(videosink_name, "tizenwlsink")) {
2026 window_info = (MMCamWindowInfo *)dp_handle;
2027 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
2028 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
2030 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
2032 } else if (!strcmp(videosink_name, "directvideosink")) {
2033 #ifdef _MMCAMCORDER_RM_SUPPORT
2034 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
2035 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
2036 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
2037 #endif /* _MMCAMCORDER_RM_SUPPORT */
2039 window_info = (MMCamWindowInfo *)dp_handle;
2040 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
2041 window_info->surface_id,
2042 window_info->rect.x,
2043 window_info->rect.y,
2044 window_info->rect.width,
2045 window_info->rect.height);
2046 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
2047 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
2048 window_info->rect.x,
2049 window_info->rect.y,
2050 window_info->rect.width,
2051 window_info->rect.height);
2053 MMCAM_LOG_WARNING("dp_handle is null");
2056 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
2059 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
2060 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
2063 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
2064 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
2066 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
2069 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
2071 switch (zoom_attr) {
2072 case MM_DISPLAY_SCALE_DEFAULT:
2075 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
2078 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
2082 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
2087 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
2088 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
2089 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
2090 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
2092 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
2093 if (!strcmp(videosink_name, "tizenwlsink")) {
2094 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
2095 rect_x, rect_y, rect_width, rect_height);
2098 "dst-roi-x", rect_x,
2099 "dst-roi-y", rect_y,
2100 "dst-roi-w", rect_width,
2101 "dst-roi-h", rect_height,
2107 return MM_ERROR_NONE;
2111 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
2114 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2115 _MMCamcorderSubContext *sc = NULL;
2117 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2119 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2121 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2124 case _MMCamcorder_CMD_PREVIEW_START:
2125 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
2127 case _MMCamcorder_CMD_CAPTURE:
2128 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
2131 MMCAM_LOG_WARNING("unknown command : %d", cmd);
2132 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
2135 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
2136 category, "FrameStabilityCount", &sc->frame_stability_count);
2138 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
2139 cmd, sc->frame_stability_count);
2141 return MM_ERROR_NONE;
2144 /* Retreive device information and set them to attributes */
2145 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
2147 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2148 _MMCamcorderSubContext *sc = NULL;
2149 GstCameraControl *control = NULL;
2150 GstCameraControlExifInfo exif_info = {0,};
2152 mmf_return_val_if_fail(hcamcorder, FALSE);
2153 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2155 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
2157 if (sc && sc->element) {
2158 int err = MM_ERROR_NONE;
2159 char *err_name = NULL;
2160 double focal_len = 0.0;
2162 /* Video input device */
2163 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2164 /* Exif related information */
2165 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2166 if (control != NULL) {
2167 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
2168 if (exif_info.focal_len_denominator != 0)
2169 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
2171 MMCAM_LOG_ERROR("Fail to get camera control interface!");
2176 /* Set values to attributes */
2177 err = mm_camcorder_set_attributes(handle, &err_name,
2178 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
2180 if (err != MM_ERROR_NONE) {
2181 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
2182 SAFE_FREE(err_name);
2186 MMCAM_LOG_WARNING("Sub context isn't exist.");
2193 static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure)
2195 const gchar *format_string = NULL;
2198 MMCAM_LOG_WARNING("NULL structure");
2199 return GST_MAKE_FOURCC('N', 'U', 'L', 'L');
2202 if (gst_structure_has_name(structure, "video/x-h264"))
2203 return GST_MAKE_FOURCC('H', '2', '6', '4');
2205 if (gst_structure_has_name(structure, "video/x-h265"))
2206 return GST_MAKE_FOURCC('H', '2', '6', '5');
2208 if (gst_structure_has_name(structure, "video/x-vp8"))
2209 return GST_MAKE_FOURCC('V', 'P', '8', '0');
2211 if (gst_structure_has_name(structure, "video/x-vp9"))
2212 return GST_MAKE_FOURCC('V', 'P', '9', '0');
2214 if (gst_structure_has_name(structure, "video/x-jpeg") ||
2215 gst_structure_has_name(structure, "image/jpeg"))
2216 return GST_MAKE_FOURCC('M', 'J', 'P', 'G');
2218 format_string = gst_structure_get_string(structure, "format");
2221 return GST_STR_FOURCC(format_string);
2223 return GST_MAKE_FOURCC('N', 'O', 'N', 'E');
2227 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview_common(mmf_camcorder_t *hcamcorder,
2228 GstPad *pad, GstBuffer *buffer, int stream_id, int flag_mask)
2230 int flag_current = 0;
2231 int ret_attr = MM_ERROR_NONE;
2232 _MMCamcorderSubContext *sc = NULL;
2233 g_autoptr(GstSample) sample = NULL;
2234 g_autoptr(GstCaps) caps = NULL;
2236 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
2237 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
2239 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2240 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
2242 /* The first H.264 frame should not be skipped for vstream cb. */
2243 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2244 !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2245 MMCAM_LOG_WARNING("Not ready for stream callback[stream_id:%d]", stream_id);
2246 return GST_PAD_PROBE_OK;
2249 ret_attr = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
2250 MMCAM_VIDEO_STREAM_CALLBACK_FLAG, &flag_current,
2252 if (ret_attr != MM_ERROR_NONE) {
2253 MMCAM_LOG_WARNING("get preview callback flag failed[0x%x]", ret_attr);
2254 return GST_PAD_PROBE_OK;
2257 MMCAM_LOG_DEBUG("flag [current:0x%08x,mask:0x%08x]", flag_current, flag_mask);
2259 /* workaround: it will be removed after mmsvc-camera is updated. */
2260 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
2261 if (hcamcorder->vstream_cb && flag_current == 0) {
2262 MMCAM_LOG_DEBUG("vstream_cb, but NULL flag, update it NORMAL");
2263 flag_current = MM_CAMCORDER_VIDEO_STREAM_CALLBACK_FLAG_NORMAL;
2265 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
2267 if (!(flag_current & flag_mask))
2268 return GST_PAD_PROBE_OK;
2270 /* make sample with buffer and caps */
2271 caps = gst_pad_get_current_caps(pad);
2272 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2274 sample = gst_sample_new(buffer, caps, NULL, NULL);
2275 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2277 return _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, stream_id) ? \
2278 GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP;
2282 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2284 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2285 _MMCamcorderSubContext *sc = NULL;
2286 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2288 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
2289 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
2291 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
2292 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
2294 if (sc->drop_vframe > 0) {
2295 if (sc->pass_first_vframe > 0) {
2296 sc->pass_first_vframe--;
2297 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2300 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2301 return GST_PAD_PROBE_DROP;
2303 } else if (sc->frame_stability_count > 0) {
2304 sc->frame_stability_count--;
2305 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2306 return GST_PAD_PROBE_DROP;
2309 if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
2310 _mmcamcorder_measure_fps(&sc->kpi);
2312 return __mmcamcorder_video_dataprobe_preview_common(hcamcorder,
2314 MM_CAMCORDER_VIDEO_STREAM_ID_NORMAL,
2315 MM_CAMCORDER_VIDEO_STREAM_CALLBACK_FLAG_NORMAL);
2319 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview2(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2321 return __mmcamcorder_video_dataprobe_preview_common(MMF_CAMCORDER(u_data),
2322 pad, GST_PAD_PROBE_INFO_BUFFER(info),
2323 MM_CAMCORDER_VIDEO_STREAM_ID_INTERNAL,
2324 MM_CAMCORDER_VIDEO_STREAM_CALLBACK_FLAG_INTERNAL);
2328 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2330 gboolean ret = TRUE;
2331 GstSample *sample = NULL;
2332 GstCaps *caps = NULL;
2334 caps = gst_pad_get_allowed_caps(pad);
2335 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2337 sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
2338 gst_caps_unref(caps);
2339 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2341 ret = _mmcamcorder_video_push_buffer(u_data, sample);
2343 gst_sample_unref(sample);
2345 return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
2349 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2351 MMCamcorderMuxedStreamDataType stream;
2352 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2353 _MMCamcorderSubContext *sc = NULL;
2354 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2357 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2358 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2359 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2361 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2362 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2364 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2365 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2366 return GST_PAD_PROBE_OK;
2369 /* call application callback */
2370 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2372 if (hcamcorder->mstream_cb) {
2373 stream.data = (void *)mapinfo.data;
2374 stream.length = mapinfo.size;
2375 stream.offset = sc->muxed_stream_offset;
2376 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2379 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2381 /* calculate current offset */
2382 sc->muxed_stream_offset += mapinfo.size;
2384 gst_buffer_unmap(buffer, &mapinfo);
2386 return GST_PAD_PROBE_OK;
2390 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2392 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2393 mmf_camcorder_t *hcamcorder = NULL;
2394 _MMCamcorderSubContext *sc = NULL;
2395 GstObject *parent = NULL;
2397 switch (GST_EVENT_TYPE(event)) {
2398 case GST_EVENT_UNKNOWN:
2399 /* upstream events */
2401 case GST_EVENT_SEEK:
2402 case GST_EVENT_NAVIGATION:
2403 case GST_EVENT_LATENCY:
2404 /* downstream serialized events */
2405 case GST_EVENT_BUFFERSIZE:
2406 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2410 GstTagList *tag_list = NULL;
2411 _MMCamcorderReplayGain *replay_gain = NULL;
2413 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2415 hcamcorder = MMF_CAMCORDER(u_data);
2416 if (!hcamcorder || !hcamcorder->sub_context) {
2417 MMCAM_LOG_WARNING("NULL handle");
2421 replay_gain = &hcamcorder->sub_context->replay_gain;
2423 gst_event_parse_tag(event, &tag_list);
2425 MMCAM_LOG_WARNING("failed to get tag list");
2429 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2430 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2434 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2435 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2439 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2440 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2444 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2445 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2449 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2450 replay_gain->track_peak, replay_gain->track_gain,
2451 replay_gain->album_peak, replay_gain->album_gain);
2454 case GST_EVENT_SEGMENT:
2455 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2457 hcamcorder = MMF_CAMCORDER(u_data);
2459 MMCAM_LOG_WARNING("NULL handle");
2463 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2465 MMCAM_LOG_WARNING("NULL sub context");
2469 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2470 MMCAM_LOG_WARNING("no encoder sink");
2474 parent = gst_pad_get_parent(pad);
2476 MMCAM_LOG_WARNING("get parent failed");
2480 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2481 const GstSegment *segment;
2482 gst_event_parse_segment(event, &segment);
2483 if (segment->format == GST_FORMAT_BYTES) {
2484 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2485 sc->muxed_stream_offset, segment->start);
2487 sc->muxed_stream_offset = (unsigned long long)segment->start;
2491 gst_object_unref(parent);
2494 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2496 /* bidirectional events */
2497 case GST_EVENT_FLUSH_START:
2498 case GST_EVENT_FLUSH_STOP:
2499 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2502 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2506 return GST_PAD_PROBE_OK;
2510 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2512 int result = MM_CAMCORDER_MR475;
2515 result = MM_CAMCORDER_MR475; /*AMR475*/
2516 else if (bitrate < 5900)
2517 result = MM_CAMCORDER_MR515; /*AMR515*/
2518 else if (bitrate < 6700)
2519 result = MM_CAMCORDER_MR59; /*AMR59*/
2520 else if (bitrate < 7400)
2521 result = MM_CAMCORDER_MR67; /*AMR67*/
2522 else if (bitrate < 7950)
2523 result = MM_CAMCORDER_MR74; /*AMR74*/
2524 else if (bitrate < 10200)
2525 result = MM_CAMCORDER_MR795; /*AMR795*/
2526 else if (bitrate < 12200)
2527 result = MM_CAMCORDER_MR102; /*AMR102*/
2529 result = MM_CAMCORDER_MR122; /*AMR122*/
2535 int _mmcamcorder_get_eos_message(MMHandleType handle)
2538 int ret = MM_ERROR_NONE;
2540 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2541 _MMCamcorderSubContext *sc = NULL;
2543 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2544 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2545 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2547 MMCAM_LOG_INFO("START");
2549 _MMCAMCORDER_LOCK(handle);
2551 if (sc->bget_eos == FALSE) {
2552 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2553 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2554 MMCAM_LOG_INFO("EOS signal received");
2556 MMCAM_LOG_ERROR("EOS wait time out");
2558 if (hcamcorder->error_code == MM_ERROR_NONE)
2559 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2562 MMCAM_LOG_INFO("already got EOS");
2565 _MMCAMCORDER_UNLOCK(handle);
2567 if (hcamcorder->error_code == MM_ERROR_NONE) {
2568 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2569 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2570 if (sc->info_video->b_committing)
2571 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2573 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2574 if (sc->info_audio->b_committing)
2575 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2578 ret = hcamcorder->error_code;
2579 MMCAM_LOG_ERROR("error 0x%x", ret);
2582 MMCAM_LOG_INFO("END");
2588 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2591 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2593 mmf_return_if_fail(handle && remove_element);
2594 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2598 for (i = first_elem ; i <= last_elem ; i++) {
2599 remove_element[i].gst = NULL;
2600 remove_element[i].id = _MMCAMCORDER_NONE;
2607 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2609 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2611 /* Check compatibility between codec and file format */
2612 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2613 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2614 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2615 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2616 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2617 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2620 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2622 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2623 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2625 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2626 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2627 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2628 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2629 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2630 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2633 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2635 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2636 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2640 return MM_ERROR_NONE;
2644 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2646 int err = MM_ERROR_NONE;
2647 int audio_codec = MM_AUDIO_CODEC_INVALID;
2648 int file_format = MM_FILE_FORMAT_INVALID;
2650 char *err_name = NULL;
2652 err = mm_camcorder_get_attributes(handle, &err_name,
2653 MMCAM_AUDIO_ENCODER, &audio_codec,
2654 MMCAM_FILE_FORMAT, &file_format,
2656 if (err != MM_ERROR_NONE) {
2657 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2658 SAFE_FREE(err_name);
2662 /* Check compatibility between audio codec and file format */
2663 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2669 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2671 int err = MM_ERROR_NONE;
2672 int video_codec = MM_VIDEO_CODEC_INVALID;
2673 int file_format = MM_FILE_FORMAT_INVALID;
2675 char *err_name = NULL;
2677 err = mm_camcorder_get_attributes(handle, &err_name,
2678 MMCAM_VIDEO_ENCODER, &video_codec,
2679 MMCAM_FILE_FORMAT, &file_format,
2681 if (err != MM_ERROR_NONE) {
2682 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2683 SAFE_FREE(err_name);
2687 /* Check compatibility between video codec and file format */
2688 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2694 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2696 const char* videosink_name = NULL;
2698 mmf_camcorder_t *hcamcorder = NULL;
2699 _MMCamcorderSubContext *sc = NULL;
2701 hcamcorder = MMF_CAMCORDER(handle);
2702 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2704 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2705 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2706 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2708 if (sc->element[videosink_index].gst) {
2709 /* Get videosink name */
2710 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2711 if (videosink_name == NULL) {
2712 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2716 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2717 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2718 !strcmp(videosink_name, "directvideosink")) {
2719 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2720 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2722 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2727 MMCAM_LOG_ERROR("Videosink element is null");
2733 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2735 const char* videosink_name = NULL;
2737 mmf_camcorder_t *hcamcorder = NULL;
2738 _MMCamcorderSubContext *sc = NULL;
2740 hcamcorder = MMF_CAMCORDER(handle);
2741 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2743 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2744 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2745 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2747 if (sc->element[videosink_index].gst) {
2748 /* Get videosink name */
2749 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2750 if (videosink_name == NULL) {
2751 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2755 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2756 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2757 !strcmp(videosink_name, "directvideosink")) {
2758 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2759 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2761 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2766 MMCAM_LOG_ERROR("Videosink element is null");
2772 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2775 _MMCamcorderSubContext *sc = NULL;
2777 mmf_camcorder_t *hcamcorder = NULL;
2779 hcamcorder = MMF_CAMCORDER(handle);
2780 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2782 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2784 MMCAM_LOG_INFO("sub context is not initialized");
2788 mm_camcorder_get_attributes(handle, NULL,
2789 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2790 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2791 MMCAM_CAMERA_FPS, &fps,
2794 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2796 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2797 sc->info_video->preview_width, sc->info_video->preview_height,
2798 fps, videosrc_rotate);
2802 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2808 unsigned int caps_fourcc = 0;
2809 gboolean do_set_caps = FALSE;
2810 GstCaps *caps = NULL;
2812 mmf_camcorder_t *hcamcorder = NULL;
2813 _MMCamcorderSubContext *sc = NULL;
2815 hcamcorder = MMF_CAMCORDER(handle);
2816 mmf_return_val_if_fail(hcamcorder, FALSE);
2818 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2820 if (!sc || !(sc->element)) {
2821 MMCAM_LOG_INFO("sub context is not initialized");
2825 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2826 MMCAM_LOG_ERROR("Video src is NULL!");
2830 if (!sc->element[_MMCAMCORDER_VIDEOSRC_CAPS].gst) {
2831 MMCAM_LOG_ERROR("Video capsfilter is NULL!");
2835 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2836 int capture_width = 0;
2837 int capture_height = 0;
2838 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2840 mm_camcorder_get_attributes(handle, NULL,
2841 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2842 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2843 MMCAM_CAPTURE_WIDTH, &capture_width,
2844 MMCAM_CAPTURE_HEIGHT, &capture_height,
2845 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2846 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2848 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2849 motion_rate, capture_width, capture_height, fps_auto,
2850 sc->info_video->video_width, sc->info_video->video_height);
2852 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2853 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2855 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2856 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2857 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2860 sc->info_video->fps = fps;
2863 /* Interleaved format does not support rotation */
2864 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2865 /* store videosrc rotation */
2866 sc->videosrc_rotate = rotate;
2868 /* Define width, height and rotate in caps */
2870 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2871 This will be applied when rotate is 0, 180 if front camera. */
2872 set_rotate = rotate * 90;
2874 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2875 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2878 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2879 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2886 set_height = height;
2889 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2892 set_height = height;
2894 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2897 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_CAPS].gst, "caps", &caps);
2898 if (caps && !gst_caps_is_any(caps)) {
2899 GstStructure *structure = NULL;
2901 structure = gst_caps_get_structure(caps, 0);
2904 int caps_height = 0;
2907 int caps_rotate = 0;
2909 caps_fourcc = _mmcamcorder_get_structure_fourcc(structure);
2911 gst_structure_get(structure,
2912 "width", G_TYPE_INT, &caps_width,
2913 "height", G_TYPE_INT, &caps_height,
2914 "framerate", GST_TYPE_FRACTION, &caps_fps_n, &caps_fps_d,
2915 "rotate", G_TYPE_INT, &caps_rotate,
2918 #ifdef _MMCAMCORDER_PRODUCT_TV
2919 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2920 if (set_width == caps_width && set_height == caps_height &&
2921 set_rotate == caps_rotate && fps == caps_fps_n) {
2922 MMCAM_LOG_INFO("No need to replace caps.");
2924 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]",
2925 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2926 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2927 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2928 set_width, set_height, fps, set_rotate);
2932 if (set_width == caps_width && set_height == caps_height &&
2933 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2934 MMCAM_LOG_INFO("No need to replace caps.");
2936 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]",
2937 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2938 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2939 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2940 set_width, set_height, fps, set_rotate);
2944 #else /*_MMCAMCORDER_PRODUCT_TV */
2945 if (set_width == caps_width && set_height == caps_height &&
2946 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2947 MMCAM_LOG_INFO("No need to replace caps.");
2949 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]",
2950 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2951 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2952 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2953 set_width, set_height, fps, set_rotate);
2956 #endif /*_MMCAMCORDER_PRODUCT_TV */
2958 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2962 MMCAM_LOG_INFO("No caps. set new one...");
2967 gst_caps_unref(caps);
2969 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2970 /* assume that it's camera capture mode */
2971 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2977 caps = _mmcamcorder_get_video_caps(handle,
2978 sc->info_image->preview_format, set_width, set_height, fps, set_rotate);
2980 MMCAM_LOG_ERROR("There are no caps");
2984 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_CAPS].gst, "caps", caps);
2985 gst_caps_unref(caps);
2991 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2993 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2994 _MMCamcorderSubContext *sc = NULL;
2996 mmf_return_val_if_fail(hcamcorder, FALSE);
2998 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3002 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
3004 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
3008 /* Interleaved format does not support FLIP */
3009 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
3010 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
3011 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
3013 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
3015 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
3016 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
3018 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
3022 MMCAM_LOG_WARNING("element is NULL");
3030 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
3032 GstCameraControl *control = NULL;
3033 _MMCamcorderSubContext *sc = NULL;
3034 GstElement *v_src = NULL;
3038 mmf_return_val_if_fail(handle, FALSE);
3040 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3044 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
3047 MMCAM_LOG_WARNING("videosrc element is NULL");
3051 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
3053 /* set anti-shake with camera control */
3054 if (!GST_IS_CAMERA_CONTROL(v_src)) {
3055 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
3059 control = GST_CAMERA_CONTROL(v_src);
3060 if (gst_camera_control_set_ahs(control, set_value)) {
3061 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
3064 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
3071 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
3073 _MMCamcorderSubContext *sc = NULL;
3074 GstElement *v_src = NULL;
3076 mmf_return_val_if_fail(handle, FALSE);
3078 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3082 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
3084 MMCAM_LOG_WARNING("videosrc element is NULL");
3088 /* check property of videosrc element - support VDIS */
3089 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
3090 int video_width = 0;
3091 int video_height = 0;
3093 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
3094 MMCAM_LOG_INFO("ENABLE video stabilization");
3096 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
3097 mm_camcorder_get_attributes(handle, NULL,
3098 MMCAM_VIDEO_WIDTH, &video_width,
3099 MMCAM_VIDEO_HEIGHT, &video_height,
3102 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
3103 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
3104 video_width, video_height);
3106 g_object_set(G_OBJECT(v_src),
3107 "enable-vdis-mode", TRUE,
3110 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
3111 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
3112 video_width, video_height);
3117 g_object_set(G_OBJECT(v_src),
3118 "enable-vdis-mode", FALSE,
3121 MMCAM_LOG_INFO("DISABLE video stabilization");
3123 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
3124 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
3127 MMCAM_LOG_WARNING("no property for video stabilization");
3134 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
3138 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3139 _MMCamcorderSubContext *sc = NULL;
3141 mmf_return_val_if_fail(hcamcorder, FALSE);
3143 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3147 mm_camcorder_get_attributes(handle, NULL,
3148 MMCAM_CAMERA_FPS, &fps,
3151 MMCAM_LOG_INFO("set %dx%d", width, height);
3153 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
3157 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
3159 _MMCamcorderSubContext *sc = NULL;
3161 if ((void *)handle == NULL) {
3162 MMCAM_LOG_WARNING("handle is NULL");
3166 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3168 MMCAM_LOG_WARNING("subcontext is NULL");
3172 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3173 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3177 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
3179 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
3185 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
3187 _MMCamcorderSubContext *sc = NULL;
3189 if ((void *)handle == NULL) {
3190 MMCAM_LOG_WARNING("handle is NULL");
3194 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3196 MMCAM_LOG_WARNING("subcontext is NULL");
3200 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3201 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3205 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
3207 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3213 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3215 GstStructure *props = NULL;
3216 char stream_props[64] = {'\0',};
3218 if (element == NULL || stream_type == NULL || stream_index < 0) {
3219 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3223 snprintf(stream_props, sizeof(stream_props) - 1,
3224 "props,media.role=%s, media.parent_id=%d",
3225 stream_type, stream_index);
3227 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3229 props = gst_structure_from_string(stream_props, NULL);
3231 MMCAM_LOG_ERROR("failed to create GstStructure");
3235 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3237 gst_structure_free(props);
3243 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3245 int ret = MM_ERROR_NONE;
3246 _MMCamcorderSubContext *sc = NULL;
3247 mmf_camcorder_t *hcamcorder = NULL;
3248 const char *videodecoder_name = NULL;
3249 char videodecoder_name_final[32] = {'\0',};
3250 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3251 #ifdef _MMCAMCORDER_RM_SUPPORT
3252 int decoder_index = 0;
3253 #endif /* _MMCAMCORDER_RM_SUPPORT */
3255 if ((void *)handle == NULL) {
3256 MMCAM_LOG_WARNING("handle is NULL");
3260 hcamcorder = MMF_CAMCORDER(handle);
3262 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3264 MMCAM_LOG_WARNING("subcontext is NULL");
3268 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3269 hcamcorder->recreate_decoder == FALSE) {
3270 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3271 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3275 mm_camcorder_get_attributes(handle, NULL,
3276 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3279 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3280 MMCAM_LOG_INFO("no need to control decoder element");
3284 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3285 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3286 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3290 MMCAM_LOG_INFO("start");
3292 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
3293 if (videodecoder_name == NULL) {
3294 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
3298 /* set state as NULL */
3299 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3300 if (ret != MM_ERROR_NONE) {
3301 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3305 /* remove decoder - pads will be unlinked automatically in remove function */
3306 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3307 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3308 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3312 /* check decoder element */
3313 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3314 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3315 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3316 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3319 #ifdef _MMCAMCORDER_RM_SUPPORT
3320 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3321 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3324 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
3325 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
3327 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3328 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
3330 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
3332 #endif /* _MMCAMCORDER_RM_SUPPORT */
3333 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
3334 #ifdef _MMCAMCORDER_RM_SUPPORT
3336 #endif /* _MMCAMCORDER_RM_SUPPORT */
3338 /* create decoder */
3339 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "vsrc_dec");
3340 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3341 MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
3345 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
3347 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3348 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3349 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3351 /* add to pipeline */
3352 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3353 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3354 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3355 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3360 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3361 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3362 MMCAM_LOG_INFO("Link vsrc_q to decoder OK");
3364 MMCAM_LOG_ERROR("Link vsrc_q to decoder FAILED");
3368 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3369 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3370 MMCAM_LOG_INFO("Link decoder to vsink_q OK");
3372 MMCAM_LOG_ERROR("Link decoder to vsink_q FAILED");
3376 /* set state READY */
3377 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3378 if (ret != MM_ERROR_NONE) {
3379 MMCAM_LOG_ERROR("failed to set READY to decoder");
3383 MMCAM_LOG_INFO("done");
3389 int _mmcamcorder_set_video_stream_callback_flag(MMHandleType handle, gboolean enable, int flag)
3391 int ret = MM_ERROR_NONE;
3392 int flag_current = MM_CAMCORDER_VIDEO_STREAM_CALLBACK_FLAG_NONE;
3393 int flag_new = MM_CAMCORDER_VIDEO_STREAM_CALLBACK_FLAG_NONE;
3395 MMCAM_LOG_INFO("enable[%d], flag[0x%08x]", enable, flag);
3397 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK_FLAG(handle);
3399 ret = mm_camcorder_get_attributes(handle, NULL,
3400 MMCAM_VIDEO_STREAM_CALLBACK_FLAG, &flag_current,
3402 if (ret != MM_ERROR_NONE) {
3403 MMCAM_LOG_ERROR("get vstream callback flag failed[0x%x]", ret);
3404 goto _SET_VIDEO_STREAM_CALLBACK_FLAG_DONE;
3407 MMCAM_LOG_INFO("current flag[0x%08x]", flag_current);
3410 flag_new = flag_current | flag;
3412 flag_new = flag_current & ~flag;
3414 ret = mm_camcorder_set_attributes(handle, NULL,
3415 MMCAM_VIDEO_STREAM_CALLBACK_FLAG, flag_new,
3417 if (ret != MM_ERROR_NONE) {
3418 MMCAM_LOG_ERROR("set vstream callback flag[0x%x] failed[0x%x]", flag_new, ret);
3419 goto _SET_VIDEO_STREAM_CALLBACK_FLAG_DONE;
3422 MMCAM_LOG_INFO("new flag[0x%08x]", flag_new);
3424 _SET_VIDEO_STREAM_CALLBACK_FLAG_DONE:
3425 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK_FLAG(handle);
3431 #ifdef _MMCAMCORDER_PRODUCT_TV
3432 bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3434 _MMCamcorderSubContext *sc = NULL;
3435 mmf_camcorder_t *hcamcorder = NULL;
3437 const gchar *mime = NULL;
3439 GstCaps *decsink_caps = NULL;
3440 GstStructure *decsink_struct = NULL;
3442 mmf_return_val_if_fail(handle, false);
3443 mmf_return_val_if_fail(max_width, false);
3444 mmf_return_val_if_fail(max_height, false);
3446 hcamcorder = MMF_CAMCORDER(handle);
3447 mmf_return_val_if_fail(hcamcorder, false);
3449 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3451 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3453 MMCAM_LOG_ERROR("There are no decoder caps");
3457 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3458 if (!decsink_caps) {
3459 gst_object_unref(sinkpad);
3460 MMCAM_LOG_ERROR("There is no decoder sink caps");
3464 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3465 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3466 if (!decsink_struct) {
3467 MMCAM_LOG_ERROR("There are no structure from caps");
3468 gst_object_unref(decsink_caps);
3469 gst_object_unref(sinkpad);
3472 mime = gst_structure_get_name(decsink_struct);
3473 if (!strcmp(mime, "video/x-h264")) {
3474 MMCAM_LOG_INFO("h264 caps structure found");
3475 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3476 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3477 if (gst_structure_has_field(decsink_struct, "maxheight"))
3478 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3480 } else if (!strcmp(mime, "video/x-jpeg")) {
3481 MMCAM_LOG_INFO("mjpeg caps structure found");
3482 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3483 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3484 if (gst_structure_has_field(decsink_struct, "maxheight"))
3485 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3489 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3490 gst_object_unref(decsink_caps);
3491 gst_object_unref(sinkpad);
3493 if (*max_width <= 0 || *max_height <= 0)
3498 #endif /* _MMCAMCORDER_PRODUCT_TV */