4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 =======================================================================================*/
25 #include <gst/allocators/gsttizenmemory.h>
26 #include <gst/audio/audio-format.h>
27 #include <gst/video/videooverlay.h>
31 #include <tbm_bufmgr.h>
32 #include <tbm_surface.h>
33 #include <tbm_surface_internal.h>
35 #include "mm_camcorder_internal.h"
36 #include "mm_camcorder_gstcommon.h"
38 /*-----------------------------------------------------------------------
39 | GLOBAL VARIABLE DEFINITIONS for internal |
40 -----------------------------------------------------------------------*/
41 /* Table for compatibility between audio codec and file format */
42 static gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
43 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
44 /*AMR*/ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
45 /*G723.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
46 /*MP3*/ { 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
47 /*OGG*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
48 /*AAC*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
49 /*WMA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
50 /*MMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 /*ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
52 /*WAVE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
53 /*WAVE_NEW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
54 /*MIDI*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
55 /*IMELODY*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
56 /*MXMF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
57 /*MPA*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
58 /*MP2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
59 /*G711*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
60 /*G722*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
61 /*G722.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
62 /*G722.2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
63 /*G723*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
64 /*G726*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
65 /*G728*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
66 /*G729*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
67 /*G729A*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
68 /*G729.1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
69 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
70 /*AAC_LC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
71 /*AAC_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
72 /*AAC_SRS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
73 /*AAC_LTP*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
74 /*AAC_HE_V1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
75 /*AAC_HE_V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
76 /*AC3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
77 /*ALAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
78 /*ATRAC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
79 /*SPEEX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
80 /*VORBIS*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
81 /*AIFF*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
82 /*AU*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
83 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
84 /*PCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
85 /*ALAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 /*MULAW*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 /*MS_ADPCM*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
90 /* Table for compatibility between video codec and file format */
91 static gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
92 /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
93 /*NONE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
94 /*H263*/ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
95 /*H264*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
96 /*H26L*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
97 /*MPEG4*/ { 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
98 /*MPEG1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
99 /*WMV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
100 /*DIVX*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
101 /*XVID*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
102 /*H261*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
103 /*H262*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
104 /*H263V2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
105 /*H263V3*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
106 /*MJPEG*/ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
107 /*MPEG2*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
108 /*MPEG4_SIMPLE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
109 /*MPEG4_ADV*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
110 /*MPEG4_MAIN*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
111 /*MPEG4_CORE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
112 /*MPEG4_ACE*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
113 /*MPEG4_ARTS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
114 /*MPEG4_AVC*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
115 /*REAL*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
116 /*VC1*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
117 /*AVS*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
118 /*CINEPAK*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
119 /*INDEO*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
120 /*THEORA*/ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
124 /*-----------------------------------------------------------------------
125 | LOCAL VARIABLE DEFINITIONS for internal |
126 -----------------------------------------------------------------------*/
127 #define USE_AUDIO_CLOCK_TUNE
128 #define _MMCAMCORDER_WAIT_EOS_TIME 60.0 /* sec */
129 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM 6
130 #define _MMCAMCORDER_NANOSEC_PER_1SEC 1000000000
131 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC 1000
132 #define _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG "request-codec-config"
135 /*-----------------------------------------------------------------------
136 | LOCAL FUNCTION PROTOTYPES: |
137 -----------------------------------------------------------------------*/
138 /* STATIC INTERNAL FUNCTION */
140 * These are video data probing functions.
141 * If there are pads which set probe callback by gst_pad_add_probe(),
142 * the functions will be called when data stream pass through the pad.
144 * @param[in] pad probing pad which calls this function.
145 * @param[in] buffer buffer which contains stream data.
146 * @param[in] u_data user data.
147 * @return Refer #GstPadProbeReturn in gstpad.h
149 * @see __mmcamcorder_create_preview_pipeline()
151 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
152 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
154 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
155 static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure);
157 static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
158 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory);
159 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format);
161 /*=======================================================================================
162 | FUNCTION DEFINITIONS |
163 =======================================================================================*/
164 static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
168 mmf_return_val_if_fail(buffer, FALSE);
169 mmf_return_val_if_fail(stream, FALSE);
170 mmf_return_val_if_fail(map_info, FALSE);
172 stream->length_total = map_info->size;
174 switch (stream->format) {
175 case MM_PIXEL_FORMAT_NV12: /* fall through */
176 case MM_PIXEL_FORMAT_NV21:
177 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
178 stream->data.yuv420sp.y = map_info->data;
179 stream->data.yuv420sp.length_y = stream->width * stream->height;
180 stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
181 stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
182 stream->stride[0] = stream->width;
183 stream->elevation[0] = stream->height;
184 stream->stride[1] = stream->width;
185 stream->elevation[1] = stream->height >> 1;
186 stream->num_planes = 2;
189 case MM_PIXEL_FORMAT_I420:
190 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
191 stream->data.yuv420p.y = map_info->data;
192 stream->data.yuv420p.length_y = stream->width * stream->height;
193 stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
194 stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
195 stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
196 stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
197 stream->stride[0] = stream->width;
198 stream->elevation[0] = stream->height;
199 stream->stride[1] = stream->stride[2] = stream->width >> 1;
200 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
201 stream->num_planes = 3;
204 case MM_PIXEL_FORMAT_422P:
205 stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
206 stream->data.yuv422p.y = map_info->data;
207 stream->data.yuv422p.length_y = stream->width * stream->height;
208 stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
209 stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
210 stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
211 stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
212 stream->stride[0] = stream->width;
213 stream->elevation[0] = stream->height;
214 stream->stride[1] = stream->stride[2] = stream->width;
215 stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
216 stream->num_planes = 3;
219 case MM_PIXEL_FORMAT_YUYV: /* fall through */
220 case MM_PIXEL_FORMAT_UYVY: /* fall through */
221 case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
222 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
223 stream->data.yuv422.yuv = map_info->data;
224 stream->data.yuv422.length_yuv = stream->length_total;
225 stream->stride[0] = stream->width << 1;
226 stream->elevation[0] = stream->height;
227 stream->num_planes = 1;
230 case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
231 case MM_PIXEL_FORMAT_ENCODED_MJPEG: /* fall through */
232 case MM_PIXEL_FORMAT_ENCODED_VP8: /* fall through */
233 case MM_PIXEL_FORMAT_ENCODED_VP9: /* fall through */
234 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
235 stream->data.encoded.data = map_info->data;
236 stream->data.encoded.length_data = stream->length_total;
237 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
238 stream->data.encoded.is_header_included = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_HEADER);
239 stream->num_planes = 1;
242 case MM_PIXEL_FORMAT_INVZ:
243 stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
244 stream->data.depth.data = map_info->data;
245 stream->data.depth.length_data = stream->length_total;
246 stream->stride[0] = stream->width << 1;
247 stream->elevation[0] = stream->height;
248 stream->num_planes = 1;
251 case MM_PIXEL_FORMAT_RGBA: /* fall through */
252 case MM_PIXEL_FORMAT_ARGB:
253 stream->data_type = MM_CAM_STREAM_DATA_RGB;
254 stream->data.rgb.data = map_info->data;
255 stream->data.rgb.length_data = stream->length_total;
256 stream->stride[0] = stream->width << 2;
257 stream->elevation[0] = stream->height;
258 stream->num_planes = 1;
262 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
271 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory)
275 int tbm_ret = TBM_SURFACE_ERROR_NONE;
276 tbm_bo_handle bo_handle = {NULL, };
277 tbm_surface_info_s ts_info;
279 mmf_return_val_if_fail(stream, FALSE);
280 mmf_return_val_if_fail(buffer, FALSE);
281 mmf_return_val_if_fail(memory, FALSE);
283 if (_mmcamcorder_is_encoded_preview_pixel_format(stream->format)) {
284 stream->bo[0] = gst_tizen_memory_get_bos(memory, 0);
286 bo_handle = tbm_bo_get_handle(stream->bo[0], TBM_DEVICE_CPU);
287 if (!bo_handle.ptr) {
288 MMCAM_LOG_ERROR("tbm_bo_get_handle failed[bo:%p,memory:%p]", stream->bo[0], memory);
292 stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
293 stream->num_planes = 1;
294 stream->stride[0] = stream->width;
295 stream->elevation[0] = stream->height;
296 stream->data.encoded.data = bo_handle.ptr;
297 stream->length_total = gst_memory_get_sizes(memory, NULL, NULL);
298 stream->data.encoded.length_data = stream->length_total;
299 stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
300 stream->data.encoded.is_header_included = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_HEADER);
302 MMCAM_LOG_VERBOSE("[ENCODED] length[%u], is_delta[%d], is_header_included[%d]",
303 stream->data.encoded.length_data,
304 stream->data.encoded.is_delta_frame,
305 stream->data.encoded.is_header_included);
310 memset(&ts_info, 0x0, sizeof(tbm_surface_info_s));
312 tbm_ret = tbm_surface_get_info((tbm_surface_h)gst_tizen_memory_get_surface(memory), &ts_info);
313 if (tbm_ret != TBM_SURFACE_ERROR_NONE) {
314 MMCAM_LOG_ERROR("get tbm surface info failed[0x%x]", tbm_ret);
318 stream->length_total = ts_info.size;
319 for (i = 0 ; i < ts_info.num_planes ; i++) {
320 stream->stride[i] = ts_info.planes[i].stride;
321 stream->elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
322 MMCAM_LOG_VERBOSE(" plane[%d] %dx%d", i, stream->stride[i], stream->elevation[i]);
325 num_bos = gst_tizen_memory_get_num_bos(memory);
326 for (i = 0 ; i < num_bos ; i++)
327 stream->bo[i] = gst_tizen_memory_get_bos(memory, i);
330 switch (stream->format) {
331 case MM_PIXEL_FORMAT_NV12: /* fall through */
332 case MM_PIXEL_FORMAT_NV21:
333 stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
334 stream->num_planes = 2;
335 stream->data.yuv420sp.y = ts_info.planes[0].ptr;
336 stream->data.yuv420sp.length_y = ts_info.planes[0].size;
337 stream->data.yuv420sp.uv = ts_info.planes[1].ptr;
338 stream->data.yuv420sp.length_uv = ts_info.planes[1].size;
340 MMCAM_LOG_VERBOSE("[420SP] 0[%p,%u], 1[%p,%u]",
341 stream->data.yuv420sp.y, stream->data.yuv420sp.length_y,
342 stream->data.yuv420sp.uv, stream->data.yuv420sp.length_uv);
345 case MM_PIXEL_FORMAT_I420:
346 stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
347 stream->num_planes = 3;
348 stream->data.yuv420p.y = ts_info.planes[0].ptr;
349 stream->data.yuv420p.length_y = ts_info.planes[0].size;
350 stream->data.yuv420p.u = ts_info.planes[1].ptr;
351 stream->data.yuv420p.length_u = ts_info.planes[1].size;
352 stream->data.yuv420p.v = ts_info.planes[2].ptr;
353 stream->data.yuv420p.length_v = ts_info.planes[2].size;
355 MMCAM_LOG_VERBOSE("[I420] 0[%p,%u], 1[%p,%u], 2[%p,%u]",
356 stream->data.yuv420p.y, stream->data.yuv420p.length_y,
357 stream->data.yuv420p.u, stream->data.yuv420p.length_u,
358 stream->data.yuv420p.v, stream->data.yuv420p.length_v);
361 case MM_PIXEL_FORMAT_YUYV:
362 stream->data_type = MM_CAM_STREAM_DATA_YUV422;
363 stream->num_planes = 1;
364 stream->data.yuv422.yuv = ts_info.planes[0].ptr;
365 stream->data.yuv422.length_yuv = ts_info.planes[0].size;
367 MMCAM_LOG_VERBOSE("[YUYV] 0[%p,%u]",
368 stream->data.yuv422.yuv, stream->data.yuv422.length_yuv);
372 MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
380 static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format)
383 case MM_PIXEL_FORMAT_ENCODED_H264:
385 case MM_PIXEL_FORMAT_ENCODED_VP9:
388 MMCAM_LOG_WARNING("unsupported format[%d]", format);
394 int _mmcamcorder_request_codec_config(GstElement *videosrc_element)
396 if (!videosrc_element || !G_TYPE_CHECK_INSTANCE(videosrc_element)) {
397 MMCAM_LOG_WARNING("invalid videosrc element[%p]", videosrc_element);
398 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
401 if (!g_signal_parse_name(_MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG,
402 G_TYPE_FROM_INSTANCE(videosrc_element), NULL, NULL, FALSE)) {
403 MMCAM_LOG_WARNING("no signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
404 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
407 MMCAM_LOG_INFO("emit signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
409 g_signal_emit_by_name(videosrc_element, _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
411 return MM_ERROR_NONE;
415 gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sample, gboolean is_preview, int stream_id)
418 gboolean ret_cb = TRUE;
419 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
420 _MMCamcorderSubContext *sc = NULL;
421 MMCamcorderVideoStreamDataType stream;
423 GstBuffer *buffer = NULL;
424 GstMemory *memory = NULL;
426 GstCaps *caps = NULL;
427 GstStructure *structure = NULL;
429 mmf_return_val_if_fail(hcamcorder, FALSE);
431 buffer = gst_sample_get_buffer(sample);
432 mmf_return_val_if_fail(buffer, FALSE);
433 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
435 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
436 mmf_return_val_if_fail(sc, FALSE);
438 memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
440 caps = gst_sample_get_caps(sample);
441 mmf_return_val_if_fail(caps, FALSE);
443 structure = gst_caps_get_structure(caps, 0);
444 mmf_return_val_if_fail(structure, FALSE);
446 stream.format = _mmcamcorder_get_pixel_format(caps, TRUE);
447 gst_structure_get(structure,
448 "width", G_TYPE_INT, &stream.width,
449 "height", G_TYPE_INT, &stream.height,
452 memory = gst_buffer_peek_memory(buffer, 0);
454 MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
458 structure = gst_mini_object_get_qdata(GST_MINI_OBJECT_CAST(buffer), hcamcorder->buffer_quark);
459 if (structure && gst_structure_has_field(structure, "focus-state")) {
460 gst_structure_get(structure,
461 "focus-state", G_TYPE_INT, &stream.focus_state,
462 "facing-direction", G_TYPE_INT, &stream.facing_direction,
463 "flip", G_TYPE_INT, &stream.flip,
464 "rotation", G_TYPE_INT, &stream.rotation,
467 MMCAM_LOG_VERBOSE("structure[%p], [fs:%d,fd:%d,f:%d,r:%d]", structure,
468 stream.focus_state, stream.facing_direction, stream.flip, stream.rotation);
471 if (gst_is_tizen_memory(memory)) {
472 if (!__mmcamcorder_set_stream_data_zero_copy(&stream, buffer, memory))
473 goto _INVOKE_VIDEO_STREAM_CB_DONE;
475 memset(&map_info, 0x0, sizeof(GstMapInfo));
477 if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE)) {
478 MMCAM_LOG_ERROR("map failed for memory[%p]", memory);
482 if (!__mmcamcorder_set_stream_data(&stream, buffer, &map_info))
483 goto _INVOKE_VIDEO_STREAM_CB_DONE;
486 MMCAM_LOG_DEBUG("VideoStreamData : format[%d], resolution[%dx%d], stream_id[%d]",
487 stream.format, stream.width, stream.height, stream_id);
489 stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
490 stream.extra_stream_id = stream_id;
491 stream.internal_buffer = buffer;
493 /* invoke application callback */
495 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
496 if (hcamcorder->vstream_cb)
497 hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
498 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
500 _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
501 if (hcamcorder->vedecision_cb)
502 ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
503 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
506 _INVOKE_VIDEO_STREAM_CB_DONE:
507 if (!gst_is_tizen_memory(memory))
508 gst_memory_unmap(memory, &map_info);
510 for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
511 tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
512 tbm_bo_unmap(stream.bo[i]);
519 int _mmcamcorder_create_preview_elements(MMHandleType handle)
521 int err = MM_ERROR_NONE;
523 int camera_rotate = 0;
527 int capture_width = 0;
528 int capture_height = 0;
529 int capture_quality = 0;
530 int video_stabilization = 0;
532 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
533 const char *videosrc_name = NULL;
534 const char *videosink_name = NULL;
535 const char *videoconvert_name = NULL;
536 const char *videodecoder_name = NULL;
537 const char *videoparse_name = NULL;
538 const char *decoder_conf_name = NULL;
539 char videodecoder_name_final[32] = {'\0',};
540 char *err_name = NULL;
541 #ifdef _MMCAMCORDER_RM_SUPPORT
542 int decoder_index = 0;
543 #endif /* _MMCAMCORDER_RM_SUPPORT */
544 GstElement *sink_element = NULL;
545 GstCameraControl *control = NULL;
546 int sink_element_size = 0;
549 int extra_preview_enable = 0;
551 GList *element_list = NULL;
553 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
554 _MMCamcorderSubContext *sc = NULL;
555 type_element *videosrc_element = NULL;
556 type_int_array *input_index = NULL;
558 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
560 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
561 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
562 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
566 /* Check existence */
567 for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
568 if (sc->element[i].gst) {
569 if (((GObject *)sc->element[i].gst)->ref_count > 0)
570 gst_object_unref(sc->element[i].gst);
572 MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
576 /* Get video device index info */
577 _mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl,
578 CONFIGURE_CATEGORY_CTRL_CAMERA,
581 if (input_index == NULL) {
582 MMCAM_LOG_ERROR("Failed to get input_index");
583 return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
586 err = mm_camcorder_get_attributes(handle, &err_name,
587 MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
588 MMCAM_CAMERA_FPS, &fps,
589 MMCAM_CAMERA_ROTATION, &camera_rotate,
590 MMCAM_CAMERA_FLIP, &camera_flip,
591 MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
592 MMCAM_CAMERA_ANTI_HANDSHAKE, &anti_shake,
593 MMCAM_CAPTURE_WIDTH, &capture_width,
594 MMCAM_CAPTURE_HEIGHT, &capture_height,
595 MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
596 MMCAM_IMAGE_ENCODER, &codectype,
597 MMCAM_IMAGE_ENCODER_QUALITY, &capture_quality,
598 MMCAM_DISPLAY_SURFACE, &display_surface_type,
599 MMCAM_EXTRA_PREVIEW_ENABLE, &extra_preview_enable,
601 if (err != MM_ERROR_NONE) {
602 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
607 if (hcamcorder->support_user_buffer) {
608 err = mm_camcorder_get_attributes(handle, NULL,
609 MMCAM_USER_BUFFER_FD, &fds, &fd_number,
611 if (err != MM_ERROR_NONE || fd_number < 1) {
612 MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
617 for (i = 0 ; i < fd_number ; i++)
618 MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
622 /* Get fourcc from picture format */
623 sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
625 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
626 hcamcorder->conf_ctrl, CONFIGURE_CATEGORY_CTRL_CAMERA, "AltVideosrcElement",
627 &videosrc_element, &videosrc_name);
629 /* Skip getting "VideosrcElement" if alternative element exists. */
630 if (videosrc_name == NULL) {
631 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
632 hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
633 &videosrc_element, &videosrc_name);
637 * Create child element
639 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err);
641 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
644 * This is for "tizencamerasrc" element only.
645 * The camera HAL library will be loaded when "hal-name" property is set.
646 * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
648 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
650 /* camera properties */
651 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
652 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
653 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
654 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-quality", capture_quality);
655 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
656 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "extra-preview", extra_preview_enable);
657 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
659 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
661 /* set camera flip */
662 _mmcamcorder_set_videosrc_flip(handle, camera_flip);
664 /* set video stabilization mode */
665 _mmcamcorder_set_videosrc_stabilization(handle, video_stabilization);
667 /* set anti handshake mode */
668 _mmcamcorder_set_videosrc_anti_shake(handle, anti_shake);
670 if (sc->is_modified_rate)
671 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
673 /* Set basic information of videosrc element */
674 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, videosrc_element);
676 /* Set video device index */
677 if (hcamcorder->is_network) {
678 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
680 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
681 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
683 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
687 /* set user buffer fd to videosrc element */
688 if (hcamcorder->support_user_buffer) {
689 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
690 if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
691 MMCAM_LOG_ERROR("set user buffer fd failed");
692 goto pipeline_creation_error;
696 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
697 /* get recreate_decoder flag */
698 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
699 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
701 &hcamcorder->recreate_decoder);
704 if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
705 _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
706 switch (sc->info_image->preview_format) {
707 case MM_PIXEL_FORMAT_ENCODED_H264:
708 decoder_conf_name = "VideodecoderElementH264";
710 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
711 decoder_conf_name = "VideodecoderElementMJPEG";
713 case MM_PIXEL_FORMAT_ENCODED_VP8:
714 decoder_conf_name = "VideodecoderElementVP8";
716 case MM_PIXEL_FORMAT_ENCODED_VP9:
717 decoder_conf_name = "VideodecoderElementVP9";
720 MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
721 goto pipeline_creation_error;
724 /* get video decoder element and name */
725 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
726 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
728 &sc->VideodecoderElement);
730 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
733 if (!videodecoder_name) {
734 MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
735 goto pipeline_creation_error;
738 #ifdef _MMCAMCORDER_RM_SUPPORT
739 MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
740 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
741 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
743 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
744 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
745 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
746 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
748 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
750 #endif /* _MMCAMCORDER_RM_SUPPORT */
751 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
752 #ifdef _MMCAMCORDER_RM_SUPPORT
754 #endif /* _MMCAMCORDER_RM_SUPPORT */
756 videoparse_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
758 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_PARSE, videoparse_name, "videosrc_parse", element_list, err);
760 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
762 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
765 MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
767 /* Get videosink name */
768 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
770 if (!videosink_name) {
771 MMCAM_LOG_ERROR("failed to get videosink name");
772 goto pipeline_creation_error;
775 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
777 MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
779 if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
780 /* get video convert name */
781 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
783 if (videoconvert_name) {
784 MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
785 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
787 MMCAM_LOG_ERROR("failed to get videoconvert element name");
790 /* check sink element in attribute */
791 mm_camcorder_get_attributes(handle, NULL,
792 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
797 MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
799 MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
801 _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
803 /* reset attribute */
805 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
806 mm_attrs_set_data(attrs, attr_index, NULL, 0);
807 mm_attrs_commit(attrs, attr_index);
809 MMCAM_LOG_WARNING("attribute is NULL");
810 err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
811 goto pipeline_creation_error;
814 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
816 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
819 if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
820 MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
821 err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
822 goto pipeline_creation_error;
825 /* Set caps by rotation */
826 _mmcamcorder_set_videosrc_rotation(handle, camera_rotate);
828 /* add elements to main pipeline */
829 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
830 MMCAM_LOG_ERROR("element_list add error.");
831 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
832 goto pipeline_creation_error;
836 if (!_mmcamcorder_link_elements(element_list)) {
837 MMCAM_LOG_ERROR("element link error.");
838 err = MM_ERROR_CAMCORDER_GST_LINK;
839 goto pipeline_creation_error;
843 g_list_free(element_list);
847 return MM_ERROR_NONE;
849 pipeline_creation_error:
850 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
851 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
852 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
853 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_FILT);
854 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_SINK);
855 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
856 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
857 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
860 g_list_free(element_list);
868 int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
870 int err = MM_ERROR_NONE;
875 int a_enc = MM_AUDIO_CODEC_AMR;
876 int a_dev = MM_AUDIO_DEVICE_MIC;
878 char *err_name = NULL;
879 const char *audiosrc_name = NULL;
880 char *cat_name = NULL;
881 char *stream_type = NULL;
882 int stream_type_len = 0;
883 int stream_index = 0;
884 int buffer_interval = 0;
886 int replay_gain_enable = FALSE;
887 double replay_gain_ref_level = 0.0;
889 GstCaps *caps = NULL;
891 GList *element_list = NULL;
893 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
894 _MMCamcorderSubContext *sc = NULL;
895 _MMCamcorderGstElement *last_element = NULL;
896 type_element *audiosrc_element = NULL;
898 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
900 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
901 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
902 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
906 err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
907 if (err != MM_ERROR_NONE)
910 err = mm_camcorder_get_attributes(handle, &err_name,
911 MMCAM_AUDIO_DEVICE, &a_dev,
912 MMCAM_AUDIO_ENCODER, &a_enc,
913 MMCAM_AUDIO_ENCODER_BITRATE, &val,
914 MMCAM_AUDIO_SAMPLERATE, &rate,
915 MMCAM_AUDIO_FORMAT, &format,
916 MMCAM_AUDIO_CHANNEL, &channel,
917 MMCAM_AUDIO_VOLUME, &volume,
918 MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable,
919 MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level,
920 MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
921 MMCAM_SOUND_STREAM_INDEX, &stream_index,
923 if (err != MM_ERROR_NONE) {
924 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
929 /* Check existence */
930 if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst) {
931 if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
932 gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
934 MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
937 /* Create bin element */
938 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN, "audiosource_bin", err);
940 if (a_dev == MM_AUDIO_DEVICE_MODEM) {
941 cat_name = strdup("AudiomodemsrcElement");
943 /* MM_AUDIO_DEVICE_MIC or others */
944 cat_name = strdup("AudiosrcElement");
947 if (cat_name == NULL) {
948 MMCAM_LOG_ERROR("strdup failed.");
949 err = MM_ERROR_CAMCORDER_LOW_MEMORY;
950 goto pipeline_creation_error;
953 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
954 hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, cat_name,
955 &audiosrc_element, &audiosrc_name);
960 MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
962 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
964 /* set sound stream info */
965 _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
967 /* set audiosrc properties in ini configuration */
968 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, audiosrc_element);
971 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
972 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
973 "AudioBufferInterval",
976 if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
977 MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
978 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
981 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
983 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE, "queue", "audiosrc_queue", element_list, err);
984 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-buffers", 0);
985 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
986 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
988 /* Set basic information */
989 if (a_enc != MM_AUDIO_CODEC_VORBIS) {
991 const gchar* format_name = NULL;
993 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err);
996 /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */
997 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0);
999 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "mute", FALSE);
1000 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", volume);
1003 if (format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE) {
1005 format_name = "S16LE";
1006 } else { /* MM_CAMCORDER_AUDIO_FORMAT_PCM_U8 */
1011 caps = gst_caps_new_simple("audio/x-raw",
1012 "rate", G_TYPE_INT, rate,
1013 "channels", G_TYPE_INT, channel,
1014 "format", G_TYPE_STRING, format_name,
1016 MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
1017 rate, channel, depth, volume);
1019 /* what are the audio encoder which should get audio/x-raw-float? */
1020 caps = gst_caps_new_simple("audio/x-raw",
1021 "rate", G_TYPE_INT, rate,
1022 "channels", G_TYPE_INT, channel,
1023 "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
1025 MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
1026 rate, channel, BYTE_ORDER);
1030 MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
1031 replay_gain_enable, replay_gain_ref_level);
1033 if (replay_gain_enable) {
1034 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err);
1035 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level);
1036 /* If num-tracks is not set, album gain and peak event is not come. */
1037 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1);
1041 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps);
1042 gst_caps_unref(caps);
1045 MMCAM_LOG_ERROR("create caps error");
1046 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1047 goto pipeline_creation_error;
1050 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
1051 MMCAM_LOG_ERROR("element add error.");
1052 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1053 goto pipeline_creation_error;
1056 if (!_mmcamcorder_link_elements(element_list)) {
1057 MMCAM_LOG_ERROR("element link error.");
1058 err = MM_ERROR_CAMCORDER_GST_LINK;
1059 goto pipeline_creation_error;
1062 last_element = (_MMCamcorderGstElement*)(g_list_last(element_list)->data);
1063 pad = gst_element_get_static_pad(last_element->gst, "src");
1064 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
1065 gst_object_unref(pad);
1067 MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
1068 err = MM_ERROR_CAMCORDER_GST_LINK;
1069 goto pipeline_creation_error;
1072 gst_object_unref(pad);
1076 g_list_free(element_list);
1077 element_list = NULL;
1080 return MM_ERROR_NONE;
1082 pipeline_creation_error:
1083 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC);
1084 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT);
1085 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_QUE);
1086 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL);
1087 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_AUDIOSRC_BIN);
1090 g_list_free(element_list);
1091 element_list = NULL;
1098 void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
1103 MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
1108 MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
1109 type, codec, bitrate);
1113 if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
1114 /* audio encoder bitrate setting */
1116 case MM_AUDIO_CODEC_AMR:
1117 set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
1118 MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
1119 MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
1121 case MM_AUDIO_CODEC_MP3:
1122 set_value = bitrate / 1000;
1123 MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
1124 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
1126 case MM_AUDIO_CODEC_AAC:
1127 MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
1128 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1131 MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
1135 /* video encoder bitrate setting */
1136 MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
1137 MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
1144 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
1146 int err = MM_ERROR_NONE;
1151 int encodebin_profile = 0;
1152 int auto_audio_convert = 0;
1153 int auto_audio_resample = 0;
1154 int auto_color_space = 0;
1155 int cap_format = MM_PIXEL_FORMAT_INVALID;
1156 const char *gst_element_venc_name = NULL;
1157 const char *gst_element_aenc_name = NULL;
1158 const char *gst_element_ienc_name = NULL;
1159 const char *gst_element_mux_name = NULL;
1160 const char *gst_element_rsink_name = NULL;
1161 const char *gst_element_vscale_name = NULL;
1162 const char *str_profile = NULL;
1163 const char *str_aac = NULL;
1164 const char *str_aar = NULL;
1165 const char *str_acs = NULL;
1166 char *err_name = NULL;
1167 const char *videoconvert_name = NULL;
1168 GstCaps *audio_caps = NULL;
1169 GstCaps *video_caps = NULL;
1170 GstCaps *videoscale_caps = NULL;
1172 GList *element_list = NULL;
1174 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1175 _MMCamcorderSubContext *sc = NULL;
1176 type_element *VideoencElement = NULL;
1177 type_element *AudioencElement = NULL;
1178 type_element *ImageencElement = NULL;
1179 type_element *MuxElement = NULL;
1180 type_element *RecordsinkElement = NULL;
1181 type_element *VideoscaleElement = NULL;
1183 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1185 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1186 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1187 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1189 MMCAM_LOG_INFO("start - profile : %d", profile);
1191 /* Check existence */
1192 if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
1193 if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
1194 gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
1196 MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
1199 /* Create bin element */
1200 _MMCAMCORDER_BIN_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_BIN, "encodesink_bin", err);
1202 /* Create child element */
1203 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1204 GstCaps *caps_from_pad = NULL;
1205 char *caps_str = NULL;
1207 /* create appsrc and capsfilter */
1208 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
1210 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
1212 /* set appsrc as live source */
1213 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
1214 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
1215 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
1217 /* set capsfilter */
1218 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1219 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1220 MMCAM_LOG_INFO("get pad from videosrc_filter");
1221 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
1223 MMCAM_LOG_INFO("get pad from videosrc_que");
1224 pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1227 MMCAM_LOG_ERROR("get videosrc_que src pad failed");
1228 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1229 goto pipeline_creation_error;
1232 caps_from_pad = gst_pad_get_allowed_caps(pad);
1233 video_caps = gst_caps_copy(caps_from_pad);
1234 gst_caps_unref(caps_from_pad);
1235 caps_from_pad = NULL;
1236 gst_object_unref(pad);
1240 video_caps = gst_caps_fixate(video_caps);
1243 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
1247 MMCAM_LOG_ERROR("create recording pipeline caps failed");
1248 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1249 goto pipeline_creation_error;
1252 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1253 if (sc->info_video->use_videoscale) {
1254 gst_caps_set_simple(video_caps,
1255 "width", G_TYPE_INT, sc->info_video->preview_width,
1256 "height", G_TYPE_INT, sc->info_video->preview_height,
1258 videoscale_caps = gst_caps_copy(video_caps);
1260 gst_caps_set_simple(video_caps,
1261 "width", G_TYPE_INT, sc->info_video->video_width,
1262 "height", G_TYPE_INT, sc->info_video->video_height,
1267 caps_str = gst_caps_to_string(video_caps);
1269 MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
1274 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
1276 gst_caps_unref(video_caps);
1280 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
1281 sc->info_video->use_videoscale) {
1282 if (!videoscale_caps) {
1283 MMCAM_LOG_ERROR("no videoscale caps");
1284 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1285 goto pipeline_creation_error;
1288 gst_caps_set_simple(videoscale_caps,
1289 "width", G_TYPE_INT, sc->info_video->video_width,
1290 "height", G_TYPE_INT, sc->info_video->video_height,
1293 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1294 CONFIGURE_CATEGORY_MAIN_RECORD,
1295 "VideoscaleElement",
1296 &VideoscaleElement);
1298 if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
1299 MMCAM_LOG_ERROR("failed to get videoscale element name");
1300 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1301 goto pipeline_creation_error;
1304 caps_str = gst_caps_to_string(videoscale_caps);
1306 MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
1311 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
1312 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
1314 MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
1316 gst_caps_unref(videoscale_caps);
1317 videoscale_caps = NULL;
1320 /* release element_list, they will be placed out of encodesink bin */
1322 g_list_free(element_list);
1323 element_list = NULL;
1326 /* connect signal for ready to push buffer */
1327 MMCAMCORDER_SIGNAL_CONNECT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst,
1328 _MMCAMCORDER_HANDLER_VIDEOREC,
1330 _mmcamcorder_ready_to_encode_callback,
1334 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
1335 "tizenencodebin", "encodesink_encbin", element_list, err);
1337 /* check element availability */
1338 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1339 err = mm_camcorder_get_attributes(handle, &err_name,
1340 MMCAM_CAPTURE_FORMAT, &cap_format,
1343 err = mm_camcorder_get_attributes(handle, &err_name,
1344 MMCAM_AUDIO_ENCODER, &audio_enc,
1345 MMCAM_AUDIO_CHANNEL, &channel,
1346 MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
1347 MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
1351 if (err != MM_ERROR_NONE) {
1353 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1354 SAFE_FREE(err_name);
1356 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1359 goto pipeline_creation_error;
1362 MMCAM_LOG_INFO("Profile[%d]", profile);
1364 /* Set information */
1365 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1366 str_profile = "VideoProfile";
1367 str_aac = "VideoAutoAudioConvert";
1368 str_aar = "VideoAutoAudioResample";
1369 str_acs = "VideoAutoColorSpace";
1370 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1371 str_profile = "AudioProfile";
1372 str_aac = "AudioAutoAudioConvert";
1373 str_aar = "AudioAutoAudioResample";
1374 str_acs = "AudioAutoColorSpace";
1375 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1376 str_profile = "ImageProfile";
1377 str_aac = "ImageAutoAudioConvert";
1378 str_aar = "ImageAutoAudioResample";
1379 str_acs = "ImageAutoColorSpace";
1382 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_profile, &encodebin_profile);
1383 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aac, &auto_audio_convert);
1384 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
1385 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
1387 MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
1388 encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
1390 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
1391 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", auto_audio_convert);
1392 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-resample", auto_audio_resample);
1393 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-colorspace", auto_color_space);
1394 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "use-video-toggle", FALSE);
1396 /* get video convert element name */
1397 _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
1400 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1401 int use_venc_queue = 0;
1403 VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
1405 if (!VideoencElement) {
1406 MMCAM_LOG_ERROR("Fail to get type element");
1407 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1408 goto pipeline_creation_error;
1411 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
1412 /* set parse element */
1413 gst_element_venc_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
1414 if (!gst_element_venc_name)
1415 gst_element_venc_name = "identity";
1417 _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
1420 if (gst_element_venc_name) {
1421 MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
1423 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
1424 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
1426 MMCAM_LOG_ERROR("Fail to get video encoder name");
1427 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1428 goto pipeline_creation_error;
1431 /* set color space converting element */
1432 if (auto_color_space) {
1433 MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
1435 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
1436 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
1438 /* set colorspace plugin property setting */
1439 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, sc->VideoconvertElement);
1441 /* fourcc type was removed in GST 1.0 */
1442 if (hcamcorder->use_zero_copy_format) {
1443 if (strstr(gst_element_venc_name, "omx")) {
1444 video_caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "SN12", NULL);
1447 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vcaps", video_caps);
1448 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VCONV].gst, "dst-buffer-num", _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM);
1450 gst_caps_unref(video_caps);
1453 MMCAM_LOG_WARNING("failed to create caps");
1456 MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
1461 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1462 CONFIGURE_CATEGORY_MAIN_RECORD,
1463 "UseVideoEncoderQueue",
1466 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
1469 if (sc->audio_disable == FALSE &&
1470 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1471 int use_aenc_queue = 0;
1473 AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
1474 if (!AudioencElement) {
1475 MMCAM_LOG_ERROR("Fail to get type element");
1476 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1477 goto pipeline_creation_error;
1480 _mmcamcorder_conf_get_value_element_name(AudioencElement, &gst_element_aenc_name);
1482 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "aenc-name", gst_element_aenc_name);
1483 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC, "audio-encode", err);
1485 if (audio_enc == MM_AUDIO_CODEC_AMR && channel == 2) {
1486 audio_caps = gst_caps_new_simple("audio/x-raw",
1487 "channels", G_TYPE_INT, 1,
1489 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1490 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1491 gst_caps_unref(audio_caps);
1495 if (audio_enc == MM_AUDIO_CODEC_OGG) {
1496 audio_caps = gst_caps_new_empty_simple("audio/x-raw");
1497 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "auto-audio-convert", TRUE);
1498 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
1499 gst_caps_unref(audio_caps);
1501 MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
1504 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
1505 CONFIGURE_CATEGORY_MAIN_RECORD,
1506 "UseAudioEncoderQueue",
1508 if (use_aenc_queue) {
1509 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_AENC_QUE, "use-aenc-queue", err);
1510 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-time", 0);
1511 MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "max-size-buffers", 0);
1515 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1516 if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
1517 ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
1518 if (!ImageencElement) {
1519 MMCAM_LOG_ERROR("Fail to get type element");
1520 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1521 goto pipeline_creation_error;
1524 _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name);
1526 /* raw format - set dummy element */
1527 gst_element_ienc_name = "identity";
1530 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name);
1531 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err);
1535 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1536 MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
1538 MMCAM_LOG_ERROR("Fail to get type element");
1539 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1540 goto pipeline_creation_error;
1543 _mmcamcorder_conf_get_value_element_name(MuxElement, &gst_element_mux_name);
1545 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "mux-name", gst_element_mux_name);
1546 _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_MUX, "mux", err);
1548 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, MuxElement);
1552 if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1554 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1555 CONFIGURE_CATEGORY_MAIN_RECORD,
1556 "RecordsinkElement",
1557 &RecordsinkElement);
1558 _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name);
1560 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, gst_element_rsink_name, NULL, element_list, err);
1562 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, RecordsinkElement);
1565 _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SINK, "fakesink", NULL, element_list, err);
1568 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1569 /* property setting in ini */
1570 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
1572 /* bitrate setting */
1573 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
1574 v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
1577 if (sc->audio_disable == FALSE &&
1578 profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
1579 /* property setting in ini */
1580 _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
1582 /* bitrate setting */
1583 _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
1584 a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
1587 MMCAM_LOG_INFO("Element creation complete");
1589 /* Add element to bin */
1590 if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
1591 MMCAM_LOG_ERROR("element add error.");
1592 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
1593 goto pipeline_creation_error;
1596 MMCAM_LOG_INFO("Element add complete");
1598 if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
1599 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
1600 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
1601 gst_object_unref(pad);
1603 MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1604 err = MM_ERROR_CAMCORDER_GST_LINK;
1605 goto pipeline_creation_error;
1607 gst_object_unref(pad);
1610 if (sc->audio_disable == FALSE) {
1611 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1612 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1613 gst_object_unref(pad);
1615 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1616 err = MM_ERROR_CAMCORDER_GST_LINK;
1617 goto pipeline_creation_error;
1619 gst_object_unref(pad);
1622 } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
1623 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
1624 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
1625 gst_object_unref(pad);
1627 MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1628 err = MM_ERROR_CAMCORDER_GST_LINK;
1629 goto pipeline_creation_error;
1631 gst_object_unref(pad);
1635 pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
1636 if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
1637 gst_object_unref(pad);
1639 MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
1640 err = MM_ERROR_CAMCORDER_GST_LINK;
1641 goto pipeline_creation_error;
1643 gst_object_unref(pad);
1647 MMCAM_LOG_INFO("Get pad complete");
1649 /* Link internal element */
1650 if (!_mmcamcorder_link_elements(element_list)) {
1651 MMCAM_LOG_ERROR("element link error.");
1652 err = MM_ERROR_CAMCORDER_GST_LINK;
1653 goto pipeline_creation_error;
1657 g_list_free(element_list);
1659 MMCAM_LOG_INFO("done");
1661 return MM_ERROR_NONE;
1663 pipeline_creation_error:
1664 _mmcamcorder_remove_all_handlers(handle, _MMCAMCORDER_HANDLER_VIDEOREC);
1666 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
1667 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
1668 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
1669 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
1670 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
1671 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
1672 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
1673 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
1674 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_MUX);
1675 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
1676 _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
1679 g_list_free(element_list);
1681 if (videoscale_caps)
1682 gst_caps_unref(videoscale_caps);
1688 int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
1690 int err = MM_ERROR_NONE;
1692 GstPad *srcpad = NULL;
1695 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1696 _MMCamcorderSubContext *sc = NULL;
1698 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1700 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1701 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1702 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1706 /** Create gstreamer element **/
1708 _MMCAMCORDER_PIPELINE_MAKE(sc, sc->element, _MMCAMCORDER_MAIN_PIPE, "camera_pipeline", err);
1711 err = _mmcamcorder_create_preview_elements((MMHandleType)hcamcorder);
1712 if (err != MM_ERROR_NONE)
1713 goto pipeline_creation_error;
1715 /* Set data probe function */
1716 if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
1717 MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
1718 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1720 MMCAM_LOG_ERROR("there is no queue plugin");
1721 goto pipeline_creation_error;
1725 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1726 __mmcamcorder_video_dataprobe_preview, hcamcorder);
1728 gst_object_unref(srcpad);
1731 MMCAM_LOG_ERROR("failed to get srcpad");
1732 goto pipeline_creation_error;
1735 /* set dataprobe for video recording if it does not support dual stream. */
1736 if (sc->info_video->record_dual_stream == FALSE) {
1737 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
1738 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
1740 srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
1742 MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
1743 __mmcamcorder_video_dataprobe_record, hcamcorder);
1744 gst_object_unref(srcpad);
1748 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
1750 /* set sync handler */
1751 gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
1753 gst_object_unref(bus);
1757 err = _mmcamcorder_initialize_capture_mode(handle);
1758 if (err != MM_ERROR_NONE) {
1759 MMCAM_LOG_ERROR("initialize capture mode[%d] failed", hcamcorder->capture_mode);
1760 goto pipeline_creation_error;
1763 /* extra preview mode */
1764 err = _mmcamcorder_initialize_extra_preview_mode(handle);
1765 if (err != MM_ERROR_NONE) {
1766 MMCAM_LOG_ERROR("initialize extra preview mode[%d] failed", hcamcorder->extra_preview.mode);
1767 goto pipeline_creation_error;
1770 return MM_ERROR_NONE;
1772 pipeline_creation_error:
1773 _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_MAIN_PIPE);
1778 void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpointer handle)
1780 int ret = MM_ERROR_NONE;
1781 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1782 _MMCamcorderSubContext *sc = NULL;
1784 /*MMCAM_LOG_INFO("start");*/
1786 mmf_return_if_fail(hcamcorder);
1787 mmf_return_if_fail(hcamcorder->sub_context);
1788 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1791 if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
1792 sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
1793 ret = _mmcamcorder_request_codec_config(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1794 MMCAM_LOG_WARNING("Push buffer to encoding pipeline[request codec config:0x%x]", ret);
1799 int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* VideosinkElement)
1801 int err = MM_ERROR_NONE;
1806 int rect_height = 0;
1808 int rotation = MM_DISPLAY_ROTATION_NONE;
1809 int flip = MM_FLIP_NONE;
1810 int display_mode = MM_DISPLAY_MODE_DEFAULT;
1811 int display_geometry_method = MM_DISPLAY_METHOD_LETTER_BOX;
1812 int origin_size = 0;
1815 int do_scaling = FALSE;
1816 int *dp_handle = NULL;
1817 MMCamWindowInfo *window_info = NULL;
1819 char *err_name = NULL;
1820 const char *videosink_name = NULL;
1822 GstElement *vsink = NULL;
1824 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1825 _MMCamcorderSubContext *sc = NULL;
1829 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1831 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1832 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1833 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1834 mmf_return_val_if_fail(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1836 vsink = sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst;
1838 /* Get video display information */
1839 err = mm_camcorder_get_attributes(handle, &err_name,
1840 MMCAM_DISPLAY_RECT_X, &rect_x,
1841 MMCAM_DISPLAY_RECT_Y, &rect_y,
1842 MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
1843 MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
1844 MMCAM_DISPLAY_ROTATION, &rotation,
1845 MMCAM_DISPLAY_FLIP, &flip,
1846 MMCAM_DISPLAY_VISIBLE, &visible,
1847 MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
1848 MMCAM_DISPLAY_MODE, &display_mode,
1849 MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
1850 MMCAM_DISPLAY_SCALE, &zoom_attr,
1851 MMCAM_DISPLAY_EVAS_DO_SCALING, &do_scaling,
1853 if (err != MM_ERROR_NONE) {
1855 MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
1856 SAFE_FREE(err_name);
1858 MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
1864 _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
1866 if (!videosink_name) {
1867 MMCAM_LOG_ERROR("failed to get videosink name");
1868 return MM_ERROR_CAMCORDER_INTERNAL;
1871 MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
1873 /* Set display handle */
1874 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
1877 MMCAM_LOG_INFO("xid = %lu )", xid);
1878 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
1880 MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
1881 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
1883 } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
1884 MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
1887 MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
1888 MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
1890 MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
1891 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
1893 } else if (!strcmp(videosink_name, "tizenwlsink")) {
1895 window_info = (MMCamWindowInfo *)dp_handle;
1896 MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
1897 gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
1899 MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
1901 } else if (!strcmp(videosink_name, "directvideosink")) {
1902 #ifdef _MMCAMCORDER_RM_SUPPORT
1903 /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
1904 MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
1905 MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
1906 #endif /* _MMCAMCORDER_RM_SUPPORT */
1908 window_info = (MMCamWindowInfo *)dp_handle;
1909 MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
1910 window_info->surface_id,
1911 window_info->rect.x,
1912 window_info->rect.y,
1913 window_info->rect.width,
1914 window_info->rect.height);
1915 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
1916 gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
1917 window_info->rect.x,
1918 window_info->rect.y,
1919 window_info->rect.width,
1920 window_info->rect.height);
1922 MMCAM_LOG_WARNING("dp_handle is null");
1925 MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
1928 MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
1929 videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
1932 if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
1933 !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
1935 MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
1938 MMCAMCORDER_G_OBJECT_SET(vsink, "flip", flip);
1940 switch (zoom_attr) {
1941 case MM_DISPLAY_SCALE_DEFAULT:
1944 case MM_DISPLAY_SCALE_DOUBLE_LENGTH:
1947 case MM_DISPLAY_SCALE_TRIPLE_LENGTH:
1951 MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
1956 MMCAMCORDER_G_OBJECT_SET(vsink, "display-geometry-method", display_geometry_method);
1957 MMCAMCORDER_G_OBJECT_SET(vsink, "display-mode", display_mode);
1958 MMCAMCORDER_G_OBJECT_SET(vsink, "visible", visible);
1959 MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
1961 if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
1962 if (!strcmp(videosink_name, "tizenwlsink")) {
1963 gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink),
1964 rect_x, rect_y, rect_width, rect_height);
1967 "dst-roi-x", rect_x,
1968 "dst-roi-y", rect_y,
1969 "dst-roi-w", rect_width,
1970 "dst-roi-h", rect_height,
1976 return MM_ERROR_NONE;
1980 int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
1983 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1984 _MMCamcorderSubContext *sc = NULL;
1986 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1988 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1990 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1993 case _MMCamcorder_CMD_PREVIEW_START:
1994 category = CONFIGURE_CATEGORY_CTRL_CAMERA;
1996 case _MMCamcorder_CMD_CAPTURE:
1997 category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
2000 MMCAM_LOG_WARNING("unknown command : %d", cmd);
2001 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
2004 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
2005 category, "FrameStabilityCount", &sc->frame_stability_count);
2007 MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
2008 cmd, sc->frame_stability_count);
2010 return MM_ERROR_NONE;
2013 /* Retreive device information and set them to attributes */
2014 gboolean _mmcamcorder_get_device_info(MMHandleType handle)
2016 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2017 _MMCamcorderSubContext *sc = NULL;
2018 GstCameraControl *control = NULL;
2019 GstCameraControlExifInfo exif_info = {0,};
2021 mmf_return_val_if_fail(hcamcorder, FALSE);
2022 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2024 memset(&exif_info, 0x0, sizeof(GstCameraControlExifInfo));
2026 if (sc && sc->element) {
2027 int err = MM_ERROR_NONE;
2028 char *err_name = NULL;
2029 double focal_len = 0.0;
2031 /* Video input device */
2032 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2033 /* Exif related information */
2034 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2035 if (control != NULL) {
2036 gst_camera_control_get_exif_info(control, &exif_info); /* get video input device information */
2037 if (exif_info.focal_len_denominator != 0)
2038 focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
2040 MMCAM_LOG_ERROR("Fail to get camera control interface!");
2045 /* Set values to attributes */
2046 err = mm_camcorder_set_attributes(handle, &err_name,
2047 MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
2049 if (err != MM_ERROR_NONE) {
2050 MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
2051 SAFE_FREE(err_name);
2055 MMCAM_LOG_WARNING("Sub context isn't exist.");
2062 static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure)
2064 const gchar *format_string = NULL;
2067 MMCAM_LOG_WARNING("NULL structure");
2068 return GST_MAKE_FOURCC('N', 'U', 'L', 'L');
2071 if (gst_structure_has_name(structure, "video/x-h264"))
2072 return GST_MAKE_FOURCC('H', '2', '6', '4');
2074 if (gst_structure_has_name(structure, "video/x-h265"))
2075 return GST_MAKE_FOURCC('H', '2', '6', '5');
2077 if (gst_structure_has_name(structure, "video/x-vp8"))
2078 return GST_MAKE_FOURCC('V', 'P', '8', '0');
2080 if (gst_structure_has_name(structure, "video/x-vp9"))
2081 return GST_MAKE_FOURCC('V', 'P', '9', '0');
2083 if (gst_structure_has_name(structure, "video/x-jpeg") ||
2084 gst_structure_has_name(structure, "image/jpeg"))
2085 return GST_MAKE_FOURCC('M', 'J', 'P', 'G');
2087 format_string = gst_structure_get_string(structure, "format");
2090 return GST_STR_FOURCC(format_string);
2092 return GST_MAKE_FOURCC('N', 'O', 'N', 'E');
2095 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2097 gboolean ret = TRUE;
2098 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2099 _MMCamcorderSubContext *sc = NULL;
2100 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2101 GstSample *sample = NULL;
2102 GstCaps *caps = NULL;
2104 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
2105 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
2106 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
2108 sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
2109 mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
2111 if (sc->drop_vframe > 0) {
2112 if (sc->pass_first_vframe > 0) {
2113 sc->pass_first_vframe--;
2114 MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
2117 MMCAM_LOG_INFO("Drop video frame by drop_vframe");
2118 return GST_PAD_PROBE_DROP;
2120 } else if (sc->frame_stability_count > 0) {
2121 sc->frame_stability_count--;
2122 MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
2123 return GST_PAD_PROBE_DROP;
2126 if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
2127 _mmcamcorder_measure_fps(&sc->kpi);
2129 /* The first H.264 frame should not be skipped for vstream cb. */
2130 if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
2131 !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2132 MMCAM_LOG_WARNING("Not ready for stream callback");
2133 return GST_PAD_PROBE_OK;
2136 /* make sample with buffer and caps */
2137 caps = gst_pad_get_allowed_caps(pad);
2138 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2140 sample = gst_sample_new(buffer, caps, NULL, NULL);
2141 gst_caps_unref(caps);
2142 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2144 ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
2146 gst_sample_unref(sample);
2149 return GST_PAD_PROBE_OK;
2151 return GST_PAD_PROBE_DROP;
2155 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2157 gboolean ret = TRUE;
2158 GstSample *sample = NULL;
2159 GstCaps *caps = NULL;
2161 caps = gst_pad_get_allowed_caps(pad);
2162 mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
2164 sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
2165 gst_caps_unref(caps);
2166 mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
2168 ret = _mmcamcorder_video_push_buffer(u_data, sample);
2170 gst_sample_unref(sample);
2172 return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
2176 GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2178 MMCamcorderMuxedStreamDataType stream;
2179 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
2180 _MMCamcorderSubContext *sc = NULL;
2181 GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
2184 mmf_return_val_if_fail(buffer, GST_PAD_PROBE_OK);
2185 mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_OK);
2186 mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK);
2188 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2189 mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
2191 if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
2192 MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
2193 return GST_PAD_PROBE_OK;
2196 /* call application callback */
2197 _MMCAMCORDER_LOCK_MSTREAM_CALLBACK(hcamcorder);
2199 if (hcamcorder->mstream_cb) {
2200 stream.data = (void *)mapinfo.data;
2201 stream.length = mapinfo.size;
2202 stream.offset = sc->muxed_stream_offset;
2203 hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
2206 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
2208 /* calculate current offset */
2209 sc->muxed_stream_offset += mapinfo.size;
2211 gst_buffer_unmap(buffer, &mapinfo);
2213 return GST_PAD_PROBE_OK;
2217 GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
2219 GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
2220 mmf_camcorder_t *hcamcorder = NULL;
2221 _MMCamcorderSubContext *sc = NULL;
2222 GstObject *parent = NULL;
2224 switch (GST_EVENT_TYPE(event)) {
2225 case GST_EVENT_UNKNOWN:
2226 /* upstream events */
2228 case GST_EVENT_SEEK:
2229 case GST_EVENT_NAVIGATION:
2230 case GST_EVENT_LATENCY:
2231 /* downstream serialized events */
2232 case GST_EVENT_BUFFERSIZE:
2233 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2237 GstTagList *tag_list = NULL;
2238 _MMCamcorderReplayGain *replay_gain = NULL;
2240 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2242 hcamcorder = MMF_CAMCORDER(u_data);
2243 if (!hcamcorder || !hcamcorder->sub_context) {
2244 MMCAM_LOG_WARNING("NULL handle");
2248 replay_gain = &hcamcorder->sub_context->replay_gain;
2250 gst_event_parse_tag(event, &tag_list);
2252 MMCAM_LOG_WARNING("failed to get tag list");
2256 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
2257 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
2261 if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
2262 MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
2266 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
2267 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2271 if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
2272 MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
2276 MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
2277 replay_gain->track_peak, replay_gain->track_gain,
2278 replay_gain->album_peak, replay_gain->album_gain);
2281 case GST_EVENT_SEGMENT:
2282 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2284 hcamcorder = MMF_CAMCORDER(u_data);
2286 MMCAM_LOG_WARNING("NULL handle");
2290 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2292 MMCAM_LOG_WARNING("NULL sub context");
2296 if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2297 MMCAM_LOG_WARNING("no encoder sink");
2301 parent = gst_pad_get_parent(pad);
2303 MMCAM_LOG_WARNING("get parent failed");
2307 if (parent == (GstObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
2308 const GstSegment *segment;
2309 gst_event_parse_segment(event, &segment);
2310 if (segment->format == GST_FORMAT_BYTES) {
2311 MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
2312 sc->muxed_stream_offset, segment->start);
2314 sc->muxed_stream_offset = (unsigned long long)segment->start;
2318 gst_object_unref(parent);
2322 MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2324 /* bidirectional events */
2325 case GST_EVENT_FLUSH_START:
2326 case GST_EVENT_FLUSH_STOP:
2327 MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2330 MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
2334 return GST_PAD_PROBE_OK;
2338 int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate)
2340 int result = MM_CAMCORDER_MR475;
2343 result = MM_CAMCORDER_MR475; /*AMR475*/
2344 else if (bitrate < 5900)
2345 result = MM_CAMCORDER_MR515; /*AMR515*/
2346 else if (bitrate < 6700)
2347 result = MM_CAMCORDER_MR59; /*AMR59*/
2348 else if (bitrate < 7400)
2349 result = MM_CAMCORDER_MR67; /*AMR67*/
2350 else if (bitrate < 7950)
2351 result = MM_CAMCORDER_MR74; /*AMR74*/
2352 else if (bitrate < 10200)
2353 result = MM_CAMCORDER_MR795; /*AMR795*/
2354 else if (bitrate < 12200)
2355 result = MM_CAMCORDER_MR102; /*AMR102*/
2357 result = MM_CAMCORDER_MR122; /*AMR122*/
2363 int _mmcamcorder_get_eos_message(MMHandleType handle)
2366 int ret = MM_ERROR_NONE;
2368 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2369 _MMCamcorderSubContext *sc = NULL;
2371 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2372 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2373 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2375 MMCAM_LOG_INFO("START");
2377 _MMCAMCORDER_LOCK(handle);
2379 if (sc->bget_eos == FALSE) {
2380 end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
2381 if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
2382 MMCAM_LOG_INFO("EOS signal received");
2384 MMCAM_LOG_ERROR("EOS wait time out");
2386 if (hcamcorder->error_code == MM_ERROR_NONE)
2387 hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2390 MMCAM_LOG_INFO("already got EOS");
2393 _MMCAMCORDER_UNLOCK(handle);
2395 if (hcamcorder->error_code == MM_ERROR_NONE) {
2396 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2397 mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2398 if (sc->info_video->b_committing)
2399 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2401 mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2402 if (sc->info_audio->b_committing)
2403 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2406 ret = hcamcorder->error_code;
2407 MMCAM_LOG_ERROR("error 0x%x", ret);
2410 MMCAM_LOG_INFO("END");
2416 void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int first_elem, int last_elem)
2419 _MMCamcorderGstElement *remove_element = (_MMCamcorderGstElement *)element;
2421 mmf_return_if_fail(handle && remove_element);
2422 mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
2426 for (i = first_elem ; i <= last_elem ; i++) {
2427 remove_element[i].gst = NULL;
2428 remove_element[i].id = _MMCAMCORDER_NONE;
2435 int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
2437 mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2439 /* Check compatibility between codec and file format */
2440 if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
2441 if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
2442 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2443 if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2444 MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2445 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2448 MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2450 MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
2451 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2453 } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
2454 if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
2455 file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
2456 if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
2457 MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
2458 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2461 MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
2463 MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
2464 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
2468 return MM_ERROR_NONE;
2472 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
2474 int err = MM_ERROR_NONE;
2475 int audio_codec = MM_AUDIO_CODEC_INVALID;
2476 int file_format = MM_FILE_FORMAT_INVALID;
2478 char *err_name = NULL;
2480 err = mm_camcorder_get_attributes(handle, &err_name,
2481 MMCAM_AUDIO_ENCODER, &audio_codec,
2482 MMCAM_FILE_FORMAT, &file_format,
2484 if (err != MM_ERROR_NONE) {
2485 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2486 SAFE_FREE(err_name);
2490 /* Check compatibility between audio codec and file format */
2491 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
2497 int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
2499 int err = MM_ERROR_NONE;
2500 int video_codec = MM_VIDEO_CODEC_INVALID;
2501 int file_format = MM_FILE_FORMAT_INVALID;
2503 char *err_name = NULL;
2505 err = mm_camcorder_get_attributes(handle, &err_name,
2506 MMCAM_VIDEO_ENCODER, &video_codec,
2507 MMCAM_FILE_FORMAT, &file_format,
2509 if (err != MM_ERROR_NONE) {
2510 MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
2511 SAFE_FREE(err_name);
2515 /* Check compatibility between video codec and file format */
2516 err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
2522 bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate, int videosink_index)
2524 const char* videosink_name = NULL;
2526 mmf_camcorder_t *hcamcorder = NULL;
2527 _MMCamcorderSubContext *sc = NULL;
2529 hcamcorder = MMF_CAMCORDER(handle);
2530 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2532 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2533 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2534 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2536 if (sc->element[videosink_index].gst) {
2537 /* Get videosink name */
2538 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2539 if (videosink_name == NULL) {
2540 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2544 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2545 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2546 !strcmp(videosink_name, "directvideosink")) {
2547 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
2548 MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
2550 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
2555 MMCAM_LOG_ERROR("Videosink element is null");
2561 bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int videosink_index)
2563 const char* videosink_name = NULL;
2565 mmf_camcorder_t *hcamcorder = NULL;
2566 _MMCamcorderSubContext *sc = NULL;
2568 hcamcorder = MMF_CAMCORDER(handle);
2569 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2571 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2572 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2573 mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2575 if (sc->element[videosink_index].gst) {
2576 /* Get videosink name */
2577 _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
2578 if (videosink_name == NULL) {
2579 MMCAM_LOG_ERROR("Please check videosink element in configuration file");
2583 if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
2584 !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
2585 !strcmp(videosink_name, "directvideosink")) {
2586 MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
2587 MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
2589 MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
2594 MMCAM_LOG_ERROR("Videosink element is null");
2600 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
2603 _MMCamcorderSubContext *sc = NULL;
2605 mmf_camcorder_t *hcamcorder = NULL;
2607 hcamcorder = MMF_CAMCORDER(handle);
2608 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2610 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2612 MMCAM_LOG_INFO("sub context is not initialized");
2616 mm_camcorder_get_attributes(handle, NULL,
2617 MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
2618 MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
2619 MMCAM_CAMERA_FPS, &fps,
2622 MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
2624 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
2625 sc->info_video->preview_width, sc->info_video->preview_height,
2626 fps, videosrc_rotate);
2630 bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, int width, int height, int fps, int rotate)
2636 unsigned int caps_fourcc = 0;
2637 gboolean do_set_caps = FALSE;
2638 GstCaps *caps = NULL;
2640 mmf_camcorder_t *hcamcorder = NULL;
2641 _MMCamcorderSubContext *sc = NULL;
2643 hcamcorder = MMF_CAMCORDER(handle);
2644 mmf_return_val_if_fail(hcamcorder, FALSE);
2646 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2648 if (!sc || !(sc->element)) {
2649 MMCAM_LOG_INFO("sub context is not initialized");
2653 if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2654 MMCAM_LOG_ERROR("Video src is NULL!");
2658 if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
2659 MMCAM_LOG_ERROR("Video filter is NULL!");
2663 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2664 int capture_width = 0;
2665 int capture_height = 0;
2666 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
2668 mm_camcorder_get_attributes(handle, NULL,
2669 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
2670 MMCAM_CAMERA_FPS_AUTO, &fps_auto,
2671 MMCAM_CAPTURE_WIDTH, &capture_width,
2672 MMCAM_CAPTURE_HEIGHT, &capture_height,
2673 MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
2674 MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
2676 MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
2677 motion_rate, capture_width, capture_height, fps_auto,
2678 sc->info_video->video_width, sc->info_video->video_height);
2680 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst,
2681 "high-speed-fps", (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE ? fps : 0));
2683 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
2684 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
2685 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "fps-auto", fps_auto);
2688 sc->info_video->fps = fps;
2691 /* Interleaved format does not support rotation */
2692 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2693 /* store videosrc rotation */
2694 sc->videosrc_rotate = rotate;
2696 /* Define width, height and rotate in caps */
2698 /* This will be applied when rotate is 0, 90, 180, 270 if rear camera.
2699 This will be applied when rotate is 0, 180 if front camera. */
2700 set_rotate = rotate * 90;
2702 if (rotate == MM_VIDEO_INPUT_ROTATION_90 ||
2703 rotate == MM_VIDEO_INPUT_ROTATION_270) {
2706 if (hcamcorder->device_type == MM_VIDEO_DEVICE_CAMERA1) {
2707 if (rotate == MM_VIDEO_INPUT_ROTATION_90)
2714 set_height = height;
2717 sc->videosrc_rotate = MM_VIDEO_INPUT_ROTATION_NONE;
2720 set_height = height;
2722 MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
2725 MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
2726 if (caps && !gst_caps_is_any(caps)) {
2727 GstStructure *structure = NULL;
2729 structure = gst_caps_get_structure(caps, 0);
2732 int caps_height = 0;
2735 int caps_rotate = 0;
2737 caps_fourcc = _mmcamcorder_get_structure_fourcc(structure);
2739 gst_structure_get(structure,
2740 "width", G_TYPE_INT, &caps_width,
2741 "height", G_TYPE_INT, &caps_height,
2742 "framerate", GST_TYPE_FRACTION, &caps_fps_n, &caps_fps_d,
2743 "rotate", G_TYPE_INT, &caps_rotate,
2746 #ifdef _MMCAMCORDER_PRODUCT_TV
2747 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
2748 if (set_width == caps_width && set_height == caps_height &&
2749 set_rotate == caps_rotate && fps == caps_fps_n) {
2750 MMCAM_LOG_INFO("No need to replace caps.");
2752 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]",
2753 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2754 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2755 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2756 set_width, set_height, fps, set_rotate);
2760 if (set_width == caps_width && set_height == caps_height &&
2761 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2762 MMCAM_LOG_INFO("No need to replace caps.");
2764 MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d/%d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
2765 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2766 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2767 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2768 set_width, set_height, fps, set_rotate);
2772 #else /*_MMCAMCORDER_PRODUCT_TV */
2773 if (set_width == caps_width && set_height == caps_height &&
2774 fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
2775 MMCAM_LOG_INFO("No need to replace caps.");
2777 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]",
2778 caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
2779 caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
2780 fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
2781 set_width, set_height, fps, set_rotate);
2784 #endif /*_MMCAMCORDER_PRODUCT_TV */
2786 MMCAM_LOG_INFO("can not get structure of caps. set new one...");
2790 MMCAM_LOG_INFO("No caps. set new one...");
2795 gst_caps_unref(caps);
2799 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2800 /* assume that it's camera capture mode */
2801 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
2807 caps = _mmcamcorder_get_video_caps(handle,
2808 sc->info_image->preview_format, set_width, set_height, fps, set_rotate);
2810 MMCAM_LOG_ERROR("There are no caps");
2814 MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
2815 gst_caps_unref(caps);
2821 bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
2823 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2824 _MMCamcorderSubContext *sc = NULL;
2826 mmf_return_val_if_fail(hcamcorder, FALSE);
2828 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2832 MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
2834 if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
2838 /* Interleaved format does not support FLIP */
2839 if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) {
2840 hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
2841 vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
2843 MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
2845 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
2846 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
2848 MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
2852 MMCAM_LOG_WARNING("element is NULL");
2860 bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
2862 GstCameraControl *control = NULL;
2863 _MMCamcorderSubContext *sc = NULL;
2864 GstElement *v_src = NULL;
2868 mmf_return_val_if_fail(handle, FALSE);
2870 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2874 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2877 MMCAM_LOG_WARNING("videosrc element is NULL");
2881 set_value = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_ANTI_HANDSHAKE, anti_shake);
2883 /* set anti-shake with camera control */
2884 if (!GST_IS_CAMERA_CONTROL(v_src)) {
2885 MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
2889 control = GST_CAMERA_CONTROL(v_src);
2890 if (gst_camera_control_set_ahs(control, set_value)) {
2891 MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
2894 MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
2901 bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilization)
2903 _MMCamcorderSubContext *sc = NULL;
2904 GstElement *v_src = NULL;
2906 mmf_return_val_if_fail(handle, FALSE);
2908 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2912 v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
2914 MMCAM_LOG_WARNING("videosrc element is NULL");
2918 /* check property of videosrc element - support VDIS */
2919 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(v_src)), "enable-vdis-mode")) {
2920 int video_width = 0;
2921 int video_height = 0;
2923 if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2924 MMCAM_LOG_INFO("ENABLE video stabilization");
2926 /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
2927 mm_camcorder_get_attributes(handle, NULL,
2928 MMCAM_VIDEO_WIDTH, &video_width,
2929 MMCAM_VIDEO_HEIGHT, &video_height,
2932 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
2933 MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
2934 video_width, video_height);
2936 g_object_set(G_OBJECT(v_src),
2937 "enable-vdis-mode", TRUE,
2940 MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
2941 sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
2942 video_width, video_height);
2947 g_object_set(G_OBJECT(v_src),
2948 "enable-vdis-mode", FALSE,
2951 MMCAM_LOG_INFO("DISABLE video stabilization");
2953 } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
2954 MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
2957 MMCAM_LOG_WARNING("no property for video stabilization");
2964 bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int height)
2968 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2969 _MMCamcorderSubContext *sc = NULL;
2971 mmf_return_val_if_fail(hcamcorder, FALSE);
2973 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2977 mm_camcorder_get_attributes(handle, NULL,
2978 MMCAM_CAMERA_FPS, &fps,
2981 MMCAM_LOG_INFO("set %dx%d", width, height);
2983 return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
2987 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
2989 _MMCamcorderSubContext *sc = NULL;
2991 if ((void *)handle == NULL) {
2992 MMCAM_LOG_WARNING("handle is NULL");
2996 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2998 MMCAM_LOG_WARNING("subcontext is NULL");
3002 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3003 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3007 MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
3009 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
3015 bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
3017 _MMCamcorderSubContext *sc = NULL;
3019 if ((void *)handle == NULL) {
3020 MMCAM_LOG_WARNING("handle is NULL");
3024 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3026 MMCAM_LOG_WARNING("subcontext is NULL");
3030 if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
3031 MMCAM_LOG_WARNING("videosrc plugin is NULL");
3035 MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
3037 MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
3043 bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
3045 GstStructure *props = NULL;
3046 char stream_props[64] = {'\0',};
3048 if (element == NULL || stream_type == NULL || stream_index < 0) {
3049 MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
3053 snprintf(stream_props, sizeof(stream_props) - 1,
3054 "props,media.role=%s, media.parent_id=%d",
3055 stream_type, stream_index);
3057 MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
3059 props = gst_structure_from_string(stream_props, NULL);
3061 MMCAM_LOG_ERROR("failed to create GstStructure");
3065 MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
3067 gst_structure_free(props);
3074 bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
3076 int ret = MM_ERROR_NONE;
3077 _MMCamcorderSubContext *sc = NULL;
3078 mmf_camcorder_t *hcamcorder = NULL;
3079 const char *videodecoder_name = NULL;
3080 char videodecoder_name_final[32] = {'\0',};
3081 int display_surface_type = MM_DISPLAY_SURFACE_NULL;
3082 #ifdef _MMCAMCORDER_RM_SUPPORT
3083 int decoder_index = 0;
3084 #endif /* _MMCAMCORDER_RM_SUPPORT */
3086 if ((void *)handle == NULL) {
3087 MMCAM_LOG_WARNING("handle is NULL");
3091 hcamcorder = MMF_CAMCORDER(handle);
3093 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3095 MMCAM_LOG_WARNING("subcontext is NULL");
3099 if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
3100 hcamcorder->recreate_decoder == FALSE) {
3101 MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
3102 sc->info_image->preview_format, hcamcorder->recreate_decoder);
3106 mm_camcorder_get_attributes(handle, NULL,
3107 MMCAM_DISPLAY_SURFACE, &display_surface_type,
3110 if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
3111 MMCAM_LOG_INFO("no need to control decoder element");
3115 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
3116 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3117 MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
3121 MMCAM_LOG_INFO("start");
3123 _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
3124 if (videodecoder_name == NULL) {
3125 MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
3129 /* set state as NULL */
3130 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
3131 if (ret != MM_ERROR_NONE) {
3132 MMCAM_LOG_ERROR("failed to set NULL to decoder");
3136 /* remove decoder - pads will be unlinked automatically in remove function */
3137 if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3138 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3139 MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
3143 /* check decoder element */
3144 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
3145 MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
3146 G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3147 ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
3150 #ifdef _MMCAMCORDER_RM_SUPPORT
3151 if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
3152 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
3155 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
3156 } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
3158 if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
3159 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
3161 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
3163 #endif /* _MMCAMCORDER_RM_SUPPORT */
3164 snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
3165 #ifdef _MMCAMCORDER_RM_SUPPORT
3167 #endif /* _MMCAMCORDER_RM_SUPPORT */
3169 /* create decoder */
3170 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "videosrc_decode");
3171 if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
3172 MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
3176 _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
3178 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
3179 g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3180 (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3182 /* add to pipeline */
3183 if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
3184 sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
3185 MMCAM_LOG_ERROR("failed to add decoder to pipeline");
3186 gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
3191 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
3192 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
3193 MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
3195 MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
3199 if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
3200 GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
3201 MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
3203 MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
3207 /* set state READY */
3208 ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
3209 if (ret != MM_ERROR_NONE) {
3210 MMCAM_LOG_ERROR("failed to set READY to decoder");
3214 MMCAM_LOG_INFO("done");
3219 #ifdef _MMCAMCORDER_PRODUCT_TV
3220 bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
3222 _MMCamcorderSubContext *sc = NULL;
3223 mmf_camcorder_t *hcamcorder = NULL;
3225 const gchar *mime = NULL;
3227 GstCaps *decsink_caps = NULL;
3228 GstStructure *decsink_struct = NULL;
3230 mmf_return_val_if_fail(handle, false);
3231 mmf_return_val_if_fail(max_width, false);
3232 mmf_return_val_if_fail(max_height, false);
3234 hcamcorder = MMF_CAMCORDER(handle);
3235 mmf_return_val_if_fail(hcamcorder, false);
3237 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3239 sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
3241 MMCAM_LOG_ERROR("There are no decoder caps");
3245 decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
3246 if (!decsink_caps) {
3247 gst_object_unref(sinkpad);
3248 MMCAM_LOG_ERROR("There is no decoder sink caps");
3252 for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
3253 decsink_struct = gst_caps_get_structure(decsink_caps, index);
3254 if (!decsink_struct) {
3255 MMCAM_LOG_ERROR("There are no structure from caps");
3256 gst_object_unref(decsink_caps);
3257 gst_object_unref(sinkpad);
3260 mime = gst_structure_get_name(decsink_struct);
3261 if (!strcmp(mime, "video/x-h264")) {
3262 MMCAM_LOG_INFO("h264 caps structure found");
3263 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3264 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3265 if (gst_structure_has_field(decsink_struct, "maxheight"))
3266 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3268 } else if (!strcmp(mime, "video/x-jpeg")) {
3269 MMCAM_LOG_INFO("mjpeg caps structure found");
3270 if (gst_structure_has_field(decsink_struct, "maxwidth"))
3271 *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
3272 if (gst_structure_has_field(decsink_struct, "maxheight"))
3273 *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
3277 MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
3278 gst_object_unref(decsink_caps);
3279 gst_object_unref(sinkpad);
3281 if (*max_width <= 0 || *max_height <= 0)
3286 #endif /* _MMCAMCORDER_PRODUCT_TV */