fix double free
[platform/core/multimedia/libmm-streamrecorder.git] / src / include / mm_streamrecorder_attribute.h
1 /*
2  * libmm-streamrecorder
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyuntae Kim <ht1211.kim@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #ifndef __MM_STREAMRECORDER_ATTRIBUTE_H__
23 #define __MM_STREAMRECORDER_ATTRIBUTE_H__
24
25 /*=======================================================================================
26 | INCLUDE FILES                                                                         |
27 ========================================================================================*/
28 #include <mm_types.h>
29 #include <mm_attrs.h>
30 #include <mm_attrs_private.h>
31 #include <stdarg.h>
32 #include "mm_streamrecorder_internal.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /*=======================================================================================
39 | GLOBAL DEFINITIONS AND DECLARATIONS FOR STREAMRECORDER                                        |
40 ========================================================================================*/
41 /* Disabled
42 #define GET_AND_STORE_ATTRS_AFTER_SCENE_MODE
43 */
44
45 /*=======================================================================================
46 | MACRO DEFINITIONS                                                                     |
47 ========================================================================================*/
48 /**
49  * Caster of attributes handle
50  */
51 #define MMF_STREAMRECORDER_ATTRS(h) (((mmf_streamrecorder_t *)(h))->attributes)
52
53 /*=======================================================================================
54 | ENUM DEFINITIONS                                                                      |
55 ========================================================================================*/
56 /**
57  * Enumerations for streamrecorder attribute ID.
58  */
59 typedef enum {
60         MM_STR_VIDEO_BUFFER_TYPE,       /* 0 */
61         MM_STR_VIDEO_FORMAT,
62         MM_STR_VIDEO_FRAMERATE,
63         MM_STR_VIDEO_ENCODER_BITRATE,
64         MM_STR_VIDEO_RESOLUTION_WIDTH,
65         MM_STR_VIDEO_RESOLUTION_HEIGHT,
66         MM_STR_AUDIO_FORMAT,
67         MM_STR_AUDIO_ENCODER_BITRATE,
68         MM_STR_AUDIO_SAMPLERATE,
69         MM_STR_VIDEO_ENCODER,
70         MM_STR_AUDIO_ENCODER,   /* 10 */
71         MM_STR_AUDIO_CHENNEL_COUNT,
72         MM_STR_FILE_FORMAT,
73         MM_STR_TARGET_FILE_NAME,
74         MM_STR_VIDEO_ENABLE,
75         MM_STR_AUDIO_ENABLE,
76         MM_STR_MODE,
77         MM_STR_TARGET_MAX_SIZE,
78         MM_STR_TARGET_TIME_LIMIT,
79         MM_STR_NUM
80 } MMStreamRecorderAttrsID;
81
82
83 /*=======================================================================================
84 | TYPE DEFINITIONS                                                                      |
85 ========================================================================================*/
86 typedef bool(*mmf_streamrecorder_commit_func_t) (MMHandleType handle, int attr_idx, const mmf_value_t *value);
87
88 /*=======================================================================================
89 | STRUCTURE DEFINITIONS                                                                 |
90 ========================================================================================*/
91 typedef struct {
92         MMStreamRecorderAttrsID attrid;
93         char *name;
94         int value_type;
95         int flags;
96         union {
97                 void *value_void;
98                 char *value_string;
99                 int value_int;
100                 double value_double;
101         } default_value;                /* default value */
102         MMStreamRecorderAttrsValidType validity_type;
103         union {
104                 int *int_array;
105                 int int_min;
106                 double *double_array;
107                 double double_min;
108         } validity_value_1;
109         union {
110                 int int_max;
111                 double double_max;
112                 int count;
113         } validity_value_2;
114         mmf_streamrecorder_commit_func_t attr_commit;
115 } mm_streamrecorder_attr_construct_info;
116
117 /*=======================================================================================
118 | CONSTANT DEFINITIONS                                                                  |
119 ========================================================================================*/
120
121 /*=======================================================================================
122 | STATIC VARIABLES                                                                      |
123 ========================================================================================*/
124
125 /*=======================================================================================
126 | EXTERN GLOBAL VARIABLE                                                                |
127 ========================================================================================*/
128
129 /*=======================================================================================
130 | GLOBAL FUNCTION PROTOTYPES                                                            |
131 ========================================================================================*/
132 /**
133  * This function allocates structure of attributes and sets initial values.
134  *
135  * @param[in]   handle          Handle of streamrecorder.
136  * @param[in]   info            Preset information of streamrecorder.
137  * @return      This function returns allocated structure of attributes.
138  * @remarks
139  * @see         _mmstreamrecorder_dealloc_attribute()
140  *
141  */
142 MMHandleType _mmstreamrecorder_alloc_attribute(MMHandleType handle);
143
144 /**
145  * This function release structure of attributes.
146  *
147  * @param[in]   attrs           Handle of streamrecorder attribute.
148  * @return      void
149  * @remarks
150  * @see         _mmstreamrecorder_alloc_attribute()
151  *
152  */
153 void _mmstreamrecorder_dealloc_attribute(MMHandleType attrs);
154
155 /**
156  * This is a meta  function to get attributes of streamrecorder with given attribute names.
157  *
158  * @param[in]   handle          Handle of streamrecorder.
159  * @param[out]  err_attr_name   Specifies the name of attributes that made an error. If the function doesn't make an error, this will be null.
160  * @param[in]   attribute_name  attribute name that user want to get.
161  * @param[in]   var_args        Specifies variable arguments.
162  * @return      This function returns MM_ERROR_NONE on Success, minus on Failure.
163  * @remarks     You can retrieve multiple attributes at the same time.  @n
164  * @see         _mmstreamrecorder_set_attributes
165  */
166 int _mmstreamrecorder_get_attributes(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list var_args);
167
168 /**
169  * This is a meta  function to set attributes of steamrecorder with given attribute names.
170  *
171  * @param[in]   handle          Handle of streamrecorder.
172  * @param[out]  err_attr_name   Specifies the name of attributes that made an error. If the function doesn't make an error, this will be null.
173  * @param[in]   attribute_name  attribute name that user want to set.
174  * @param[in]   var_args        Specifies variable arguments.
175  * @return      This function returns MM_ERROR_NONE on Success, minus on Failure.
176  * @remarks     You can put multiple attributes to streamrecorder at the same time.  @n
177  * @see         _mmstreamrecorder_get_attributes
178  */
179 int _mmstreamrecorder_set_attributes(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list var_args);
180
181 /**
182  * This is a meta  function to get detail information of the attribute.
183  *
184  * @param[in]   handle          Handle of streamrecorder.
185  * @param[in]   attr_name       attribute name that user want to get information.
186  * @param[out]  info            a structure that holds information related with the attribute.
187  * @return      This function returns MM_ERROR_NONE on Success, minus on Failure.
188  * @remarks     If the function succeeds, 'info' holds detail information about the attribute, such as type, flag, validity_type, validity_values  @n
189  * @see         _mmstreamrecorder_get_attributes, _mmstreamrecorder_set_attributes
190  */
191 int _mmstreamrecorder_get_attribute_info(MMHandleType handle, const char *attr_name, MMStreamRecorderAttrsInfo * info);
192
193 /*=======================================================================================
194 | STREAMRECORDER INTERNAL LOCAL                                                         |
195 ========================================================================================*/
196 /**
197  * A commit function to set streamrecorder attributes
198  * If the attribute needs actual setting, this function handles that activity.
199  * When application sets an attribute, setting function in MSL common calls this function.
200  * If this function fails, original value will not change.
201  *
202  * @param[in]   attr_idx        Attribute index of subcategory.
203  * @param[in]   attr_name       Attribute name.
204  * @param[in]   value           Handle of streamrecorder.
205  * @param[in]   commit_param    Allocation type of streamrecorder context.
206  * @return      This function returns TRUE on success, or FALSE on failure
207  * @remarks
208  * @see
209  *
210  */
211 bool _mmstreamrecorder_commit_streamrecorder_attrs(int attr_idx, const char *attr_name, const mmf_value_t *value, void *commit_param);
212
213 bool _mmstreamrecorder_commit_video_enable(MMHandleType handle, int attr_idx, const mmf_value_t *value);
214
215 bool _mmstreamrecorder_commit_video_encoder(MMHandleType handle, int attr_idx, const mmf_value_t *value);
216
217 bool _mmstreamrecorder_commit_audio_enable(MMHandleType handle, int attr_idx, const mmf_value_t *value);
218
219 bool _mmstreamrecorder_commit_audio_encoder(MMHandleType handle, int attr_idx, const mmf_value_t *value);
220
221 bool _mmstreamrecorder_commit_audio_samplingrate(MMHandleType handle, int attr_idx, const mmf_value_t *value);
222
223 bool _mmstreamrecorder_commit_audio_bitformat(MMHandleType handle, int attr_idx, const mmf_value_t *value);
224
225 bool _mmstreamrecorder_commit_audio_channel(MMHandleType handle, int attr_idx, const mmf_value_t *value);
226
227 bool _mmstreamrecorder_commit_audio_bitrate(MMHandleType handle, int attr_idx, const mmf_value_t *value);
228
229 /**
230  * check whether supported or not
231  *
232  * @param[in]   handle          Handle of streamrecorder.
233  * @param[in]   attr_index      index of attribute to check.
234  * @return      bool            TRUE if supported or FALSE
235  */
236 bool _mmstreamrecorder_check_supported_attribute(MMHandleType handle, int attr_index);
237
238 bool _mmstreamrecorder_commit_video_bitrate(MMHandleType handle, int attr_idx, const mmf_value_t *value);
239
240 #ifdef __cplusplus
241 }
242 #endif
243 #endif                                                  /* __MM_STREAMRECORDER_ATTRIBUTE_H__ */