--- /dev/null
+#include <dlog.h>
+#include <media_codec.h>
+#include <media_codec_port.h>
+#include <media_codec_ini.h>
+#include <media_codec_spec_emul.h>
+#include <media_codec_internal.h>
+
+mc_codec_spec_t spec_emul[MEDIA_CODEC_MAX_CODEC_TYPE];
+mc_ini_t mc_ini;
+
+int __convert_error_code_internal(int code, char *func_name)
+{
+ int ret = MEDIACODEC_ERROR_INVALID_OPERATION;
+ char *msg = "MEDIACOODEC_INVALID_OPERATION";
+
+ switch (code) {
+ case MC_ERROR_NONE:
+ ret = MEDIACODEC_ERROR_NONE;
+ msg = "MEDIACODEC_ERROR_NONE";
+ break;
+ case MC_PARAM_ERROR:
+ case MC_INVALID_ARG:
+ ret = MEDIACODEC_ERROR_INVALID_PARAMETER;
+ msg = "MEDIACODEC_ERROR_INVALID_PARAMETER";
+ break;
+ case MC_PERMISSION_DENIED:
+ ret = MEDIACODEC_ERROR_PERMISSION_DENIED;
+ msg = "MEDIACODEC_ERROR_PERMISSION_DENIED";
+ break;
+ case MC_INVALID_STATUS:
+ ret = MEDIACODEC_ERROR_INVALID_STATE;
+ msg = "MEDIACODEC_ERROR_INVALID_STATE";
+ break;
+ case MC_NOT_SUPPORTED:
+ ret = MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE;
+ msg = "MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE";
+ break;
+ case MC_ERROR:
+ case MC_INTERNAL_ERROR:
+ case MC_HW_ERROR:
+ ret = MEDIACODEC_ERROR_INVALID_OPERATION;
+ msg = "MEDIACODEC_ERROR_INVALID_OPERATION";
+ break;
+ case MC_INVALID_STREAM:
+ ret = MEDIACODEC_ERROR_INVALID_STREAM;
+ msg = "MEDIACODEC_ERROR_INVALID_STREAM";
+ break;
+ case MC_CODEC_NOT_FOUND:
+ ret = MEDIACODEC_ERROR_CODEC_NOT_FOUND;
+ msg = "MEDIACODEC_ERROR_CODEC_NOT_FOUND";
+ break;
+ case MC_ERROR_DECODE:
+ ret = MEDIACODEC_ERROR_DECODE;
+ msg = "MEDIACODEC_ERROR_DECODE";
+ break;
+ case MC_INVALID_IN_BUF:
+ ret = MEDIACODEC_ERROR_INVALID_INBUFFER;
+ msg = "MEDIACODEC_ERROR_INVALID_INBUFFER";
+ break;
+ case MC_INVALID_OUT_BUF:
+ ret = MEDIACODEC_ERROR_INVALID_OUTBUFFER;
+ msg = "MEDIACODEC_ERROR_INVALID_OUTBUFFER";
+ break;
+ case MC_NOT_INITIALIZED:
+ ret = MEDIACODEC_ERROR_NOT_INITIALIZED;
+ msg = "MEDIACODEC_ERROR_NOT_INITIALIZED";
+ break;
+ case MC_OUTPUT_BUFFER_EMPTY:
+ case MC_OUTPUT_BUFFER_OVERFLOW:
+ ret = MEDIACODEC_ERROR_BUFFER_NOT_AVAILABLE;
+ msg = "MEDIACODEC_ERROR_BUFFER_NOT_AVAILABLE";
+ break;
+ case MC_OUT_OF_MEMORY:
+ ret = MEDIACODEC_ERROR_OUT_OF_MEMORY;
+ msg = "MEDIACODEC_ERROR_OUT_OF_MEMORY";
+ break;
+ default:
+ ret = MEDIACODEC_ERROR_INTERNAL;
+ msg = "MEDIACODEC_ERROR_INTERNAL";
+ break;
+ }
+ LOGD("[%s] %s(0x%08x) : core fw error(0x%x)", func_name, msg, ret, code);
+ return ret;
+}
+
+int mediacodec_foreach_supported_codec_static(mediacodec_supported_codec_cb callback, void *user_data)
+{
+ int ret;
+
+ if (!mc_ini.loaded) {
+ ret = mc_ini_load(&mc_ini);
+ if (ret != MC_ERROR_NONE)
+ goto ERROR;
+
+ mc_ini.loaded = TRUE;
+ }
+
+ _mc_create_codec_map_from_ini_static(&mc_ini, spec_emul);
+
+ LOGD("set supported_codec_cb(%p)", callback);
+ ret = _mediacodec_foreach_supported_codec(callback, user_data);
+
+ if (ret != MEDIACODEC_ERROR_NONE)
+ return __convert_error_code_internal(ret, (char *)__FUNCTION__);
+ else
+ return MEDIACODEC_ERROR_NONE;
+
+ERROR:
+ return MEDIACODEC_ERROR_INVALID_PARAMETER;
+}
#include <media_codec_port_gst.h>
#include <media_codec_spec_emul.h>
-static mc_codec_spec_t spec_emul[MEDIA_CODEC_MAX_CODEC_TYPE];
+mc_ini_t mc_ini;
+mc_codec_spec_t spec_emul[MEDIA_CODEC_MAX_CODEC_TYPE];
int mc_create(MMHandleType *mediacodec)
{
mc_handle_t *new_mediacodec = NULL;
int ret = MC_ERROR_NONE;
- int i;
/* alloc mediacodec structure */
new_mediacodec = (mc_handle_t *)g_malloc(sizeof(mc_handle_t));
goto ERROR;
}
memset(new_mediacodec, 0, sizeof(mc_handle_t));
- memset(spec_emul, 0, sizeof(mc_codec_spec_t)*MEDIA_CODEC_MAX_CODEC_TYPE);
new_mediacodec->is_encoder = false;
new_mediacodec->is_video = false;
new_mediacodec->ports[0] = NULL;
new_mediacodec->ports[1] = NULL;
- new_mediacodec->num_supported_codecs = 0;
new_mediacodec->num_supported_decoder = 0;
new_mediacodec->num_supported_encoder = 0;
new_mediacodec->core = NULL;
+ new_mediacodec->ini = &mc_ini;
/* load ini files */
- ret = mc_ini_load(&new_mediacodec->ini);
- if (ret != MC_ERROR_NONE)
- goto ERROR;
- _mc_create_codec_map_from_ini(new_mediacodec, spec_emul);
+ if (!mc_ini.loaded) {
+ ret = mc_ini_load(&mc_ini);
+ if (ret != MC_ERROR_NONE)
+ goto ERROR;
- for (i = 0; i < new_mediacodec->num_supported_codecs; i++) {
- new_mediacodec->supported_codecs =
- g_list_append(new_mediacodec->supported_codecs, GINT_TO_POINTER(spec_emul[i].codec_id));
+ mc_ini.loaded = TRUE;
}
+ _mc_create_codec_map_from_ini(new_mediacodec, spec_emul);
+
/* create decoder map from ini */
_mc_create_decoder_map_from_ini(new_mediacodec);
}
mc_handle->is_prepared = false;
- g_list_free(mc_handle->supported_codecs);
/* free mediacodec structure */
if (mc_handle) {
if (!GET_IS_HW(flags) && !GET_IS_SW(flags))
flags |= MEDIACODEC_SUPPORT_TYPE_SW;
- for (i = 0; i < mc_handle->num_supported_codecs; i++) {
+ for (i = 0; i < mc_handle->ini->num_supported_codecs; i++) {
if ((codec_id == spec_emul[i].codec_id) && (flags == spec_emul[i].codec_type))
break;
}
- LOGD("support_list : %d, i : %d", mc_handle->num_supported_codecs, i);
+ LOGD("support_list : %d, i : %d", mc_handle->ini->num_supported_codecs, i);
- if (i == mc_handle->num_supported_codecs)
+ if (i == mc_handle->ini->num_supported_codecs)
return MC_NOT_SUPPORTED;
mc_handle->port_type = spec_emul[i].port_type;
return ret;
}
-int _mediacodec_foreach_supported_codec(MMHandleType mediacodec, mediacodec_supported_codec_cb callback, void *user_data)
+int _mediacodec_foreach_supported_codec(mediacodec_supported_codec_cb callback, void *user_data)
{
- int ret = MC_ERROR_NONE;
- mc_handle_t *mc_handle = (mc_handle_t *)mediacodec;
- int codecs_num;
- gpointer tmp;
+ int ret = MEDIACODEC_NONE;
+ int i;
+ int index;
- if (!mc_handle) {
- LOGE("fail invaild param\n");
- return MC_INVALID_ARG;
- }
+ gboolean codec[CODEC_NR_ITEMS] = {0,};
- if (mc_handle->supported_codecs) {
- codecs_num = g_list_length(mc_handle->supported_codecs);
- LOGD("supported_codecs : %d", codecs_num);
+ for (i = 0; i < mc_ini.num_supported_codecs; i++) {
+ index = codec_type_to_simple_enumeration(spec_emul[i].codec_id);
+ codec[index] = TRUE;
+ }
- while (codecs_num) {
- tmp = g_list_nth_data(mc_handle->supported_codecs, codecs_num - 1);
- if (tmp) {
- if (!callback(GPOINTER_TO_INT(tmp), user_data)) {
- ret = MEDIACODEC_ERROR_INTERNAL;
- goto CALLBACK_ERROR;
- }
+ for (i = 0; i < CODEC_NR_ITEMS; i++) {
+ if (codec[i]) {
+ index = simple_to_codec_type_enumeration(i);
+ if (!callback(index, user_data)) {
+ goto CALLBACK_ERROR;
}
- codecs_num--;
}
+ }
- if (!callback(-1, user_data)) {
- ret = MEDIACODEC_ERROR_INTERNAL;
- goto CALLBACK_ERROR;
- }
+ if (!callback(-1, user_data)) {
+ ret = MEDIACODEC_ERROR_INTERNAL;
+ goto CALLBACK_ERROR;
}
CALLBACK_ERROR:
void _mc_create_decoder_map_from_ini(mc_handle_t *mediacodec)
{
int indx = 0, count = 0;
- int codec_list = mediacodec->ini.codec_list;
+ int codec_list = mediacodec->ini->codec_list;
for (indx = 0; indx < codec_list; indx++) {
- if (strcmp(mediacodec->ini.codec[indx].codec_info[0].name, "")) {
- mediacodec->decoder_map[count].id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[0].name, "")) {
+ mediacodec->decoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
mediacodec->decoder_map[count].hardware = 1; /* hardware */
- mediacodec->decoder_map[count].type.factory_name = mediacodec->ini.codec[indx].codec_info[0].name;
- mediacodec->decoder_map[count].type.mime = mediacodec->ini.codec[indx].codec_info[0].mime;
+ mediacodec->decoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[0].name;
+ mediacodec->decoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[0].mime;
mediacodec->decoder_map[count].type.out_format =
- _mc_convert_media_format_str_to_int(mediacodec->ini.codec[indx].codec_info[0].format);
+ _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[0].format);
count++;
}
- if (strcmp(mediacodec->ini.codec[indx].codec_info[2].name, "")) {
- mediacodec->decoder_map[count].id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[2].name, "")) {
+ mediacodec->decoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
mediacodec->decoder_map[count].hardware = 0; /* software */
- mediacodec->decoder_map[count].type.factory_name = mediacodec->ini.codec[indx].codec_info[2].name;
- mediacodec->decoder_map[count].type.mime = mediacodec->ini.codec[indx].codec_info[2].mime;
+ mediacodec->decoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[2].name;
+ mediacodec->decoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[2].mime;
mediacodec->decoder_map[count].type.out_format =
- _mc_convert_media_format_str_to_int(mediacodec->ini.codec[indx].codec_info[2].format);
+ _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[2].format);
count++;
}
}
void _mc_create_encoder_map_from_ini(mc_handle_t *mediacodec)
{
int indx = 0, count = 0;
- int codec_list = mediacodec->ini.codec_list;
+ int codec_list = mediacodec->ini->codec_list;
for (indx = 0; indx < codec_list; indx++) {
- if (strcmp(mediacodec->ini.codec[indx].codec_info[1].name, "")) {
- mediacodec->encoder_map[count].id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[1].name, "")) {
+ mediacodec->encoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
mediacodec->encoder_map[count].hardware = 1;
- mediacodec->encoder_map[count].type.factory_name = mediacodec->ini.codec[indx].codec_info[1].name;
- mediacodec->encoder_map[count].type.mime = mediacodec->ini.codec[indx].codec_info[1].mime;
+ mediacodec->encoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[1].name;
+ mediacodec->encoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[1].mime;
mediacodec->encoder_map[count].type.out_format =
- _mc_convert_media_format_str_to_int(mediacodec->ini.codec[indx].codec_info[1].format);
+ _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[1].format);
count++;
}
- if (strcmp(mediacodec->ini.codec[indx].codec_info[3].name, "")) {
- mediacodec->encoder_map[count].id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[3].name, "")) {
+ mediacodec->encoder_map[count].id = mediacodec->ini->codec[indx].codec_id;
mediacodec->encoder_map[count].hardware = 0;
- mediacodec->encoder_map[count].type.factory_name = mediacodec->ini.codec[indx].codec_info[3].name;
- mediacodec->encoder_map[count].type.mime = mediacodec->ini.codec[indx].codec_info[3].mime;
+ mediacodec->encoder_map[count].type.factory_name = mediacodec->ini->codec[indx].codec_info[3].name;
+ mediacodec->encoder_map[count].type.mime = mediacodec->ini->codec[indx].codec_info[3].mime;
mediacodec->encoder_map[count].type.out_format =
- _mc_convert_media_format_str_to_int(mediacodec->ini.codec[indx].codec_info[3].format);
+ _mc_convert_media_format_str_to_int(mediacodec->ini->codec[indx].codec_info[3].format);
count++;
}
}
void _mc_create_codec_map_from_ini(mc_handle_t *mediacodec, mc_codec_spec_t *spec_emul)
{
int indx = 0, count = 0;
- int codec_list = mediacodec->ini.codec_list;
+ int codec_list = mediacodec->ini->codec_list;
for (indx = 0; indx < codec_list; indx++) {
- if (strcmp(mediacodec->ini.codec[indx].codec_info[0].name, "")) {
- spec_emul[count].codec_id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[0].name, "")) {
+ spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_HW;
spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
count++;
}
- if (strcmp(mediacodec->ini.codec[indx].codec_info[1].name, "")) {
- spec_emul[count].codec_id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[1].name, "")) {
+ spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW;
spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
count++;
}
- if (strcmp(mediacodec->ini.codec[indx].codec_info[2].name, "")) {
- spec_emul[count].codec_id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[2].name, "")) {
+ spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW;
spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
count++;
}
- if (strcmp(mediacodec->ini.codec[indx].codec_info[3].name, "")) {
- spec_emul[count].codec_id = mediacodec->ini.codec[indx].codec_id;
+ if (strcmp(mediacodec->ini->codec[indx].codec_info[3].name, "")) {
+ spec_emul[count].codec_id = mediacodec->ini->codec[indx].codec_id;
spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW;
spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
count++;
}
}
- mediacodec->num_supported_codecs = count;
+ mediacodec->ini->num_supported_codecs = count;
LOGE("supported codecs :%d", count);
return;
}
+void _mc_create_codec_map_from_ini_static(mc_ini_t *ini, mc_codec_spec_t *spec_emul)
+{
+ int indx = 0, count = 0;
+ int codec_list = ini->codec_list;
+ for (indx = 0; indx < codec_list; indx++) {
+ if (strcmp(ini->codec[indx].codec_info[0].name, "")) {
+ spec_emul[count].codec_id = ini->codec[indx].codec_id;
+ spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_HW;
+ spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
+ count++;
+ }
+ if (strcmp(ini->codec[indx].codec_info[1].name, "")) {
+ spec_emul[count].codec_id = ini->codec[indx].codec_id;
+ spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW;
+ spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
+ count++;
+ }
+ if (strcmp(ini->codec[indx].codec_info[2].name, "")) {
+ spec_emul[count].codec_id = ini->codec[indx].codec_id;
+ spec_emul[count].codec_type = MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW;
+ spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
+ count++;
+ }
+ if (strcmp(ini->codec[indx].codec_info[3].name, "")) {
+ spec_emul[count].codec_id = ini->codec[indx].codec_id;
+ spec_emul[count].codec_type = MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW;
+ spec_emul[count].port_type = MEDIACODEC_PORT_TYPE_GST;
+ count++;
+ }
+ }
+
+ ini->num_supported_codecs = count;
+ LOGE("supported codecs :%d", count);
+ return;
+}
+
+const int codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id)
+{
+ guint media_codec_id_u = (guint)media_codec_id;
+
+ switch (media_codec_id_u) {
+ case MEDIACODEC_L16:
+ return L16;
+ case MEDIACODEC_ALAW:
+ return ALAW;
+ case MEDIACODEC_ULAW:
+ return ULAW;
+ case MEDIACODEC_AMR_NB:
+ return AMR_NB;
+ case MEDIACODEC_AMR_WB:
+ return AMR_WB;
+ case MEDIACODEC_G729:
+ return G729;
+ case MEDIACODEC_AAC_LC:
+ return AAC_LC;
+ case MEDIACODEC_AAC_HE:
+ return AAC_HE;
+ case MEDIACODEC_AAC_HE_PS:
+ return AAC_HE_PS;
+ case MEDIACODEC_MP3:
+ return MP3;
+ case MEDIACODEC_VORBIS:
+ return VORBIS;
+ case MEDIACODEC_FLAC:
+ return FLAC;
+ case MEDIACODEC_WMAV1:
+ return WMAV1;
+ case MEDIACODEC_WMAV2:
+ return WMAV2;
+ case MEDIACODEC_WMAPRO:
+ return WMAPRO;
+ case MEDIACODEC_WMALSL:
+ return WMALSL;
+ case MEDIACODEC_H261:
+ return H261;
+ case MEDIACODEC_H263:
+ return H263;
+ case MEDIACODEC_H264:
+ return H264;
+ case MEDIACODEC_MJPEG:
+ return MJPEG;
+ case MEDIACODEC_MPEG1:
+ return MPEG1;
+ case MEDIACODEC_MPEG2:
+ return MPEG2;
+ case MEDIACODEC_MPEG4:
+ return MPEG4;
+ case MEDIACODEC_HEVC:
+ return HEVC;
+ case MEDIACODEC_VP8:
+ return VP8;
+ case MEDIACODEC_VP9:
+ return VP9;
+ case MEDIACODEC_VC1:
+ return VC1;
+ default:
+ return NONE;
+ }
+}
+
+const int simple_to_codec_type_enumeration(codec_type_e codec_id)
+{
+ guint codec_id_u = (guint)codec_id;
+
+ switch (codec_id_u) {
+ case L16:
+ return MEDIACODEC_L16;
+ case ALAW:
+ return MEDIACODEC_ALAW;
+ case ULAW:
+ return MEDIACODEC_ULAW;
+ case AMR_NB:
+ return MEDIACODEC_AMR_NB;
+ case AMR_WB:
+ return MEDIACODEC_AMR_WB;
+ case G729:
+ return MEDIACODEC_G729;
+ case AAC_LC:
+ return MEDIACODEC_AAC_LC;
+ case AAC_HE:
+ return MEDIACODEC_AAC_HE;
+ case AAC_HE_PS:
+ return MEDIACODEC_AAC_HE_PS;
+ case MP3:
+ return MEDIACODEC_MP3;
+ case VORBIS:
+ return MEDIACODEC_VORBIS;
+ case FLAC:
+ return MEDIACODEC_FLAC;
+ case WMAV1:
+ return MEDIACODEC_WMAV1;
+ case WMAV2:
+ return MEDIACODEC_WMAV2;
+ case WMAPRO:
+ return MEDIACODEC_WMAPRO;
+ case WMALSL:
+ return MEDIACODEC_WMALSL;
+ case H261:
+ return MEDIACODEC_H261;
+ case H263:
+ return MEDIACODEC_H263;
+ case H264:
+ return MEDIACODEC_H264;
+ case MJPEG:
+ return MEDIACODEC_MJPEG;
+ case MPEG1:
+ return MEDIACODEC_MPEG1;
+ case MPEG2:
+ return MEDIACODEC_MPEG2;
+ case MPEG4:
+ return MEDIACODEC_MPEG4;
+ case HEVC:
+ return MEDIACODEC_HEVC;
+ case VP8:
+ return MEDIACODEC_VP8;
+ case VP9:
+ return MEDIACODEC_VP9;
+ case VC1:
+ return MEDIACODEC_VC1;
+ default:
+ return NONE;
+ }
+}