Commit 7cb43670 authored by François Grisez's avatar François Grisez

Check on runtime whether MediaCodec supports a given format before registering...

Check on runtime whether MediaCodec supports a given format before registering the according filter.
parent 9189359d
Pipeline #372 failed with stage
in 0 seconds
......@@ -541,6 +541,28 @@ bool_t AMediaImage_isAvailable(void) {
return ms_get_android_sdk_version() >= 22;
}
bool_t AMediaCodec_checkCodecAvailability(const char *mime) {
bool_t res = TRUE;
AMediaCodec *encoder = NULL, *decoder = NULL;
encoder = AMediaCodec_createEncoderByType(mime);
if (encoder) {
AMediaCodec_delete(encoder);
} else {
ms_warning("MediaCodec: '%s' format not supported for encoding", mime);
res = FALSE;
}
decoder = AMediaCodec_createDecoderByType(mime);
if (decoder) {
AMediaCodec_delete(decoder);
} else {
ms_warning("MediaCodec: '%s' format not supported for decoding", mime);
res = FALSE;
}
if (res) ms_message("MediaCodec: '%s' format supported", mime);
return res;
}
////////////////////////////////////////////////////
// //
......
......@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "mediastreamer2/mscommon.h"
#include "mediastreamer2/msvideo.h"
#include <media/NdkMediaCodec.h>
#include "media/NdkMediaCodec.h"
#ifdef __cplusplus
extern "C" {
......@@ -44,6 +44,10 @@ bool AMediaCodec_getOutputImage(AMediaCodec *codec, int index, AMediaImage *imag
void AMediaImage_close(AMediaImage *image);
bool_t AMediaImage_isAvailable(void);
bool_t AMediaCodec_checkCodecAvailability(const char *mime);
#ifdef __cplusplus
} // extern "C"
#endif
......@@ -61,6 +61,7 @@ extern void _register_videotoolbox_if_supported(MSFactory *factory);
#ifdef __ANDROID__
#include <android/log.h>
#include "android_mediacodec.h"
#endif
......@@ -203,7 +204,6 @@ extern MSFilterDesc ms_MediaCodecH264Decoder_desc;
extern MSFilterDesc ms_MediaCodecH264Encoder_desc;
extern MSFilterDesc ms_MediaCodecH265Decoder_desc;
extern MSFilterDesc ms_MediaCodecH265Encoder_desc;
extern bool_t AMediaImage_isAvailable(void);
#endif
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
......@@ -272,11 +272,15 @@ void ms_factory_init_voip(MSFactory *obj){
#if defined(__ANDROID__) && defined(VIDEO_ENABLED)
if (AMediaImage_isAvailable()) {
ms_factory_register_filter(obj, &ms_MediaCodecH264Decoder_desc);
ms_factory_register_filter(obj, &ms_MediaCodecH264Encoder_desc);
if (AMediaCodec_checkCodecAvailability("video/avc")) {
ms_factory_register_filter(obj, &ms_MediaCodecH264Decoder_desc);
ms_factory_register_filter(obj, &ms_MediaCodecH264Encoder_desc);
}
if (AMediaCodec_checkCodecAvailability("video/hevc")) {
ms_factory_register_filter(obj, &ms_MediaCodecH265Decoder_desc);
ms_factory_register_filter(obj, &ms_MediaCodecH265Encoder_desc);
}
}
ms_factory_register_filter(obj, &ms_MediaCodecH265Decoder_desc);
ms_factory_register_filter(obj, &ms_MediaCodecH265Encoder_desc);
#endif
/* register builtin VoIP MSFilter's */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment