Changeset 0d0dffabce3a6d428e8a0dfbfb585ddcef543f7b

Show
Ignore:
Timestamp:
06/29/03 22:58:16 (5 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1056920296 +0000
git-parent:

[e2a71ad58c5a2c688ff6db265ed3b289452da126]

git-author:
Gildas Bazin <gbazin@videolan.org> 1056920296 +0000
Message:

* configure.ac, modules/mux/ogg.c, modules/stream_out/transcode.c: vorbis transcoding support (the transcoder still doesn't support vorbis decoding though, so no vorbis -> else transcoding)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • configure.ac

    rc0d6278 r0d0dffa  
    11dnl Autoconf settings for vlc 
    2 dnl $Id: configure.ac,v 1.16 2003/06/28 14:31:40 sam Exp $ 
     2dnl $Id: configure.ac,v 1.17 2003/06/29 20:58:16 gbazin Exp $ 
    33 
    44AC_INIT(vlc,0.6.0) 
     
    15351535  dnl XXX: we don't link with -lavcodec blah blah blah 
    15361536  dnl AX_ADD_LDFLAGS([encoder_ffmpeg],[${LDFLAGS_ffmpeg}]) 
     1537 
     1538  AC_CHECK_HEADERS(vorbis/vorbisenc.h vorbis/codec.h, 
     1539    AX_ADD_LDFLAGS([stream_out_transcode],[-lvorbisenc -lvorbis -logg]) ) 
    15371540fi 
    15381541 
  • modules/mux/ogg.c

    r8b67039 r0d0dffa  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: ogg.c,v 1.6 2003/06/23 23:51:31 gbazin Exp $ 
     5 * $Id: ogg.c,v 1.7 2003/06/29 20:58:16 gbazin Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    650650            p_stream->i_length = 0; 
    651651 
    652             msg_Dbg( p_mux, "writing data..." ); 
    653652            sout_AccessOutWrite( p_mux->p_access, p_og ); 
    654653 
  • modules/stream_out/transcode.c

    r209f2ea r0d0dffa  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: transcode.c,v 1.18 2003/06/25 21:47:05 fenrir Exp $ 
     5 * $Id: transcode.c,v 1.19 2003/06/29 20:58:16 gbazin Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    3939#endif 
    4040 
     41/* vorbis header */ 
     42#ifdef HAVE_VORBIS_VORBISENC_H 
     43#   include <vorbis/vorbisenc.h> 
     44#endif 
     45 
    4146/***************************************************************************** 
    4247 * Exported prototypes 
     
    301306 
    302307    ImgReSampleContext *p_vresample; 
     308 
     309#ifdef HAVE_VORBIS_VORBISENC_H 
     310 
     311    /* Vorbis part */ 
     312    vorbis_info      *p_vi; 
     313    vorbis_dsp_state *p_vd; 
     314    vorbis_block     *p_vb; 
     315    vorbis_comment   *p_vc; 
     316    int              i_last_block_size; 
     317    int              i_samples_delay; 
     318    vlc_bool_t       b_headers_sent; 
     319#endif 
    303320}; 
    304321 
    305322 
    306 static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_fmt ) 
     323static sout_stream_id_t * Add( sout_stream_t *p_stream, sout_format_t *p_fmt ) 
    307324{ 
    308325    sout_stream_sys_t   *p_sys = p_stream->p_sys; 
     
    413430} 
    414431 
    415 static int     Send     ( sout_stream_t *p_stream, sout_stream_id_t *id, sout_buffer_t *p_buffer ) 
     432static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, 
     433                 sout_buffer_t *p_buffer ) 
    416434{ 
    417435    sout_stream_sys_t   *p_sys = p_stream->p_sys; 
     
    463481    { VLC_FOURCC( 'w', 'm', 'a', '1' ), CODEC_ID_WMAV1 }, 
    464482    { VLC_FOURCC( 'w', 'm', 'a', '2' ), CODEC_ID_WMAV2 }, 
     483    { VLC_FOURCC( 'v', 'o', 'r', 'b' ), CODEC_ID_VORBIS }, 
    465484 
    466485    /* video */ 
     
    526545} 
    527546 
    528 static int transcode_audio_ffmpeg_new   ( sout_stream_t *p_stream, sout_stream_id_t *id ) 
     547static int transcode_audio_ffmpeg_new( sout_stream_t *p_stream, 
     548                                       sout_stream_id_t *id ) 
    529549{ 
    530550    int i_ff_codec; 
     
    576596 
    577597    /* find encoder */ 
     598    id->i_buffer_in      = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; 
     599    id->i_buffer_in_pos = 0; 
     600    id->p_buffer_in      = malloc( id->i_buffer_in ); 
     601 
     602    id->i_buffer     = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; 
     603    id->i_buffer_pos = 0; 
     604    id->p_buffer     = malloc( id->i_buffer ); 
     605 
     606    id->i_buffer_out     = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; 
     607    id->i_buffer_out_pos = 0; 
     608    id->p_buffer_out     = malloc( id->i_buffer_out ); 
     609 
     610#ifdef HAVE_VORBIS_VORBISENC_H 
     611    if( id->f_dst.i_fourcc == VLC_FOURCC('v','o','r','b') ) 
     612    { 
     613        id->p_vi = (vorbis_info *)malloc( sizeof(vorbis_info) ); 
     614        id->p_vd = (vorbis_dsp_state *)malloc( sizeof(vorbis_dsp_state) ); 
     615        id->p_vb = (vorbis_block *)malloc( sizeof(vorbis_block) ); 
     616        id->p_vc = (vorbis_comment *)malloc( sizeof(vorbis_comment) ); 
     617 
     618        vorbis_info_init( id->p_vi ); 
     619 
     620        if( vorbis_encode_setup_managed( id->p_vi, id->f_dst.i_channels, 
     621              id->f_dst.i_sample_rate, -1, id->f_dst.i_bitrate, -1 ) || 
     622            vorbis_encode_ctl( id->p_vi, OV_ECTL_RATEMANAGE_AVG, NULL ) || 
     623             vorbis_encode_setup_init( id->p_vi ) ){} 
     624 
     625        /* add a comment */ 
     626        vorbis_comment_init( id->p_vc); 
     627        vorbis_comment_add_tag( id->p_vc, "ENCODER", "VLC media player"); 
     628 
     629        /* set up the analysis state and auxiliary encoding storage */ 
     630        vorbis_analysis_init( id->p_vd, id->p_vi ); 
     631        vorbis_block_init( id->p_vd, id->p_vb ); 
     632 
     633        id->b_headers_sent = VLC_FALSE; 
     634        id->i_last_block_size = 0; 
     635        id->i_samples_delay = 0; 
     636 
     637        return VLC_SUCCESS; 
     638    } 
     639#endif 
     640 
    578641    i_ff_codec = get_ff_codec( id->f_dst.i_fourcc ); 
    579642    if( i_ff_codec == 0 ) 
     
    601664    } 
    602665 
    603  
    604     id->i_buffer_in      = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; 
    605     id->i_buffer_in_pos = 0; 
    606     id->p_buffer_in      = malloc( id->i_buffer_in ); 
    607  
    608     id->i_buffer     = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; 
    609     id->i_buffer_pos = 0; 
    610     id->p_buffer     = malloc( id->i_buffer ); 
    611  
    612     id->i_buffer_out     = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; 
    613     id->i_buffer_out_pos = 0; 
    614     id->p_buffer_out     = malloc( id->i_buffer_out ); 
    615  
    616666    return VLC_SUCCESS; 
    617667} 
    618668 
    619 static void transcode_audio_ffmpeg_close ( sout_stream_t *p_stream, sout_stream_id_t *id ) 
     669static void transcode_audio_ffmpeg_close( sout_stream_t *p_stream, 
     670                                          sout_stream_id_t *id ) 
    620671{ 
    621672    if( id->ff_dec ) 
     
    623674        avcodec_close( id->ff_dec_c ); 
    624675    } 
    625     avcodec_close( id->ff_enc_c ); 
     676 
     677#ifdef HAVE_VORBIS_VORBISENC_H 
     678    if( id->f_dst.i_fourcc == VLC_FOURCC('v','o','r','b') ) 
     679    { 
     680        vorbis_block_clear( id->p_vb ); 
     681        vorbis_dsp_clear( id->p_vd ); 
     682        vorbis_comment_clear( id->p_vc ); 
     683        vorbis_info_clear( id->p_vi );  /* must be called last */ 
     684 
     685        free( id->p_vi ); 
     686        free( id->p_vd ); 
     687        free( id->p_vb ); 
     688        free( id->p_vc ); 
     689    } 
     690    else 
     691#endif 
     692        avcodec_close( id->ff_enc_c ); 
    626693 
    627694    free( id->ff_dec_c ); 
    628     free( id->ff_enc_c ); 
     695    if( id->f_dst.i_fourcc != VLC_FOURCC('v','o','r','b') ) 
     696        free( id->ff_enc_c ); 
    629697 
    630698    free( id->p_buffer_in ); 
     
    633701} 
    634702 
    635 static int transcode_audio_ffmpeg_process( sout_stream_t *p_stream, sout_stream_id_t *id, 
    636                                            sout_buffer_t *in, sout_buffer_t **out ) 
     703static int transcode_audio_ffmpeg_process( sout_stream_t *p_stream, 
     704                                           sout_stream_id_t *id, 
     705                                           sout_buffer_t *in, 
     706                                           sout_buffer_t **out ) 
    637707{ 
    638708    vlc_bool_t b_again = VLC_FALSE; 
     
    641711 
    642712    /* gather data into p_buffer_in */ 
     713    if( id->f_dst.i_fourcc == VLC_FOURCC( 'v', 'o', 'r', 'b' ) ) 
     714    id->i_dts = in->i_dts - 
     715                (mtime_t)1000000 * (mtime_t)id->i_samples_delay / 
     716                (mtime_t)id->f_dst.i_sample_rate; 
     717    else 
    643718    id->i_dts = in->i_dts - 
    644719                (mtime_t)1000000 * 
     
    646721                (mtime_t)id->ff_enc_c->sample_rate; 
    647722 
    648     if( id->i_buffer_in_pos + in->i_size > id->i_buffer_in ) 
     723    if( id->i_buffer_in_pos + (int)in->i_size > id->i_buffer_in ) 
    649724    { 
    650725        /* extend buffer_in */ 
     
    653728    } 
    654729    memcpy( &id->p_buffer_in[id->i_buffer_in_pos], 
    655             in->p_buffer, 
    656             in->i_size ); 
     730            in->p_buffer, in->i_size ); 
    657731    id->i_buffer_in_pos += in->i_size; 
    658732 
    659733    do 
    660734    { 
    661         /* decode as many data as possible */ 
     735        /* decode as much data as possible */ 
    662736        if( id->ff_dec ) 
    663737        { 
     
    670744 
    671745                i_used = avcodec_decode_audio( id->ff_dec_c, 
    672                                                (int16_t*)&id->p_buffer[id->i_buffer_pos], &i_buffer_size, 
    673                                                id->p_buffer_in, id->i_buffer_in_pos ); 
    674  
    675                 /* msg_Warn( p_stream, "avcodec_decode_audio: %d used", i_used ); */ 
     746                         (int16_t*)&id->p_buffer[id->i_buffer_pos], 
     747                         &i_buffer_size, id->p_buffer_in, 
     748                         id->i_buffer_in_pos ); 
     749 
     750                /* msg_Warn( p_stream, "avcodec_decode_audio: %d used", 
     751                             i_used ); */ 
    676752                id->i_buffer_pos += i_buffer_size; 
    677753 
     
    711787            { 
    712788                int8_t *sin = (int8_t*)id->p_buffer_in; 
    713                 int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) / 2, id->i_buffer_in_pos ); 
     789                int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) 
     790                                           / 2, id->i_buffer_in_pos ); 
    714791                i_used = i_samples; 
    715792                while( i_samples > 0 ) 
     
    722799            { 
    723800                int8_t *sin = (int8_t*)id->p_buffer_in; 
    724                 int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) / 2, id->i_buffer_in_pos ); 
     801                int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) 
     802                                           / 2, id->i_buffer_in_pos ); 
    725803                i_used = i_samples; 
    726804                while( i_samples > 0 ) 
     
    732810            else if( id->f_src.i_fourcc == VLC_FOURCC( 's', '1', '6', 'l' ) ) 
    733811            { 
    734                 int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) / 2, id->i_buffer_in_pos / 2); 
     812                int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) 
     813                                           / 2, id->i_buffer_in_pos / 2); 
    735814#ifdef WORDS_BIGENDIAN 
    736815                uint8_t *sin = (uint8_t*)id->p_buffer_in; 
     
    754833            else if( id->f_src.i_fourcc == VLC_FOURCC( 's', '1', '6', 'b' ) ) 
    755834            { 
    756                 int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) / 2, id->i_buffer_in_pos / 2); 
     835                int     i_samples = __MIN( ( id->i_buffer - id->i_buffer_pos ) 
     836                                           / 2, id->i_buffer_in_pos / 2); 
    757837#ifdef WORDS_BIGENDIAN 
    758838                memcpy( sout, id->p_buffer_in, i_samples * 2 ); 
     
    784864        } 
    785865 
    786         /* encode as many data as possible */ 
     866        /* encode as much data as possible */ 
     867 
     868#ifdef HAVE_VORBIS_VORBISENC_H 
     869        if( id->i_buffer_pos == 0 ); 
     870        else if( id->f_dst.i_fourcc == VLC_FOURCC( 'v', 'o', 'r', 'b' ) ) 
     871        { 
     872            float **buffer; 
     873            int i, j, i_samples; 
     874            sout_buffer_t *p_out; 
     875            ogg_packet op; 
     876 
     877            if( id->i_buffer_pos == 0 ) 
     878            { 
     879                break; 
     880            } 
     881 
     882            if( !id->b_headers_sent ) 
     883            { 
     884                ogg_packet header[3]; 
     885                vorbis_analysis_headerout( id->p_vd, id->p_vc, 
     886                                           &header[0], &header[1], &header[2]); 
     887                for( i = 0; i < 3; i++ ) 
     888                { 
     889                    p_out = sout_BufferNew( p_stream->p_sout, header[i].bytes); 
     890                    memcpy( p_out->p_buffer, header[i].packet, 
     891                            header[i].bytes ); 
     892 
     893                    p_out->i_size = header[i].bytes; 
     894                    p_out->i_length = 0; 
     895 
     896                    p_out->i_dts = p_out->i_pts = 0; 
     897 
     898                    sout_BufferChain( out, p_out ); 
     899                } 
     900                id->b_headers_sent = VLC_TRUE; 
     901            } 
     902 
     903            i_samples = id->i_buffer_pos / id->f_dst.i_channels / 2; 
     904            id->i_samples_delay += i_samples; 
     905            id->i_buffer_pos = 0; 
     906 
     907            buffer = vorbis_analysis_buffer( id->p_vd, i_samples ); 
     908 
     909            /* convert samples to float and uninterleave */ 
     910            for( i = 0; i < id->f_dst.i_channels; i++ ) 
     911            { 
     912                for( j = 0 ; j < i_samples ; j++ ) 
     913                { 
     914                    buffer[i][j]= ((float)( ((int16_t *)id->p_buffer) 
     915                                  [j*id->f_dst.i_channels + i ] ))/ 32768.f; 
     916                } 
     917            } 
     918 
     919            vorbis_analysis_wrote( id->p_vd, i_samples ); 
     920 
     921            while( vorbis_analysis_blockout( id->p_vd, id->p_vb ) == 1 ) 
     922            { 
     923                vorbis_analysis( id->p_vb, NULL ); 
     924                vorbis_bitrate_addblock( id->p_vb ); 
     925 
     926                while( vorbis_bitrate_flushpacket( id->p_vd, &op ) ) 
     927                { 
     928                    int i_block_size; 
     929                    p_out = sout_BufferNew( p_stream->p_sout, op.bytes ); 
     930                    memcpy( p_out->p_buffer, op.packet, op.bytes ); 
     931 
     932                    i_block_size = vorbis_packet_blocksize( id->p_vi, &op ); 
     933 
     934                    if( i_block_size < 0 ) i_block_size = 0; 
     935                    i_samples = ( id->i_last_block_size + 
     936                                  i_block_size ) >> 2; 
     937                    id->i_last_block_size = i_block_size; 
     938 
     939                    p_out->i_size = op.bytes; 
     940                    p_out->i_length = (mtime_t)1000000 * 
     941                      (mtime_t)i_samples / 
     942                      (mtime_t)id->f_dst.i_sample_rate; 
     943 
     944                    //msg_Err( p_stream, "i_dts: %lld", id->i_dts ); 
     945 
     946                    /* FIXME */ 
     947                    p_out->i_dts = id->i_dts; 
     948                    p_out->i_pts = id->i_dts; 
     949 
     950                    id->i_samples_delay -= i_samples; 
     951 
     952                    static mtime_t i_old_dts = 0; 
     953 
     954                    /* update dts */ 
     955                    id->i_dts += p_out->i_length; 
     956                    i_old_dts = id->i_dts; 
     957                    sout_BufferChain( out, p_out ); 
     958 
     959                } 
     960            } 
     961        } 
     962        else 
     963#endif 
     964 
    787965        for( ;; ) 
    788966        { 
    789             int i_frame_size = id->ff_enc_c->frame_size * 2 * id->ff_enc_c->channels; 
     967            int i_frame_size = id->ff_enc_c->frame_size * 2 * 
     968                                 id->ff_enc_c->channels; 
    790969            int i_out_size; 
    791970            sout_buffer_t *p_out; 
     
    796975            } 
    797976 
    798             /* msg_Warn( p_stream, "avcodec_encode_audio: frame size%d", i_frame_size); */ 
     977            /* msg_Warn( p_stream, "avcodec_encode_audio: frame size%d", 
     978                         i_frame_size); */ 
    799979            i_out_size = avcodec_encode_audio( id->ff_enc_c, 
    800                                                id->p_buffer_out, id->i_buffer_out, 
    801                                                (int16_t*)id->p_buffer ); 
     980                           id->p_buffer_out, id->i_buffer_out, 
     981                           (int16_t*)id->p_buffer ); 
    802982 
    803983            if( i_out_size <= 0 ) 
     
    813993            memcpy( p_out->p_buffer, id->p_buffer_out, i_out_size ); 
    814994            p_out->i_size = i_out_size; 
    815             p_out->i_length = (mtime_t)1000000 * (mtime_t)id->ff_enc_c->frame_size / (mtime_t)id->ff_enc_c->sample_rate; 
     995            p_out->i_length = (mtime_t)1000000 * 
     996                              (mtime_t)id->ff_enc_c->frame_size / 
     997                              (mtime_t)id->ff_enc_c->sample_rate; 
     998 
    816999            /* FIXME */ 
    8171000            p_out->i_dts = id->i_dts; 
     
    8211004            id->i_dts += p_out->i_length; 
    8221005 
    823            /* msg_Warn( p_stream, "frame dts=%lld len %lld out=%d", p_out->i_dts, p_out->i_length, i_out_size ); */ 
     1006           /* msg_Warn( p_stream, "frame dts=%lld len %lld out=%d", 
     1007                        p_out->i_dts, p_out->i_length, i_out_size ); */ 
     1008 
    8241009            sout_BufferChain( out, p_out ); 
    8251010        } 
     
    8341019 * video 
    8351020 */ 
    836 static int transcode_video_ffmpeg_new   ( sout_stream_t *p_stream, sout_stream_id_t *id ) 
     1021static int transcode_video_ffmpeg_new( sout_stream_t *p_stream, 
     1022                                       sout_stream_id_t *id ) 
    8371023{ 
    8381024    sout_stream_sys_t   *p_sys = p_stream->p_sys; 
     
    11971383    return VLC_SUCCESS; 
    11981384} 
    1199