demux.c 5.65 KB
Newer Older
Gildas Bazin's avatar
 
Gildas Bazin committed
1 2 3
/*****************************************************************************
 * demux.c: demux functions for dvdplay.
 *****************************************************************************
4
 * Copyright (C) 1998-2001 the VideoLAN team
5
 * $Id$
Gildas Bazin's avatar
 
Gildas Bazin committed
6
 *
7
 * Author: Stéphane Borel <stef@via.ecp.fr>
Gildas Bazin's avatar
 
Gildas Bazin committed
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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.
 *
 * 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
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Gildas Bazin's avatar
 
Gildas Bazin committed
22 23 24 25 26 27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

28 29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include <stddef.h>
33
#include <vlc_common.h>
Clément Stenac's avatar
Clément Stenac committed
34 35
#include <vlc_input.h>
#include <vlc_access.h>
Clément Stenac's avatar
Clément Stenac committed
36
#include <vlc_interface.h>
Gildas Bazin's avatar
 
Gildas Bazin committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

#ifdef HAVE_UNISTD_H
#   include <unistd.h>
#endif

#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

#ifdef STRNCASECMP_IN_STRINGS_H
#   include <strings.h>
#endif

#include "vcd.h"
52
#include "vcdplayer.h"
Gildas Bazin's avatar
 
Gildas Bazin committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#include "intf.h"

/* how many packets vcdx_Demux will read in each loop */
/* #define vcdplay_READ_ONCE 64 */

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int  Demux         ( input_thread_t * );

/*****************************************************************************
 * Private structure
 *****************************************************************************/
struct demux_sys_t
{
    vcd_data_t * p_vcd;

    module_t *   p_module;
    mpeg_demux_t mpeg;
};

/*****************************************************************************
75
 * VCDInit: initializes structures
Gildas Bazin's avatar
 
Gildas Bazin committed
76
 *****************************************************************************/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
77
int VCDInit ( vlc_object_t *p_this )
Gildas Bazin's avatar
 
Gildas Bazin committed
78 79
{
    input_thread_t *p_input = (input_thread_t *)p_this;
80
    vcd_data_t *    p_vcd = (vcd_data_t *)p_input->p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
81 82
    demux_sys_t *   p_demux;

83
    printf("++++ VCDInit CALLED\n");
84
 
Gildas Bazin's avatar
 
Gildas Bazin committed
85 86 87 88 89 90 91 92 93

    if( p_input->stream.i_method != INPUT_METHOD_VCD )
    {
        return VLC_EGENERIC;
    }

    p_demux = p_input->p_demux_data = malloc( sizeof(demux_sys_t ) );
    if( p_demux == NULL )
    {
94
        return VLC_ENOMOD;
Gildas Bazin's avatar
 
Gildas Bazin committed
95 96 97
    }

    p_input->p_private = (void*)&p_demux->mpeg;
Gildas Bazin's avatar
 
Gildas Bazin committed
98
    p_demux->p_module = module_Need( p_input, "mpeg-system", NULL, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
99 100 101 102 103 104 105 106 107
    if( p_demux->p_module == NULL )
    {
        free( p_input->p_demux_data );
        return VLC_ENOMOD;
    }

    p_input->p_demux_data->p_vcd = p_vcd;

    p_input->pf_demux = Demux;
108
    p_input->pf_demux_control = demux_vaControlDefault;
Gildas Bazin's avatar
 
Gildas Bazin committed
109 110 111 112 113 114 115 116 117
    p_input->pf_rewind = NULL;

    p_vcd->p_intf = NULL;
    p_vcd->i_still_time = 0;

    return VLC_SUCCESS;
}

/*****************************************************************************
118
 * VCDEnd: frees unused data
Gildas Bazin's avatar
 
Gildas Bazin committed
119
 *****************************************************************************/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
120
void VCDEnd ( vlc_object_t *p_this )
Gildas Bazin's avatar
 
Gildas Bazin committed
121 122 123 124 125 126 127 128 129 130 131
{
    input_thread_t *p_input = (input_thread_t *)p_this;
    vcd_data_t *    p_vcd = p_input->p_demux_data->p_vcd;
    intf_thread_t * p_intf = NULL;

    p_intf = vlc_object_find( p_input, VLC_OBJECT_INTF, FIND_CHILD );
    if( p_intf != NULL )
    {
        intf_StopThread( p_intf );
        vlc_object_detach( p_intf );
        vlc_object_release( p_intf );
132
        vlc_object_release( p_intf );
Gildas Bazin's avatar
 
Gildas Bazin committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
    }

    p_vcd->p_intf = NULL;

    module_Unneed( p_input, p_input->p_demux_data->p_module );
    free( p_input->p_demux_data );
}

/*****************************************************************************
 * Demux
 *****************************************************************************/
static int Demux( input_thread_t * p_input )
{
    vcd_data_t *            p_vcd;
    data_packet_t *         p_data;
    ssize_t                 i_result;
    ptrdiff_t               i_remains;
    int                     i_data_nb = 0;

    p_vcd = p_input->p_demux_data->p_vcd;

    /* Read headers to compute payload length */
    do
    {
        i_result = p_input->p_demux_data->mpeg.pf_read_ps( p_input, &p_data );

        if( i_result <= 0 )
        {
            return i_result;
        }

        i_remains = p_input->p_last_data - p_input->p_current_data;

        p_input->p_demux_data->mpeg.pf_demux_ps( p_input, p_data );


        ++i_data_nb;
    }
    while( i_remains );



//    if( p_vcd->b_still && p_vcd->b_end_of_cell && p_vcd->p_intf != NULL )
    if( p_vcd->i_still_time && p_vcd->b_end_of_cell && p_vcd->p_intf != NULL )
    {
        pgrm_descriptor_t * p_pgrm;

        /* when we receive still_time flag, we have to pause immediately */
181
        var_SetInteger( p_input, "state", PAUSE_S );
Gildas Bazin's avatar
 
Gildas Bazin committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

        vcdIntfStillTime( p_vcd->p_intf, p_vcd->i_still_time );
        p_vcd->i_still_time = 0;

        vlc_mutex_lock( &p_input->stream.stream_lock );

        p_pgrm = p_input->stream.p_selected_program;
        p_pgrm->i_synchro_state = SYNCHRO_REINIT;

        vlc_mutex_unlock( &p_input->stream.stream_lock );

        input_ClockManageControl( p_input, p_pgrm, 0 );
    }

    return i_data_nb;
}