Commit b56e2184 authored by zorglub's avatar zorglub
Browse files

Fix refcount problems + fix a part of coding style problems

parent 2479a41d
/*****************************************************************************
* vcd.c : VCD input module for vlc using libcdio, libvcd and libvcdinfo.
* vcd.c : VCD input module for vlc using libcdio, libvcd and libvcdinfo.
* vlc-specific things tend to go here.
*****************************************************************************
* Copyright (C) 2000, 2003, 2004 VideoLAN
......@@ -7,7 +7,7 @@
*
* Authors: Rocky Bernstein <rocky@panix.com>
* Some code is based on the non-libcdio VCD plugin (as there really
* isn't real developer documentation yet on how to write a
* isn't real developer documentation yet on how to write a
* navigable plugin.)
*
* This program is free software; you can redistribute it and/or modify
......@@ -46,8 +46,8 @@
#define FREE_AND_NULL(ptr) if (NULL != ptr) free(ptr); ptr = NULL;
extern void VCDSetOrigin( access_t *p_access, lsn_t i_lsn, track_t i_track,
const vcdinfo_itemid_t *p_itemid );
extern void VCDSetOrigin( access_t *p_access, lsn_t i_lsn, track_t i_track,
const vcdinfo_itemid_t *p_itemid );
/*****************************************************************************
* Local prototypes
......@@ -56,8 +56,8 @@ extern void VCDSetOrigin( access_t *p_access, lsn_t i_lsn, track_t i_track,
/* First those which are accessed from outside (via pointers). */
static block_t *VCDReadBlock ( access_t * );
static int VCDControl ( access_t *p_access, int i_query,
va_list args );
static int VCDControl ( access_t *p_access, int i_query,
va_list args );
/* Now those which are strictly internal */
static vlc_bool_t VCDEntryPoints ( access_t * );
......@@ -70,7 +70,7 @@ static char *VCDParse ( access_t *,
static void VCDUpdateVar( access_t *p_access, int i_entry, int i_action,
const char *p_varname, char *p_label,
const char *p_debug_label );
const char *p_debug_label );
static vcdinfo_obj_t *vcd_Open ( vlc_object_t *p_this, const char *psz_dev );
......@@ -150,15 +150,15 @@ VCDReadBlock( access_t * p_access )
i_read = 0;
dbg_print( (INPUT_DBG_LSN), "lsn: %lu",
(long unsigned int) p_vcdplayer->i_lsn );
dbg_print( (INPUT_DBG_LSN), "lsn: %lu",
(long unsigned int) p_vcdplayer->i_lsn );
/* Allocate a block for the reading */
if( !( p_block = block_New( p_access, i_blocks * M2F2_SECTOR_SIZE ) ) )
{
msg_Err( p_access, "cannot get a new block of size: %i",
i_blocks * M2F2_SECTOR_SIZE );
block_Release( p_block );
block_Release( p_block );
return NULL;
}
......@@ -171,85 +171,85 @@ VCDReadBlock( access_t * p_access )
switch ( read_status ) {
case READ_END:
/* End reached. Return NULL to indicated this. */
/* We also set the postion to the end so the higher level
/* End reached. Return NULL to indicated this. */
/* We also set the postion to the end so the higher level
(demux?) doesn't try to keep reading. If everything works out
right this shouldn't have to happen.
*/
right this shouldn't have to happen.
*/
#if 0
if ( p_access->info.i_pos != p_access->info.i_size ) {
msg_Warn( p_access,
"At end but pos (%llu) is not size (%llu). Adjusting.",
p_access->info.i_pos, p_access->info.i_size );
p_access->info.i_pos = p_access->info.i_size;
}
if ( p_access->info.i_pos != p_access->info.i_size ) {
msg_Warn( p_access,
"At end but pos (%llu) is not size (%llu). Adjusting.",
p_access->info.i_pos, p_access->info.i_size );
p_access->info.i_pos = p_access->info.i_size;
}
#endif
#if 1
block_Release( p_block );
return NULL;
block_Release( p_block );
return NULL;
#else
{
memset(p_buf, 0, M2F2_SECTOR_SIZE);
p_buf += 2;
*p_buf = 0x01;
printf("++++hacked\n");
return p_block;
}
{
memset(p_buf, 0, M2F2_SECTOR_SIZE);
p_buf += 2;
*p_buf = 0x01;
printf("++++hacked\n");
return p_block;
}
#endif
case READ_ERROR:
/* Some sort of error. Should we increment lsn? to skip block?
*/
block_Release( p_block );
return NULL;
case READ_STILL_FRAME:
{
/* FIXME The below should be done in an event thread.
Until then...
*/
/* Some sort of error. Should we increment lsn? to skip block?
*/
block_Release( p_block );
return NULL;
case READ_STILL_FRAME:
{
/* FIXME The below should be done in an event thread.
Until then...
*/
#if 0
msleep( MILLISECONDS_PER_SEC * *p_buf );
p_vcd->in_still = VLC_FALSE;
dbg_print(INPUT_DBG_STILL, "still wait time done");
#else
vcdIntfStillTime(p_vcdplayer->p_intf, *p_buf);
msleep( MILLISECONDS_PER_SEC * *p_buf );
p_vcd->in_still = VLC_FALSE;
dbg_print(INPUT_DBG_STILL, "still wait time done");
#else
vcdIntfStillTime(p_vcdplayer->p_intf, *p_buf);
#endif
#if 1
block_Release( p_block );
return NULL;
block_Release( p_block );
return NULL;
#else
memset(p_buf, 0, M2F2_SECTOR_SIZE);
p_buf += 2;
*p_buf = 0x01;
return p_block;
memset(p_buf, 0, M2F2_SECTOR_SIZE);
p_buf += 2;
*p_buf = 0x01;
return p_block;
#endif
}
}
default:
case READ_BLOCK:
/* Read buffer */
;
/* Read buffer */
;
}
p_buf += M2F2_SECTOR_SIZE;
/* Update seekpoint */
if ( VCDINFO_ITEM_TYPE_ENTRY == p_vcdplayer->play_item.type )
{
unsigned int i_entry = p_vcdplayer->play_item.num+1;
lsn_t i_lsn = vcdinfo_get_entry_lsn(p_vcdplayer->vcd, i_entry);
if ( p_vcdplayer->i_lsn >= i_lsn && i_lsn != VCDINFO_NULL_LSN )
unsigned int i_entry = p_vcdplayer->play_item.num+1;
lsn_t i_lsn = vcdinfo_get_entry_lsn(p_vcdplayer->vcd, i_entry);
if ( p_vcdplayer->i_lsn >= i_lsn && i_lsn != VCDINFO_NULL_LSN )
{
const track_t i_track = p_vcdplayer->i_track;
p_vcdplayer->play_item.num = i_entry;
dbg_print( (INPUT_DBG_LSN|INPUT_DBG_PBC), "entry change" );
VCDSetOrigin( p_access, i_lsn, i_track,
&(p_vcdplayer->play_item) );
const track_t i_track = p_vcdplayer->i_track;
p_vcdplayer->play_item.num = i_entry;
dbg_print( (INPUT_DBG_LSN|INPUT_DBG_PBC), "entry change" );
VCDSetOrigin( p_access, i_lsn, i_track,
&(p_vcdplayer->play_item) );
}
}
}
return p_block;
}
......@@ -261,54 +261,54 @@ int
VCDSeek( access_t * p_access, int64_t i_pos )
{
if (!p_access || !p_access->p_sys) return VLC_EGENERIC;
{
vcdplayer_t *p_vcdplayer = (vcdplayer_t *)p_vcd_access->p_sys;
const input_title_t *t = p_vcdplayer->p_title[p_access->info.i_title];
unsigned int i_entry = VCDINFO_INVALID_ENTRY;
unsigned int i_entry = VCDINFO_INVALID_ENTRY;
int i_seekpoint;
/* Next sector to read */
p_access->info.i_pos = i_pos;
p_vcdplayer->i_lsn = (i_pos / (int64_t)M2F2_SECTOR_SIZE) +
p_vcdplayer->track_lsn;
p_vcdplayer->track_lsn;
switch (p_vcdplayer->play_item.type) {
case VCDINFO_ITEM_TYPE_TRACK:
case VCDINFO_ITEM_TYPE_ENTRY:
break ;
break ;
default:
p_vcdplayer->b_valid_ep = VLC_FALSE;
p_vcdplayer->b_valid_ep = VLC_FALSE;
}
/* Find entry */
if( p_vcdplayer->b_valid_ep )
{
for( i_entry = 0 ; i_entry < p_vcdplayer->i_entries ; i_entry ++ )
{
if( p_vcdplayer->i_lsn < p_vcdplayer->p_entries[i_entry] )
{
VCDUpdateVar( p_access, i_entry, VLC_VAR_SETVALUE,
"chapter", _("Entry"), "Setting entry" );
break;
}
}
{
vcdinfo_itemid_t itemid;
itemid.num = i_entry;
itemid.type = VCDINFO_ITEM_TYPE_ENTRY;
VCDSetOrigin(p_access, p_vcdplayer->i_lsn, p_vcdplayer->i_track,
&itemid);
}
}
for( i_entry = 0 ; i_entry < p_vcdplayer->i_entries ; i_entry ++ )
{
if( p_vcdplayer->i_lsn < p_vcdplayer->p_entries[i_entry] )
{
VCDUpdateVar( p_access, i_entry, VLC_VAR_SETVALUE,
"chapter", _("Entry"), "Setting entry" );
break;
}
}
{
vcdinfo_itemid_t itemid;
itemid.num = i_entry;
itemid.type = VCDINFO_ITEM_TYPE_ENTRY;
VCDSetOrigin(p_access, p_vcdplayer->i_lsn, p_vcdplayer->i_track,
&itemid);
}
}
dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
"orig %lu, cur: %lu, offset: %lld, entry %d",
(long unsigned int) p_vcdplayer->origin_lsn,
(long unsigned int) p_vcdplayer->i_lsn, i_pos,
i_entry );
"orig %lu, cur: %lu, offset: %lld, entry %d",
(long unsigned int) p_vcdplayer->origin_lsn,
(long unsigned int) p_vcdplayer->i_lsn, i_pos,
i_entry );
/* Find seekpoint */
for( i_seekpoint = 0; i_seekpoint < t->i_seekpoint; i_seekpoint++ )
{
......@@ -384,11 +384,11 @@ VCDEntryPoints( access_t * p_access )
"%s, lsn %d, byte_offset %ld",
s->psz_name, p_vcdplayer->p_entries[i],
(unsigned long int) s->i_byte_offset);
TAB_APPEND( p_vcdplayer->p_title[i_track-1]->i_seekpoint,
p_vcdplayer->p_title[i_track-1]->seekpoint, s );
TAB_APPEND( p_vcdplayer->p_title[i_track-1]->i_seekpoint,
p_vcdplayer->p_title[i_track-1]->seekpoint, s );
} else
msg_Warn( p_access, "wrong track number found in entry points" );
} else
msg_Warn( p_access, "wrong track number found in entry points" );
}
p_vcdplayer->b_valid_ep = VLC_TRUE;
return VLC_TRUE;
......@@ -417,11 +417,11 @@ VCDSegments( access_t * p_access )
t->i_size = 0; /* Not sure Segments have a size associated */
t->psz_name = strdup(_("Segments"));
/* We have one additional segment allocated so we can get the size
by subtracting seg[i+1] - seg[i].
*/
p_vcdplayer->p_segments =
p_vcdplayer->p_segments =
malloc( sizeof( lsn_t ) * (p_vcdplayer->i_segments+1) );
if( p_vcdplayer->p_segments == NULL )
{
......@@ -432,21 +432,21 @@ VCDSegments( access_t * p_access )
for( i = 0 ; i < p_vcdplayer->i_segments ; i++ )
{
char psz_segment[100];
seekpoint_t *s = vlc_seekpoint_New();
p_vcdplayer->p_segments[i] = vcdinfo_get_seg_lsn(p_vcdplayer->vcd, i);
snprintf( psz_segment, sizeof(psz_segment), "%s%02d", _("Segment "),
i );
s->i_byte_offset = 0; /* Not sure what this would mean here */
s->psz_name = strdup(psz_segment);
TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
seekpoint_t *s = vlc_seekpoint_New();
p_vcdplayer->p_segments[i] = vcdinfo_get_seg_lsn(p_vcdplayer->vcd, i);
snprintf( psz_segment, sizeof(psz_segment), "%s%02d", _("Segment "),
i );
s->i_byte_offset = 0; /* Not sure what this would mean here */
s->psz_name = strdup(psz_segment);
TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
}
p_vcdplayer->p_segments[p_vcdplayer->i_segments] =
p_vcdplayer->p_segments[p_vcdplayer->i_segments] =
p_vcdplayer->p_segments[p_vcdplayer->i_segments-1]+
vcdinfo_get_seg_sector_count(p_vcdplayer->vcd,
p_vcdplayer->i_segments-1);
vcdinfo_get_seg_sector_count(p_vcdplayer->vcd,
p_vcdplayer->i_segments-1);
return VLC_TRUE;
}
......@@ -470,29 +470,29 @@ VCDTitles( access_t * p_access )
{
vcdplayer_t *p_vcdplayer = (vcdplayer_t *) p_access->p_sys;
track_t i;
track_t i;
p_vcdplayer->i_titles = 0;
for( i = 1 ; i <= p_vcdplayer->i_tracks ; i++ )
p_vcdplayer->i_titles = 0;
for( i = 1 ; i <= p_vcdplayer->i_tracks ; i++ )
{
input_title_t *t = p_vcdplayer->p_title[i-1] =
vlc_input_title_New();
char psz_track[100];
uint32_t i_secsize =
vcdinfo_get_track_sect_count( p_vcdplayer->vcd, i );
snprintf( psz_track, sizeof(psz_track), "%s%02d", _("Track "),
i );
t->i_size = (i_secsize) * (int64_t) M2F2_SECTOR_SIZE;
t->psz_name = strdup(psz_track);
dbg_print( INPUT_DBG_MRL, "track[%d] i_size: %lld",
i, t->i_size );
p_vcdplayer->i_titles++;
}
input_title_t *t = p_vcdplayer->p_title[i-1] =
vlc_input_title_New();
char psz_track[100];
uint32_t i_secsize =
vcdinfo_get_track_sect_count( p_vcdplayer->vcd, i );
snprintf( psz_track, sizeof(psz_track), "%s%02d", _("Track "),
i );
t->i_size = (i_secsize) * (int64_t) M2F2_SECTOR_SIZE;
t->psz_name = strdup(psz_track);
dbg_print( INPUT_DBG_MRL, "track[%d] i_size: %lld",
i, t->i_size );
p_vcdplayer->i_titles++;
}
return VLC_SUCCESS;
}
}
......@@ -514,7 +514,7 @@ VCDLIDs( access_t * p_access )
"LIDs: %d", p_vcdplayer->i_lids);
if ( 0 == p_vcdplayer->i_lids ) return VLC_FALSE;
if (vcdinfo_read_psd (p_vcdplayer->vcd)) {
vcdinfo_visit_lot (p_vcdplayer->vcd, VLC_FALSE);
......@@ -539,22 +539,21 @@ VCDLIDs( access_t * p_access )
i_title = p_vcdplayer->i_tracks;
for( i_lid = 1 ; i_lid <= p_vcdplayer->i_lids ; i_lid++ )
{
char psz_lid[100];
seekpoint_t *s = vlc_seekpoint_New();
snprintf( psz_lid, sizeof(psz_lid), "%s%02d", _("LID "),
i_lid );
s->i_byte_offset = 0; /* A lid doesn't have an offset
size associated with it */
s->psz_name = strdup(psz_lid);
TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
char psz_lid[100];
seekpoint_t *s = vlc_seekpoint_New();
snprintf( psz_lid, sizeof(psz_lid), "%s%02d", _("LID "),
i_lid );
s->i_byte_offset = 0; /* A lid doesn't have an offset
size associated with it */
s->psz_name = strdup(psz_lid);
TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
}
#if DYNAMICALLY_ALLOCATED
TAB_APPEND( p_vcdplayer->i_titles, p_vcdplayer->p_title, t );
#else
#else
p_vcdplayer->p_title[p_vcdplayer->i_titles] = t;
p_vcdplayer->i_titles++;
#endif
......@@ -579,7 +578,7 @@ VCDParse( access_t * p_access, /*out*/ vcdinfo_itemid_t * p_itemid,
p_itemid->num = 1;
*play_single_item = VLC_FALSE;
}
else
else
{
p_itemid->type = VCDINFO_ITEM_TYPE_ENTRY;
p_itemid->num = 0;
......@@ -666,8 +665,8 @@ VCDParse( access_t * p_access, /*out*/ vcdinfo_itemid_t * p_itemid,
VLC_TRUE );
if( NULL == cd_drives ) return NULL;
if( cd_drives[0] == NULL )
{
cdio_free_device_list( cd_drives );
{
cdio_free_device_list( cd_drives );
return NULL;
}
psz_source = strdup( cd_drives[0] );
......@@ -686,27 +685,27 @@ VCDParse( access_t * p_access, /*out*/ vcdinfo_itemid_t * p_itemid,
Set's start origin subsequent seeks/reads
*/
void
VCDSetOrigin( access_t *p_access, lsn_t i_lsn, track_t i_track,
const vcdinfo_itemid_t *p_itemid )
VCDSetOrigin( access_t *p_access, lsn_t i_lsn, track_t i_track,
const vcdinfo_itemid_t *p_itemid )
{
vcdplayer_t *p_vcdplayer= (vcdplayer_t *)p_access->p_sys;
dbg_print( (INPUT_DBG_CALL|INPUT_DBG_LSN),
"i_lsn: %lu, track: %d", (long unsigned int) i_lsn,
i_track );
"i_lsn: %lu, track: %d", (long unsigned int) i_lsn,
i_track );
vcdplayer_set_origin(p_access, i_lsn, i_track, p_itemid);
p_access->info.i_pos = ( i_lsn - p_vcdplayer->track_lsn )
p_access->info.i_pos = ( i_lsn - p_vcdplayer->track_lsn )
* M2F2_SECTOR_SIZE;
p_access->info.i_update |= INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE
| INPUT_UPDATE_SEEKPOINT;
switch (p_vcdplayer->play_item.type) {
case VCDINFO_ITEM_TYPE_ENTRY:
case VCDINFO_ITEM_TYPE_ENTRY:
VCDUpdateVar( p_access, p_itemid->num, VLC_VAR_SETVALUE,
"chapter", _("Entry"), "Setting entry/segment");
"chapter", _("Entry"), "Setting entry/segment");
p_access->info.i_title = i_track-1;
p_access->info.i_size = p_vcdplayer->p_title[i_track-1]->i_size;
p_access->info.i_seekpoint = p_itemid->num;
......@@ -714,35 +713,35 @@ VCDSetOrigin( access_t *p_access, lsn_t i_lsn, track_t i_track,
case VCDINFO_ITEM_TYPE_SEGMENT:
VCDUpdateVar( p_access, p_itemid->num, VLC_VAR_SETVALUE,
"chapter", _("Segment"), "Setting entry/segment");
"chapter", _("Segment"), "Setting entry/segment");
/* The last title entry is the for segments (when segments exist
and they must here. The segment seekpoints are stored after
the entry seekpoints and (zeroed) lid seekpoints.
and they must here. The segment seekpoints are stored after
the entry seekpoints and (zeroed) lid seekpoints.
*/
p_access->info.i_title = p_vcdplayer->i_titles - 1;
p_access->info.i_size = 150 * M2F2_SECTOR_SIZE;
p_access->info.i_seekpoint = p_vcdplayer->i_entries
+ p_vcdplayer->i_lids + p_itemid->num;
p_access->info.i_seekpoint = p_vcdplayer->i_entries
+ p_vcdplayer->i_lids + p_itemid->num;
break;
case VCDINFO_ITEM_TYPE_TRACK:
case VCDINFO_ITEM_TYPE_TRACK:
p_access->info.i_title = i_track-1;
p_access->info.i_size = p_vcdplayer->p_title[i_track-1]->i_size;
p_access->info.i_seekpoint = vcdinfo_track_get_entry(p_vcdplayer->vcd,
i_track);
p_access->info.i_seekpoint = vcdinfo_track_get_entry(p_vcdplayer->vcd,
i_track);
break;
default:
msg_Warn( p_access, "can't set origin for play type %d",
p_vcdplayer->play_item.type );
msg_Warn( p_access, "can't set origin for play type %d",
p_vcdplayer->play_item.type );
}
VCDUpdateTitle( p_access );
}
/*****************************************************************************
* vcd_Open: Opens a VCD device or file initializes, a list of
* vcd_Open: Opens a VCD device or file initializes, a list of
tracks, segements and entry lsns and sizes and returns an opaque handle.
*****************************************************************************/
static vcdinfo_obj_t *
......@@ -766,49 +765,48 @@ vcd_Open( vlc_object_t *p_this, const char *psz_dev )
}
free(actual_dev);
/*
Save summary info on tracks, segments and entries...
/*
Save summary info on tracks, segments and entries...
*/
if ( 0 < (p_vcdplayer->i_tracks = vcdinfo_get_num_tracks(p_vcdobj)) ) {
p_vcdplayer->track = (vcdplayer_play_item_info_t *)
calloc(p_vcdplayer->i_tracks, sizeof(vcdplayer_play_item_info_t));
for (i=0; i<p_vcdplayer->i_tracks; i++) {
unsigned int track_num=i+1;
p_vcdplayer->track[i].size =
vcdinfo_get_track_sect_count(p_vcdobj, track_num);
p_vcdplayer->track[i].start_LSN =
vcdinfo_get_track_lsn(p_vcdobj, track_num);
p_vcdplayer->track = (vcdplayer_play_item_info_t *)
calloc(p_vcdplayer->i_tracks, sizeof(vcdplayer_play_item_info_t));
for (i=0; i<p_vcdplayer->i_tracks; i++) {
unsigned int track_num=i+1;
p_vcdplayer->track[i].size =
vcdinfo_get_track_sect_count(p_vcdobj, track_num);
p_vcdplayer->track[i].start_LSN =
vcdinfo_get_track_lsn(p_vcdobj, track_num);
}
} else
} else
p_vcdplayer->track = NULL;
if ( 0 < (p_vcdplayer->i_entries = vcdinfo_get_num_entries(p_vcdobj)) ) {
p_vcdplayer->entry = (vcdplayer_play_item_info_t *)
calloc(p_vcdplayer->i_entries, sizeof(vcdplayer_play_item_info_t));
for (i=0; i<p_vcdplayer->i_entries; i++) {
p_vcdplayer->entry[i].size =
vcdinfo_get_entry_sect_count(p_vcdobj, i);
p_vcdplayer->entry[i].start_LSN = vcdinfo_get_entry_lsn(p_vcdobj, i);
p_vcdplayer->entry = (vcdplayer_play_item_info_t *)
calloc(p_vcdplayer->i_entries, sizeof(vcdplayer_play_item_info_t));
for (i=0; i<p_vcdplayer->i_entries; i++) {
p_vcdplayer->entry[i].size =
vcdinfo_get_entry_sect_count(p_vcdobj, i);
p_vcdplayer->entry[i].start_LSN = vcdinfo_get_entry_lsn(p_vcdobj, i);
}
} else
} else
p_vcdplayer->entry = NULL;
if ( 0 < (p_vcdplayer->i_segments = vcdinfo_get_num_segments(p_vcdobj)) ) {
p_vcdplayer->segment = (vcdplayer_play_item_info_t *)
calloc(p_vcdplayer->i_segments, sizeof(vcdplayer_play_item_info_t));
for (i=0; i<p_vcdplayer->i_segments; i++) {
p_vcdplayer->segment[i].size =
vcdinfo_get_seg_sector_count(p_vcdobj, i);
p_vcdplayer->segment[i].start_LSN = vcdinfo_get_seg_lsn(p_vcdobj, i);
p_vcdplayer->segment = (vcdplayer_play_item_info_t *)
calloc(p_vcdplayer->i_segments, sizeof(vcdplayer_play_item_info_t));