[Android] [PATCH] aout: reset sample rate default to 4kHz~48kHz

Rafaël Carré funman at videolan.org
Wed Oct 23 15:37:36 CEST 2013


Hello,

Le 23/10/2013 06:03, Zhang Rui a écrit :
> ---
>  vlc-android/jni/aout.c | 28 ++++++++++++++++++++++++----
>  1 file changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/vlc-android/jni/aout.c b/vlc-android/jni/aout.c
> index 859509b..17cf962 100644
> --- a/vlc-android/jni/aout.c
> +++ b/vlc-android/jni/aout.c
> @@ -79,10 +79,30 @@ int aout_open(void **opaque, char *format, unsigned *rate, unsigned *nb_channels
>      LOGV ("Number of channels forced to 2, number of samples to %d", FRAME_SIZE);
>      *nb_channels = 2;
>  
> -    (*p_env)->CallVoidMethod (p_env, p_sys->j_libVlc, methodIdInitAout,
> -                              *rate, *nb_channels, FRAME_SIZE);
> -    if ((*p_env)->ExceptionCheck (p_env))
> -    {
> +    int aout_rate = *rate;
> +    while (1) {
> +        (*p_env)->CallVoidMethod (p_env, p_sys->j_libVlc, methodIdInitAout,
> +                                  aout_rate, *nb_channels, FRAME_SIZE);
> +        if ((*p_env)->ExceptionCheck (p_env) == 0) {
> +            *rate = aout_rate;
> +            break;
> +        }
> +
> +        if (aout_rate <= 0) {
> +            LOGE ("initAout failed, invalid sample rate %dHz", aout_rate);
> +        } else if (aout_rate < 4000) {
> +            while (aout_rate < 4000)
> +                aout_rate *= 2;

Nitpicking: you can use
	do
		aout_rate *= 2;
	while (aout_rate < 4000);

As you already check for aout_rate < 4000 above.

> +            LOGE ("initAout failed, try new sample rate %dHz", aout_rate);
> +            (*p_env)->ExceptionClear (p_env);
> +            continue;
> +        } else if (aout_rate > 48000) {
> +            aout_rate /= 2;

And here it could use the same while loop even if those high/low
frequencies are unlikely.

> +            LOGE ("initAout failed, try new sample rate %dHz", aout_rate);
> +            (*p_env)->ExceptionClear (p_env);
> +            continue;
> +        }

So if the frequency is e.g. 20kHz and is not supported by the driver we
will just fail instead of resampling? :(

IMHO it is more important to support all files here so I think the
simplest is to just default to 44.1kHz.

What about:
 else if (aout_rate != 44100) {
    aout_rate = 44100;
    continue;
}

?
> +
>          LOGE ("Unable to create audio player!");
>  #ifndef NDEBUG
>          (*p_env)->ExceptionDescribe (p_env);
> 



More information about the Android mailing list