From: Sejun Park Date: Thu, 29 Mar 2018 07:53:23 +0000 (+0900) Subject: Sync with tizen 4.0 X-Git-Tag: submit/tizen/20180330.043712^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F38%2F174238%2F3;p=platform%2Fcore%2Fapi%2Fmediacodec.git Sync with tizen 4.0 Change-Id: I4e77a485916bb78806c28484ea4e6a980ad53525 --- diff --git a/doc/media_codec_doc.h b/doc/media_codec_doc.h old mode 100644 new mode 100755 index 5899e57..36a1586 --- a/doc/media_codec_doc.h +++ b/doc/media_codec_doc.h @@ -33,6 +33,18 @@ * * @section CAPI_MEDIA_CODEC_MODULE_OVERVIEW Overview * + * @section CAPI_MEDIA_CODEC_FEATURE Related Features + * This API is related with the following features:\n + * - %http://tizen.org/feature/multimedia.media_codec:\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * * MEDIA CODEC API allows : * The API allows you to direct access to the media codec on device. It operates on "raw" data, so any file headers * must be stripped off. media_packet is used for zero-copy. diff --git a/include/media_codec.h b/include/media_codec.h old mode 100644 new mode 100755 index 5899592..835cbec --- a/include/media_codec.h +++ b/include/media_codec.h @@ -212,6 +212,7 @@ typedef bool (*mediacodec_supported_codec_cb)(mediacodec_codec_type_e codec_type * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_create(mediacodec_h *mediacodec); @@ -227,6 +228,7 @@ int mediacodec_create(mediacodec_h *mediacodec); * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_destroy(mediacodec_h mediacodec); @@ -246,6 +248,7 @@ int mediacodec_destroy(mediacodec_h mediacodec); * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Codec not found + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_set_codec(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, int flags); @@ -260,6 +263,7 @@ int mediacodec_set_codec(mediacodec_h mediacodec, mediacodec_codec_type_e codec_ * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_set_vdec_info(mediacodec_h mediacodec, int width, int height); @@ -278,6 +282,7 @@ int mediacodec_set_vdec_info(mediacodec_h mediacodec, int width, int height); * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_set_venc_info(mediacodec_h mediacodec, int width, int height, int fps, int target_bits); @@ -293,6 +298,7 @@ int mediacodec_set_venc_info(mediacodec_h mediacodec, int width, int height, int * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_set_adec_info(mediacodec_h mediacodec, int samplerate, int channel, int bit); @@ -309,6 +315,7 @@ int mediacodec_set_adec_info(mediacodec_h mediacodec, int samplerate, int channe * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_set_aenc_info(mediacodec_h mediacodec, int samplerate, int channel, int bit, int bitrate); @@ -336,6 +343,7 @@ int mediacodec_set_aenc_info(mediacodec_h mediacodec, int samplerate, int channe * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Unsupported codec + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre The media format has been created and the required values for configuration have been set. * @see media_format_set_video_mime() * @see media_format_set_audio_mime() @@ -359,6 +367,7 @@ int mediacodec_configure_from_media_format(mediacodec_h mediacodec, media_format * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre The mediacodec should call mediacodec_set_codec()and mediacodec_set_vdec_info()/mediacodec_set_venc_info() before calling mediacodec_prepare() * If the decoder is set by mediacodec_set_codec(), mediacodec_set_vdec_info() should be called. If the encoder is set by * mediacodec_set_codec(), mediacodec_set_venc_info() should be called. @@ -374,6 +383,7 @@ int mediacodec_prepare(mediacodec_h mediacodec); * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_unprepare(mediacodec_h mediacodec); @@ -391,6 +401,7 @@ int mediacodec_unprepare(mediacodec_h mediacodec); * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation * @retval #MEDIACODEC_ERROR_OVERFLOW_INBUFFER Overflow inputbuffer + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_process_input(mediacodec_h mediacodec, media_packet_h inbuf, uint64_t timeOutUs); @@ -407,6 +418,7 @@ int mediacodec_process_input(mediacodec_h mediacodec, media_packet_h inbuf, uint * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_get_output(mediacodec_h mediacodec, media_packet_h *outbuf, uint64_t timeOutUs); @@ -417,6 +429,7 @@ int mediacodec_get_output(mediacodec_h mediacodec, media_packet_h *outbuf, uint6 * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_flush_buffers(mediacodec_h mediacodec); @@ -429,6 +442,7 @@ int mediacodec_flush_buffers(mediacodec_h mediacodec); * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre mediacodec_set_input_buffer_used_cb should be called before mediacodec_preare(). * @post mediacodec_input_buffer_used_cb will be invoked. * @see mediacodec_set_input_buffer_used_cb() @@ -443,6 +457,7 @@ int mediacodec_set_input_buffer_used_cb(mediacodec_h mediacodec, mediacodec_inpu * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @see mediacodec_set_input_buffer_used_cb() */ int mediacodec_unset_input_buffer_used_cb(mediacodec_h mediacodec); @@ -456,6 +471,7 @@ int mediacodec_unset_input_buffer_used_cb(mediacodec_h mediacodec); * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre mediacodec_set_output_buffer_available_cb should be called before mediacodec_preare(). * @post mediacodec_output_buffer_available_cb will be invoked. * @see mediacodec_set_output_buffer_available_cb() @@ -470,6 +486,7 @@ int mediacodec_set_output_buffer_available_cb(mediacodec_h mediacodec, mediacode * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @see mediacodec_set_output_buffer_available_cb() */ int mediacodec_unset_output_buffer_available_cb(mediacodec_h mediacodec); @@ -483,6 +500,7 @@ int mediacodec_unset_output_buffer_available_cb(mediacodec_h mediacodec); * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre mediacodec_set_error_cb should be called before mediacodec_preare(). * @post mediacodec_error_cb will be invoked. * @see mediacodec_set_error_cb() @@ -497,6 +515,7 @@ int mediacodec_set_error_cb(mediacodec_h mediacodec, mediacodec_error_cb callbac * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @see mediacodec_set_error_cb() */ int mediacodec_unset_error_cb(mediacodec_h mediacodec); @@ -510,6 +529,7 @@ int mediacodec_unset_error_cb(mediacodec_h mediacodec); * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre mediacodec_set_eos_cb should be called before mediacodec_preare(). * @post mediacodec_eos_cb will be invoked. * @see mediacodec_set_eos_cb() @@ -524,6 +544,7 @@ int mediacodec_set_eos_cb(mediacodec_h mediacodec, mediacodec_eos_cb callback, v * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @see mediacodec_set_event_handler_cb() */ int mediacodec_unset_eos_cb(mediacodec_h mediacodec); @@ -537,6 +558,7 @@ int mediacodec_unset_eos_cb(mediacodec_h mediacodec); * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre mediacodec_set_buffer_status_cb should be called before mediacodec_preare(). * @post mediacodec_buffer_status_cb will be invoked. * @see mediacodec_set_buffer_status_cb() @@ -551,6 +573,7 @@ int mediacodec_set_buffer_status_cb(mediacodec_h mediacodec, mediacodec_buffer_s * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) */ int mediacodec_unset_buffer_status_cb(mediacodec_h mediacodec); @@ -563,6 +586,7 @@ int mediacodec_unset_buffer_status_cb(mediacodec_h mediacodec); * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @see mediacodec_foreach_supported_codec() */ int mediacodec_foreach_supported_codec(mediacodec_h mediacodec, mediacodec_supported_codec_cb callback, void *user_data); @@ -577,6 +601,7 @@ int mediacodec_foreach_supported_codec(mediacodec_h mediacodec, mediacodec_suppo * @return @c 0 on success, otherwise a negative error value * @retval #MEDIACODEC_ERROR_NONE Successful * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) @code #include mediacodec_h mediacodec; @@ -611,6 +636,7 @@ int mediacodec_get_supported_type(mediacodec_h mediacodec, mediacodec_codec_type * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory * @retval #MEDIACODEC_ERROR_INVALID_OPERATION The user calls mediacodec_get_packet_pool() before calling mediacodec_prepare(). + * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0) * @pre mediacodec_get_packet_pool() should be called after calling mediacodec_prepare(). * @post If the pool is used, media_packet_pool_deallocate() and media_packet_pool_destroy() should be called. * @see media_packet_pool_acquire_packet() diff --git a/include/media_codec_port.h b/include/media_codec_port.h old mode 100644 new mode 100755 index f2a732c..986bdd3 --- a/include/media_codec_port.h +++ b/include/media_codec_port.h @@ -267,8 +267,8 @@ void _mc_create_codec_map_from_ini_static(mc_ini_t *ini, mc_codec_spec_t *spec_e void _mc_create_decoder_map_from_ini(mc_handle_t *mc_handle); void _mc_create_encoder_map_from_ini(mc_handle_t *mc_handle); -const codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id); -const codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id); +mediacodec_codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id); +codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id); #ifdef __cplusplus } diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index 9f9ee77..0d2a3bb 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -4,8 +4,8 @@ Name: capi-media-codec Summary: A Media Codec library in Tizen Native API -Version: 0.5.8 -Release: 2 +Version: 0.5.10 +Release: 0 Group: Multimedia/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/media_codec_port.c b/src/media_codec_port.c old mode 100644 new mode 100755 index cf6843a..804a7cb --- a/src/media_codec_port.c +++ b/src/media_codec_port.c @@ -27,6 +27,9 @@ #include #include +static gboolean _check_support_audio_info(mediacodec_codec_type_e codec_id, int samplerate, int channel, int bit_depth); +static gboolean _check_support_video_info(mediacodec_codec_type_e codec_id, int width, int height); + int mc_create(MMHandleType *mediacodec) { mc_handle_t *new_mediacodec = NULL; @@ -168,7 +171,7 @@ int mc_set_vdec_info(MMHandleType mediacodec, int width, int height) return MC_INVALID_ARG; } - if ((width <= 0) || (height <= 0)) + if (!_check_support_video_info(mc_handle->codec_id, width, height)) return MC_PARAM_ERROR; MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && mc_handle->is_video && !mc_handle->is_encoder, @@ -192,7 +195,7 @@ int mc_set_venc_info(MMHandleType mediacodec, int width, int height, int fps, in return MC_INVALID_ARG; } - if ((width <= 0) || (height <= 0)) + if (!_check_support_video_info(mc_handle->codec_id, width, height) || fps < 0 || target_bits < 0) return MC_PARAM_ERROR; MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && mc_handle->is_video && mc_handle->is_encoder, @@ -217,7 +220,7 @@ int mc_set_adec_info(MMHandleType mediacodec, int samplerate, int channel, int b return MC_INVALID_ARG; } - if ((samplerate <= 0) || (channel <= 0) || (bit <= 0)) + if (!_check_support_audio_info(mc_handle->codec_id, samplerate, channel, bit)) return MC_PARAM_ERROR; MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && !mc_handle->is_video && !mc_handle->is_encoder, @@ -241,7 +244,7 @@ int mc_set_aenc_info(MMHandleType mediacodec, int samplerate, int channel, int b return MC_INVALID_ARG; } - if ((samplerate <= 0) || (channel <= 0) || (bit <= 0)) + if (!_check_support_audio_info(mc_handle->codec_id, samplerate, channel, bit)) return MC_PARAM_ERROR; MEDIACODEC_CHECK_CONDITION(mc_handle->codec_id && !mc_handle->is_video && mc_handle->is_encoder, @@ -287,8 +290,10 @@ int mc_configure(MMHandleType mediacodec, media_format_h format, int flags) if (type == MEDIA_FORMAT_AUDIO) { media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &bitrate); + codec_id = mimetype & codec_mask; + if (GET_IS_ENCODER(flags)) { - if ((samplerate <= 0) || (channel <= 0) || (bit <= 0) || (bitrate <= 0)) { + if (!_check_support_audio_info(codec_id, samplerate, channel, bit)) { LOGE("invalid pram is set : samplerate : %d, channel : %d, bit : %d, bitrate : %d", samplerate, channel, bit, bitrate); return MC_PARAM_ERROR; @@ -299,7 +304,7 @@ int mc_configure(MMHandleType mediacodec, media_format_h format, int flags) mc_handle->info.audio.bit_depth = bit; mc_handle->info.audio.bitrate = bitrate * 1000; } else if (GET_IS_DECODER(flags)) { - if ((samplerate <= 0) || (channel <= 0) || (bit <= 0)) { + if (!_check_support_audio_info(codec_id, samplerate, channel, bit)) { LOGE("invalid pram is set : samplerate : %d, channel : %d, bit : %d", samplerate, channel, bit); return MC_PARAM_ERROR; @@ -314,9 +319,10 @@ int mc_configure(MMHandleType mediacodec, media_format_h format, int flags) } else if (type == MEDIA_FORMAT_VIDEO) { media_format_get_video_info(format, &mimetype, &width, &height, &bitrate, NULL); media_format_get_video_frame_rate(format, &fps); + codec_id = mimetype & codec_mask; if (GET_IS_ENCODER(flags)) { - if ((width <= 0) || (height <= 0) || (bitrate <= 0) || (fps <= 0)) { + if (!_check_support_video_info(codec_id, width, height) || fps <= 0 || bitrate <= 0) { LOGE("invalid pram is set : width : %d, height : %d, bitrate : %d, fps : %d", width, height, bitrate, fps); return MC_PARAM_ERROR; @@ -327,7 +333,7 @@ int mc_configure(MMHandleType mediacodec, media_format_h format, int flags) mc_handle->info.video.framerate = fps; mc_handle->info.video.bitrate = bitrate * 1000; } else if (GET_IS_DECODER(flags)) { - if ((width <= 0) || (height <= 0)) { + if (!_check_support_video_info(codec_id, width, height)) { LOGE("invalid pram is set : width : %d, height : %d", width, height); return MC_PARAM_ERROR; @@ -347,8 +353,6 @@ int mc_configure(MMHandleType mediacodec, media_format_h format, int flags) if (!GET_IS_HW(flags) && !GET_IS_SW(flags)) flags |= MEDIACODEC_SUPPORT_TYPE_SW; - codec_id = mimetype & codec_mask; - 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; @@ -988,7 +992,7 @@ void _mc_create_codec_map_from_ini_static(mc_ini_t *ini, mc_codec_spec_t *spec_e return; } -const codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id) +codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id) { guint media_codec_id_u = (guint)media_codec_id; @@ -1052,7 +1056,7 @@ const codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e medi } } -const codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id) +mediacodec_codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id) { guint codec_id_u = (guint)codec_id; @@ -1115,3 +1119,136 @@ const codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id) return NONE; } } + +gboolean _check_support_audio_info(mediacodec_codec_type_e codec_id, int samplerate, int channel, int bit_depth) +{ + gint i = 0; + gint maxchannels = 2; + gint n_rates = 0; + gint s_bit_depth = 32; + + switch (codec_id) { + case MEDIACODEC_AMR_NB: + { + const static gint l_rates[] = { 8000 }; + maxchannels = 1; + n_rates = G_N_ELEMENTS(l_rates); + s_bit_depth = 16; /* NOTE: amrnbenc/amrnbdec surpports S16LE as format*/ + + while (i < n_rates) { + if (l_rates[i] == samplerate) + break; + i++; + } + + if (i == n_rates) { + LOGE("Invalid samplerate set"); + return false; + } + break; + } + case MEDIACODEC_AAC_LC: + case MEDIACODEC_AAC_HE: + { + const static gint l_rates[] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 }; + maxchannels = 6; + n_rates = G_N_ELEMENTS(l_rates); + s_bit_depth = 32; /* NOTE: avdec_aac/avenc_aac surpports S32LE as format*/ + + while (i < n_rates) { + if (l_rates[i] == samplerate) + break; + i++; + } + + if (i == n_rates) { + LOGE("Invalid samplerate set"); + return false; + } + break; + } + case MEDIACODEC_MP3: + { + s_bit_depth = 16; /* NOTE: amrenc/amrnbdec surpports S16LE as format*/ + break; + } + case MEDIACODEC_VORBIS: + { + s_bit_depth = 32; /* NOTE: vorbisenc/vorbisdec surpports S32LE as format */ + break; + } + case MEDIACODEC_FLAC: + { + s_bit_depth = 32; /* NOTE: avdec_flac surpports S32LE as format */ + break; + } + default: + break; + } + + if (channel < 0 || channel > maxchannels) { + LOGE("Invalid channel set"); + return false; + } + + if (bit_depth != s_bit_depth) { + LOGE("Invalid bit set"); + return false; + } + + return true; +} + +gboolean _check_support_video_info(mediacodec_codec_type_e codec_id, int width, int height) +{ + gint i = 0; + gint n_sizes = 0; + + if (width <= 0 || height <= 0) { + LOGE("Invalid resolution set"); + return false; + } + + switch (codec_id) { + case MEDIACODEC_H261: + { + const static gint widths[] = { 352, 176 }; + const static gint heights[] = { 288, 144 }; + n_sizes = G_N_ELEMENTS(widths); + + while (i < n_sizes) { + if ((widths[i] == width) && (heights[i] == height)) + break; + i++; + } + + if (i == n_sizes) { + LOGE("Invalid resolution set"); + return false; + } + break; + } + case MEDIACODEC_H263: + { + const static gint widths[] = { 352, 704, 176, 1408, 128 }; + const static gint heights[] = { 288, 576, 144, 1152, 96 }; + n_sizes = G_N_ELEMENTS(widths); + + while (i < n_sizes) { + if ((widths[i] == width) && (heights[i] == height)) + break; + i++; + } + + if (i == n_sizes) { + LOGE("Invalid resolution set"); + return false; + } + break; + } + default: + break; + } + + return true; +} diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c old mode 100644 new mode 100755 index 6d32a7b..753b309 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -64,7 +64,6 @@ static gint __gst_handle_library_error(mc_gst_core_t *core, int code); static gint __gst_handle_core_error(mc_gst_core_t *core, int code); static const gchar * _mc_error_to_string(mc_ret_e err); static const gchar * _mc_bit_to_string(int bit); -static int _mc_get_support_bit_from_format(media_format_mimetype_e format); static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboolean is_encoder, gboolean is_hw); static int _mc_gst_flush_buffers(mc_gst_core_t *core); @@ -908,36 +907,23 @@ int _mc_output_media_packet_new(mc_gst_core_t *core, bool video, bool encoder, m } mc_gst_port_def_t *port_def = &core->ports[out_port_index]->port_def; - if (encoder) { + if (video) { + media_format_set_video_mime(core->output_fmt, out_mime); + media_format_set_video_width(core->output_fmt, port_def->info.video.width); + media_format_set_video_height(core->output_fmt, port_def->info.video.height); - if (video) { - media_format_set_video_mime(core->output_fmt, out_mime); - media_format_set_video_width(core->output_fmt, port_def->info.video.width); - media_format_set_video_height(core->output_fmt, port_def->info.video.height); + if (encoder) media_format_set_video_avg_bps(core->output_fmt, port_def->info.video.bitrate); - } else { - int support_bit = 0; - support_bit = _mc_get_support_bit_from_format(out_mime); - - media_format_set_audio_mime(core->output_fmt, out_mime); - media_format_set_audio_channel(core->output_fmt, port_def->info.audio.channel); - media_format_set_audio_samplerate(core->output_fmt, port_def->info.audio.samplerate); - media_format_set_audio_bit(core->output_fmt, support_bit); - media_format_set_audio_avg_bps(core->output_fmt, port_def->info.audio.bitrate); - } } else { + media_format_set_audio_mime(core->output_fmt, out_mime); + media_format_set_audio_channel(core->output_fmt, port_def->info.audio.channel); + media_format_set_audio_samplerate(core->output_fmt, port_def->info.audio.samplerate); + media_format_set_audio_bit(core->output_fmt, port_def->info.audio.bit_depth); - if (video) { - media_format_set_video_mime(core->output_fmt, out_mime); - media_format_set_video_width(core->output_fmt, port_def->info.video.width); - media_format_set_video_height(core->output_fmt, port_def->info.video.height); - } else { - media_format_set_audio_mime(core->output_fmt, out_mime); - media_format_set_audio_channel(core->output_fmt, port_def->info.audio.channel); - media_format_set_audio_samplerate(core->output_fmt, port_def->info.audio.samplerate); - media_format_set_audio_bit(core->output_fmt, port_def->info.audio.bit_depth); - } + if (encoder) + media_format_set_audio_avg_bps(core->output_fmt, port_def->info.audio.bitrate); } + return MC_ERROR_NONE; } @@ -1090,7 +1076,7 @@ gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h format) is_format_change |= input_port_def->info.video.width != width; is_format_change |= input_port_def->info.video.height != height; - is_format_change |= (input_port_def->info.video.framerate != framerate) && (framerate != 0); + is_format_change |= ((input_port_def->info.video.framerate != framerate) && (framerate != 0)); if (is_format_change) { LOGD("Format changed : resolution %dx%d -> %dx%d, framerate %d -> %d", input_port_def->info.video.width, input_port_def->info.video.height, width, height, @@ -1101,7 +1087,7 @@ gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h format) if (core->encoder) { sformat = __mc_get_gst_input_format(mimetype, core->is_hw); - is_format_change |= input_port_def->info.video.bitrate != bitrate * 1000; + is_format_change |= ((input_port_def->info.video.bitrate != bitrate * 1000) && (bitrate != 0)); is_format_change |= g_strcmp0(input_port_def->info.video.format, sformat); if (is_format_change) { LOGD("Bitrate changed : %d -> %d", input_port_def->info.video.bitrate, bitrate); @@ -1132,7 +1118,7 @@ gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h format) } if (core->encoder) { - is_format_change |= input_port_def->info.audio.bitrate != bitrate * 1000; + is_format_change |= ((input_port_def->info.audio.bitrate != bitrate * 1000) && (bitrate != 0)); if (is_format_change) { LOGD("Bitrate changed : %d -> %d", input_port_def->info.audio.bitrate, bitrate); input_port_def->info.audio.bitrate = bitrate * 1000; @@ -1261,6 +1247,7 @@ static gpointer feed_task(gpointer data) pad = gst_element_get_static_pad(core->appsrc, "src"); gst_pad_push_event(pad, gst_event_new_stream_start("start")); gst_object_unref(pad); + is_format_change = TRUE; initiative = FALSE; } @@ -1344,6 +1331,7 @@ GstCaps *_mc_gst_aud_caps_new(mc_gst_core_t *core, mediacodec_codec_type_e codec case MEDIACODEC_AAC: if (core->encoder) { gst_caps_set_simple(caps, + "format", G_TYPE_STRING, _mc_bit_to_string(port_def->info.audio.bit_depth), "layout", G_TYPE_STRING, "interleaved", NULL); g_object_set(GST_OBJECT(core->codec), "compliance", -2, NULL); } else { @@ -1656,17 +1644,7 @@ static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboo static gint _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *mcbuffer) { - gint ret = MC_ERROR_NONE; - - MEDIACODEC_FENTER(); - - ret = gst_app_src_push_buffer(GST_APP_SRC(core->appsrc), mcbuffer->buffer); - LOGD("pushed buffer to appsrc : %p, buffer of size %" G_GSIZE_FORMAT "", - mcbuffer->buffer, gst_buffer_get_size(mcbuffer->buffer)); - - MEDIACODEC_FLEAVE(); - - return ret; + return gst_app_src_push_buffer(GST_APP_SRC(core->appsrc), mcbuffer->buffer); } media_packet_h _mc_get_input_buffer(mc_gst_core_t *core) @@ -1753,14 +1731,14 @@ mc_ret_e mc_gst_prepare(mc_handle_t *mc_handle) } /* create basic core elements */ - ret = _mc_gst_create_pipeline(mc_handle->core, factory_name); + ret = _mc_gst_create_pipeline(new_core, factory_name); if (ret != MC_ERROR_NONE) { LOGE("failed to create pipeline"); return ret; } /* link vtable */ - ret = _mc_link_vtable(mc_handle->core, id, encoder, hardware); + ret = _mc_link_vtable(new_core, id, encoder, hardware); if (ret != MC_ERROR_NONE) { LOGE("vtable link failed"); return ret; @@ -3397,33 +3375,6 @@ const gchar * _mc_bit_to_string(int bit) } } -int _mc_get_support_bit_from_format(media_format_mimetype_e format) -{ - gint bit = 0; - - switch (format) { - case MEDIA_FORMAT_PCM_S16LE: - case MEDIA_FORMAT_PCM_S16BE: - case MEDIA_FORMAT_PCM_U16LE: - case MEDIA_FORMAT_PCM_U16BE: - bit = 16; - break; - case MEDIA_FORMAT_PCM_S32LE: - case MEDIA_FORMAT_PCM_S32BE: - case MEDIA_FORMAT_PCM_U32LE: - case MEDIA_FORMAT_PCM_U32BE: - case MEDIA_FORMAT_PCM_F32LE: - case MEDIA_FORMAT_PCM_F32BE: - bit = 32; - break; - default: - LOGE("NOT SUPPORTED!!!!"); - break; - } - - return bit; -} - int _mc_get_mime(mc_gst_core_t *core) { media_format_mimetype_e mime = MEDIA_FORMAT_MAX;