[vlc-devel] [PATCH 1/4] chromaprint: add stream out chromaprint module

Rémi Denis-Courmont remi at remlab.net
Tue Feb 26 18:29:43 CET 2013


Le mardi 26 février 2013 14:51:49, Francois Cartegnie a écrit :
> +static void Close( vlc_object_t * p_this )
> +{
> +    sout_stream_t *p_stream = (sout_stream_t *)p_this;
> +    sout_stream_sys_t *p_sys = p_stream->p_sys;
> +
> +    if ( !p_sys->b_done ) Finish( p_stream );
> +
> +    if ( !p_sys->p_chromaprint_ctx ) goto end;
> +    chromaprint_free( p_sys->p_chromaprint_ctx );
> +end:

Very bad taste.

> +    free( p_sys );
> +}
> +
> +static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt
> ) +{
> +    sout_stream_sys_t *p_sys = p_stream->p_sys;
> +    sout_stream_id_t *id = NULL;
> +
> +    if ( p_fmt->i_cat == AUDIO_ES && !p_sys->id )
> +    {
> +        if( p_fmt->i_codec != VLC_CODEC_S16L )
> +        {
> +            msg_Warn( p_stream, "bad input format: need s16l" );
> +            goto error;
> +        }

Not the whole world is little endian.

> +
> +        id = malloc( sizeof( sout_stream_id_t ) );
> +        if ( !id ) goto error;
> +
> +        id->i_samplesize = p_fmt->audio.i_bitspersample >> 3;

Exactly what's the point in storing the constant 2 bytes per sample?

> +        id->i_channels = p_fmt->audio.i_channels;
> +        id->i_samplerate = p_fmt->audio.i_rate;
> +        id->i_samples = p_sys->i_duration * id->i_samplerate;
> +
> +        if ( id->i_channels > 2 || !p_sys->p_chromaprint_ctx )
> +            goto error;

This error case is backward and needlessly complicated.

> +
> +        if ( !chromaprint_start( p_sys->p_chromaprint_ctx,
> p_fmt->audio.i_rate, id->i_channels ) )
> +        {
> +            msg_Err( p_stream, "Failed starting chromaprint on %dHz %dch
> samples",
> +                     p_fmt->audio.i_rate, id->i_channels );
> +            goto error;
> +        }
> +        else
> +        {
> +            p_sys->id = id;
> +            msg_Dbg( p_stream, "Starting chromaprint on %dHz %dch
> samples",
> +                     p_fmt->audio.i_rate, id->i_channels );
> +        }
> +        return id;
> +    }
> +
> +error:
> +    if ( id != NULL )
> +        free( id );
> +    return NULL;
> +}
> +
> +static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
> +{
> +    sout_stream_sys_t *p_sys = p_stream->p_sys;
> +    Finish( p_stream );
> +    if ( p_sys->id == id ) /* not assuming only 1 id is in use.. */
> +        FREENULL( p_sys->id );
> +    else
> +        free( id );
> +    return VLC_SUCCESS;
> +}
> +
> +static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
> +                 block_t *p_buf )
> +{
> +    sout_stream_sys_t *p_sys = p_stream->p_sys;
> +    if ( p_sys->id == id )
> +    {
> +        while( p_buf )
> +        {
> +            block_t *p_next;
> +            int i_samples = p_buf->i_buffer / (id->i_samplesize *
> id->i_channels);
> +            p_sys->i_total_samples += i_samples;
> +            if ( !p_sys->b_finished && id->i_samples > 0 &&
> p_buf->i_buffer )
> +            {
> +                if(! chromaprint_feed( p_sys->p_chromaprint_ctx,
> +                                       p_buf->p_buffer,
> +                                       p_buf->i_buffer / id->i_samplesize
> ) ) +                    msg_Warn( p_stream, "feed error" );
> +                id->i_samples -= i_samples;
> +                if ( id->i_samples < 1 && !p_sys->b_finished )
> +                {
> +                    p_sys->b_finished = true;
> +                    msg_Dbg( p_stream, "Fingerprint collection finished"
> ); +                }
> +            }
> +            p_next = p_buf->p_next;
> +            block_Release( p_buf );
> +            p_buf = p_next;
> +        }
> +    }
> +    else
> +    {
> +        /* drop the whole buffer at once */
> +        block_ChainRelease( p_buf );
> +    }
> +    return VLC_SUCCESS;
> +}
> diff --git a/modules/stream_out/chromaprint_data.h
> b/modules/stream_out/chromaprint_data.h new file mode 100644
> index 0000000..6fc3077
> --- /dev/null
> +++ b/modules/stream_out/chromaprint_data.h
> @@ -0,0 +1,27 @@
> +/*************************************************************************
> **** + * chromaprint_data.h: Chromaprint's sout fingerprint data header +
> **************************************************************************
> *** + * Copyright (C) 2012 VLC authors and VideoLAN
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as published
> by + * the Free Software Foundation; either version 2.1 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> License + * along with this program; if not, write to the Free Software
> Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA
> 02110-1301, USA. +
> **************************************************************************
> ***/ +
> +struct chromaprint_fingerprint_t
> +{
> +    char *psz_fingerprint;
> +    unsigned int i_duration;
> +};
> +
> +typedef struct chromaprint_fingerprint_t chromaprint_fingerprint_t;

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list