4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyuntae Kim <ht1211.kim@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 =======================================================================================*/
27 #include "mm_streamrecorder_util.h"
28 #include "mm_streamrecorder_attribute.h"
29 #include "mm_streamrecorder_gstdispatch.h"
31 /*-----------------------------------------------------------------------
32 | MACRO DEFINITIONS: |
33 -----------------------------------------------------------------------*/
34 #define MM_STREAMRECORDER_ATTRIBUTE_MAX_VALUE 15
35 #define MM_STREAMRECORDER_RESOLUTION_MAX_VALUE 4080
37 /*---------------------------------------------------------------------------------------
38 | GLOBAL VARIABLE DEFINITIONS for internal |
39 ---------------------------------------------------------------------------------------*/
41 /* basic attributes' info */
42 mm_streamrecorder_attr_construct_info stream_attrs_const_info[] = {
45 MM_STR_VIDEO_BUFFER_TYPE, /* ID */
46 (char *)"videobuffer-type", /* Name */
47 MMF_VALUE_TYPE_INT, /* Type */
48 MM_ATTRS_FLAG_RW, /* Flag */
49 {(void *)MM_STREAMRECORDER_VIDEO_TYPE_TBM_BO}, /* Default value */
50 MM_ATTRS_VALID_TYPE_INT_RANGE, /* Validity type */
51 {.int_min = MM_STREAMRECORDER_VIDEO_TYPE_TBM_BO}, /* Validity val1 (min, *array,...) */
52 {.int_max = MM_STREAMRECORDER_VIDEO_TYPE_NORMAL_BUFFER}, /* Validity val2 (max, count, ...) */
53 NULL, /* Runtime setting function of the attribute */
57 (char *)"videosource-format",
60 {(void *)MM_STREAMRECORDER_INPUT_FORMAT_NV12},
61 MM_ATTRS_VALID_TYPE_INT_RANGE,
62 {.int_min = MM_STREAMRECORDER_INPUT_FORMAT_INVALID},
63 {.int_max = MM_STREAMRECORDER_INPUT_FORMAT_NUM},
68 MM_STR_VIDEO_FRAMERATE,
69 (char *)"video-framerate",
73 MM_ATTRS_VALID_TYPE_INT_RANGE,
75 {.int_max = _MMSTREAMRECORDER_MAX_INT},
80 MM_STR_VIDEO_ENCODER_BITRATE,
81 (char *)"video-bitrate",
85 MM_ATTRS_VALID_TYPE_INT_RANGE,
87 {.int_max = _MMSTREAMRECORDER_MAX_INT},
88 NULL, /*_mmstreamrecorder_commit_video_bitrate, */
92 MM_STR_VIDEO_RESOLUTION_WIDTH,
93 (char *)"video-resolution-width",
97 MM_ATTRS_VALID_TYPE_INT_ARRAY,
104 MM_STR_VIDEO_RESOLUTION_HEIGHT,
105 (char *)"video-resolution-height",
109 MM_ATTRS_VALID_TYPE_INT_ARRAY,
117 (char *)"audio-source-format",
120 {(void *)MM_STREAMRECORDER_AUDIO_FORMAT_PCM_S16_LE},
121 MM_ATTRS_VALID_TYPE_INT_RANGE,
122 {.int_min = MM_STREAMRECORDER_AUDIO_FORMAT_PCM_U8},
123 {.int_max = MM_STREAMRECORDER_AUDIO_FORMAT_PCM_S16_LE},
124 _mmstreamrecorder_commit_audio_bitformat,
128 MM_STR_AUDIO_ENCODER_BITRATE,
129 (char *)"audio-bitrate",
133 MM_ATTRS_VALID_TYPE_INT_RANGE,
135 {.int_max = _MMSTREAMRECORDER_MAX_INT},
136 _mmstreamrecorder_commit_audio_bitrate,
140 MM_STR_AUDIO_SAMPLERATE,
141 (char *)"audio-samplerate",
145 MM_ATTRS_VALID_TYPE_INT_RANGE,
147 {.int_max = _MMSTREAMRECORDER_MAX_INT},
148 _mmstreamrecorder_commit_audio_samplingrate,
152 MM_STR_VIDEO_ENCODER,
153 (char *)"video-encoder",
157 MM_ATTRS_VALID_TYPE_INT_ARRAY,
160 _mmstreamrecorder_commit_video_encoder,
164 MM_STR_AUDIO_ENCODER,
165 (char *)"audio-encoder",
169 MM_ATTRS_VALID_TYPE_INT_ARRAY,
172 _mmstreamrecorder_commit_audio_encoder,
176 MM_STR_AUDIO_CHENNEL_COUNT,
177 (char *)"audio-channel-count",
181 MM_ATTRS_VALID_TYPE_INT_RANGE,
183 {.int_max = _MMSTREAMRECORDER_MAX_INT},
184 _mmstreamrecorder_commit_audio_channel,
189 (char *)"file-format",
193 MM_ATTRS_VALID_TYPE_INT_ARRAY,
200 MM_STR_TARGET_FILE_NAME,
202 MMF_VALUE_TYPE_STRING,
205 MM_ATTRS_VALID_TYPE_NONE,
213 (char *)"video-enable",
217 MM_ATTRS_VALID_TYPE_NONE,
219 {_MMSTREAMRECORDER_MAX_INT},
220 _mmstreamrecorder_commit_video_enable,
225 (char *)"audio-enable",
229 MM_ATTRS_VALID_TYPE_NONE,
231 {_MMSTREAMRECORDER_MAX_INT},
232 _mmstreamrecorder_commit_audio_enable,
237 (char *)"recorder-mode",
240 {(void *)MM_STREAMRECORDER_MODE_MEDIABUFFER},
241 MM_ATTRS_VALID_TYPE_NONE,
243 {_MMSTREAMRECORDER_MAX_INT},
248 MM_STR_TARGET_MAX_SIZE,
249 (char *)"target-max-size",
253 MM_ATTRS_VALID_TYPE_INT_RANGE,
255 {.int_max = _MMSTREAMRECORDER_MAX_INT},
260 MM_STR_TARGET_TIME_LIMIT,
261 (char *)"target-time-limit",
265 MM_ATTRS_VALID_TYPE_INT_RANGE,
267 {.int_max = _MMSTREAMRECORDER_MAX_INT},
273 /*-----------------------------------------------------------------------
274 | LOCAL VARIABLE DEFINITIONS for internal |
275 -----------------------------------------------------------------------*/
277 /*-----------------------------------------------------------------------
278 | LOCAL FUNCTION PROTOTYPES: |
279 -----------------------------------------------------------------------*/
280 int _mmstreamrecorder_get_available_format(MMHandleType handle, int type, int ** format);
283 /* STATIC INTERNAL FUNCTION */
284 static int __mmstreamrecorder_set_conf_to_valid_info(MMHandleType handle)
290 total_count = _mmstreamrecorder_get_available_format(handle, KEYWORD_VIDEO_WIDTH, &format);
291 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_WIDTH].validity_value_1.int_array = format;
292 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_WIDTH].validity_value_2.count = total_count;
295 total_count = _mmstreamrecorder_get_available_format(handle, KEYWORD_VIDEO_HEIGHT, &format);
296 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_HEIGHT].validity_value_1.int_array = format;
297 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_HEIGHT].validity_value_2.count = total_count;
300 total_count = _mmstreamrecorder_get_available_format(handle, KEYWORD_AUDIO_ENCODERS, &format);
301 stream_attrs_const_info[MM_STR_AUDIO_ENCODER].validity_value_1.int_array = format;
302 stream_attrs_const_info[MM_STR_AUDIO_ENCODER].validity_value_2.count = total_count;
305 total_count = _mmstreamrecorder_get_available_format(handle, KEYWORD_VIDEO_ENCODERS, &format);
306 stream_attrs_const_info[MM_STR_VIDEO_ENCODER].validity_value_1.int_array = format;
307 stream_attrs_const_info[MM_STR_VIDEO_ENCODER].validity_value_2.count = total_count;
310 total_count = _mmstreamrecorder_get_available_format(handle, KEYWORD_FILE_FORMATS, &format);
311 stream_attrs_const_info[MM_STR_FILE_FORMAT].validity_value_1.int_array = format;
312 stream_attrs_const_info[MM_STR_FILE_FORMAT].validity_value_2.count = total_count;
314 return MM_ERROR_NONE;
317 static int __mmstreamrecorder_release_conf_valid_info(MMHandleType handle)
319 int *allocated_memory = NULL;
321 _mmstreamrec_dbg_log("START");
323 allocated_memory = (int *)(stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_WIDTH].validity_value_1.int_array);
324 if (allocated_memory) {
325 free(allocated_memory);
326 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_WIDTH].validity_value_1.int_array = NULL;
327 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_WIDTH].validity_value_2.count = 0;
330 allocated_memory = (int *)(stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_HEIGHT].validity_value_1.int_array);
331 if (allocated_memory) {
332 free(allocated_memory);
333 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_HEIGHT].validity_value_1.int_array = NULL;
334 stream_attrs_const_info[MM_STR_VIDEO_RESOLUTION_HEIGHT].validity_value_2.count = 0;
337 allocated_memory = (int *)(stream_attrs_const_info[MM_STR_AUDIO_ENCODER].validity_value_1.int_array);
338 if (allocated_memory) {
339 free(allocated_memory);
340 stream_attrs_const_info[MM_STR_AUDIO_ENCODER].validity_value_1.int_array = NULL;
341 stream_attrs_const_info[MM_STR_AUDIO_ENCODER].validity_value_2.count = 0;
344 allocated_memory = (int *)(stream_attrs_const_info[MM_STR_VIDEO_ENCODER].validity_value_1.int_array);
345 if (allocated_memory) {
346 free(allocated_memory);
347 stream_attrs_const_info[MM_STR_VIDEO_ENCODER].validity_value_1.int_array = NULL;
348 stream_attrs_const_info[MM_STR_VIDEO_ENCODER].validity_value_2.count = 0;
351 allocated_memory = (int *)(stream_attrs_const_info[MM_STR_FILE_FORMAT].validity_value_1.int_array);
352 if (allocated_memory) {
353 free(allocated_memory);
354 stream_attrs_const_info[MM_STR_FILE_FORMAT].validity_value_1.int_array = NULL;
355 stream_attrs_const_info[MM_STR_FILE_FORMAT].validity_value_2.count = 0;
357 _mmstreamrec_dbg_log("DONE");
359 return MM_ERROR_NONE;
363 static bool __mmstreamrecorder_attrs_is_supported(MMHandleType handle, int idx)
365 mmf_attrs_t *attr = (mmf_attrs_t *) handle;
368 if (mm_attrs_get_flags(handle, idx, &flag) == MM_ERROR_NONE) {
369 if (flag == MM_ATTRS_FLAG_NONE)
375 if (attr->items[idx].value_spec.type == MM_ATTRS_VALID_TYPE_INT_RANGE) {
377 mm_attrs_get_valid_range((MMHandleType) attr, idx, &min, &max);
380 } else if (attr->items[idx].value_spec.type == MM_ATTRS_VALID_TYPE_INT_ARRAY) {
383 mm_attrs_get_valid_array((MMHandleType) attr, idx, &count, &array);
391 static int __mmstreamrecorder_check_valid_pair(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list var_args)
393 #define INIT_VALUE -1
394 #define CHECK_COUNT 2
395 #define CAPTURE_RESOLUTION 1
397 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
398 MMHandleType attrs = 0;
400 int ret = MM_ERROR_NONE;
402 const char *name = NULL;
403 const char *check_pair_name[2][3] = {
404 {MMSTR_VIDEO_RESOLUTION_WIDTH, MMSTR_VIDEO_RESOLUTION_HEIGHT, "MMSTR_VIDEO_RESOLUTION_WIDTH and HEIGHT"},
408 int check_pair_value[2][2] = {
409 {INIT_VALUE, INIT_VALUE},
410 {INIT_VALUE, INIT_VALUE},
413 if (hstreamrecorder == NULL || attribute_name == NULL) {
414 _mmstreamrec_dbg_warn("handle[%p] or attribute_name[%p] is NULL.", hstreamrecorder, attribute_name);
415 return MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT;
419 *err_attr_name = NULL;
421 /* _mmstreamrec_dbg_log( "ENTER" ); */
423 attrs = MMF_STREAMRECORDER_ATTRS(handle);
425 name = attribute_name;
429 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
431 /*_mmstreamrec_dbg_log( "NAME : %s", name );*/
433 /* attribute name check */
434 if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE) {
436 *err_attr_name = strdup(name);
438 if (ret == (int)MM_ERROR_COMMON_OUT_OF_ARRAY)
439 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
445 if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
449 case MM_ATTRS_TYPE_INT:
451 va_arg((var_args), int);
454 case MM_ATTRS_TYPE_DOUBLE:
455 va_arg((var_args), double);
457 case MM_ATTRS_TYPE_STRING:
458 va_arg((var_args), char *); /* string */
459 va_arg((var_args), int); /* size */
461 case MM_ATTRS_TYPE_DATA:
462 va_arg((var_args), void *); /* data */
463 va_arg((var_args), int); /* size */
465 case MM_ATTRS_TYPE_INVALID:
467 _mmstreamrec_dbg_err("Not supported attribute type(%d, name:%s)", attr_type, name);
469 *err_attr_name = strdup(name);
470 return MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT;
474 name = va_arg(var_args, char *);
477 for (i = 0; i < CHECK_COUNT; i++) {
478 if (check_pair_value[i][0] != INIT_VALUE || check_pair_value[i][1] != INIT_VALUE) {
479 gboolean check_result = FALSE;
480 char *err_name = NULL;
481 MMStreamRecorderAttrsInfo attr_info_0, attr_info_1;
483 if (check_pair_value[i][0] == INIT_VALUE) {
484 mm_attrs_get_int_by_name(attrs, check_pair_name[i][0], &check_pair_value[i][0]);
485 err_name = strdup(check_pair_name[i][1]);
486 } else if (check_pair_value[i][1] == INIT_VALUE) {
487 mm_attrs_get_int_by_name(attrs, check_pair_name[i][1], &check_pair_value[i][1]);
488 err_name = strdup(check_pair_name[i][0]);
490 err_name = strdup(check_pair_name[i][2]);
493 mm_streamrecorder_get_attribute_info(handle, check_pair_name[i][0], &attr_info_0);
494 mm_streamrecorder_get_attribute_info(handle, check_pair_name[i][1], &attr_info_1);
496 check_result = FALSE;
498 for (j = 0; j < attr_info_0.int_array.count; j++) {
499 if (attr_info_0.int_array.array[j] == check_pair_value[i][0]
500 && attr_info_1.int_array.array[j] == check_pair_value[i][1]) {
501 _mmstreamrec_dbg_log("Valid Pair[%s,%s] existed %dx%d[index:%d]", check_pair_name[i][0], check_pair_name[i][1], check_pair_value[i][0], check_pair_value[i][1], i);
507 if (check_result == FALSE) {
508 _mmstreamrec_dbg_err("INVALID pair[%s,%s] %dx%d", check_pair_name[i][0], check_pair_name[i][1], check_pair_value[i][0], check_pair_value[i][1]);
510 *err_attr_name = err_name;
512 return MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT;
522 /*_mmstreamrec_dbg_log("DONE");*/
524 return MM_ERROR_NONE;
527 /* attribute commiter */
528 void __mmstreamrecorder_print_attrs(const char *attr_name, const mmf_value_t * value, const char *cmt_way)
530 switch (value->type) {
531 case MMF_VALUE_TYPE_INT:
532 _mmstreamrec_dbg_log("%s :(%s:%d)", cmt_way, attr_name, value->value.i_val);
534 case MMF_VALUE_TYPE_DOUBLE:
535 _mmstreamrec_dbg_log("%s :(%s:%f)", cmt_way, attr_name, value->value.d_val);
537 case MMF_VALUE_TYPE_STRING:
538 _mmstreamrec_dbg_log("%s :(%s:%s)", cmt_way, attr_name, value->value.s_val);
540 case MMF_VALUE_TYPE_DATA:
541 _mmstreamrec_dbg_log("%s :(%s:%p)", cmt_way, attr_name, value->value.p_val);
550 int _mmstreamrecorder_get_audio_codec_format(MMHandleType handle, const char *name)
552 int codec_index = MM_AUDIO_CODEC_INVALID;
555 _mmstreamrec_dbg_err("name is NULL");
556 return MM_AUDIO_CODEC_INVALID;
559 if (!strcmp(name, "AMR"))
560 codec_index = MM_AUDIO_CODEC_AMR;
561 else if (!strcmp(name, "AAC"))
562 codec_index = MM_AUDIO_CODEC_AAC;
563 else if (!strcmp(name, "PCM"))
564 codec_index = MM_AUDIO_CODEC_WAVE;
565 else if (!strcmp(name, "VORBIS"))
566 codec_index = MM_AUDIO_CODEC_VORBIS;
571 int _mmstreamrecorder_get_video_codec_format(MMHandleType handle, const char *name)
573 int codec_index = MM_VIDEO_CODEC_INVALID;
576 _mmstreamrec_dbg_err("name is NULL");
577 return MM_VIDEO_CODEC_INVALID;
580 if (!strcmp(name, "H263"))
581 codec_index = MM_VIDEO_CODEC_H263;
582 else if (!strcmp(name, "H264"))
583 codec_index = MM_VIDEO_CODEC_H264;
584 else if (!strcmp(name, "MPEG4"))
585 codec_index = MM_VIDEO_CODEC_MPEG4;
591 int _mmstreamrecorder_get_mux_format(MMHandleType handle, const char *name)
593 int mux_index = MM_FILE_FORMAT_INVALID;
596 _mmstreamrec_dbg_err("name is NULL");
597 return MM_FILE_FORMAT_INVALID;
600 if (!strcmp(name, "3GP"))
601 mux_index = MM_FILE_FORMAT_3GP;
602 else if (!strcmp(name, "AMR"))
603 mux_index = MM_FILE_FORMAT_AMR;
604 else if (!strcmp(name, "MP4"))
605 mux_index = MM_FILE_FORMAT_MP4;
606 else if (!strcmp(name, "WAV"))
607 mux_index = MM_FILE_FORMAT_WAV;
612 int _mmstreamrecorder_get_format(MMHandleType handle , int category, const char *name)
616 mmf_return_val_if_fail(name, -1);
619 case KEYWORD_AUDIO_ENCODERS:
620 fmt = _mmstreamrecorder_get_audio_codec_format(handle, name);
622 case KEYWORD_VIDEO_ENCODERS:
623 fmt = _mmstreamrecorder_get_video_codec_format(handle, name);
625 case KEYWORD_FILE_FORMATS:
626 fmt = _mmstreamrecorder_get_mux_format(handle, name);
634 int _mmstreamrecorder_get_type_count(MMHandleType handle, int type)
636 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
640 if (type == KEYWORD_VIDEO_WIDTH) {
641 while (hstreamrecorder->ini.supported_video_width[i++])
643 } else if (type == KEYWORD_VIDEO_HEIGHT) {
644 while (hstreamrecorder->ini.supported_video_height[i++])
646 } else if (type == KEYWORD_AUDIO_ENCODERS) {
647 while (hstreamrecorder->ini.supported_audio_encoders[i++][0])
649 } else if (type == KEYWORD_VIDEO_ENCODERS) {
650 while (hstreamrecorder->ini.supported_video_encoders[i++][0])
652 } else if (type == KEYWORD_FILE_FORMATS) {
653 while (hstreamrecorder->ini.supported_file_formats[i++][0])
659 void __mmstreamrecorder_get_supported_name(MMHandleType handle, int type , char **str, int i)
661 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
662 if (type == KEYWORD_AUDIO_ENCODERS) {
663 *str = hstreamrecorder->ini.supported_audio_encoders[i];
665 } else if (type == KEYWORD_VIDEO_ENCODERS) {
666 *str = hstreamrecorder->ini.supported_video_encoders[i];
668 } else if (type == KEYWORD_FILE_FORMATS) {
669 *str = hstreamrecorder->ini.supported_file_formats[i];
677 int __mmstreamrecorder_get_supported_value(MMHandleType handle, int type, int i)
679 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
681 if (type == KEYWORD_VIDEO_WIDTH)
682 return hstreamrecorder->ini.supported_video_width[i];
683 else if (type == KEYWORD_VIDEO_HEIGHT)
684 return hstreamrecorder->ini.supported_video_height[i];
690 _mmstreamrecorder_get_available_format(MMHandleType handle, int type, int ** format)
692 mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
700 mmf_return_val_if_fail(hstreamrecorder, 0);
702 count = _mmstreamrecorder_get_type_count(handle, type);
707 arr = (int*) g_malloc0(count * sizeof(int));
709 _mmstreamrec_dbg_err("malloc failed : %d", count * sizeof(int));
713 if (type == KEYWORD_VIDEO_WIDTH || type == KEYWORD_VIDEO_HEIGHT) {
714 for (i = 0 ; i < count ; i++) {
715 fmt = __mmstreamrecorder_get_supported_value(handle, type, i);
717 arr[total_count++] = fmt;
720 for (i = 0 ; i < count ; i++) {
721 __mmstreamrecorder_get_supported_name(handle, type, &name, i);
722 fmt = _mmstreamrecorder_get_format(handle, type, name);
724 arr[total_count++] = fmt;
731 /*=======================================================================
732 | FUNCTION DEFINITIONS |
733 =======================================================================*/
734 /*-----------------------------------------------------------------------
735 | GLOBAL FUNCTION DEFINITIONS: |
736 -----------------------------------------------------------------------*/
737 MMHandleType _mmstreamrecorder_alloc_attribute(MMHandleType handle)
739 _mmstreamrec_dbg_log("");
741 MMHandleType attrs = 0;
742 mmf_attrs_construct_info_t *attrs_const_info = NULL;
743 unsigned int attr_count = 0;
746 /* Create attribute constructor */
747 _mmstreamrec_dbg_log("start");
749 /* alloc 'mmf_attrs_construct_info_t' */
750 attr_count = ARRAY_SIZE(stream_attrs_const_info);
751 attrs_const_info = malloc(attr_count * sizeof(mmf_attrs_construct_info_t));
753 if (!attrs_const_info) {
754 _mmstreamrec_dbg_err("Fail to alloc constructor.");
758 for (idx = 0; idx < attr_count; idx++) {
759 /* attribute order check. This should be same. */
760 if (idx != stream_attrs_const_info[idx].attrid) {
761 _mmstreamrec_dbg_err("Please check attributes order. Is the idx same with enum val?");
762 free(attrs_const_info);
763 attrs_const_info = NULL;
767 attrs_const_info[idx].name = stream_attrs_const_info[idx].name;
768 attrs_const_info[idx].value_type = stream_attrs_const_info[idx].value_type;
769 attrs_const_info[idx].flags = stream_attrs_const_info[idx].flags;
770 attrs_const_info[idx].default_value = stream_attrs_const_info[idx].default_value.value_void;
773 _mmstreamrec_dbg_log("Create Streamrecorder Attributes[%p, %d]", attrs_const_info, attr_count);
775 attrs = mmf_attrs_new_from_data("Streamrecorder_Attributes", attrs_const_info, attr_count, _mmstreamrecorder_commit_streamrecorder_attrs, (void *)handle);
777 free(attrs_const_info);
778 attrs_const_info = NULL;
781 _mmstreamrec_dbg_err("Fail to alloc attribute handle");
785 __mmstreamrecorder_set_conf_to_valid_info(handle);
787 for (idx = 0; idx < attr_count; idx++) {
788 mmf_attrs_set_valid_type(attrs, idx, stream_attrs_const_info[idx].validity_type);
790 switch (stream_attrs_const_info[idx].validity_type) {
791 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
792 if (stream_attrs_const_info[idx].validity_value_1.int_array &&
793 stream_attrs_const_info[idx].validity_value_2.count > 0)
794 mmf_attrs_set_valid_array(attrs, idx,
795 (const int *)(stream_attrs_const_info[idx].validity_value_1.int_array),
796 stream_attrs_const_info[idx].validity_value_2.count,
797 stream_attrs_const_info[idx].default_value.value_int);
799 case MM_ATTRS_VALID_TYPE_INT_RANGE:
800 mmf_attrs_set_valid_range(attrs, idx,
801 stream_attrs_const_info[idx].validity_value_1.int_min,
802 stream_attrs_const_info[idx].validity_value_2.int_max,
803 stream_attrs_const_info[idx].default_value.value_int);
805 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
806 if (stream_attrs_const_info[idx].validity_value_1.double_array &&
807 stream_attrs_const_info[idx].validity_value_2.count > 0)
808 mmf_attrs_set_valid_double_array(attrs, idx,
809 (const double *)(stream_attrs_const_info[idx].validity_value_1.double_array),
810 stream_attrs_const_info[idx].validity_value_2.count,
811 stream_attrs_const_info[idx].default_value.value_double);
813 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
814 mmf_attrs_set_valid_double_range(attrs, idx,
815 stream_attrs_const_info[idx].validity_value_1.double_min,
816 stream_attrs_const_info[idx].validity_value_2.double_max,
817 stream_attrs_const_info[idx].default_value.value_double);
819 case MM_ATTRS_VALID_TYPE_NONE:
821 case MM_ATTRS_VALID_TYPE_INVALID:
823 _mmstreamrec_dbg_err("Valid type error.");
828 __mmstreamrecorder_release_conf_valid_info(handle);
833 void _mmstreamrecorder_dealloc_attribute(MMHandleType attrs)
835 _mmstreamrec_dbg_log("");
838 mmf_attrs_free(attrs);
840 _mmstreamrec_dbg_log("released attribute");
844 int _mmstreamrecorder_get_attributes(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list var_args)
846 MMHandleType attrs = 0;
847 int ret = MM_ERROR_NONE;
849 mmf_return_val_if_fail(handle, MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT);
851 attrs = MMF_STREAMRECORDER_ATTRS(handle);
852 mmf_return_val_if_fail(attrs, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
854 ret = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, var_args);
859 int _mmstreamrecorder_set_attributes(MMHandleType handle, char **err_attr_name, const char *attribute_name, va_list var_args)
861 MMHandleType attrs = 0;
862 int ret = MM_ERROR_NONE;
863 va_list var_args_copy;
865 mmf_return_val_if_fail(handle, MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT);
867 attrs = MMF_STREAMRECORDER_ATTRS(handle);
869 _mmstreamrec_dbg_err("handle 0x%x, attrs is NULL, attr name [%s]", handle, attribute_name);
870 return MM_ERROR_STREAMRECORDER_NOT_INITIALIZED;
873 /* copy var_args to keep original var_args */
874 va_copy(var_args_copy, var_args);
876 ret = __mmstreamrecorder_check_valid_pair(handle, err_attr_name, attribute_name, var_args);
878 _mmstreamrec_dbg_err("__mmstreamrecorder_check_valid_pair handle 0x%x, attr name [%s] , ret = %d", handle, attribute_name, ret);
880 if (ret == MM_ERROR_NONE) {
881 /* In 64bit environment, unexpected result is returned if var_args is used again. */
882 ret = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, var_args_copy);
884 va_end(var_args_copy);
886 _mmstreamrec_dbg_err("mm_attrs_set_valist handle 0x%x, attr name [%s] , ret = %d", handle, attribute_name, ret);
890 int _mmstreamrecorder_get_attribute_info(MMHandleType handle, const char *attr_name, MMStreamRecorderAttrsInfo * info)
892 MMHandleType attrs = 0;
893 MMAttrsInfo attrinfo;
894 int ret = MM_ERROR_NONE;
896 mmf_return_val_if_fail(handle, MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT);
897 mmf_return_val_if_fail(attr_name, MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT);
898 mmf_return_val_if_fail(info, MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT);
900 attrs = MMF_STREAMRECORDER_ATTRS(handle);
901 mmf_return_val_if_fail(attrs, MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT);
903 ret = mm_attrs_get_info_by_name(attrs, attr_name, (MMAttrsInfo *) & attrinfo);
905 if (ret == MM_ERROR_NONE) {
906 memset(info, 0x00, sizeof(MMStreamRecorderAttrsInfo));
907 info->type = attrinfo.type;
908 info->flag = attrinfo.flag;
909 info->validity_type = attrinfo.validity_type;
911 switch (attrinfo.validity_type) {
912 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
913 info->int_array.array = attrinfo.int_array.array;
914 info->int_array.count = attrinfo.int_array.count;
915 info->int_array.def = attrinfo.int_array.dval;
917 case MM_ATTRS_VALID_TYPE_INT_RANGE:
918 info->int_range.min = attrinfo.int_range.min;
919 info->int_range.max = attrinfo.int_range.max;
920 info->int_range.def = attrinfo.int_range.dval;
922 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
923 info->double_array.array = attrinfo.double_array.array;
924 info->double_array.count = attrinfo.double_array.count;
925 info->double_array.def = attrinfo.double_array.dval;
927 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
928 info->double_range.min = attrinfo.double_range.min;
929 info->double_range.max = attrinfo.double_range.max;
930 info->double_range.def = attrinfo.double_range.dval;
932 case MM_ATTRS_VALID_TYPE_NONE:
934 case MM_ATTRS_VALID_TYPE_INVALID:
943 bool _mmstreamrecorder_commit_streamrecorder_attrs(int attr_idx, const char *attr_name, const mmf_value_t * value, void *commit_param)
947 mmf_return_val_if_fail(commit_param, FALSE);
948 mmf_return_val_if_fail(attr_idx >= 0, FALSE);
949 mmf_return_val_if_fail(attr_name, FALSE);
950 mmf_return_val_if_fail(value, FALSE);
952 if (stream_attrs_const_info[attr_idx].attr_commit) {
953 /* _mmstreamrec_dbg_log("Dynamic commit:(%s)", attr_name); */
954 __mmstreamrecorder_print_attrs(attr_name, value, "Dynamic");
955 bret = stream_attrs_const_info[attr_idx].attr_commit((MMHandleType) commit_param, attr_idx, value);
957 /* _mmstreamrec_dbg_log("Static commit:(%s)", attr_name); */
958 __mmstreamrecorder_print_attrs(attr_name, value, "Static");
965 bool _mmstreamrecorder_commit_video_enable(MMHandleType handle, int attr_idx, const mmf_value_t *value)
967 MMHandleType attr = 0;
968 /* mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle); */
969 _MMStreamRecorderSubContext *sc = NULL;
970 _MMStreamRecorderVideoInfo *info = NULL;
972 mmf_return_val_if_fail(handle, FALSE);
973 attr = MMF_STREAMRECORDER_ATTRS(handle);
974 mmf_return_val_if_fail(attr, FALSE);
975 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
977 _mmstreamrec_dbg_log("(%d)", attr_idx);
979 mmf_return_val_if_fail(sc, FALSE);
981 info = (_MMStreamRecorderVideoInfo *) sc->info_video;
983 if (info == NULL && value->value.i_val != 0) {
984 if (_mmstreamrecorder_alloc_subcontext_videoinfo(handle))
991 bool _mmstreamrecorder_commit_video_encoder(MMHandleType handle, int attr_idx, const mmf_value_t *value)
993 MMHandleType attr = 0;
994 _MMStreamRecorderSubContext *sc = NULL;
995 _MMStreamRecorderVideoInfo *info = NULL;
997 mmf_return_val_if_fail(handle, FALSE);
998 attr = MMF_STREAMRECORDER_ATTRS(handle);
999 mmf_return_val_if_fail(attr, FALSE);
1000 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1001 mmf_return_val_if_fail(sc, FALSE);
1003 info = (_MMStreamRecorderVideoInfo *) sc->info_video;
1004 mmf_return_val_if_fail(info, FALSE);
1006 _mmstreamrec_dbg_log("(%d)", attr_idx);
1008 info->iVideoEncoder = value->value.i_val;
1013 bool _mmstreamrecorder_commit_audio_enable(MMHandleType handle, int attr_idx, const mmf_value_t *value)
1015 MMHandleType attr = 0;
1016 /* mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle); */
1017 _MMStreamRecorderSubContext *sc = NULL;
1018 _MMStreamRecorderAudioInfo *info = NULL;
1020 mmf_return_val_if_fail(handle, FALSE);
1021 attr = MMF_STREAMRECORDER_ATTRS(handle);
1022 mmf_return_val_if_fail(attr, FALSE);
1023 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1024 mmf_return_val_if_fail(sc, FALSE);
1026 _mmstreamrec_dbg_log("(%d)", attr_idx);
1028 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1030 if (info == NULL && value->value.i_val != 0) {
1031 if (_mmstreamrecorder_alloc_subcontext_audioinfo(handle))
1038 bool _mmstreamrecorder_commit_audio_encoder(MMHandleType handle, int attr_idx, const mmf_value_t *value)
1040 MMHandleType attr = 0;
1041 _MMStreamRecorderSubContext *sc = NULL;
1042 _MMStreamRecorderAudioInfo *info = NULL;
1044 mmf_return_val_if_fail(handle, FALSE);
1045 attr = MMF_STREAMRECORDER_ATTRS(handle);
1046 mmf_return_val_if_fail(attr, FALSE);
1047 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1048 mmf_return_val_if_fail(sc, FALSE);
1050 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1051 mmf_return_val_if_fail(info, FALSE);
1053 _mmstreamrec_dbg_log("(%d)", attr_idx);
1055 info->iAudioEncoder = value->value.i_val;
1060 bool _mmstreamrecorder_commit_audio_samplingrate(MMHandleType handle, int attr_idx, const mmf_value_t *value)
1062 MMHandleType attr = 0;
1063 _MMStreamRecorderSubContext *sc = NULL;
1064 _MMStreamRecorderAudioInfo *info = NULL;
1066 mmf_return_val_if_fail(handle, FALSE);
1067 attr = MMF_STREAMRECORDER_ATTRS(handle);
1068 mmf_return_val_if_fail(attr, FALSE);
1069 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1070 mmf_return_val_if_fail(sc, FALSE);
1072 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1073 mmf_return_val_if_fail(info, FALSE);
1075 _mmstreamrec_dbg_log("(%d)", attr_idx);
1077 info->iSamplingRate = value->value.i_val;
1082 bool _mmstreamrecorder_commit_audio_bitformat(MMHandleType handle, int attr_idx, const mmf_value_t *value)
1084 MMHandleType attr = 0;
1085 _MMStreamRecorderSubContext *sc = NULL;
1086 _MMStreamRecorderAudioInfo *info = NULL;
1088 mmf_return_val_if_fail(handle, FALSE);
1089 attr = MMF_STREAMRECORDER_ATTRS(handle);
1090 mmf_return_val_if_fail(attr, FALSE);
1091 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1092 mmf_return_val_if_fail(sc, FALSE);
1094 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1095 mmf_return_val_if_fail(info, FALSE);
1097 _mmstreamrec_dbg_log("(%d)", attr_idx);
1099 if (value->value.i_val == MM_STREAMRECORDER_AUDIO_FORMAT_PCM_U8)
1100 info->audio_encode_depth = 16;
1102 info->audio_encode_depth = 8;
1107 bool _mmstreamrecorder_commit_video_bitrate(MMHandleType handle, int attr_idx, const mmf_value_t *value)
1109 MMHandleType attr = 0;
1110 _MMStreamRecorderSubContext *sc = NULL;
1113 mmf_return_val_if_fail(handle, FALSE);
1114 attr = MMF_STREAMRECORDER_ATTRS(handle);
1115 mmf_return_val_if_fail(attr, FALSE);
1116 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1117 mmf_return_val_if_fail(sc, FALSE);
1119 v_bitrate = value->value.i_val;
1121 if (sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst) {
1122 MMSTREAMRECORDER_G_OBJECT_SET(sc->encode_element[_MMSTREAMRECORDER_ENCSINK_VENC].gst, "bitrate", v_bitrate);
1123 _mmstreamrec_dbg_log("video bitrate set to encoder success = %d", v_bitrate);
1125 _mmstreamrec_dbg_log("_MMSTREAMRECORDER_ENCSINK_VENC is null %d", attr_idx);
1130 bool _mmstreamrecorder_commit_audio_bitrate(MMHandleType handle, int attr_idx, const mmf_value_t *value)
1132 MMHandleType attr = 0;
1133 _MMStreamRecorderSubContext *sc = NULL;
1134 _MMStreamRecorderAudioInfo *info = NULL;
1136 mmf_return_val_if_fail(handle, FALSE);
1137 attr = MMF_STREAMRECORDER_ATTRS(handle);
1138 mmf_return_val_if_fail(attr, FALSE);
1139 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1140 mmf_return_val_if_fail(sc, FALSE);
1142 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1143 mmf_return_val_if_fail(info, FALSE);
1145 _mmstreamrec_dbg_log("(%d)", attr_idx);
1147 info->iBitrate = value->value.i_val;
1152 bool _mmstreamrecorder_commit_audio_channel(MMHandleType handle, int attr_idx, const mmf_value_t *value)
1154 MMHandleType attr = 0;
1155 _MMStreamRecorderSubContext *sc = NULL;
1156 _MMStreamRecorderAudioInfo *info = NULL;
1158 mmf_return_val_if_fail(handle, FALSE);
1159 attr = MMF_STREAMRECORDER_ATTRS(handle);
1160 mmf_return_val_if_fail(attr, FALSE);
1161 sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
1162 mmf_return_val_if_fail(sc, FALSE);
1164 info = (_MMStreamRecorderAudioInfo *) sc->info_audio;
1165 mmf_return_val_if_fail(info, FALSE);
1167 _mmstreamrec_dbg_log("(%d)", attr_idx);
1169 info->iChannels = value->value.i_val;