2 * Copyright (c) 2011 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_transcode.h>
23 #include <video_util.h>
24 #include <video_util_private.h>
25 #include <system_info.h>
31 #define LOG_TAG "CAPI_MEDIA_VIDEO_UTIL"
33 #define UTIL_SAFE_FREE(src) \
41 #define UTIL_STRING_VALID(str) \
42 ((str != NULL && strlen(str) > 0) ? true : false)
44 #define VIDEO_UTIL_MINIMUM_WIDTH 128
45 #define VIDEO_UTIL_MINIMUM_HEIGHT 96
46 #define VIDEO_UTIL_MINIMUM_DURATION 1000 /* 1 sec */
47 #define VIDEO_UTIL_MINIMUM_FPS 5
48 #define VIDEO_UTIL_MAXIMUM_FPS 30
49 #define VIDEO_UTIL_MAXIMUM_BPS 4294967295UL
51 static int __video_util_create_transcode_handle(video_util_s *handle);
52 static int __video_util_destroy_transcode_handle(video_util_s *handle);
53 static int __video_util_check_transcode_is_busy(video_util_s * handle, bool *is_busy);
54 static bool __video_util_check_video_codec(video_util_video_codec_e video_codec);
55 static bool __video_util_check_audio_codec(video_util_audio_codec_e audio_codec);
56 static bool __video_util_check_file_format(video_util_file_format_e file_format);
57 static bool __video_util_check_resolution(int width, int height);
58 static bool __video_util_check_duration(int duration);
59 static bool __video_util_check_fps(int fps);
60 static video_util_error_e __video_util_error_convert(int error);
61 static void __video_util_transcode_progress_cb(unsigned long current_position, unsigned long duration, void *user_data);
62 static void __video_util_transcode_completed_cb(int error, void *user_data);
63 static bool __video_util_type_callback(int codec_type, void *user_data);
64 static int __video_util_foreach_supported_type(video_util_type_e type, video_util_supported_type_cb callback, void *user_data);
66 static int __video_util_create_transcode_handle(video_util_s *handle)
68 int ret = VIDEO_UTIL_ERROR_NONE;
69 MMHandleType transcode_h = 0;
71 ret = mm_transcode_create(&transcode_h);
72 if (ret != MM_ERROR_NONE) {
73 if (ret == MM_ERROR_TRANSCODE_INVALID_VALUE) {
74 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
75 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
76 } else if (ret == MM_ERROR_TRANSCODE_NOT_SUPPORT_FORMAT) {
77 video_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
78 return VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
80 video_util_error("INVALID_OPERATION(0x%08x)", ret);
81 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
85 ret = mm_transcode_prepare(transcode_h, handle->input_path, handle->file_format, handle->video_codec, handle->audio_codec);
86 if (ret != MM_ERROR_NONE) {
87 if (ret == MM_ERROR_TRANSCODE_INVALID_VALUE) {
88 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
89 ret = VIDEO_UTIL_ERROR_INVALID_PARAMETER;
90 } else if (ret == MM_ERROR_TRANSCODE_NOT_SUPPORT_FORMAT) {
91 video_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
92 return VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
94 video_util_error("INVALID_OPERATION(0x%08x)", ret);
95 ret = VIDEO_UTIL_ERROR_INVALID_OPERATION;
99 if (ret == MM_ERROR_NONE)
100 handle->transcode_h = transcode_h;
102 __video_util_destroy_transcode_handle(handle);
107 /* when should make new trandcode handle? input_filepath or file_format or video_codec or audio_codec is modified */
108 static int __video_util_destroy_transcode_handle(video_util_s *handle)
110 int ret = VIDEO_UTIL_ERROR_NONE;
112 if (handle->transcode_h) {
113 ret = mm_transcode_destroy(handle->transcode_h);
114 if (ret != MM_ERROR_NONE) {
115 video_util_error("INVALID_OPERATION (0x%08x)", ret);
116 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
120 handle->transcode_h = 0;
125 int __video_util_check_transcode_is_busy(video_util_s *handle, bool *is_busy)
127 int ret = VIDEO_UTIL_ERROR_NONE;
129 if (handle->transcode_h) {
130 ret = mm_transcode_is_busy(handle->transcode_h, is_busy);
131 if (ret != MM_ERROR_NONE) {
132 video_util_error("INVALID_OPERATION(0x%08x)", ret);
133 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
142 static bool __video_util_check_video_codec(video_util_video_codec_e video_codec)
144 if ((video_codec < 0) || (video_codec > VIDEO_UTIL_VIDEO_CODEC_NONE)) {
145 video_util_error("invalid video_codec [%d]", video_codec);
152 static bool __video_util_check_audio_codec(video_util_audio_codec_e audio_codec)
154 if ((audio_codec < 0) || (audio_codec > VIDEO_UTIL_AUDIO_CODEC_NONE)) {
155 video_util_error("invalid audio_codec [%d]", audio_codec);
162 static bool __video_util_check_file_format(video_util_file_format_e file_format)
164 if ((file_format < 0) || (file_format >= VIDEO_UTIL_FILE_FORMAT_MAX)) {
165 video_util_error("invalid file_format [%d]", file_format);
172 static bool __video_util_check_resolution(int width, int height)
174 if (((width > 0) && (width < VIDEO_UTIL_MINIMUM_WIDTH)) || (width < 0)) {
175 video_util_error("invalid width [%d]", width);
179 if (((height > 0) && (height < VIDEO_UTIL_MINIMUM_HEIGHT)) || (height < 0)) {
180 video_util_error("invalid height [%d]", height);
187 static bool __video_util_check_duration(int duration)
189 if (((duration > 0) && (duration < VIDEO_UTIL_MINIMUM_DURATION)) || (duration < 0)) {
190 video_util_error("invalid duration [%d]", duration);
197 static bool __video_util_check_fps(int fps)
199 if ((fps < 0) || ((fps > 0) && (fps < VIDEO_UTIL_MINIMUM_FPS)) || (fps > VIDEO_UTIL_MAXIMUM_FPS)) {
200 video_util_error("invalid fps [%d]", fps);
207 static video_util_error_e __video_util_error_convert(int error)
209 if (error == MM_ERROR_NONE) {
210 video_util_debug("Error None");
211 return VIDEO_UTIL_ERROR_NONE;
212 } else if (error == MM_ERROR_TRANSCODE_INVALID_VALUE) {
213 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
214 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
215 } else if (error == MM_ERROR_TRANSCODE_NOT_SUPPORT_FORMAT) {
216 video_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
217 return VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
219 video_util_error("INVALID_OPERATION(0x%08x)", error);
220 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
224 static void __video_util_transcode_progress_cb(unsigned long current_position, unsigned long duration, void *user_data)
226 video_util_s *_handle = (video_util_s *)user_data;
228 if ((_handle != NULL) && (_handle->_util_cb != NULL)
229 && (_handle->_util_cb->transcode_progress_cb != NULL))
230 _handle->_util_cb->transcode_progress_cb(current_position, duration, _handle->_util_cb->user_data);
235 static void __video_util_transcode_completed_cb(int error, void *user_data)
237 int error_value = VIDEO_UTIL_ERROR_NONE;
238 video_util_s *_handle = (video_util_s *)user_data;
240 if ((_handle != NULL) && (_handle->_util_cb != NULL)
241 && (_handle->_util_cb->transcode_completed_cb != NULL)) {
242 error_value = __video_util_error_convert(error);
243 _handle->_util_cb->transcode_completed_cb(error_value, _handle->_util_cb->user_data);
246 UTIL_SAFE_FREE(_handle->_util_cb);
251 static bool __video_util_type_callback(int codec_type, void *user_data)
253 video_util_type_cb_s *codec_cb = (video_util_type_cb_s *)user_data;
255 if (codec_cb != NULL) {
256 if (codec_cb->supported_type_cb)
257 codec_cb->supported_type_cb(codec_type, codec_cb->user_data);
263 static int __video_util_foreach_supported_type(video_util_type_e type, video_util_supported_type_cb callback, void *user_data)
265 int ret = VIDEO_UTIL_ERROR_NONE;
267 video_util_type_cb_s *codec_cb = (video_util_type_cb_s *)calloc(1, sizeof(video_util_type_cb_s));
268 codec_cb->user_data = user_data;
269 codec_cb->supported_type_cb = (video_util_supported_type_cb)callback;
271 if (type == VIDEO_UTIL_TYPE_FORMAT)
272 ret = mm_transcode_get_supported_container_format((mm_transcode_support_type_callback)__video_util_type_callback, (void *)codec_cb);
273 else if (type == VIDEO_UTIL_TYPE_VIDEO_ENC)
274 ret = mm_transcode_get_supported_video_encoder((mm_transcode_support_type_callback)__video_util_type_callback, (void *)codec_cb);
275 else if (type == VIDEO_UTIL_TYPE_AUDIO_ENC)
276 ret = mm_transcode_get_supported_audio_encoder((mm_transcode_support_type_callback)__video_util_type_callback, (void *)codec_cb);
278 video_util_error("Invalid type (%d)", type);
279 ret = VIDEO_UTIL_ERROR_INVALID_PARAMETER;
282 UTIL_SAFE_FREE(codec_cb);
287 int video_util_create(video_util_h *handle)
289 int ret = VIDEO_UTIL_ERROR_NONE;
291 bool transcoder_supported = false;
292 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
293 if (false == transcoder_supported) {
294 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
295 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
298 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
299 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
302 if (handle == NULL) {
303 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
304 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
307 video_util_s *_handle = (video_util_s *)calloc(1, sizeof(video_util_s));
308 if (_handle == NULL) {
309 video_util_error("OUT_OF_MEMORY(0x%08x)", VIDEO_UTIL_ERROR_OUT_OF_MEMORY);
310 return VIDEO_UTIL_ERROR_OUT_OF_MEMORY;
313 _handle->input_path = NULL;
314 _handle->accurate_mode = false;
315 _handle->video_codec = 0;
316 _handle->audio_codec = 0;
317 _handle->file_format = 0;
321 _handle->transcode_h = 0;
322 _handle->_util_cb = NULL;
324 *handle = (video_util_h)_handle;
329 int video_util_destroy(video_util_h handle)
331 int ret = VIDEO_UTIL_ERROR_NONE;
332 video_util_s *_handle = NULL;
333 bool transcoder_supported = false;
334 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
335 if (false == transcoder_supported) {
336 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
337 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
340 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
341 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
344 _handle = (video_util_s *)handle;
345 if (_handle == NULL) {
346 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
347 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
350 ret = __video_util_destroy_transcode_handle(_handle);
352 UTIL_SAFE_FREE(_handle->_util_cb);
353 video_util_debug("FREE(_handle->_util_cb)");
354 UTIL_SAFE_FREE(_handle->input_path);
355 UTIL_SAFE_FREE(_handle);
360 int video_util_set_file_path(video_util_h handle, const char *file_path)
362 int ret = VIDEO_UTIL_ERROR_NONE;
363 video_util_s *_handle = NULL;
364 bool is_busy = false;
365 bool transcoder_supported = false;
366 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
367 if (false == transcoder_supported) {
368 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
369 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
372 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
373 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
376 _handle = (video_util_s *)handle;
377 if ((_handle != NULL) && (UTIL_STRING_VALID(file_path))) {
378 video_util_secure_info("file_path [%s]\n", file_path);
380 if (_handle->input_path != NULL) {
381 ret = __video_util_check_transcode_is_busy(_handle, &is_busy);
382 if (ret != VIDEO_UTIL_ERROR_NONE)
386 video_util_error("BUSY!! Transcoding is already running.\n");
387 return VIDEO_UTIL_ERROR_BUSY;
389 ret = __video_util_destroy_transcode_handle(_handle);
390 if (ret != VIDEO_UTIL_ERROR_NONE)
393 UTIL_SAFE_FREE(_handle->input_path);
397 _handle->input_path = strdup(file_path);
398 if (_handle->input_path == NULL) {
399 video_util_error("OUT_OF_MEMORY(0x%08x)", VIDEO_UTIL_ERROR_OUT_OF_MEMORY);
400 return VIDEO_UTIL_ERROR_OUT_OF_MEMORY;
403 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
404 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
410 int video_util_set_accurate_mode(video_util_h handle, bool accurate_mode)
412 int ret = VIDEO_UTIL_ERROR_NONE;
413 video_util_s *_handle = NULL;
414 bool transcoder_supported = false;
415 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
416 if (false == transcoder_supported) {
417 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
418 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
421 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
422 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
425 _handle = (video_util_s *)handle;
426 if (_handle != NULL) {
427 _handle->accurate_mode = accurate_mode;
429 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
430 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
436 int video_util_set_video_codec(video_util_h handle, video_util_video_codec_e codec)
438 int ret = VIDEO_UTIL_ERROR_NONE;
439 video_util_s *_handle = NULL;
440 bool is_busy = false;
441 bool transcoder_supported = false;
442 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
443 if (false == transcoder_supported) {
444 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
445 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
448 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
449 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
452 _handle = (video_util_s *)handle;
453 if ((_handle != NULL) && (__video_util_check_video_codec(codec))) {
454 ret = __video_util_check_transcode_is_busy(_handle, &is_busy);
455 if (ret != VIDEO_UTIL_ERROR_NONE)
459 video_util_error("BUSY!! Transcoding is already running.\n");
460 return VIDEO_UTIL_ERROR_BUSY;
462 ret = __video_util_destroy_transcode_handle(_handle);
463 if (ret != VIDEO_UTIL_ERROR_NONE)
467 _handle->video_codec = codec;
469 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
470 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
476 int video_util_set_audio_codec(video_util_h handle, video_util_audio_codec_e codec)
478 int ret = VIDEO_UTIL_ERROR_NONE;
479 video_util_s *_handle = NULL;
480 bool is_busy = false;
481 bool transcoder_supported = false;
482 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
483 if (false == transcoder_supported) {
484 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
485 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
488 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
489 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
492 _handle = (video_util_s *)handle;
493 if ((_handle != NULL) && (__video_util_check_audio_codec(codec))) {
494 ret = __video_util_check_transcode_is_busy(_handle, &is_busy);
495 if (ret != VIDEO_UTIL_ERROR_NONE)
499 video_util_error("BUSY!! Transcoding is already running.\n");
500 return VIDEO_UTIL_ERROR_BUSY;
502 ret = __video_util_destroy_transcode_handle(_handle);
503 if (ret != VIDEO_UTIL_ERROR_NONE)
507 _handle->audio_codec = codec;
509 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
510 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
516 int video_util_set_file_format(video_util_h handle, video_util_file_format_e format)
518 int ret = VIDEO_UTIL_ERROR_NONE;
519 video_util_s *_handle = NULL;
520 bool is_busy = false;
521 bool transcoder_supported = false;
522 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
523 if (false == transcoder_supported) {
524 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
525 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
528 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
529 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
532 _handle = (video_util_s *)handle;
533 if ((_handle != NULL) && (__video_util_check_file_format(format))) {
534 ret = __video_util_check_transcode_is_busy(_handle, &is_busy);
535 if (ret != VIDEO_UTIL_ERROR_NONE)
539 video_util_error("BUSY!! Transcoding is already running.\n");
540 return VIDEO_UTIL_ERROR_BUSY;
542 ret = __video_util_destroy_transcode_handle(_handle);
543 if (ret != VIDEO_UTIL_ERROR_NONE)
547 _handle->file_format = format;
549 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
550 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
556 int video_util_set_resolution(video_util_h handle, int width, int height)
558 int ret = VIDEO_UTIL_ERROR_NONE;
559 video_util_s *_handle = NULL;
560 bool transcoder_supported = false;
561 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
562 if (false == transcoder_supported) {
563 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
564 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
567 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
568 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
571 _handle = (video_util_s *)handle;
572 if ((_handle != NULL) && (__video_util_check_resolution(width, height))) {
573 _handle->width = width;
574 _handle->height = height;
576 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
577 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
583 int video_util_set_fps(video_util_h handle, int fps)
585 int ret = VIDEO_UTIL_ERROR_NONE;
586 video_util_s *_handle = NULL;
587 bool transcoder_supported = false;
588 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
589 if (false == transcoder_supported) {
590 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
591 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
594 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
595 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
598 _handle = (video_util_s *)handle;
599 if (_handle && __video_util_check_fps(fps)) {
602 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
603 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
609 int video_util_start_transcoding(video_util_h handle, unsigned long start, unsigned long duration, const char *out_path, video_util_transcoding_progress_cb progress_cb, video_util_transcoding_completed_cb completed_cb, void *user_data)
611 int ret = VIDEO_UTIL_ERROR_NONE;
612 video_util_s *_handle = NULL;
613 mm_seek_mode_e accurate_mode = MM_SEEK_NUM;
614 bool is_busy = false;
615 bool transcoder_supported = false;
616 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
617 if (false == transcoder_supported) {
618 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
619 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
622 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
623 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
626 _handle = (video_util_s *)handle;
627 video_util_debug("start [%d] duration [%d]\n", start, duration);
629 if (_handle && (__video_util_check_duration(duration)) && (UTIL_STRING_VALID(_handle->input_path)) && (UTIL_STRING_VALID(out_path)) && completed_cb) {
630 if (!_handle->transcode_h) {
631 ret = __video_util_create_transcode_handle(_handle);
632 if (ret != MM_ERROR_NONE)
635 if (!_handle->transcode_h) {
636 video_util_error("INVALID_OPERATION(0x%08x)", VIDEO_UTIL_ERROR_INVALID_OPERATION);
637 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
640 ret = __video_util_check_transcode_is_busy(_handle, &is_busy);
641 if (ret != VIDEO_UTIL_ERROR_NONE)
645 video_util_error("BUSY!! Transcoding is already running.\n");
646 return VIDEO_UTIL_ERROR_BUSY;
650 video_util_debug("width [%d] height [%d] fps [%d]v_codec [%d] a_codec [%d] file_format [%d] accurate [%d]\n", _handle->width, _handle->height, _handle->fps, _handle->video_codec, _handle->audio_codec, _handle->file_format, _handle->accurate_mode);
652 _handle->_util_cb = (video_util_cb_s *)calloc(1, sizeof(video_util_cb_s));
653 if (!_handle->_util_cb) {
654 video_util_error("Error _util_cb");
655 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
657 _handle->_util_cb->user_data = user_data;
658 _handle->_util_cb->transcode_completed_cb = completed_cb;
659 _handle->_util_cb->transcode_progress_cb = progress_cb;
661 if (_handle->accurate_mode)
662 accurate_mode = MM_SEEK_ACCURATE;
664 accurate_mode = MM_SEEK_INACCURATE;
666 ret = mm_transcode(_handle->transcode_h, _handle->width, _handle->height, _handle->fps, start, duration, accurate_mode, out_path, (mm_transcode_progress_callback)__video_util_transcode_progress_cb, (mm_transcode_completed_callback)__video_util_transcode_completed_cb, (void *)_handle);
668 if (ret != MM_ERROR_NONE) {
669 UTIL_SAFE_FREE(_handle->_util_cb);
671 if (ret == MM_ERROR_TRANSCODE_INVALID_VALUE) {
672 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
673 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
674 } else if (ret == MM_ERROR_TRANSCODE_NOT_SUPPORT_FORMAT) {
675 video_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
676 return VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
678 video_util_error("INVALID_OPERATION(0x%08x)", ret);
679 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
683 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
684 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
690 int video_util_cancel_transcoding(video_util_h handle)
692 int ret = VIDEO_UTIL_ERROR_NONE;
693 video_util_s *_handle = NULL;
694 bool transcoder_supported = false;
695 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
696 if (false == transcoder_supported) {
697 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
698 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
701 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
702 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
705 _handle = (video_util_s *)handle;
706 if (_handle && (_handle->transcode_h)) {
707 ret = mm_transcode_cancel(_handle->transcode_h);
708 if (ret != MM_ERROR_NONE) {
709 video_util_error("INVALID_OPERATION(0x%08x)", ret);
710 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
713 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
714 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
717 UTIL_SAFE_FREE(_handle->_util_cb);
718 video_util_debug("FREE(_handle->_util_cb)");
723 int video_util_get_progress_transcoding(video_util_h handle, unsigned long *current_position, unsigned long *duration)
725 int ret = VIDEO_UTIL_ERROR_NONE;
726 video_util_s *_handle = NULL;
728 bool transcoder_supported = false;
729 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
730 if (false == transcoder_supported) {
731 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
732 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
735 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
736 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
739 _handle = (video_util_s *)handle;
740 if (_handle && current_position && duration) {
741 if (_handle->transcode_h) {
742 ret = mm_transcode_get_attrs(_handle->transcode_h, (mm_containerformat_e *)&value, (mm_videoencoder_e *)&value, (mm_audioencoder_e *)&value, current_position, duration, (unsigned int *)&value, (unsigned int *)&value);
743 if (ret != MM_ERROR_NONE) {
744 video_util_error("INVALID_OPERATION(0x%08x)", ret);
745 return VIDEO_UTIL_ERROR_INVALID_OPERATION;
748 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
749 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
752 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
753 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
759 int video_util_foreach_supported_file_format(video_util_h handle, video_util_supported_file_format_cb callback, void *user_data)
761 int ret = VIDEO_UTIL_ERROR_NONE;
762 video_util_s *_handle = NULL;
763 bool transcoder_supported = false;
764 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
765 if (false == transcoder_supported) {
766 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
767 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
770 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
771 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
774 _handle = (video_util_s *)handle;
775 if (_handle && callback) {
776 ret = __video_util_foreach_supported_type(VIDEO_UTIL_TYPE_FORMAT, (video_util_supported_type_cb)callback, user_data);
778 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
779 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
785 int video_util_foreach_supported_video_codec(video_util_h handle, video_util_supported_video_encoder_cb callback, void *user_data)
787 int ret = VIDEO_UTIL_ERROR_NONE;
788 video_util_s *_handle = NULL;
789 bool transcoder_supported = false;
790 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
791 if (false == transcoder_supported) {
792 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
793 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
796 _handle = (video_util_s *)handle;
797 if (_handle && callback) {
798 ret = __video_util_foreach_supported_type(VIDEO_UTIL_TYPE_VIDEO_ENC, (video_util_supported_type_cb)callback, user_data);
800 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
801 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;
807 int video_util_foreach_supported_audio_codec(video_util_h handle, video_util_supported_audio_encoder_cb callback, void *user_data)
809 int ret = VIDEO_UTIL_ERROR_NONE;
810 video_util_s *_handle = NULL;
811 bool transcoder_supported = false;
812 if (0 == system_info_get_platform_bool(TRANSCODER_FEATURE_PATH, &transcoder_supported)) {
813 if (false == transcoder_supported) {
814 video_util_error("VIDEO_UTIL_ERROR_NOT_SUPPORTED(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
815 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
818 video_util_error("Error - System Info of Platform(0x%08x)", VIDEO_UTIL_ERROR_NOT_SUPPORTED);
819 return VIDEO_UTIL_ERROR_NOT_SUPPORTED;
822 _handle = (video_util_s *)handle;
823 if (_handle && callback) {
824 ret = __video_util_foreach_supported_type(VIDEO_UTIL_TYPE_AUDIO_ENC, (video_util_supported_type_cb)callback, user_data);
826 video_util_error("INVALID_PARAMETER(0x%08x)", VIDEO_UTIL_ERROR_INVALID_PARAMETER);
827 return VIDEO_UTIL_ERROR_INVALID_PARAMETER;