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.
23 #include <media_codec.h>
24 #include <media_codec_private.h>
25 #include <media_codec_port.h>
26 #include <media_codec_port_gst.h>
27 #include <media_codec_spec_emul.h>
28 #include <media_codec_ini.h>
30 static gboolean _check_support_audio_info(mediacodec_codec_type_e codec_id, int samplerate, int channel, int bit_depth);
31 static gboolean _check_support_video_info(mediacodec_codec_type_e codec_id, int width, int height);
33 int mc_create(MMHandleType *mediacodec)
35 mc_handle_t *new_mediacodec = NULL;
36 int ret = MC_ERROR_NONE;
38 /* alloc mediacodec structure */
39 new_mediacodec = (mc_handle_t *)g_malloc(sizeof(mc_handle_t));
41 if (!new_mediacodec) {
42 LOGE("Cannot allocate memory for mediacodec");
46 memset(new_mediacodec, 0, sizeof(mc_handle_t));
48 new_mediacodec->is_encoder = false;
49 new_mediacodec->is_video = false;
50 new_mediacodec->is_hw = true;
51 new_mediacodec->is_prepared = false;
52 new_mediacodec->codec_id = MEDIACODEC_NONE;
54 new_mediacodec->ports[0] = NULL;
55 new_mediacodec->ports[1] = NULL;
57 new_mediacodec->num_supported_decoder = 0;
58 new_mediacodec->num_supported_encoder = 0;
60 new_mediacodec->core = NULL;
61 new_mediacodec->ini = &mc_ini;
65 ret = mc_ini_load(&mc_ini);
66 if (ret != MC_ERROR_NONE)
72 _mc_create_codec_map_from_ini(new_mediacodec, spec_emul);
74 /* create decoder map from ini */
75 _mc_create_decoder_map_from_ini(new_mediacodec);
77 /* create encoder map from ini */
78 _mc_create_encoder_map_from_ini(new_mediacodec);
80 *mediacodec = (MMHandleType)new_mediacodec;
85 g_free(new_mediacodec);
86 return MC_INVALID_ARG;
89 int mc_destroy(MMHandleType mediacodec)
91 int ret = MC_ERROR_NONE;
92 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
95 LOGE("fail invaild param\n");
96 return MC_INVALID_ARG;
99 LOGD("mediacodec : %p", mediacodec);
101 if (mc_handle->core != NULL) {
102 if (mc_gst_unprepare(mc_handle) != MC_ERROR_NONE) {
103 LOGE("mc_gst_unprepare() failed");
108 mc_handle->is_prepared = false;
110 /* free mediacodec structure */
112 g_free((void *)mc_handle);
119 int mc_set_codec(MMHandleType mediacodec, mediacodec_codec_type_e codec_id, int flags)
121 int ret = MC_ERROR_NONE;
122 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
126 LOGE("fail invaild param");
127 return MC_INVALID_ARG;
130 /* Mandatory setting */
131 if (!GET_IS_ENCODER(flags) && !GET_IS_DECODER(flags)) {
132 LOGE("should be encoder or decoder");
133 return MC_PARAM_ERROR;
136 /* if user doesn't set codec-type, s/w codec would be set */
137 if (!GET_IS_HW(flags) && !GET_IS_SW(flags))
138 flags |= MEDIACODEC_SUPPORT_TYPE_SW;
140 for (i = 0; i < mc_handle->ini->num_supported_codecs; i++) {
141 if ((codec_id == spec_emul[i].codec_id) && (flags == spec_emul[i].codec_type))
144 LOGD("support_list : %d, i : %d", mc_handle->ini->num_supported_codecs, i);
146 if (i == mc_handle->ini->num_supported_codecs)
147 return MC_NOT_SUPPORTED;
149 mc_handle->port_type = spec_emul[i].port_type;
151 mc_handle->is_encoder = GET_IS_ENCODER(flags) ? 1 : 0;
152 mc_handle->is_hw = GET_IS_HW(flags) ? 1 : 0;
153 mc_handle->codec_id = codec_id;
154 mc_handle->is_video = CHECK_BIT(codec_id, 13);
156 mc_handle->is_prepared = false;
158 LOGD("encoder : %d, hardware : %d, codec_id : %x, video : %d",
159 mc_handle->is_encoder, mc_handle->is_hw, mc_handle->codec_id, mc_handle->is_video);
164 int mc_set_vdec_info(MMHandleType mediacodec, int width, int height)
166 int ret = MC_ERROR_NONE;
167 mc_handle_t* mc_handle = (mc_handle_t *)mediacodec;
170 LOGE("fail invaild param\n");
171 return MC_INVALID_ARG;
174 if (!_check_support_video_info(mc_handle->codec_id, width, height)) {
175 LOGE("invaild param[res %dx%d]", width, height);
176 return MC_PARAM_ERROR;
179 MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && mc_handle->is_video && !mc_handle->is_encoder,
180 MC_INVALID_ARG, "MEDIACODEC_ERROR_INVALID_PARAMETER");
182 mc_handle->info.video.width = width;
183 mc_handle->info.video.height = height;
185 mc_handle->is_prepared = true;
190 int mc_set_venc_info(MMHandleType mediacodec, int width, int height, int fps, int target_bits)
192 int ret = MC_ERROR_NONE;
193 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
196 LOGE("fail invaild param\n");
197 return MC_INVALID_ARG;
200 if (!_check_support_video_info(mc_handle->codec_id, width, height) || fps < 0 || target_bits < 0) {
201 LOGE("invaild param[res %dx%d, fps %d, target_bits %d]", width, height, fps, target_bits);
202 return MC_PARAM_ERROR;
205 MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && mc_handle->is_video && mc_handle->is_encoder,
206 MC_INVALID_ARG, "MEDIACODEC_ERROR_INVALID_PARAMETER");
208 mc_handle->info.video.width = width;
209 mc_handle->info.video.height = height;
210 mc_handle->info.video.framerate = fps;
211 mc_handle->info.video.bitrate = target_bits * 1000;
212 mc_handle->is_prepared = true;
217 int mc_set_adec_info(MMHandleType mediacodec, int samplerate, int channel, int bit)
219 int ret = MC_ERROR_NONE;
220 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
223 LOGE("fail invaild param\n");
224 return MC_INVALID_ARG;
227 if (!_check_support_audio_info(mc_handle->codec_id, samplerate, channel, bit)) {
228 LOGE("invaild param[samplerate %d, channel %d, bit %d]", samplerate, channel, bit);
229 return MC_PARAM_ERROR;
232 MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && !mc_handle->is_video && !mc_handle->is_encoder,
233 MC_INVALID_ARG, "MEDIACODEC_ERROR_INVALID_PARAMETER");
235 mc_handle->info.audio.samplerate = samplerate;
236 mc_handle->info.audio.channel = channel;
237 mc_handle->info.audio.bit_depth = bit;
238 mc_handle->is_prepared = true;
243 int mc_set_aenc_info(MMHandleType mediacodec, int samplerate, int channel, int bit, int bitrate)
245 int ret = MC_ERROR_NONE;
246 mc_handle_t * mc_handle = (mc_handle_t *) mediacodec;
249 LOGE("fail invaild param\n");
250 return MC_INVALID_ARG;
253 if (!_check_support_audio_info(mc_handle->codec_id, samplerate, channel, bit) || bitrate < 0) {
254 LOGE("invaild param[samplerate %d, channel %d, bit %d, bitrate %d]", samplerate, channel, bit, bitrate);
255 return MC_PARAM_ERROR;
258 MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && !mc_handle->is_video && mc_handle->is_encoder,
259 MC_INVALID_ARG, "MEDIACODEC_ERROR_INVALID_PARAMETER");
261 mc_handle->info.audio.samplerate = samplerate;
262 mc_handle->info.audio.channel = channel;
263 mc_handle->info.audio.bit_depth = bit;
264 mc_handle->info.audio.bitrate = bitrate * 1000;
266 mc_handle->is_prepared = true;
271 int mc_configure(MMHandleType mediacodec, media_format_h format, int flags)
273 int ret = MC_ERROR_NONE;
274 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
276 const int codec_mask = 0xFFF0;
285 media_format_type_e type;
286 media_format_mimetype_e mimetype;
289 LOGE("fail invaild param");
290 return MC_INVALID_ARG;
293 if (media_format_get_type(format, &type) != MEDIA_FORMAT_ERROR_NONE) {
294 LOGE("failed to retrieve type");
295 return MC_INVALID_ARG;
298 if (type == MEDIA_FORMAT_AUDIO) {
299 media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &bitrate);
301 codec_id = mimetype & codec_mask;
303 if (GET_IS_ENCODER(flags)) {
304 if (!_check_support_audio_info(codec_id, samplerate, channel, bit)) {
305 LOGE("invalid pram is set : samplerate : %d, channel : %d, bit : %d, bitrate : %d",
306 samplerate, channel, bit, bitrate);
307 return MC_PARAM_ERROR;
310 mc_handle->info.audio.samplerate = samplerate;
311 mc_handle->info.audio.channel = channel;
312 mc_handle->info.audio.bit_depth = bit;
313 mc_handle->info.audio.bitrate = bitrate * 1000;
314 } else if (GET_IS_DECODER(flags)) {
315 if (!_check_support_audio_info(codec_id, samplerate, channel, bit)) {
316 LOGE("invalid pram is set : samplerate : %d, channel : %d, bit : %d",
317 samplerate, channel, bit);
318 return MC_PARAM_ERROR;
320 mc_handle->info.audio.samplerate = samplerate;
321 mc_handle->info.audio.channel = channel;
322 mc_handle->info.audio.bit_depth = bit;
324 LOGE("either an encoder or a decoder must be set");
325 return MC_PARAM_ERROR;
327 } else if (type == MEDIA_FORMAT_VIDEO) {
328 media_format_get_video_info(format, &mimetype, &width, &height, &bitrate, NULL);
329 media_format_get_video_frame_rate(format, &fps);
330 codec_id = mimetype & codec_mask;
332 if (GET_IS_ENCODER(flags)) {
333 if (!_check_support_video_info(codec_id, width, height) || fps <= 0 || bitrate <= 0) {
334 LOGE("invalid pram is set : width : %d, height : %d, bitrate : %d, fps : %d",
335 width, height, bitrate, fps);
336 return MC_PARAM_ERROR;
339 mc_handle->info.video.width = width;
340 mc_handle->info.video.height = height;
341 mc_handle->info.video.framerate = fps;
342 mc_handle->info.video.bitrate = bitrate * 1000;
343 } else if (GET_IS_DECODER(flags)) {
344 if (!_check_support_video_info(codec_id, width, height)) {
345 LOGE("invalid pram is set : width : %d, height : %d",
347 return MC_PARAM_ERROR;
350 mc_handle->info.video.width = width;
351 mc_handle->info.video.height = height;
353 LOGE("either an encoder or a decoder must be set");
354 return MC_PARAM_ERROR;
357 LOGE("invalid format type is set");
358 return MC_PARAM_ERROR;
361 if (!GET_IS_HW(flags) && !GET_IS_SW(flags))
362 flags |= MEDIACODEC_SUPPORT_TYPE_SW;
364 for (i = 0; i < mc_handle->ini->num_supported_codecs; i++) {
365 if ((codec_id == spec_emul[i].codec_id) && (flags == spec_emul[i].codec_type))
368 LOGD("support_list : %d, i : %d", mc_handle->ini->num_supported_codecs, i);
370 if (i == mc_handle->ini->num_supported_codecs)
371 return MC_CODEC_NOT_FOUND;
373 mc_handle->port_type = spec_emul[i].port_type;
375 mc_handle->is_encoder = GET_IS_ENCODER(flags) ? 1 : 0;
376 mc_handle->is_hw = GET_IS_HW(flags) ? 1 : 0;
377 mc_handle->codec_id = codec_id;
378 mc_handle->is_video = CHECK_BIT(codec_id, 13);
380 mc_handle->is_prepared = true;
382 LOGD("encoder : %d, hardware : %d, codec_id : %x, video : %d",
383 mc_handle->is_encoder, mc_handle->is_hw, mc_handle->codec_id, mc_handle->is_video);
388 int mc_prepare(MMHandleType mediacodec)
390 int ret = MC_ERROR_NONE;
391 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
394 LOGE("fail invaild param\n");
395 return MC_INVALID_ARG;
398 if (!mc_handle->is_prepared)
399 return MC_NOT_INITIALIZED;
401 /* setting core details */
402 switch (mc_handle->port_type) {
403 case MEDIACODEC_PORT_TYPE_GENERAL:
406 case MEDIACODEC_PORT_TYPE_OMX:
409 case MEDIACODEC_PORT_TYPE_GST:
410 ret = mc_gst_prepare(mc_handle);
420 int mc_unprepare(MMHandleType mediacodec)
422 int ret = MC_ERROR_NONE;
423 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
426 LOGE("fail invaild param\n");
427 return MC_INVALID_ARG;
430 /* deinit core details */
431 switch (mc_handle->port_type) {
432 case MEDIACODEC_PORT_TYPE_GENERAL:
435 case MEDIACODEC_PORT_TYPE_OMX:
438 case MEDIACODEC_PORT_TYPE_GST:
439 ret = mc_gst_unprepare(mc_handle);
449 int mc_process_input(MMHandleType mediacodec, media_packet_h inbuf, uint64_t timeOutUs)
451 int ret = MC_ERROR_NONE;
453 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
456 LOGE("fail invaild param");
457 return MC_INVALID_ARG;
461 LOGE("invaild input buffer");
462 return MC_INVALID_IN_BUF;
465 switch (mc_handle->port_type) {
466 case MEDIACODEC_PORT_TYPE_GENERAL:
469 case MEDIACODEC_PORT_TYPE_OMX:
472 case MEDIACODEC_PORT_TYPE_GST:
473 ret = mc_gst_process_input(mc_handle, inbuf, timeOutUs);
483 int mc_get_output(MMHandleType mediacodec, media_packet_h *outbuf, uint64_t timeOutUs)
485 int ret = MC_ERROR_NONE;
486 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
489 LOGE("fail invaild param\n");
490 return MC_INVALID_ARG;
493 /* setting core details */
494 switch (mc_handle->port_type) {
495 case MEDIACODEC_PORT_TYPE_GENERAL:
498 case MEDIACODEC_PORT_TYPE_OMX:
501 case MEDIACODEC_PORT_TYPE_GST:
502 ret = mc_gst_get_output(mc_handle, outbuf, timeOutUs);
512 int mc_flush_buffers(MMHandleType mediacodec)
514 int ret = MC_ERROR_NONE;
515 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
518 LOGE("fail invaild param\n");
519 return MC_INVALID_ARG;
522 /* setting core details */
523 switch (mc_handle->port_type) {
524 case MEDIACODEC_PORT_TYPE_GENERAL:
527 case MEDIACODEC_PORT_TYPE_OMX:
530 case MEDIACODEC_PORT_TYPE_GST:
531 ret = mc_gst_flush_buffers(mc_handle);
541 int mc_get_supported_type(MMHandleType mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type)
543 int ret = MC_ERROR_NONE;
544 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
545 mc_codec_map_t *codec_map;
546 int num_supported_codec = 0;
552 LOGE("fail invaild param\n");
553 return MC_INVALID_ARG;
556 codec_map = encoder ? mc_handle->encoder_map : mc_handle->decoder_map;
557 num_supported_codec = encoder ? mc_handle->num_supported_encoder : mc_handle->num_supported_decoder;
559 for (i = 0; i < num_supported_codec; i++) {
560 if (codec_map[i].id == codec_type) {
561 if (codec_map[i].hardware)
562 *support_type |= MEDIACODEC_SUPPORT_TYPE_HW;
564 *support_type |= MEDIACODEC_SUPPORT_TYPE_SW;
571 int mc_set_empty_buffer_cb(MMHandleType mediacodec, mediacodec_input_buffer_used_cb callback, void *user_data)
573 int ret = MC_ERROR_NONE;
574 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
577 LOGE("fail invaild param\n");
578 return MC_INVALID_ARG;
581 if (mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) {
582 LOGE("Already set mediacodec_empty_buffer_cb");
583 return MC_PARAM_ERROR;
586 return MC_INVALID_ARG;
588 LOGD("Set empty buffer callback(cb = %p, data = %p)", callback, user_data);
590 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER] = (mc_empty_buffer_cb) callback;
591 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER] = user_data;
593 return MC_ERROR_NONE;
599 int mc_unset_empty_buffer_cb(MMHandleType mediacodec)
601 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
604 LOGE("fail invaild param\n");
605 return MC_INVALID_ARG;
608 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER] = NULL;
609 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER] = NULL;
611 return MC_ERROR_NONE;
614 int mc_set_fill_buffer_cb(MMHandleType mediacodec, mediacodec_output_buffer_available_cb callback, void *user_data)
616 int ret = MC_ERROR_NONE;
617 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
620 LOGE("fail invaild param\n");
621 return MC_INVALID_ARG;
624 if (mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]) {
625 LOGE("Already set mediacodec_fill_buffer_cb");
626 return MC_PARAM_ERROR;
629 return MC_INVALID_ARG;
631 LOGD("Set fill buffer callback(cb = %p, data = %p)", callback, user_data);
633 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER] = (mc_fill_buffer_cb) callback;
634 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_FILLBUFFER] = user_data;
635 return MC_ERROR_NONE;
641 int mc_unset_fill_buffer_cb(MMHandleType mediacodec)
643 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
646 LOGE("fail invaild param\n");
647 return MC_INVALID_ARG;
650 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER] = NULL;
651 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_FILLBUFFER] = NULL;
653 return MC_ERROR_NONE;
656 int mc_set_error_cb(MMHandleType mediacodec, mediacodec_error_cb callback, void *user_data)
658 int ret = MC_ERROR_NONE;
659 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
662 LOGE("fail invaild param\n");
663 return MC_INVALID_ARG;
666 if (mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR]) {
667 LOGE("Already set mediacodec_fill_buffer_cb\n");
668 return MC_PARAM_ERROR;
671 return MC_INVALID_ARG;
673 LOGD("Set event handler callback(cb = %p, data = %p)\n", callback, user_data);
675 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR] = (mc_error_cb) callback;
676 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_ERROR] = user_data;
677 return MC_ERROR_NONE;
683 int mc_unset_error_cb(MMHandleType mediacodec)
685 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
688 LOGE("fail invaild param");
689 return MC_INVALID_ARG;
692 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR] = NULL;
693 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_ERROR] = NULL;
695 return MC_ERROR_NONE;
698 int mc_set_eos_cb(MMHandleType mediacodec, mediacodec_eos_cb callback, void *user_data)
700 int ret = MC_ERROR_NONE;
701 mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
704 LOGE("fail invaild param\n");
705 return MC_INVALID_ARG;
708 if (mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_EOS]) {
709 LOGE("Already set mediacodec_fill_buffer_cb");
710 return MC_PARAM_ERROR;
713 return MC_INVALID_ARG;
715 LOGD("Set event handler callback(cb = %p, data = %p)\n", callback, user_data);
717 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_EOS] = (mc_eos_cb) callback;
718 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_EOS] = user_data;
719 return MC_ERROR_NONE;
725 int mc_unset_eos_cb(MMHandleType mediacodec)
727 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
730 LOGE("fail invaild param\n");
731 return MC_INVALID_ARG;
734 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_EOS] = NULL;
735 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_EOS] = NULL;
737 return MC_ERROR_NONE;
740 int mc_set_buffer_status_cb(MMHandleType mediacodec, mediacodec_buffer_status_cb callback, void *user_data)
742 int ret = MC_ERROR_NONE;
743 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
746 LOGE("fail invaild param\n");
747 return MC_INVALID_ARG;
750 if (mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_BUFFER_STATUS]) {
751 LOGE("Already set mediacodec_need_data_cb\n");
752 return MC_PARAM_ERROR;
755 return MC_INVALID_ARG;
757 LOGD("Set start feed callback(cb = %p, data = %p)\n", callback, user_data);
759 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_BUFFER_STATUS] = (mc_buffer_status_cb) callback;
760 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_BUFFER_STATUS] = user_data;
761 return MC_ERROR_NONE;
767 int mc_unset_buffer_status_cb(MMHandleType mediacodec)
769 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
772 LOGE("fail invaild param\n");
773 return MC_INVALID_ARG;
776 mc_handle->user_cb[_MEDIACODEC_EVENT_TYPE_BUFFER_STATUS] = NULL;
777 mc_handle->user_data[_MEDIACODEC_EVENT_TYPE_BUFFER_STATUS] = NULL;
779 return MC_ERROR_NONE;
782 int _mediacodec_foreach_supported_codec(mediacodec_supported_codec_cb callback, void *user_data)
787 gboolean codec[CODEC_NR_ITEMS] = {0,};
789 for (i = 0; i < mc_ini.num_supported_codecs; i++) {
790 index = (int)codec_type_to_simple_enumeration(spec_emul[i].codec_id);
794 for (i = 0; i < CODEC_NR_ITEMS; i++) {
796 index = (int)simple_to_codec_type_enumeration(i);
797 if (!callback(index, user_data)) {
798 LOGW("stop foreach callback");
806 return MEDIACODEC_ERROR_NONE;
809 int mc_get_packet_pool(MMHandleType mediacodec, media_packet_pool_h *pool)
811 int ret = MC_ERROR_NONE;
812 mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
815 LOGE("fail invaild param\n");
816 return MC_INVALID_ARG;
819 /* setting core details */
820 switch (mc_handle->port_type) {
821 case MEDIACODEC_PORT_TYPE_GENERAL:
824 case MEDIACODEC_PORT_TYPE_OMX:
827 case MEDIACODEC_PORT_TYPE_GST:
828 ret = mc_gst_get_packet_pool(mc_handle, pool);
838 void _mc_create_decoder_map_from_ini(mc_handle_t *mediacodec)
840 int indx = 0, count = 0;
841 int codec_list = mediacodec->ini->codec_list;
842 for (indx = 0; indx < codec_list; indx++) {
843 if (strcmp(mediacodec->ini->codec[indx].codec_info[0].name, "")) {
844 mediacodec->decoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
845 mediacodec->decoder_map[count].hardware = 1; /* hardware */
846 mediacodec->decoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[0].name;
847 mediacodec->decoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[0].mime;
848 mediacodec->decoder_map[count].type.out_format =
849 _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[0].format);
853 if (strcmp(mediacodec->ini->codec[indx].codec_info[2].name, "")) {
854 mediacodec->decoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
855 mediacodec->decoder_map[count].hardware = 0; /* software */
856 mediacodec->decoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[2].name;
857 mediacodec->decoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[2].mime;
858 mediacodec->decoder_map[count].type.out_format =
859 _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[2].format);
863 mediacodec->num_supported_decoder = count;
868 void _mc_create_encoder_map_from_ini(mc_handle_t *mediacodec)
870 int indx = 0, count = 0;
871 int codec_list = mediacodec->ini->codec_list;
873 for (indx = 0; indx < codec_list; indx++) {
874 if (strcmp(mediacodec->ini->codec[indx].codec_info[1].name, "")) {
875 mediacodec->encoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
876 mediacodec->encoder_map[count].hardware = 1;
877 mediacodec->encoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[1].name;
878 mediacodec->encoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[1].mime;
879 mediacodec->encoder_map[count].type.out_format =
880 _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[1].format);
884 if (strcmp(mediacodec->ini->codec[indx].codec_info[3].name, "")) {
885 mediacodec->encoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
886 mediacodec->encoder_map[count].hardware = 0;
887 mediacodec->encoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[3].name;
888 mediacodec->encoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[3].mime;
889 mediacodec->encoder_map[count].type.out_format =
890 _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[3].format);
894 mediacodec->num_supported_encoder = count;
898 void _mc_create_codec_map_from_ini(mc_handle_t *mediacodec, mc_codec_spec_t *spec_emul)
900 int indx = 0, count = 0;
901 int codec_list = mediacodec->ini->codec_list;
903 for (indx = 0; indx < codec_list; indx++) {
904 if (strcmp(mediacodec->ini->codec[indx].codec_info[0].name, "")) {
905 spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
906 spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_HW;
907 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
910 if (strcmp(mediacodec->ini->codec[indx].codec_info[1].name, "")) {
911 spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
912 spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW;
913 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
916 if (strcmp(mediacodec->ini->codec[indx].codec_info[2].name, "")) {
917 spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
918 spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW;
919 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
922 if (strcmp(mediacodec->ini->codec[indx].codec_info[3].name, "")) {
923 spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
924 spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW;
925 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
930 mediacodec->ini->num_supported_codecs = count;
931 LOGE("supported codecs :%d", count);
935 void _mc_create_codec_map_from_ini_static(mc_ini_t *ini, mc_codec_spec_t *spec_emul)
937 int indx = 0, count = 0;
938 int codec_list = ini->codec_list;
940 for (indx = 0; indx < codec_list; indx++) {
941 if (strcmp(ini->codec[indx].codec_info[0].name, "")) {
942 spec_emul[count].codec_id = ini->codec[indx].codec_id;
943 spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_HW;
944 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
947 if (strcmp(ini->codec[indx].codec_info[1].name, "")) {
948 spec_emul[count].codec_id = ini->codec[indx].codec_id;
949 spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW;
950 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
953 if (strcmp(ini->codec[indx].codec_info[2].name, "")) {
954 spec_emul[count].codec_id = ini->codec[indx].codec_id;
955 spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW;
956 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
959 if (strcmp(ini->codec[indx].codec_info[3].name, "")) {
960 spec_emul[count].codec_id = ini->codec[indx].codec_id;
961 spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW;
962 spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
967 ini->num_supported_codecs = count;
968 LOGE("supported codecs :%d", count);
972 codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id)
974 guint media_codec_id_u = (guint)media_codec_id;
976 switch (media_codec_id_u) {
979 case MEDIACODEC_ALAW:
981 case MEDIACODEC_ULAW:
983 case MEDIACODEC_AMR_NB:
985 case MEDIACODEC_AMR_WB:
987 case MEDIACODEC_G729:
989 case MEDIACODEC_AAC_LC:
991 case MEDIACODEC_AAC_HE:
993 case MEDIACODEC_AAC_HE_PS:
997 case MEDIACODEC_VORBIS:
999 case MEDIACODEC_FLAC:
1001 case MEDIACODEC_WMAV1:
1003 case MEDIACODEC_WMAV2:
1005 case MEDIACODEC_WMAPRO:
1007 case MEDIACODEC_WMALSL:
1009 case MEDIACODEC_H261:
1011 case MEDIACODEC_H263:
1013 case MEDIACODEC_H264:
1015 case MEDIACODEC_MJPEG:
1017 case MEDIACODEC_MPEG1:
1019 case MEDIACODEC_MPEG2:
1021 case MEDIACODEC_MPEG4:
1023 case MEDIACODEC_HEVC:
1025 case MEDIACODEC_VP8:
1027 case MEDIACODEC_VP9:
1029 case MEDIACODEC_VC1:
1031 case MEDIACODEC_OPUS:
1038 mediacodec_codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id)
1040 guint codec_id_u = (guint)codec_id;
1042 switch (codec_id_u) {
1044 return MEDIACODEC_L16;
1046 return MEDIACODEC_ALAW;
1048 return MEDIACODEC_ULAW;
1050 return MEDIACODEC_AMR_NB;
1052 return MEDIACODEC_AMR_WB;
1054 return MEDIACODEC_G729;
1056 return MEDIACODEC_AAC_LC;
1058 return MEDIACODEC_AAC_HE;
1060 return MEDIACODEC_AAC_HE_PS;
1062 return MEDIACODEC_MP3;
1064 return MEDIACODEC_VORBIS;
1066 return MEDIACODEC_FLAC;
1068 return MEDIACODEC_WMAV1;
1070 return MEDIACODEC_WMAV2;
1072 return MEDIACODEC_WMAPRO;
1074 return MEDIACODEC_WMALSL;
1076 return MEDIACODEC_H261;
1078 return MEDIACODEC_H263;
1080 return MEDIACODEC_H264;
1082 return MEDIACODEC_MJPEG;
1084 return MEDIACODEC_MPEG1;
1086 return MEDIACODEC_MPEG2;
1088 return MEDIACODEC_MPEG4;
1090 return MEDIACODEC_HEVC;
1092 return MEDIACODEC_VP8;
1094 return MEDIACODEC_VP9;
1096 return MEDIACODEC_VC1;
1098 return MEDIACODEC_OPUS;
1104 gboolean _check_support_audio_info(mediacodec_codec_type_e codec_id, int samplerate, int channel, int bit_depth)
1107 gint maxchannels = 2;
1109 gint s_bit_depth = 32;
1112 case MEDIACODEC_AMR_NB:
1114 const static gint l_rates[] = { 8000 };
1116 n_rates = G_N_ELEMENTS(l_rates);
1117 s_bit_depth = 16; /* NOTE: amrnbenc/amrnbdec surpports S16LE as format*/
1119 while (i < n_rates) {
1120 if (l_rates[i] == samplerate)
1126 LOGE("Invalid samplerate set");
1131 case MEDIACODEC_AAC_LC:
1132 case MEDIACODEC_AAC_HE:
1134 const static gint l_rates[] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 };
1136 n_rates = G_N_ELEMENTS(l_rates);
1137 s_bit_depth = 32; /* NOTE: avdec_aac/avenc_aac surpports S32LE as format*/
1139 while (i < n_rates) {
1140 if (l_rates[i] == samplerate)
1146 LOGE("Invalid samplerate set");
1151 case MEDIACODEC_MP3:
1153 s_bit_depth = 16; /* NOTE: amrenc/amrnbdec surpports S16LE as format*/
1156 case MEDIACODEC_VORBIS:
1158 s_bit_depth = 32; /* NOTE: vorbisenc/vorbisdec surpports S32LE as format */
1161 case MEDIACODEC_FLAC:
1163 s_bit_depth = 32; /* NOTE: avdec_flac surpports S32LE as format */
1166 case MEDIACODEC_OPUS:
1168 s_bit_depth = 16; /* NOTE: opusenc/ opusdec support S16LE as format according to opus specification*/
1175 if (channel < 0 || channel > maxchannels) {
1176 LOGE("Invalid channel set");
1180 if (bit_depth != s_bit_depth) {
1181 LOGE("Invalid bit set");
1188 gboolean _check_support_video_info(mediacodec_codec_type_e codec_id, int width, int height)
1193 if (width <= 0 || height <= 0) {
1194 LOGE("Invalid resolution set");
1199 case MEDIACODEC_H261:
1201 const static gint widths[] = { 352, 176 };
1202 const static gint heights[] = { 288, 144 };
1203 n_sizes = G_N_ELEMENTS(widths);
1205 while (i < n_sizes) {
1206 if ((widths[i] == width) && (heights[i] == height))
1212 LOGE("Invalid resolution set");
1217 case MEDIACODEC_H263:
1219 const static gint widths[] = { 352, 704, 176, 1408, 128 };
1220 const static gint heights[] = { 288, 576, 144, 1152, 96 };
1221 n_sizes = G_N_ELEMENTS(widths);
1223 while (i < n_sizes) {
1224 if ((widths[i] == width) && (heights[i] == height))
1230 LOGE("Invalid resolution set");