+#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;
+}