2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <mm_streamrecorder.h>
22 #include <streamrecorder_private.h>
30 #define LOWSET_DECIBEL -300.0
32 int __convert_streamrecorder_error_code(const char *func, int code)
34 int ret = STREAMRECORDER_ERROR_INVALID_OPERATION;
35 const char *errorstr = NULL;
38 case STREAMRECORDER_ERROR_INVALID_PARAMETER:
39 ret = STREAMRECORDER_ERROR_INVALID_PARAMETER;
40 errorstr = "INVALID_PARAMETER";
43 ret = STREAMRECORDER_ERROR_NONE;
44 errorstr = "ERROR_NONE";
46 case MM_ERROR_STREAMRECORDER_INVALID_ARGUMENT:
47 case MM_ERROR_COMMON_INVALID_ATTRTYPE:
48 ret = STREAMRECORDER_ERROR_INVALID_PARAMETER;
49 errorstr = "INVALID_PARAMETER";
51 case MM_ERROR_COMMON_INVALID_PERMISSION:
52 ret = STREAMRECORDER_ERROR_PERMISSION_DENIED;
53 errorstr = "ERROR_PERMISSION_DENIED";
55 case MM_ERROR_STREAMRECORDER_NOT_INITIALIZED:
56 ret = STREAMRECORDER_ERROR_INVALID_STATE;
57 errorstr = "INVALID_STATE";
59 case MM_ERROR_STREAMRECORDER_GST_CORE:
60 case MM_ERROR_STREAMRECORDER_GST_LIBRARY:
61 case MM_ERROR_STREAMRECORDER_GST_RESOURCE:
62 case MM_ERROR_STREAMRECORDER_GST_STREAM:
63 case MM_ERROR_STREAMRECORDER_GST_STATECHANGE:
64 case MM_ERROR_STREAMRECORDER_GST_NEGOTIATION:
65 case MM_ERROR_STREAMRECORDER_GST_LINK:
66 case MM_ERROR_STREAMRECORDER_GST_FLOW_ERROR:
67 case MM_ERROR_STREAMRECORDER_ENCODER:
68 case MM_ERROR_STREAMRECORDER_ENCODER_BUFFER:
69 case MM_ERROR_STREAMRECORDER_ENCODER_WRONG_TYPE:
70 case MM_ERROR_STREAMRECORDER_ENCODER_WORKING:
71 case MM_ERROR_STREAMRECORDER_RESPONSE_TIMEOUT:
72 case MM_ERROR_STREAMRECORDER_CMD_IS_RUNNING:
73 ret = STREAMRECORDER_ERROR_INVALID_OPERATION;
74 errorstr = "INVALID_OPERATION";
76 case MM_ERROR_STREAMRECORDER_RESOURCE_CREATION:
77 case MM_ERROR_COMMON_OUT_OF_MEMORY:
78 ret = STREAMRECORDER_ERROR_OUT_OF_MEMORY;
79 errorstr = "OUT_OF_MEMORY";
81 case MM_ERROR_OUT_OF_STORAGE:
82 ret = STREAMRECORDER_ERROR_OUT_OF_STORAGE;
83 errorstr = "OUT_OF_STORAGE";
85 case MM_ERROR_COMMON_OUT_OF_ARRAY:
86 case MM_ERROR_COMMON_OUT_OF_RANGE:
87 case MM_ERROR_COMMON_ATTR_NOT_EXIST:
88 ret = STREAMRECORDER_ERROR_NOT_SUPPORTED;
89 errorstr = "NOT_SUPPORTED";
92 ret = STREAMRECORDER_ERROR_INVALID_OPERATION;
93 errorstr = "INVALID_OPERATION";
98 LOGE("[%s] %s(0x%08x) : core frameworks error code(0x%08x)", func, errorstr, ret, code);
103 static streamrecorder_state_e __streamrecorder_state_convert(void *mm_state)
105 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
106 MMStreamRecorderStateType srstate = (MMStreamRecorderStateType)mm_state;
109 case MM_STREAMRECORDER_STATE_NONE:
110 state = STREAMRECORDER_STATE_NONE;
112 case MM_STREAMRECORDER_STATE_CREATED:
113 state = STREAMRECORDER_STATE_CREATED;
115 case MM_STREAMRECORDER_STATE_PREPARED:
116 state = STREAMRECORDER_STATE_PREPARED;
118 case MM_STREAMRECORDER_STATE_RECORDING:
119 state = STREAMRECORDER_STATE_RECORDING;
121 case MM_STREAMRECORDER_STATE_PAUSED:
122 state = STREAMRECORDER_STATE_PAUSED;
125 state = STREAMRECORDER_STATE_NONE;
132 static int _streamrecorder_check_and_set_attribute(streamrecorder_h recorder, const char *attribute_name, int set_value)
134 int ret = MM_ERROR_NONE;
136 MMStreamRecorderStateType mmstate;
137 streamrecorder_s *handle = (streamrecorder_s *)recorder;
139 if (recorder == NULL) {
140 LOGE("handle is NULL");
141 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
144 mm_streamrecorder_get_state(handle->mm_handle, &mmstate);
145 if (mmstate >= MM_STREAMRECORDER_STATE_RECORDING) {
146 LOGE("invalid state %d", mmstate);
147 return STREAMRECORDER_ERROR_INVALID_STATE;
150 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
151 attribute_name, set_value,
154 if (ret != MM_ERROR_NONE) {
155 LOGE("set [%s] failed 0x%x", attribute_name, ret);
160 return __convert_streamrecorder_error_code(attribute_name, ret);
164 int _streamrecorder_set_videosource_buffer(streamrecorder_h recorder)
166 int ret = STREAMRECORDER_ERROR_NONE;
167 if (recorder == NULL)
168 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
170 streamrecorder_s *handle = (streamrecorder_s *)recorder;
172 mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
173 MMSTR_RECORDER_MODE, MM_STREAMRECORDER_MODE_MEDIABUFFER,
176 mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
177 MMSTR_VIDEO_ENABLE, true,
184 int _streamrecorder_set_audiosource_buffer(streamrecorder_h recorder)
186 int ret = STREAMRECORDER_ERROR_NONE;
187 if (recorder == NULL)
188 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
190 streamrecorder_s *handle;
191 handle = (streamrecorder_s *) recorder;
192 mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
193 MMSTR_RECORDER_MODE, MM_STREAMRECORDER_MODE_MEDIABUFFER,
196 mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
197 MMSTR_AUDIO_ENABLE, true,
203 int _streamrecorder_get_state(streamrecorder_h recorder, streamrecorder_state_e *state)
205 int ret = STREAMRECORDER_ERROR_NONE;
206 MMStreamRecorderStateType srstate;
208 if (recorder == NULL) {
209 LOGE("NULL pointer handle");
210 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
213 LOGE("NULL pointer state");
214 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
217 streamrecorder_s *handle = (streamrecorder_s *)recorder;
220 ret = mm_streamrecorder_get_state(handle->mm_handle, &srstate);
221 if (ret != MM_ERROR_NONE) {
222 return __convert_streamrecorder_error_code(__func__, ret);
224 *state = __streamrecorder_state_convert((void *)srstate);
226 return STREAMRECORDER_ERROR_NONE;
229 int _streamrecorder_destroy(streamrecorder_h recorder)
231 streamrecorder_s *handle = NULL;
232 int ret = MM_ERROR_NONE;
233 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
234 if (recorder == NULL) {
235 LOGE("NULL pointer handle");
236 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
239 handle = (streamrecorder_s *)recorder;
241 ret = streamrecorder_get_state(recorder, &state);
242 if (ret != MM_ERROR_NONE) {
243 LOGE("stramrecorder_unrealize fail");
244 return __convert_streamrecorder_error_code(__func__, ret);
247 if (state != STREAMRECORDER_STATE_CREATED) {
248 LOGE("STREAMRECORDER_ERROR_INVALID_STATE (state:%d)", state);
249 return STREAMRECORDER_ERROR_INVALID_STATE;
252 ret = mm_streamrecorder_destroy(handle->mm_handle);
254 if (ret == MM_ERROR_NONE) {
259 return __convert_streamrecorder_error_code(__func__, ret);
262 int _streamrecorder_prepare(streamrecorder_h recorder)
264 int ret = MM_ERROR_NONE;
265 streamrecorder_s *handle = (streamrecorder_s *)recorder;
266 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
268 if (recorder == NULL) {
269 LOGE("NULL pointer handle");
270 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
272 ret = streamrecorder_get_state(recorder, &state);
273 if (ret != MM_ERROR_NONE) {
274 return __convert_streamrecorder_error_code(__func__, ret);
277 if (state != STREAMRECORDER_STATE_CREATED) {
278 LOGE("STREAMRECORDER_ERROR_INVALID_STATE (state:%d)", state);
279 return STREAMRECORDER_ERROR_INVALID_STATE;
282 ret = mm_streamrecorder_realize(handle->mm_handle);
283 if (ret != MM_ERROR_NONE) {
284 LOGE("prepare fail");
285 return __convert_streamrecorder_error_code(__func__, ret);
288 return STREAMRECORDER_ERROR_NONE;
291 int _streamrecorder_unprepare(streamrecorder_h recorder)
293 int ret = MM_ERROR_NONE;
294 streamrecorder_s *handle = (streamrecorder_s *)recorder;
295 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
297 if (recorder == NULL) {
298 LOGE("NULL pointer handle");
299 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
302 ret = streamrecorder_get_state(recorder, &state);
303 if (ret != MM_ERROR_NONE) {
304 return __convert_streamrecorder_error_code(__func__, ret);
307 if (state != STREAMRECORDER_STATE_CREATED) {
308 LOGE("STREAMRECORDER_ERROR_INVALID_STATE (state:%d)", state);
309 return STREAMRECORDER_ERROR_INVALID_STATE;
312 ret = mm_streamrecorder_unrealize(handle->mm_handle);
313 if (ret != MM_ERROR_NONE) {
314 LOGE("stramrecorder_unrealize fail");
316 return __convert_streamrecorder_error_code(__func__, ret);
319 int _streamrecorder_start(streamrecorder_h recorder)
321 int ret = MM_ERROR_NONE;
322 streamrecorder_s *handle = (streamrecorder_s *)recorder;
323 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
325 if (recorder == NULL) {
326 LOGE("NULL pointer handle");
327 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
330 ret = streamrecorder_get_state(recorder, &state);
331 if (ret != MM_ERROR_NONE) {
332 return __convert_streamrecorder_error_code(__func__, ret);
335 if (!(state == STREAMRECORDER_STATE_PREPARED || state == STREAMRECORDER_STATE_PAUSED)) {
336 LOGE("STREAMRECORDER_ERROR_INVALID_STATE (state:%d)", state);
337 return STREAMRECORDER_ERROR_INVALID_STATE;
340 return __convert_streamrecorder_error_code(__func__, mm_streamrecorder_record(handle->mm_handle));
343 int _streamrecorder_pause(streamrecorder_h recorder)
345 int ret = MM_ERROR_NONE;
346 streamrecorder_s *handle = (streamrecorder_s *)recorder;
347 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
349 if (recorder == NULL) {
350 LOGE("NULL pointer handle");
351 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
354 ret = streamrecorder_get_state(recorder, &state);
355 if (ret != MM_ERROR_NONE) {
356 return __convert_streamrecorder_error_code(__func__, ret);
359 if (state != STREAMRECORDER_STATE_RECORDING) {
360 LOGE("STREAMRECORDER_ERROR_INVALID_STATE (state:%d)", state);
361 return STREAMRECORDER_ERROR_INVALID_STATE;
365 return __convert_streamrecorder_error_code(__func__, mm_streamrecorder_pause(handle->mm_handle));
368 int _streamrecorder_commit(streamrecorder_h recorder)
370 int ret = MM_ERROR_NONE;
371 streamrecorder_s *handle = (streamrecorder_s *)recorder;
372 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
374 if (recorder == NULL) {
375 LOGE("NULL pointer handle");
376 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
379 ret = streamrecorder_get_state(recorder, &state);
380 if (ret != MM_ERROR_NONE) {
381 return __convert_streamrecorder_error_code(__func__, ret);
384 if (!(state == STREAMRECORDER_STATE_RECORDING || state == STREAMRECORDER_STATE_PAUSED)) {
385 LOGE("STREAMRECORDER_ERROR_INVALID_STATE (state:%d)", state);
386 return STREAMRECORDER_ERROR_INVALID_STATE;
389 return __convert_streamrecorder_error_code(__func__, mm_streamrecorder_commit(handle->mm_handle));
392 int _streamrecorder_cancel(streamrecorder_h recorder)
394 streamrecorder_s *handle = (streamrecorder_s *)recorder;
396 if (recorder == NULL) {
397 LOGE("NULL pointer handle");
398 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
401 return __convert_streamrecorder_error_code(__func__, mm_streamrecorder_cancel(handle->mm_handle));
404 int _streamrecorder_set_video_framerate(streamrecorder_h recorder , int framerate)
406 int ret = MM_ERROR_NONE;
407 streamrecorder_s *handle = (streamrecorder_s *)recorder;
409 if (recorder == NULL) {
410 LOGE("NULL pointer handle");
411 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
414 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
415 MMSTR_VIDEO_FRAMERATE, framerate,
418 return __convert_streamrecorder_error_code(__func__, ret);
422 int _streamrecorder_get_video_framerate(streamrecorder_h recorder, int *framerate)
424 int ret = MM_ERROR_NONE;
425 streamrecorder_s *handle = (streamrecorder_s *)recorder;
427 if (recorder == NULL) {
428 LOGE("NULL pointer handle");
429 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
432 if (framerate == NULL) {
433 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
436 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
437 MMSTR_VIDEO_FRAMERATE, framerate,
440 return __convert_streamrecorder_error_code(__func__, ret);
443 int _streamrecorder_set_video_source_format(streamrecorder_h recorder , int format)
445 int ret = MM_ERROR_NONE;
446 streamrecorder_s *handle = (streamrecorder_s *)recorder;
448 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
449 MMSTR_VIDEO_SOURCE_FORMAT, format,
452 return __convert_streamrecorder_error_code(__func__, ret);
455 int _streamrecorder_get_video_source_format(streamrecorder_h recorder, int *format)
457 int ret = MM_ERROR_NONE;
458 streamrecorder_s *handle = (streamrecorder_s *)recorder;
460 if (format == NULL) {
461 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
464 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
465 MMSTR_VIDEO_SOURCE_FORMAT, format,
468 return __convert_streamrecorder_error_code(__func__, ret);
471 int _streamrecorder_set_video_resolution(streamrecorder_h recorder, int width, int height)
473 int ret = MM_ERROR_NONE;
474 streamrecorder_s *handle = (streamrecorder_s *)recorder;
475 streamrecorder_state_e state = STREAMRECORDER_STATE_NONE;
477 if (handle == NULL) {
478 LOGE("NULL pointer handle");
479 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
481 streamrecorder_get_state(recorder, &state);
482 if (state > STREAMRECORDER_STATE_CREATED) {
483 LOGE("STREAMRECORDER_ERROR_INVALID_STATE (state:%d)", state);
484 return STREAMRECORDER_ERROR_INVALID_STATE;
487 if (width == 0 || height == 0) {
488 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
491 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
492 MMSTR_VIDEO_RESOLUTION_WIDTH, width,
493 MMSTR_VIDEO_RESOLUTION_HEIGHT, height,
496 return __convert_streamrecorder_error_code(__func__, ret);
499 int _streamrecorder_get_video_resolution(streamrecorder_h recorder, int *width, int *height)
501 int ret = MM_ERROR_NONE;
502 streamrecorder_s *handle = (streamrecorder_s *)recorder;
505 LOGE("NULL pointer handle");
506 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
510 if (!width || !height) {
511 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
512 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
515 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
516 MMSTR_VIDEO_RESOLUTION_WIDTH , width,
517 MMSTR_VIDEO_RESOLUTION_HEIGHT , height,
519 return __convert_streamrecorder_error_code(__func__, ret);
522 int _streamrecorder_foreach_supported_video_resolution(streamrecorder_h recorder, streamrecorder_supported_video_resolution_cb foreach_cb, void *user_data)
525 int ret = MM_ERROR_NONE;
526 streamrecorder_s * handle = (streamrecorder_s *)recorder;
529 LOGE("NULL pointer handle");
530 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
535 LOGE("NULL pointer callback");
536 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
539 MMStreamRecorderAttrsInfo video_width;
540 MMStreamRecorderAttrsInfo video_height;
541 ret = mm_streamrecorder_get_attribute_info(handle->mm_handle, MMSTR_VIDEO_RESOLUTION_WIDTH, &video_width);
542 ret |= mm_streamrecorder_get_attribute_info(handle->mm_handle, MMSTR_VIDEO_RESOLUTION_HEIGHT, &video_height);
544 if (ret != MM_ERROR_NONE) {
545 return __convert_streamrecorder_error_code(__func__, ret);
547 for (i = 0 ; i < video_width.int_array.count ; i++) {
548 if (!foreach_cb(video_width.int_array.array[i], video_height.int_array.array[i], user_data)) {
553 return STREAMRECORDER_ERROR_NONE;
557 int _streamrecorder_set_filename(streamrecorder_h recorder, const char *filename)
559 int ret = MM_ERROR_NONE;
560 streamrecorder_s *handle = (streamrecorder_s *)recorder;
562 if (recorder == NULL) {
563 LOGE("handle is NULL");
564 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
567 if (filename == NULL) {
568 LOGE("filename is NULL");
569 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
572 MMStreamRecorderStateType mmstate = MM_STREAMRECORDER_STATE_NONE;
573 mm_streamrecorder_get_state(handle->mm_handle, &mmstate);
574 if (mmstate >= MM_STREAMRECORDER_STATE_RECORDING) {
575 LOGE("invalid state %d", mmstate);
576 return STREAMRECORDER_ERROR_INVALID_STATE;
578 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
579 MMSTR_FILENAME, filename, strlen(filename),
581 return __convert_streamrecorder_error_code(__func__, ret);
584 int _streamrecorder_get_filename(streamrecorder_h recorder, char **filename)
586 int ret = MM_ERROR_NONE;
587 char *record_filename = NULL;
588 int record_filename_size;
589 streamrecorder_s *handle = (streamrecorder_s *)recorder;
591 if (recorder == NULL) {
592 LOGE("handle is NULL");
593 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
596 if (filename == NULL) {
597 LOGE("filename is NULL");
598 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
601 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
602 MMSTR_FILENAME, &record_filename, &record_filename_size,
604 if (ret == MM_ERROR_NONE && record_filename) {
605 *filename = strdup(record_filename);
607 LOGE("internal return (0x%08x), get filename p:%p", ret, record_filename);
610 return __convert_streamrecorder_error_code(__func__, ret);
613 int _streamrecorder_set_file_format(streamrecorder_h recorder, streamrecorder_file_format_e format)
615 int format_table[5] = {MM_FILE_FORMAT_3GP, /* STREAMRECORDER_FILE_FORMAT_3GP */
616 MM_FILE_FORMAT_MP4, /* STREAMRECORDER_FILE_FORMAT_MP4 */
617 MM_FILE_FORMAT_AMR, /* STREAMRECORDER_FILE_FORMAT_AMR */
618 MM_FILE_FORMAT_AAC, /* STREAMRECORDER_FILE_FORMAT_ADTS */
619 MM_FILE_FORMAT_WAV, /* STREAMRECORDER_FILE_FORMAT_WAV */
621 if (recorder == NULL) {
622 LOGE("handle is NULL");
623 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
626 if (format < STREAMRECORDER_FILE_FORMAT_3GP || format > STREAMRECORDER_FILE_FORMAT_WAV) {
627 LOGE("invalid format %d", format);
628 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
630 return _streamrecorder_check_and_set_attribute(recorder, MMSTR_FILE_FORMAT, format_table[format]);
634 int _streamrecorder_get_file_format(streamrecorder_h recorder, streamrecorder_file_format_e *format)
636 int ret = MM_ERROR_NONE;
637 streamrecorder_s *handle = (streamrecorder_s *)recorder;
640 if (recorder == NULL) {
641 LOGE("handle is NULL");
642 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
645 if (format == NULL) {
646 LOGE("format is NULL");
647 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
650 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
651 MMSTR_FILE_FORMAT, &mm_format,
653 if (ret == MM_ERROR_NONE) {
655 case MM_FILE_FORMAT_3GP:
656 *format = STREAMRECORDER_FILE_FORMAT_3GP;
658 case MM_FILE_FORMAT_MP4:
659 *format = STREAMRECORDER_FILE_FORMAT_MP4;
661 case MM_FILE_FORMAT_AMR:
662 *format = STREAMRECORDER_FILE_FORMAT_AMR;
664 case MM_FILE_FORMAT_AAC:
665 *format = STREAMRECORDER_FILE_FORMAT_ADTS;
667 case MM_FILE_FORMAT_WAV:
668 *format = STREAMRECORDER_FILE_FORMAT_WAV;
671 ret = MM_ERROR_STREAMRECORDER_INTERNAL;
676 return __convert_streamrecorder_error_code(__func__, ret);
679 int _streamrecorder_foreach_supported_file_format(streamrecorder_h recorder, streamrecorder_supported_file_format_cb foreach_cb, void *user_data)
682 int ret = MM_ERROR_NONE;
683 streamrecorder_s *handle = (streamrecorder_s *)recorder;
686 if (recorder == NULL) {
687 LOGE("NULL pointer handle");
688 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
690 if (foreach_cb == NULL) {
691 LOGE("NULL pointer foreach_cb");
692 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
695 MMStreamRecorderAttrsInfo info;
696 ret = mm_streamrecorder_get_attribute_info(handle->mm_handle, MMSTR_FILE_FORMAT, &info);
697 if (ret != MM_ERROR_NONE) {
698 LOGE("mm_streamrecorder_get_attribute_info failed 0x%x", ret);
699 return __convert_streamrecorder_error_code(__func__, ret);
702 for (i = 0 ; i < info.int_array.count ; i++) {
703 switch (info.int_array.array[i]) {
704 case MM_FILE_FORMAT_3GP:
705 format = STREAMRECORDER_FILE_FORMAT_3GP;
707 case MM_FILE_FORMAT_MP4:
708 format = STREAMRECORDER_FILE_FORMAT_MP4;
710 case MM_FILE_FORMAT_AMR:
711 format = STREAMRECORDER_FILE_FORMAT_AMR;
713 case MM_FILE_FORMAT_AAC:
714 format = STREAMRECORDER_FILE_FORMAT_ADTS;
716 case MM_FILE_FORMAT_WAV:
717 format = STREAMRECORDER_FILE_FORMAT_WAV;
724 if (format != -1 && !foreach_cb(format, user_data)) {
729 return STREAMRECORDER_ERROR_NONE;
732 int _streamrecorder_set_size_limit(streamrecorder_h recorder, int kbyte)
734 int ret = MM_ERROR_NONE;
735 streamrecorder_s *handle = (streamrecorder_s *)recorder;
737 if (recorder == NULL) {
738 LOGE("NULL pointer handle");
739 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
743 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
746 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
747 MMSTR_TARGET_MAX_SIZE, kbyte,
749 return __convert_streamrecorder_error_code(__func__, ret);
752 int _streamrecorder_set_time_limit(streamrecorder_h recorder, int second)
754 int ret = MM_ERROR_NONE;
755 streamrecorder_s *handle = (streamrecorder_s *)recorder;
757 if (recorder == NULL) {
758 LOGE("NULL pointer handle");
759 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
763 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
766 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
767 MMSTR_TARGET_TIME_LIMIT, second,
769 return __convert_streamrecorder_error_code(__func__, ret);
772 int _streamrecorder_set_audio_encoder(streamrecorder_h recorder, streamrecorder_audio_codec_e codec)
774 int audio_table[3] = { MM_AUDIO_CODEC_AMR, /* STREAMRECORDER_AUDIO_CODEC_AMR */
775 MM_AUDIO_CODEC_AAC, /* STREAMRECORDER_AUDIO_CODEC_AAC */
776 MM_AUDIO_CODEC_WAVE /* STREAMRECORDER_AUDIO_CODEC_PCM */
779 if (recorder == NULL) {
780 LOGE("handle is NULL");
781 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
784 if ((codec < STREAMRECORDER_AUDIO_CODEC_AMR || codec > STREAMRECORDER_AUDIO_CODEC_PCM)) {
785 LOGE("invalid parameter : codec %d", codec);
786 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
789 return _streamrecorder_check_and_set_attribute(recorder, MMSTR_AUDIO_ENCODER, audio_table[codec]);
792 int _streamrecorder_get_audio_encoder(streamrecorder_h recorder, streamrecorder_audio_codec_e *codec)
794 int ret = MM_ERROR_NONE;
796 int audio_enable = 0;
797 streamrecorder_s *handle = (streamrecorder_s *)recorder;
799 if (recorder == NULL) {
800 LOGE("handle is NULL");
801 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
805 LOGE("codec is NULL");
806 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
809 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
810 MMSTR_AUDIO_ENCODER, &mm_codec,
811 MMSTR_AUDIO_ENABLE, &audio_enable,
814 if (ret == MM_ERROR_NONE && audio_enable != 0) {
816 case MM_AUDIO_CODEC_AMR:
817 *codec = STREAMRECORDER_AUDIO_CODEC_AMR;
819 case MM_AUDIO_CODEC_AAC:
820 *codec = STREAMRECORDER_AUDIO_CODEC_AAC;
822 case MM_AUDIO_CODEC_WAVE:
823 *codec = STREAMRECORDER_AUDIO_CODEC_PCM;
826 ret = MM_ERROR_STREAMRECORDER_INTERNAL;
830 ret = MM_ERROR_STREAMRECORDER_INTERNAL;
833 return __convert_streamrecorder_error_code(__func__, ret);
836 int _streamrecorder_set_video_encoder(streamrecorder_h recorder, streamrecorder_video_codec_e codec)
838 int ret = MM_ERROR_NONE;
839 int video_table[2] = {MM_VIDEO_CODEC_H263, /* STREAMRECORDER_VIDEO_CODEC_H263 */
840 MM_VIDEO_CODEC_MPEG4, /* STREAMRECORDER_VIDEO_CODEC_MPEG4 */
842 streamrecorder_s *handle = (streamrecorder_s *)recorder;
844 if (handle == NULL) {
845 LOGE("handle is NULL");
846 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
850 if (codec < STREAMRECORDER_VIDEO_CODEC_H263 || codec > STREAMRECORDER_VIDEO_CODEC_MPEG4) {
851 LOGE("invalid codec %d", codec);
852 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
855 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL,
856 MMSTR_VIDEO_ENCODER, video_table[codec],
858 return __convert_streamrecorder_error_code(__func__, ret);
861 int _streamrecorder_get_video_encoder(streamrecorder_h recorder, streamrecorder_video_codec_e *codec)
863 int ret = MM_ERROR_NONE;
865 int video_enable = 0;
866 streamrecorder_s *handle = (streamrecorder_s *)recorder;
868 if (handle == NULL) {
869 LOGE("handle is NULL");
870 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
873 LOGE("codec is NULL");
874 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
877 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
878 MMSTR_VIDEO_ENABLE, &video_enable,
879 MMSTR_VIDEO_ENCODER, &mm_codec,
881 if (ret == MM_ERROR_NONE && video_enable != 0) {
883 case MM_VIDEO_CODEC_H263:
884 *codec = STREAMRECORDER_VIDEO_CODEC_H263;
886 case MM_VIDEO_CODEC_MPEG4:
887 *codec = STREAMRECORDER_VIDEO_CODEC_MPEG4;
890 ret = MM_ERROR_STREAMRECORDER_INTERNAL;
894 ret = MM_ERROR_STREAMRECORDER_INTERNAL;
897 return __convert_streamrecorder_error_code(__func__, ret);
901 int _streamrecorder_set_audio_samplerate(streamrecorder_h recorder, int samplerate)
903 if (samplerate < 1) {
904 LOGE("invalid samplerate %d", samplerate);
905 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
908 return _streamrecorder_check_and_set_attribute(recorder, MMSTR_AUDIO_SAMPLERATE, samplerate);
912 int _streamrecorder_set_audio_encoder_bitrate(streamrecorder_h recorder, int bitrate)
915 LOGE("invalid bitrate %d", bitrate);
916 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
919 return _streamrecorder_check_and_set_attribute(recorder, MMSTR_AUDIO_BITRATE, bitrate);
923 int _streamrecorder_set_video_encoder_bitrate(streamrecorder_h recorder, int bitrate)
925 int ret = MM_ERROR_NONE;
926 streamrecorder_s *handle = (streamrecorder_s *)recorder;
928 if (handle == NULL) {
929 LOGE("handle is NULL");
930 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
934 LOGE("Invalid bitrate %d", bitrate);
935 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
938 ret = mm_streamrecorder_set_attributes(handle->mm_handle, NULL, MMSTR_VIDEO_BITRATE, bitrate, NULL);
940 return __convert_streamrecorder_error_code(__func__, ret);
943 int _streamrecorder_get_size_limit(streamrecorder_h recorder, int *kbyte)
945 int ret = MM_ERROR_NONE;
946 streamrecorder_s *handle = (streamrecorder_s *)recorder;
948 if (recorder == NULL) {
949 LOGE("handle is NULL");
950 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
954 LOGE("Size limit is NULL");
955 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
958 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL, MMSTR_TARGET_MAX_SIZE, kbyte, NULL);
960 return __convert_streamrecorder_error_code(__func__, ret);
963 int _streamrecorder_get_time_limit(streamrecorder_h recorder, int *second)
965 int ret = MM_ERROR_NONE;
966 streamrecorder_s *handle = (streamrecorder_s *)recorder;
968 if (recorder == NULL) {
969 LOGE("handle is NULL");
970 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
973 if (second == NULL) {
974 LOGE("Time limit is NULL");
975 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
978 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL, MMSTR_TARGET_TIME_LIMIT, second, NULL);
980 return __convert_streamrecorder_error_code(__func__, ret);
984 int _streamrecorder_get_audio_samplerate(streamrecorder_h recorder, int *samplerate)
986 int ret = MM_ERROR_NONE;
987 streamrecorder_s *handle = (streamrecorder_s *)recorder;
989 if (recorder == NULL) {
990 LOGE("handle is NULL");
991 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
994 if (samplerate == NULL) {
995 LOGE("samplerate is NULL");
996 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
999 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
1000 MMSTR_AUDIO_SAMPLERATE, samplerate,
1003 return __convert_streamrecorder_error_code(__func__, ret);
1006 int _streamrecorder_get_audio_encoder_bitrate(streamrecorder_h recorder, int *bitrate)
1008 int ret = MM_ERROR_NONE;
1009 streamrecorder_s *handle = (streamrecorder_s *)recorder;
1011 if (recorder == NULL) {
1012 LOGE("handle is NULL");
1013 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1016 if (bitrate == NULL) {
1017 LOGE("bitrate is NULL");
1018 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1021 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
1022 MMSTR_AUDIO_BITRATE, bitrate,
1025 return __convert_streamrecorder_error_code(__func__, ret);
1028 int _streamrecorder_get_video_encoder_bitrate(streamrecorder_h recorder, int *bitrate)
1030 int ret = MM_ERROR_NONE;
1031 streamrecorder_s *handle = (streamrecorder_s *)recorder;
1033 if (handle == NULL) {
1034 LOGE("handle is NULL");
1035 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1038 if (bitrate == NULL) {
1039 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1041 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
1042 MMSTR_VIDEO_BITRATE, bitrate,
1044 return __convert_streamrecorder_error_code(__func__, ret);
1047 int _streamrecorder_foreach_supported_audio_encoder(streamrecorder_h recorder, streamrecorder_supported_audio_encoder_cb foreach_cb, void *user_data)
1050 int ret = MM_ERROR_NONE;
1052 streamrecorder_s *handle = (streamrecorder_s *)recorder;
1054 if (recorder == NULL) {
1055 LOGE("handle is NULL");
1056 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1058 if (foreach_cb == NULL) {
1059 LOGE("foreach_cb is NULL");
1060 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1063 MMStreamRecorderAttrsInfo info;
1064 ret = mm_streamrecorder_get_attribute_info(handle->mm_handle, MMSTR_AUDIO_ENCODER, &info);
1065 if (ret != MM_ERROR_NONE) {
1066 return __convert_streamrecorder_error_code(__func__, ret);
1069 for (i = 0 ; i < info.int_array.count ; i++) {
1070 switch (info.int_array.array[i]) {
1071 case MM_AUDIO_CODEC_AMR:
1072 codec = STREAMRECORDER_AUDIO_CODEC_AMR;
1074 case MM_AUDIO_CODEC_AAC:
1075 codec = STREAMRECORDER_AUDIO_CODEC_AAC;
1077 case MM_AUDIO_CODEC_WAVE:
1078 codec = STREAMRECORDER_AUDIO_CODEC_PCM;
1084 if (codec != -1 && !foreach_cb(codec, user_data)) {
1089 return STREAMRECORDER_ERROR_NONE;
1093 int _streamrecorder_foreach_supported_video_encoder(streamrecorder_h recorder, streamrecorder_supported_video_encoder_cb foreach_cb, void *user_data)
1096 int ret = MM_ERROR_NONE;
1098 streamrecorder_s *handle = (streamrecorder_s *)recorder;
1100 if (handle == NULL) {
1101 LOGE("handle is NULL");
1102 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1104 if (foreach_cb == NULL) {
1105 LOGE("foreach_cb is NULL");
1106 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1109 MMStreamRecorderAttrsInfo info;
1110 ret = mm_streamrecorder_get_attribute_info(handle->mm_handle, MMSTR_VIDEO_ENCODER, &info);
1111 if (ret != MM_ERROR_NONE) {
1112 return __convert_streamrecorder_error_code(__func__, ret);
1115 for (i = 0 ; i < info.int_array.count ; i++) {
1116 switch (info.int_array.array[i]) {
1117 case MM_VIDEO_CODEC_H263:
1118 codec = STREAMRECORDER_VIDEO_CODEC_H263;
1120 case MM_VIDEO_CODEC_MPEG4:
1121 codec = STREAMRECORDER_VIDEO_CODEC_MPEG4;
1128 if (codec != -1 && !foreach_cb(codec, user_data)) {
1133 return STREAMRECORDER_ERROR_NONE;
1138 int _streamrecorder_set_audio_channel(streamrecorder_h recorder, int channel_count)
1140 if (channel_count < 1) {
1141 LOGE("invalid channel %d", channel_count);
1142 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1145 return _streamrecorder_check_and_set_attribute(recorder, MMSTR_AUDIO_CHANNEL, channel_count);
1148 int _streamrecorder_get_audio_channel(streamrecorder_h recorder, int *channel_count)
1150 int ret = MM_ERROR_NONE;
1151 streamrecorder_s *handle = (streamrecorder_s *)recorder;
1153 if (recorder == NULL) {
1154 LOGE("handle is NULL");
1155 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1157 if (channel_count == NULL) {
1158 LOGE("channel_count is NULL");
1159 return STREAMRECORDER_ERROR_INVALID_PARAMETER;
1162 ret = mm_streamrecorder_get_attributes(handle->mm_handle, NULL,
1163 MMSTR_AUDIO_CHANNEL, channel_count,
1166 return __convert_streamrecorder_error_code(__func__, ret);