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

« back to all changes in this revision

Viewing changes to modules/mux/mpeg/ps.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:
3
3
 *       multiplexer module for vlc
4
4
 *****************************************************************************
5
5
 * Copyright (C) 2001, 2002 the VideoLAN team
6
 
 * $Id: 300f52cbe8ff5bac43e1e2512f8cbc01e67764c6 $
 
6
 * $Id$
7
7
 *
8
8
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9
9
 *          Eric Petit <titer@videolan.org>
27
27
/*****************************************************************************
28
28
 * Preamble
29
29
 *****************************************************************************/
30
 
#include <stdlib.h>
31
 
 
32
 
#include <vlc/vlc.h>
33
 
#include <vlc/input.h>
34
 
#include <vlc/sout.h>
35
 
 
36
 
#include "codecs.h"
 
30
 
 
31
#ifdef HAVE_CONFIG_H
 
32
# include "config.h"
 
33
#endif
 
34
 
 
35
#include <vlc_common.h>
 
36
#include <vlc_plugin.h>
 
37
#include <vlc_sout.h>
 
38
#include <vlc_codecs.h>
 
39
#include <vlc_block.h>
 
40
 
37
41
#include "bits.h"
38
42
#include "pes.h"
39
43
 
40
 
#include "iso_lang.h"
 
44
#include <vlc_iso_lang.h>
41
45
 
42
46
/*****************************************************************************
43
47
 * Module descriptor
58
62
#define SOUT_CFG_PREFIX "sout-ps-"
59
63
 
60
64
vlc_module_begin();
61
 
    set_description( _("PS muxer") );
 
65
    set_description( N_("PS muxer") );
62
66
    set_shortname( "MPEG-PS" );
63
67
    set_category( CAT_SOUT );
64
68
    set_subcategory( SUBCAT_SOUT_MUX );
69
73
    set_callbacks( Open, Close );
70
74
 
71
75
    add_integer( SOUT_CFG_PREFIX "dts-delay", 200, NULL, DTS_TEXT,
72
 
                 DTS_LONGTEXT, VLC_TRUE );
 
76
                 DTS_LONGTEXT, true );
73
77
    add_integer( SOUT_CFG_PREFIX "pes-max-size", PES_PAYLOAD_SIZE_MAX, NULL,
74
 
                 PES_SIZE_TEXT, PES_SIZE_LONGTEXT, VLC_TRUE );
 
78
                 PES_SIZE_TEXT, PES_SIZE_LONGTEXT, true );
75
79
vlc_module_end();
76
80
 
77
81
/*****************************************************************************
91
95
static void MuxWriteSystemHeader( sout_mux_t *, block_t **, mtime_t );
92
96
static void MuxWritePSM         ( sout_mux_t *, block_t **, mtime_t );
93
97
 
94
 
static void StreamIdInit        ( vlc_bool_t *id, int i_range );
95
 
static int  StreamIdGet         ( vlc_bool_t *id, int i_id_min, int i_id_max );
96
 
static void StreamIdRelease     ( vlc_bool_t *id, int i_id_min, int i_id );
 
98
static void StreamIdInit        ( bool *id, int i_range );
 
99
static int  StreamIdGet         ( bool *id, int i_id_min, int i_id_max );
 
100
static void StreamIdRelease     ( bool *id, int i_id_min, int i_id );
97
101
 
98
102
typedef struct ps_stream_s
99
103
{
109
113
struct sout_mux_sys_t
110
114
{
111
115
    /* Which id are unused */
112
 
    vlc_bool_t  stream_id_mpga[16]; /* 0xc0 -> 0xcf */
113
 
    vlc_bool_t  stream_id_mpgv[16]; /* 0xe0 -> 0xef */
114
 
    vlc_bool_t  stream_id_a52[8];   /* 0x80 -> 0x87 <- FIXME I'm not sure */
115
 
    vlc_bool_t  stream_id_spu[32];  /* 0x20 -> 0x3f */
116
 
    vlc_bool_t  stream_id_dts[8];   /* 0x88 -> 0x8f */
117
 
    vlc_bool_t  stream_id_lpcm[16]; /* 0xa0 -> 0xaf */
 
116
    bool  stream_id_mpga[16]; /* 0xc0 -> 0xcf */
 
117
    bool  stream_id_mpgv[16]; /* 0xe0 -> 0xef */
 
118
    bool  stream_id_a52[8];   /* 0x80 -> 0x87 <- FIXME I'm not sure */
 
119
    bool  stream_id_spu[32];  /* 0x20 -> 0x3f */
 
120
    bool  stream_id_dts[8];   /* 0x88 -> 0x8f */
 
121
    bool  stream_id_lpcm[16]; /* 0xa0 -> 0xaf */
118
122
 
119
123
    int i_audio_bound;
120
124
    int i_video_bound;
122
126
    int i_system_header;
123
127
    int i_dts_delay;
124
128
    int i_rate_bound; /* units of 50 bytes/second */
125
 
    
 
129
 
126
130
    int64_t i_instant_bitrate;
127
131
    int64_t i_instant_size;
128
132
    int64_t i_instant_dts;
129
133
 
130
 
    vlc_bool_t b_mpeg2;
 
134
    bool b_mpeg2;
131
135
 
132
136
    int i_pes_max_size;
133
137
 
135
139
    uint32_t crc32_table[256];
136
140
};
137
141
 
138
 
static const char *ppsz_sout_options[] = {
 
142
static const char *const ppsz_sout_options[] = {
139
143
    "dts-delay", "pes-max-size", NULL
140
144
};
141
145
 
149
153
    vlc_value_t val;
150
154
 
151
155
    msg_Info( p_mux, "Open" );
152
 
    sout_CfgParse( p_mux, SOUT_CFG_PREFIX, ppsz_sout_options, p_mux->p_cfg );
 
156
    config_ChainParse( p_mux, SOUT_CFG_PREFIX, ppsz_sout_options, p_mux->p_cfg );
153
157
 
154
158
    p_mux->pf_control   = Control;
155
159
    p_mux->pf_addstream = AddStream;
228
232
 *****************************************************************************/
229
233
static int Control( sout_mux_t *p_mux, int i_query, va_list args )
230
234
{
231
 
    vlc_bool_t *pb_bool;
 
235
    VLC_UNUSED(p_mux);
 
236
    bool *pb_bool;
232
237
    char **ppsz;
233
238
 
234
 
   switch( i_query )
235
 
   {
236
 
       case MUX_CAN_ADD_STREAM_WHILE_MUXING:
237
 
           pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
238
 
           *pb_bool = VLC_TRUE;
239
 
           return VLC_SUCCESS;
240
 
 
241
 
       case MUX_GET_ADD_STREAM_WAIT:
242
 
           pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
243
 
           *pb_bool = VLC_FALSE;
244
 
           return VLC_SUCCESS;
245
 
 
246
 
       case MUX_GET_MIME:
247
 
           ppsz = (char**)va_arg( args, char ** );
248
 
           *ppsz = strdup( "video/mpeg" );
249
 
           return VLC_SUCCESS;
 
239
    switch( i_query )
 
240
    {
 
241
        case MUX_CAN_ADD_STREAM_WHILE_MUXING:
 
242
            pb_bool = (bool*)va_arg( args, bool * );
 
243
            *pb_bool = true;
 
244
            return VLC_SUCCESS;
 
245
 
 
246
        case MUX_GET_ADD_STREAM_WAIT:
 
247
            pb_bool = (bool*)va_arg( args, bool * );
 
248
            *pb_bool = false;
 
249
            return VLC_SUCCESS;
 
250
 
 
251
        case MUX_GET_MIME:
 
252
            ppsz = (char**)va_arg( args, char ** );
 
253
            *ppsz = strdup( "video/mpeg" );
 
254
            return VLC_SUCCESS;
250
255
 
251
256
        default:
252
257
            return VLC_EGENERIC;
253
 
   }
 
258
    }
254
259
}
255
260
 
256
261
/*****************************************************************************
260
265
{
261
266
    sout_mux_sys_t  *p_sys = p_mux->p_sys;
262
267
    ps_stream_t *p_stream;
263
 
    
 
268
 
264
269
 
265
270
    msg_Dbg( p_mux, "adding input codec=%4.4s",
266
271
             (char*)&p_input->p_fmt->i_codec );
344
349
    p_sys->i_instant_bitrate += p_input->p_fmt->i_bitrate + 1000/* overhead */;
345
350
 
346
351
    /* FIXME -- spec requires  an upper limit rate boundary in the system header;
347
 
       our codecs are VBR; using 2x nominal rate, convert to 50 bytes/sec */ 
 
352
       our codecs are VBR; using 2x nominal rate, convert to 50 bytes/sec */
348
353
    p_sys->i_rate_bound += p_input->p_fmt->i_bitrate * 2 / (8 * 50);
349
354
    p_sys->i_psm_version++;
350
355
 
516
521
 
517
522
        /* Get and mux a packet */
518
523
        p_data = block_FifoGet( p_input->p_fifo );
519
 
        E_( EStoPES )( p_mux->p_sout, &p_data, p_data,
 
524
         EStoPES ( p_mux->p_sout, &p_data, p_data,
520
525
                       p_input->p_fmt, p_stream->i_stream_id,
521
526
                       p_sys->b_mpeg2, 0, 0, p_sys->i_pes_max_size );
522
527
 
540
545
/*****************************************************************************
541
546
 *
542
547
 *****************************************************************************/
543
 
static void StreamIdInit( vlc_bool_t *id, int i_range )
 
548
static void StreamIdInit( bool *id, int i_range )
544
549
{
545
550
    int i;
546
551
 
547
552
    for( i = 0; i < i_range; i++ )
548
553
    {
549
 
        id[i] = VLC_TRUE;
 
554
        id[i] = true;
550
555
    }
551
556
}
552
 
static int StreamIdGet( vlc_bool_t *id, int i_id_min, int i_id_max )
 
557
static int StreamIdGet( bool *id, int i_id_min, int i_id_max )
553
558
{
554
559
    int i;
555
560
 
557
562
    {
558
563
        if( id[i] )
559
564
        {
560
 
            id[i] = VLC_FALSE;
 
565
            id[i] = false;
561
566
 
562
567
            return i_id_min + i;
563
568
        }
564
569
    }
565
570
    return -1;
566
571
}
567
 
static void StreamIdRelease( vlc_bool_t *id, int i_id_min, int i_id )
 
572
static void StreamIdRelease( bool *id, int i_id_min, int i_id )
568
573
{
569
 
    id[i_id - i_id_min] = VLC_TRUE;
 
574
    id[i_id - i_id_min] = true;
570
575
}
571
576
 
572
577
static void MuxWritePackHeader( sout_mux_t *p_mux, block_t **p_buf,
631
636
    sout_mux_sys_t  *p_sys = p_mux->p_sys;
632
637
    block_t   *p_hdr;
633
638
    bits_buffer_t   bits;
634
 
    vlc_bool_t      b_private;
 
639
    bool      b_private;
635
640
    int i_rate_bound;
636
641
 
637
642
    int             i_nb_private, i_nb_stream;
664
669
    bits_write( &bits, 32, 0x01bb );
665
670
    bits_write( &bits, 16, 12 - 6 + i_nb_stream * 3 );
666
671
    bits_write( &bits, 1,  1 ); // marker bit
667
 
    bits_write( &bits, 22, i_rate_bound); 
 
672
    bits_write( &bits, 22, i_rate_bound);
668
673
    bits_write( &bits, 1,  1 ); // marker bit
669
674
 
670
675
    bits_write( &bits, 6,  p_sys->i_audio_bound );
680
685
    bits_write( &bits, 7,  0xff ); // reserved bits
681
686
 
682
687
    /* stream_id table */
683
 
    for( i = 0, b_private = VLC_FALSE; i < p_mux->i_nb_inputs; i++ )
 
688
    for( i = 0, b_private = false; i < p_mux->i_nb_inputs; i++ )
684
689
    {
685
690
        sout_input_t *p_input;
686
691
        ps_stream_t *p_stream;
694
699
            {
695
700
                continue;
696
701
            }
697
 
            b_private = VLC_TRUE;
 
702
            b_private = true;
698
703
            /* Write stream id */
699
704
            bits_write( &bits, 8, 0xbd );
700
705
        }
791
796
    /* CRC32 */
792
797
    {
793
798
        uint32_t i_crc = 0xffffffff;
794
 
        for( i = 0; i < p_hdr->i_buffer; i++ )
 
799
        for( i = 0; (size_t)i < p_hdr->i_buffer; i++ )
795
800
        i_crc = (i_crc << 8) ^
796
801
            p_sys->crc32_table[((i_crc >> 24) ^ p_hdr->p_buffer[i]) & 0xff];
797
802
 
807
812
static int MuxGetStream( sout_mux_t *p_mux, int *pi_stream, mtime_t *pi_dts )
808
813
{
809
814
    mtime_t i_dts;
810
 
    int     i_stream;
811
 
    int     i;
 
815
    int     i_stream, i;
812
816
 
813
817
    for( i = 0, i_dts = 0, i_stream = -1; i < p_mux->i_nb_inputs; i++ )
814
818
    {
815
819
        sout_input_t *p_input = p_mux->pp_inputs[i];
816
820
        block_t *p_data;
817
821
 
818
 
        if( p_input->p_fifo->i_depth <= 0 )
 
822
        if( block_FifoCount( p_input->p_fifo ) <= 0 )
819
823
        {
820
824
            if( p_input->p_fmt->i_cat == AUDIO_ES ||
821
825
                p_input->p_fmt->i_cat == VIDEO_ES )