a52.c 13.7 KB
Newer Older
1
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
2
 * a52.c: parse A/52 audio sync info and packetize the stream
3
 *****************************************************************************
4
 * Copyright (C) 2001-2002 the VideoLAN team
5
 * $Id$
6
 *
7
 * Authors: Stéphane Borel <stef@via.ecp.fr>
8
 *          Christophe Massiot <massiot@via.ecp.fr>
9
 *          Gildas Bazin <gbazin@videolan.org>
10
 *
11 12 13 14
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
15
 *
16 17 18 19 20 21 22
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 25 26 27 28
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
29 30 31 32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include <vlc_common.h>
34
#include <vlc_plugin.h>
Clément Stenac's avatar
Clément Stenac committed
35 36 37
#include <vlc_codec.h>
#include <vlc_aout.h>
#include <vlc_block_helper.h>
38 39

#include "a52.h"
Gildas Bazin's avatar
 
Gildas Bazin committed
40

41 42 43 44 45 46 47
/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
static int  OpenDecoder   ( vlc_object_t * );
static int  OpenPacketizer( vlc_object_t * );
static void CloseCommon   ( vlc_object_t * );

48 49 50 51 52 53
vlc_module_begin ()
    set_description( N_("A/52 parser") )
    set_capability( "decoder", 100 )
    set_callbacks( OpenDecoder, CloseCommon )
    set_category( CAT_INPUT )
    set_subcategory( SUBCAT_INPUT_ACODEC )
54

55 56 57 58 59
    add_submodule ()
    set_description( N_("A/52 audio packetizer") )
    set_capability( "packetizer", 10 )
    set_callbacks( OpenPacketizer, CloseCommon )
vlc_module_end ()
Gildas Bazin's avatar
 
Gildas Bazin committed
60

Christophe Massiot's avatar
Christophe Massiot committed
61
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
62
 * decoder_sys_t : decoder descriptor
Christophe Massiot's avatar
Christophe Massiot committed
63
 *****************************************************************************/
64

Gildas Bazin's avatar
 
Gildas Bazin committed
65
struct decoder_sys_t
Christophe Massiot's avatar
Christophe Massiot committed
66
{
Gildas Bazin's avatar
 
Gildas Bazin committed
67
    /* Module mode */
68
    bool b_packetizer;
Gildas Bazin's avatar
 
Gildas Bazin committed
69

Christophe Massiot's avatar
Christophe Massiot committed
70
    /*
Gildas Bazin's avatar
 
Gildas Bazin committed
71
     * Input properties
Christophe Massiot's avatar
Christophe Massiot committed
72
     */
Gildas Bazin's avatar
 
Gildas Bazin committed
73
    int i_state;
Gildas Bazin's avatar
 
Gildas Bazin committed
74

Gildas Bazin's avatar
 
Gildas Bazin committed
75
    block_bytestream_t bytestream;
Christophe Massiot's avatar
Christophe Massiot committed
76 77

    /*
Gildas Bazin's avatar
 
Gildas Bazin committed
78
     * Common properties
Christophe Massiot's avatar
Christophe Massiot committed
79
     */
80
    date_t  end_date;
Gildas Bazin's avatar
 
Gildas Bazin committed
81

Gildas Bazin's avatar
 
Gildas Bazin committed
82
    mtime_t i_pts;
83 84

    vlc_a52_header_t frame;
Gildas Bazin's avatar
 
Gildas Bazin committed
85 86 87 88 89 90 91
};

enum {

    STATE_NOSYNC,
    STATE_SYNC,
    STATE_HEADER,
Gildas Bazin's avatar
 
Gildas Bazin committed
92 93 94
    STATE_NEXT_SYNC,
    STATE_GET_DATA,
    STATE_SEND_DATA
Gildas Bazin's avatar
 
Gildas Bazin committed
95
};
96

97
/****************************************************************************
98
 * Local prototypes
99
 ****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
100
static void *DecodeBlock  ( decoder_t *, block_t ** );
101

Gildas Bazin's avatar
 
Gildas Bazin committed
102 103 104
static uint8_t       *GetOutBuffer ( decoder_t *, void ** );
static aout_buffer_t *GetAoutBuffer( decoder_t * );
static block_t       *GetSoutBuffer( decoder_t * );
105 106

/*****************************************************************************
107
 * OpenCommon: probe the decoder/packetizer and return score
108
 *****************************************************************************/
109
static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
110
{
Gildas Bazin's avatar
 
Gildas Bazin committed
111
    decoder_t *p_dec = (decoder_t*)p_this;
Gildas Bazin's avatar
 
Gildas Bazin committed
112
    decoder_sys_t *p_sys;
113
    vlc_fourcc_t i_codec;
Gildas Bazin's avatar
 
Gildas Bazin committed
114

115
    switch( p_dec->fmt_in.i_codec )
Gildas Bazin's avatar
 
Gildas Bazin committed
116
    {
117 118
    case VLC_CODEC_A52:
        i_codec = VLC_CODEC_A52;
119
        break;
120
    case VLC_CODEC_EAC3:
121 122 123 124
        /* XXX ugly hack, a52 does not support eac3 so no eac3 pass-through
         * support */
        if( !b_packetizer )
            return VLC_EGENERIC;
125
        i_codec = VLC_CODEC_EAC3;
126 127
        break;
    default:
Gildas Bazin's avatar
 
Gildas Bazin committed
128 129
        return VLC_EGENERIC;
    }
130

Gildas Bazin's avatar
 
Gildas Bazin committed
131
    /* Allocate the memory needed to store the decoder's structure */
Gildas Bazin's avatar
 
Gildas Bazin committed
132
    if( ( p_dec->p_sys = p_sys =
Gildas Bazin's avatar
 
Gildas Bazin committed
133
          (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
134
        return VLC_ENOMEM;
Gildas Bazin's avatar
 
Gildas Bazin committed
135 136

    /* Misc init */
137
    p_sys->b_packetizer = b_packetizer;
Gildas Bazin's avatar
 
Gildas Bazin committed
138
    p_sys->i_state = STATE_NOSYNC;
139
    date_Set( &p_sys->end_date, 0 );
140
    p_sys->i_pts = VLC_TS_INVALID;
Gildas Bazin's avatar
 
Gildas Bazin committed
141

142
    p_sys->bytestream = block_BytestreamInit();
Gildas Bazin's avatar
 
Gildas Bazin committed
143 144 145

    /* Set output properties */
    p_dec->fmt_out.i_cat = AUDIO_ES;
146
    p_dec->fmt_out.i_codec = i_codec;
147
    p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */
148
    p_dec->fmt_out.audio.i_bytes_per_frame = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
149 150

    /* Set callback */
151 152 153 154 155 156
    if( b_packetizer )
        p_dec->pf_packetize    = (block_t *(*)(decoder_t *, block_t **))
            DecodeBlock;
    else
        p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
            DecodeBlock;
Gildas Bazin's avatar
 
Gildas Bazin committed
157 158 159
    return VLC_SUCCESS;
}

160
static int OpenDecoder( vlc_object_t *p_this )
Gildas Bazin's avatar
 
Gildas Bazin committed
161
{
162 163 164
    /* HACK: Don't use this codec if we don't have an dts audio filter */
    if( !module_exists( "a52tofloat32" ) )
        return VLC_EGENERIC;
165 166
    return OpenCommon( p_this, false );
}
Gildas Bazin's avatar
 
Gildas Bazin committed
167

168 169 170
static int OpenPacketizer( vlc_object_t *p_this )
{
    return OpenCommon( p_this, true );
Gildas Bazin's avatar
 
Gildas Bazin committed
171 172
}

173
/****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
174
 * DecodeBlock: the whole thing
175 176 177
 ****************************************************************************
 * This function is called just after the thread is launched.
 ****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
178
static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
179
{
Gildas Bazin's avatar
 
Gildas Bazin committed
180
    decoder_sys_t *p_sys = p_dec->p_sys;
181
    uint8_t p_header[VLC_A52_HEADER_SIZE];
Gildas Bazin's avatar
 
Gildas Bazin committed
182 183
    uint8_t *p_buf;
    void *p_out_buffer;
Gildas Bazin's avatar
 
Gildas Bazin committed
184

Gildas Bazin's avatar
 
Gildas Bazin committed
185 186
    if( !pp_block || !*pp_block ) return NULL;

187
    if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
Gildas Bazin's avatar
 
Gildas Bazin committed
188
    {
189 190 191
        if( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED )
        {
            p_sys->i_state = STATE_NOSYNC;
192
            block_BytestreamEmpty( &p_sys->bytestream );
193
        }
194
        date_Set( &p_sys->end_date, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
195 196
        block_Release( *pp_block );
        return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
197 198
    }

199
    if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID)
Gildas Bazin's avatar
 
Gildas Bazin committed
200
    {
201 202 203
        /* We've just started the stream, wait for the first PTS. */
        block_Release( *pp_block );
        return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
204 205
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
206
    block_BytestreamPush( &p_sys->bytestream, *pp_block );
207

Gildas Bazin's avatar
 
Gildas Bazin committed
208
    while( 1 )
209
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
210 211 212
        switch( p_sys->i_state )
        {
        case STATE_NOSYNC:
Gildas Bazin's avatar
 
Gildas Bazin committed
213 214
            while( block_PeekBytes( &p_sys->bytestream, p_header, 2 )
                   == VLC_SUCCESS )
Gildas Bazin's avatar
 
Gildas Bazin committed
215
            {
Gildas Bazin's avatar
 
Gildas Bazin committed
216 217 218 219 220 221
                if( p_header[0] == 0x0b && p_header[1] == 0x77 )
                {
                    p_sys->i_state = STATE_SYNC;
                    break;
                }
                block_SkipByte( &p_sys->bytestream );
Gildas Bazin's avatar
 
Gildas Bazin committed
222
            }
Gildas Bazin's avatar
 
Gildas Bazin committed
223
            if( p_sys->i_state != STATE_SYNC )
Gildas Bazin's avatar
 
Gildas Bazin committed
224
            {
225
                block_BytestreamFlush( &p_sys->bytestream );
226

Gildas Bazin's avatar
 
Gildas Bazin committed
227
                /* Need more data */
Gildas Bazin's avatar
 
Gildas Bazin committed
228
                return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
229
            }
Gildas Bazin's avatar
 
Gildas Bazin committed
230

Gildas Bazin's avatar
 
Gildas Bazin committed
231 232
        case STATE_SYNC:
            /* New frame, set the Presentation Time Stamp */
Gildas Bazin's avatar
 
Gildas Bazin committed
233
            p_sys->i_pts = p_sys->bytestream.p_block->i_pts;
234
            if( p_sys->i_pts > VLC_TS_INVALID &&
235
                p_sys->i_pts != date_Get( &p_sys->end_date ) )
Gildas Bazin's avatar
 
Gildas Bazin committed
236
            {
237
                date_Set( &p_sys->end_date, p_sys->i_pts );
Gildas Bazin's avatar
 
Gildas Bazin committed
238 239 240 241
            }
            p_sys->i_state = STATE_HEADER;

        case STATE_HEADER:
242
            /* Get A/52 frame header (VLC_A52_HEADER_SIZE bytes) */
Gildas Bazin's avatar
 
Gildas Bazin committed
243
            if( block_PeekBytes( &p_sys->bytestream, p_header,
244
                                 VLC_A52_HEADER_SIZE ) != VLC_SUCCESS )
Gildas Bazin's avatar
 
Gildas Bazin committed
245
            {
Gildas Bazin's avatar
 
Gildas Bazin committed
246
                /* Need more data */
Gildas Bazin's avatar
 
Gildas Bazin committed
247
                return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
248 249
            }

Gildas Bazin's avatar
 
Gildas Bazin committed
250
            /* Check if frame is valid and get frame info */
251
            if( vlc_a52_header_Parse( &p_sys->frame, p_header, VLC_A52_HEADER_SIZE ) )
Gildas Bazin's avatar
 
Gildas Bazin committed
252
            {
Gildas Bazin's avatar
 
Gildas Bazin committed
253 254
                msg_Dbg( p_dec, "emulated sync word" );
                block_SkipByte( &p_sys->bytestream );
Gildas Bazin's avatar
 
Gildas Bazin committed
255 256 257
                p_sys->i_state = STATE_NOSYNC;
                break;
            }
258

Gildas Bazin's avatar
 
Gildas Bazin committed
259
            p_sys->i_state = STATE_NEXT_SYNC;
Gildas Bazin's avatar
 
Gildas Bazin committed
260

Gildas Bazin's avatar
 
Gildas Bazin committed
261 262
        case STATE_NEXT_SYNC:
            /* TODO: If pp_block == NULL, flush the buffer without checking the
Gildas Bazin's avatar
 
Gildas Bazin committed
263 264
             * next sync word */

Gildas Bazin's avatar
 
Gildas Bazin committed
265 266
            /* Check if next expected frame contains the sync word */
            if( block_PeekOffsetBytes( &p_sys->bytestream,
267
                                       p_sys->frame.i_size, p_header, 2 )
Gildas Bazin's avatar
 
Gildas Bazin committed
268 269 270 271
                != VLC_SUCCESS )
            {
                /* Need more data */
                return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
272
            }
Gildas Bazin's avatar
 
Gildas Bazin committed
273

Gildas Bazin's avatar
 
Gildas Bazin committed
274 275 276 277 278 279 280 281
            if( p_sys->b_packetizer &&
                p_header[0] == 0 && p_header[1] == 0 )
            {
                /* A52 wav files and audio CD's use stuffing */
                p_sys->i_state = STATE_GET_DATA;
                break;
            }

Gildas Bazin's avatar
 
Gildas Bazin committed
282
            if( p_header[0] != 0x0b || p_header[1] != 0x77 )
Gildas Bazin's avatar
 
Gildas Bazin committed
283
            {
Gildas Bazin's avatar
 
Gildas Bazin committed
284 285 286 287 288
                msg_Dbg( p_dec, "emulated sync word "
                         "(no sync on following frame)" );
                p_sys->i_state = STATE_NOSYNC;
                block_SkipByte( &p_sys->bytestream );
                break;
Gildas Bazin's avatar
 
Gildas Bazin committed
289
            }
Gildas Bazin's avatar
 
Gildas Bazin committed
290 291
            p_sys->i_state = STATE_SEND_DATA;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
292

Gildas Bazin's avatar
 
Gildas Bazin committed
293 294 295 296
        case STATE_GET_DATA:
            /* Make sure we have enough data.
             * (Not useful if we went through NEXT_SYNC) */
            if( block_WaitBytes( &p_sys->bytestream,
297
                                 p_sys->frame.i_size ) != VLC_SUCCESS )
Gildas Bazin's avatar
 
Gildas Bazin committed
298 299
            {
                /* Need more data */
Gildas Bazin's avatar
 
Gildas Bazin committed
300
                return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
301
            }
Gildas Bazin's avatar
 
Gildas Bazin committed
302
            p_sys->i_state = STATE_SEND_DATA;
Gildas Bazin's avatar
 
Gildas Bazin committed
303

Gildas Bazin's avatar
 
Gildas Bazin committed
304 305 306
        case STATE_SEND_DATA:
            if( !(p_buf = GetOutBuffer( p_dec, &p_out_buffer )) )
            {
307
                //p_dec->b_error = true;
Gildas Bazin's avatar
 
Gildas Bazin committed
308 309
                return NULL;
            }
Gildas Bazin's avatar
 
Gildas Bazin committed
310

Gildas Bazin's avatar
 
Gildas Bazin committed
311 312
            /* Copy the whole frame into the buffer. When we reach this point
             * we already know we have enough data available. */
313
            block_GetBytes( &p_sys->bytestream, p_buf, p_sys->frame.i_size );
Gildas Bazin's avatar
 
Gildas Bazin committed
314 315

            /* Make sure we don't reuse the same pts twice */
Gildas Bazin's avatar
 
Gildas Bazin committed
316
            if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts )
317
                p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
318

Gildas Bazin's avatar
 
Gildas Bazin committed
319 320
            /* So p_block doesn't get re-added several times */
            *pp_block = block_BytestreamPop( &p_sys->bytestream );
321

Gildas Bazin's avatar
 
Gildas Bazin committed
322
            p_sys->i_state = STATE_NOSYNC;
Gildas Bazin's avatar
 
Gildas Bazin committed
323

Gildas Bazin's avatar
 
Gildas Bazin committed
324
            return p_out_buffer;
325
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
326
    }
327

Gildas Bazin's avatar
 
Gildas Bazin committed
328
    return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
329
}
330

Gildas Bazin's avatar
 
Gildas Bazin committed
331
/*****************************************************************************
332
 * CloseCommon: clean up the decoder
Gildas Bazin's avatar
 
Gildas Bazin committed
333
 *****************************************************************************/
334
static void CloseCommon( vlc_object_t *p_this )
Gildas Bazin's avatar
 
Gildas Bazin committed
335
{
Gildas Bazin's avatar
 
Gildas Bazin committed
336
    decoder_t *p_dec = (decoder_t*)p_this;
Gildas Bazin's avatar
 
Gildas Bazin committed
337
    decoder_sys_t *p_sys = p_dec->p_sys;
338

Gildas Bazin's avatar
 
Gildas Bazin committed
339
    block_BytestreamRelease( &p_sys->bytestream );
340

Gildas Bazin's avatar
 
Gildas Bazin committed
341
    free( p_sys );
Gildas Bazin's avatar
 
Gildas Bazin committed
342
}
343

Gildas Bazin's avatar
 
Gildas Bazin committed
344
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
345
 * GetOutBuffer:
Gildas Bazin's avatar
 
Gildas Bazin committed
346
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
347
static uint8_t *GetOutBuffer( decoder_t *p_dec, void **pp_out_buffer )
Gildas Bazin's avatar
 
Gildas Bazin committed
348 349
{
    decoder_sys_t *p_sys = p_dec->p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
350
    uint8_t *p_buf;
Gildas Bazin's avatar
 
Gildas Bazin committed
351

352
    if( p_dec->fmt_out.audio.i_rate != p_sys->frame.i_rate )
Gildas Bazin's avatar
 
Gildas Bazin committed
353
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
354
        msg_Info( p_dec, "A/52 channels:%d samplerate:%d bitrate:%d",
355
                  p_sys->frame.i_channels, p_sys->frame.i_rate, p_sys->frame.i_bitrate );
Gildas Bazin's avatar
 
Gildas Bazin committed
356

357 358
        date_Init( &p_sys->end_date, p_sys->frame.i_rate, 1 );
        date_Set( &p_sys->end_date, p_sys->i_pts );
Gildas Bazin's avatar
 
Gildas Bazin committed
359 360
    }

361 362 363 364
    p_dec->fmt_out.audio.i_rate     = p_sys->frame.i_rate;
    p_dec->fmt_out.audio.i_channels = p_sys->frame.i_channels;
    if( p_dec->fmt_out.audio.i_bytes_per_frame < p_sys->frame.i_size )
        p_dec->fmt_out.audio.i_bytes_per_frame = p_sys->frame.i_size;
365
    p_dec->fmt_out.audio.i_frame_length = p_sys->frame.i_samples;
Gildas Bazin's avatar
 
Gildas Bazin committed
366

367
    p_dec->fmt_out.audio.i_original_channels = p_sys->frame.i_channels_conf;
Gildas Bazin's avatar
 
Gildas Bazin committed
368
    p_dec->fmt_out.audio.i_physical_channels =
369
        p_sys->frame.i_channels_conf & AOUT_CHAN_PHYSMASK;
Gildas Bazin's avatar
 
Gildas Bazin committed
370

371
    p_dec->fmt_out.i_bitrate = p_sys->frame.i_bitrate;
Gildas Bazin's avatar
 
Gildas Bazin committed
372

Gildas Bazin's avatar
 
Gildas Bazin committed
373
    if( p_sys->b_packetizer )
Gildas Bazin's avatar
 
Gildas Bazin committed
374
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
375 376 377 378 379 380 381 382 383
        block_t *p_sout_buffer = GetSoutBuffer( p_dec );
        p_buf = p_sout_buffer ? p_sout_buffer->p_buffer : NULL;
        *pp_out_buffer = p_sout_buffer;
    }
    else
    {
        aout_buffer_t *p_aout_buffer = GetAoutBuffer( p_dec );
        p_buf = p_aout_buffer ? p_aout_buffer->p_buffer : NULL;
        *pp_out_buffer = p_aout_buffer;
Gildas Bazin's avatar
 
Gildas Bazin committed
384 385
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
386
    return p_buf;
Gildas Bazin's avatar
 
Gildas Bazin committed
387 388 389
}

/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
390
 * GetAoutBuffer:
Gildas Bazin's avatar
 
Gildas Bazin committed
391
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
392
static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
Gildas Bazin's avatar
 
Gildas Bazin committed
393 394
{
    decoder_sys_t *p_sys = p_dec->p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
395
    aout_buffer_t *p_buf;
Gildas Bazin's avatar
 
Gildas Bazin committed
396

397
    p_buf = decoder_NewAudioBuffer( p_dec, p_sys->frame.i_samples );
Gildas Bazin's avatar
 
Gildas Bazin committed
398
    if( p_buf == NULL ) return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
399

400
    p_buf->i_pts = date_Get( &p_sys->end_date );
401 402
    p_buf->i_length = date_Increment( &p_sys->end_date,
                                      p_sys->frame.i_samples ) - p_buf->i_pts;
Gildas Bazin's avatar
 
Gildas Bazin committed
403

Gildas Bazin's avatar
 
Gildas Bazin committed
404
    return p_buf;
405 406 407
}

/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
408
 * GetSoutBuffer:
409
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
410
static block_t *GetSoutBuffer( decoder_t *p_dec )
411
{
Gildas Bazin's avatar
 
Gildas Bazin committed
412
    decoder_sys_t *p_sys = p_dec->p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
413
    block_t *p_block;
Gildas Bazin's avatar
 
Gildas Bazin committed
414

415
    p_block = block_New( p_dec, p_sys->frame.i_size );
Gildas Bazin's avatar
 
Gildas Bazin committed
416
    if( p_block == NULL ) return NULL;
417

418
    p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date );
Gildas Bazin's avatar
 
Gildas Bazin committed
419

420
    p_block->i_length =
421
        date_Increment( &p_sys->end_date, p_sys->frame.i_samples ) - p_block->i_pts;
Gildas Bazin's avatar
 
Gildas Bazin committed
422 423

    return p_block;
424
}
425