~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/audio_filter/converter/dtstofloat32.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *   (http://developers.videolan.org/libdca.html).
5
5
 *****************************************************************************
6
6
 * Copyright (C) 2001, 2002libdca the VideoLAN team
7
 
 * $Id: 1d7c79a1fffe22d84b6d17467c7e8eb5f5ee6864 $
 
7
 * $Id$
8
8
 *
9
9
 * Author: Gildas Bazin <gbazin@videolan.org>
10
10
 *
26
26
/*****************************************************************************
27
27
 * Preamble
28
28
 *****************************************************************************/
29
 
#include <vlc/vlc.h>
30
 
 
31
 
#include <stdlib.h>                                      /* malloc(), free() */
32
 
#include <string.h>                                              /* strdup() */
33
 
 
34
 
#include <dts.h>                                       /* libdca header file */
35
 
 
36
 
#include <vlc/decoder.h>
37
 
#include "aout_internal.h"
 
29
#ifdef HAVE_CONFIG_H
 
30
# include "config.h"
 
31
#endif
 
32
 
 
33
#include <vlc_common.h>
 
34
#include <vlc_plugin.h>
 
35
 
 
36
 
 
37
#include <dca.h>                                       /* libdca header file */
 
38
 
 
39
#include <vlc_aout.h>
 
40
#include <vlc_block.h>
38
41
#include "vlc_filter.h"
39
42
 
40
43
/*****************************************************************************
52
55
static void CloseFilter( vlc_object_t * );
53
56
static block_t *Convert( filter_t *, block_t * );
54
57
 
55
 
/* libdca channel order */
 
58
/* libdca channel order
 
59
 * FIXME middle values should be checked */
56
60
static const uint32_t pi_channels_in[] =
57
 
{ AOUT_CHAN_CENTER, AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
58
 
  AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_LFE, 0 };
59
 
/* our internal channel order (WG-4 order) */
60
 
static const uint32_t pi_channels_out[] =
61
 
{ AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
62
 
  AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 };
 
61
{ AOUT_CHAN_LFE, AOUT_CHAN_LEFT, AOUT_CHAN_CENTER, AOUT_CHAN_RIGHT,
 
62
  AOUT_CHAN_REARLEFT, AOUT_CHAN_REARCENTER, AOUT_CHAN_REARRIGHT,
 
63
  AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
 
64
  0 };
63
65
 
64
66
/*****************************************************************************
65
67
 * Local structures
66
68
 *****************************************************************************/
67
69
struct filter_sys_t
68
70
{
69
 
    dts_state_t * p_libdts; /* libdca internal structure */
70
 
    vlc_bool_t b_dynrng; /* see below */
 
71
    dca_state_t * p_libdca; /* libdca internal structure */
 
72
    bool b_dynrng; /* see below */
71
73
    int i_flags; /* libdca flags, see dtsdec/doc/libdts.txt */
72
 
    vlc_bool_t b_dontwarn;
 
74
    bool b_dontwarn;
73
75
    int i_nb_channels; /* number of float32 per sample */
74
76
 
75
77
    int pi_chan_table[AOUT_CHAN_MAX]; /* channel reordering */
90
92
    set_category( CAT_INPUT );
91
93
    set_subcategory( SUBCAT_INPUT_ACODEC );
92
94
    set_shortname( "DCA" );
93
 
    set_description( _("DTS Coherent Acoustics audio decoder") );
94
 
    add_bool( "dts-dynrng", 1, NULL, DYNRNG_TEXT, DYNRNG_LONGTEXT, VLC_FALSE );
 
95
    set_description( N_("DTS Coherent Acoustics audio decoder") );
 
96
    add_bool( "dts-dynrng", 1, NULL, DYNRNG_TEXT, DYNRNG_LONGTEXT, false );
95
97
    set_capability( "audio filter", 100 );
96
98
    set_callbacks( Create, Destroy );
97
99
 
98
100
    add_submodule();
99
 
    set_description( _("DTS Coherent Acoustics audio decoder") );
 
101
    set_description( N_("DTS Coherent Acoustics audio decoder") );
100
102
    set_capability( "audio filter2", 100 );
101
103
    set_callbacks( OpenFilter, CloseFilter );
102
104
vlc_module_end();
125
127
    p_sys = malloc( sizeof(filter_sys_t) );
126
128
    p_filter->p_sys = (struct aout_filter_sys_t *)p_sys;
127
129
    if( p_sys == NULL )
128
 
    {
129
 
        msg_Err( p_filter, "out of memory" );
130
130
        return -1;
131
 
    }
132
131
 
133
132
    i_ret = Open( VLC_OBJECT(p_filter), p_sys,
134
133
                  p_filter->input, p_filter->output );
140
139
}
141
140
 
142
141
/*****************************************************************************
143
 
 * Open: 
 
142
 * Open:
144
143
 *****************************************************************************/
145
144
static int Open( vlc_object_t *p_this, filter_sys_t *p_sys,
146
145
                 audio_format_t input, audio_format_t output )
158
157
              || (output.i_original_channels
159
158
                   & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
160
159
        {
161
 
            p_sys->i_flags = DTS_MONO;
 
160
            p_sys->i_flags = DCA_MONO;
162
161
        }
163
162
        break;
164
163
 
165
164
    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT:
166
165
        if ( output.i_original_channels & AOUT_CHAN_DOLBYSTEREO )
167
166
        {
168
 
            p_sys->i_flags = DTS_DOLBY;
 
167
            p_sys->i_flags = DCA_DOLBY;
169
168
        }
170
169
        else if ( input.i_original_channels == AOUT_CHAN_CENTER )
171
170
        {
172
 
            p_sys->i_flags = DTS_MONO;
 
171
            p_sys->i_flags = DCA_MONO;
173
172
        }
174
173
        else if ( input.i_original_channels & AOUT_CHAN_DUALMONO )
175
174
        {
176
 
            p_sys->i_flags = DTS_CHANNEL;
 
175
            p_sys->i_flags = DCA_CHANNEL;
177
176
        }
178
177
        else
179
178
        {
180
 
            p_sys->i_flags = DTS_STEREO;
 
179
            p_sys->i_flags = DCA_STEREO;
181
180
        }
182
181
        break;
183
182
 
184
183
    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER:
185
 
        p_sys->i_flags = DTS_3F;
 
184
        p_sys->i_flags = DCA_3F;
186
185
        break;
187
186
 
188
187
    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER:
189
 
        p_sys->i_flags = DTS_2F1R;
 
188
        p_sys->i_flags = DCA_2F1R;
190
189
        break;
191
190
 
192
191
    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
193
192
          | AOUT_CHAN_REARCENTER:
194
 
        p_sys->i_flags = DTS_3F1R;
 
193
        p_sys->i_flags = DCA_3F1R;
195
194
        break;
196
195
 
197
196
    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
198
197
          | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
199
 
        p_sys->i_flags = DTS_2F2R;
 
198
        p_sys->i_flags = DCA_2F2R;
200
199
        break;
201
200
 
202
201
    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
203
202
          | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
204
 
        p_sys->i_flags = DTS_3F2R;
 
203
        p_sys->i_flags = DCA_3F2R;
205
204
        break;
206
205
 
207
206
    default:
211
210
    }
212
211
    if ( output.i_physical_channels & AOUT_CHAN_LFE )
213
212
    {
214
 
        p_sys->i_flags |= DTS_LFE;
 
213
        p_sys->i_flags |= DCA_LFE;
215
214
    }
216
 
    //p_sys->i_flags |= DTS_ADJUST_LEVEL;
 
215
    //p_sys->i_flags |= DCA_ADJUST_LEVEL;
217
216
 
218
217
    /* Initialize libdca */
219
 
    p_sys->p_libdts = dts_init( 0 );
220
 
    if( p_sys->p_libdts == NULL )
 
218
    p_sys->p_libdca = dca_init( 0 );
 
219
    if( p_sys->p_libdca == NULL )
221
220
    {
222
221
        msg_Err( p_this, "unable to initialize libdca" );
223
222
        return VLC_EGENERIC;
224
223
    }
225
224
 
226
 
    aout_CheckChannelReorder( pi_channels_in, pi_channels_out,
 
225
    aout_CheckChannelReorder( pi_channels_in, NULL,
227
226
                              output.i_physical_channels & AOUT_CHAN_PHYSMASK,
228
227
                              p_sys->i_nb_channels,
229
228
                              p_sys->pi_chan_table );
300
299
    /* Needs to be called so the decoder knows which type of bitstream it is
301
300
     * dealing with. */
302
301
    int i_sample_rate, i_bit_rate, i_frame_length;
303
 
    if( !dts_syncinfo( p_sys->p_libdts, p_in_buf->p_buffer, &i_flags,
 
302
    if( !dca_syncinfo( p_sys->p_libdca, p_in_buf->p_buffer, &i_flags,
304
303
                       &i_sample_rate, &i_bit_rate, &i_frame_length ) )
305
304
    {
306
305
        msg_Warn( p_aout, "libdca couldn't sync on frame" );
309
308
    }
310
309
 
311
310
    i_flags = p_sys->i_flags;
312
 
    dts_frame( p_sys->p_libdts, p_in_buf->p_buffer,
 
311
    dca_frame( p_sys->p_libdca, p_in_buf->p_buffer,
313
312
               &i_flags, &i_sample_level, 0 );
314
313
 
315
 
    if ( (i_flags & DTS_CHANNEL_MASK) != (p_sys->i_flags & DTS_CHANNEL_MASK)
 
314
    if ( (i_flags & DCA_CHANNEL_MASK) != (p_sys->i_flags & DCA_CHANNEL_MASK)
316
315
          && !p_sys->b_dontwarn )
317
316
    {
318
317
        msg_Warn( p_aout,
319
318
                  "libdca couldn't do the requested downmix 0x%x->0x%x",
320
 
                  p_sys->i_flags  & DTS_CHANNEL_MASK,
321
 
                  i_flags & DTS_CHANNEL_MASK );
 
319
                  p_sys->i_flags  & DCA_CHANNEL_MASK,
 
320
                  i_flags & DCA_CHANNEL_MASK );
322
321
 
323
322
        p_sys->b_dontwarn = 1;
324
323
    }
325
324
 
326
325
    if( 0)//!p_sys->b_dynrng )
327
326
    {
328
 
        dts_dynrng( p_sys->p_libdts, NULL, NULL );
 
327
        dca_dynrng( p_sys->p_libdca, NULL, NULL );
329
328
    }
330
329
 
331
 
    for ( i = 0; i < dts_blocks_num(p_sys->p_libdts); i++ )
 
330
    for ( i = 0; i < dca_blocks_num(p_sys->p_libdca); i++ )
332
331
    {
333
332
        sample_t * p_samples;
334
333
 
335
 
        if( dts_block( p_sys->p_libdts ) )
 
334
        if( dca_block( p_sys->p_libdca ) )
336
335
        {
337
 
            msg_Warn( p_aout, "dts_block failed for block %d", i );
 
336
            msg_Warn( p_aout, "dca_block failed for block %d", i );
338
337
            break;
339
338
        }
340
339
 
341
 
        p_samples = dts_samples( p_sys->p_libdts );
 
340
        p_samples = dca_samples( p_sys->p_libdca );
342
341
 
343
 
        if ( (p_sys->i_flags & DTS_CHANNEL_MASK) == DTS_MONO
344
 
              && (p_filter->output.i_physical_channels 
 
342
        if ( (p_sys->i_flags & DCA_CHANNEL_MASK) == DCA_MONO
 
343
              && (p_filter->output.i_physical_channels
345
344
                   & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
346
345
        {
347
346
            Duplicate( (float *)(p_out_buf->p_buffer + i * i_bytes_per_block),
373
372
    aout_filter_t *p_filter = (aout_filter_t *)p_this;
374
373
    filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
375
374
 
376
 
    dts_free( p_sys->p_libdts );
 
375
    dca_free( p_sys->p_libdca );
377
376
    free( p_sys );
378
377
}
379
378
 
380
379
/*****************************************************************************
381
 
 * OpenFilter: 
 
380
 * OpenFilter:
382
381
 *****************************************************************************/
383
382
static int OpenFilter( vlc_object_t *p_this )
384
383
{
393
392
 
394
393
    p_filter->fmt_out.audio.i_format =
395
394
        p_filter->fmt_out.i_codec = VLC_FOURCC('f','l','3','2');
 
395
    p_filter->fmt_out.audio.i_bitspersample =
 
396
        aout_BitsPerSample( p_filter->fmt_out.i_codec );
396
397
 
397
398
    /* Allocate the memory needed to store the module's structure */
398
399
    p_sys = p_filter->p_sys = malloc( sizeof(filter_sys_t) );
399
400
    if( p_sys == NULL )
400
 
    {
401
 
        msg_Err( p_filter, "out of memory" );
402
 
        return VLC_EGENERIC;
403
 
    }
404
 
 
405
 
    /* Allocate the memory needed to store the module's structure */
406
 
    p_filter->p_sys = p_sys = malloc( sizeof(filter_sys_t) );
407
 
    if( p_sys == NULL )
408
 
    {
409
 
        msg_Err( p_filter, "out of memory" );
410
 
        return VLC_EGENERIC;
411
 
    }
 
401
        return VLC_ENOMEM;
412
402
 
413
403
    i_ret = Open( VLC_OBJECT(p_filter), p_sys,
414
404
                  p_filter->fmt_in.audio, p_filter->fmt_out.audio );
427
417
    filter_t *p_filter = (filter_t *)p_this;
428
418
    filter_sys_t *p_sys = p_filter->p_sys;
429
419
 
430
 
    dts_free( p_sys->p_libdts );
 
420
    dca_free( p_sys->p_libdca );
431
421
    free( p_sys );
432
422
}
433
423
 
440
430
 
441
431
    if( !p_block || !p_block->i_samples )
442
432
    {
443
 
        if( p_block ) p_block->pf_release( p_block );
 
433
        if( p_block )
 
434
            block_Release( p_block );
444
435
        return NULL;
445
436
    }
446
437
 
452
443
    if( !p_out )
453
444
    {
454
445
        msg_Warn( p_filter, "can't get output buffer" );
455
 
        p_block->pf_release( p_block );
 
446
        block_Release( p_block );
456
447
        return NULL;
457
448
    }
458
449
 
479
470
    p_out->i_buffer = out_buf.i_nb_bytes;
480
471
    p_out->i_samples = out_buf.i_nb_samples;
481
472
 
482
 
    p_block->pf_release( p_block );
 
473
    block_Release( p_block );
483
474
 
484
475
    return p_out;
485
476
}