if (error_count > 10)
{
hb_error("bd: Error, too many consecutive read errors");
- return 0;
+ hb_set_work_error(d->h, HB_ERROR_READ);
+ return NULL;
}
continue;
}
else if ( result == 0 )
{
- return 0;
+ return NULL;
}
error_count = 0;
static uint64_t align_to_next_packet(BLURAY *bd, uint8_t *pkt)
{
- uint8_t buf[MAX_HOLE];
+ int result;
+ uint8_t buf[MAX_HOLE];
uint64_t pos = 0;
uint64_t start = bd_tell(bd);
uint64_t orig;
while (1)
{
- if (bd_read(bd, buf+off, sizeof(buf)-off) == sizeof(buf)-off)
+ result = bd_read(bd, buf + off, sizeof(buf) - off);
+ if (result == sizeof(buf) - off)
{
const uint8_t *bp = buf;
int i;
memcpy(buf, buf + sizeof(buf) - off, off);
start += sizeof(buf) - off;
}
+ else if (result < 0)
+ {
+ return -1;
+ }
else
{
return 0;
bd_seek(bd, off);
while (off > bd_tell(bd))
{
- if (bd_read(bd, buf, 192) != 192)
+ result = bd_read(bd, buf, 192);
+ if (result < 0)
{
- break;
+ return -1;
+ }
+ else if (result != 192)
+ {
+ return 0;
}
}
return start - orig + pos;
// lost sync - back up to where we started then try to re-establish.
uint64_t pos = bd_tell(bd);
uint64_t pos2 = align_to_next_packet(bd, pkt);
- if ( pos2 == 0 )
+ if (pos2 < 0)
+ {
+ return -1;
+ }
+ else if (pos2 == 0)
{
- hb_log( "next_packet: eof while re-establishing sync @ %"PRIu64"", pos );
+ hb_log("next_packet: eof while re-establishing sync @ %"PRIu64"", pos );
return 0;
}
- hb_log( "next_packet: sync lost @ %"PRIu64", regained after %"PRIu64" bytes",
+ hb_log("next_packet: sync lost @ %"PRIu64", regained after %"PRIu64" bytes",
pos, pos2 );
}
}
typedef struct hb_lock_s hb_lock_t;
typedef enum
{
- HB_ERROR_NONE = 0,
- HB_ERROR_CANCELED ,
- HB_ERROR_WRONG_INPUT,
- HB_ERROR_INIT ,
- HB_ERROR_UNKNOWN
+ HB_ERROR_NONE = 0,
+ HB_ERROR_CANCELED = 1,
+ HB_ERROR_WRONG_INPUT = 2,
+ HB_ERROR_INIT = 3,
+ HB_ERROR_UNKNOWN = 4,
+ HB_ERROR_READ = 5
} hb_error_code;
#include "ports.h"
#include "dvdread/ifo_print.h"
#include "dvdread/nav_read.h"
-static hb_dvd_t * hb_dvdread_init( char * path );
+static hb_dvd_t * hb_dvdread_init( hb_handle_t * h, char * path );
static void hb_dvdread_close( hb_dvd_t ** _d );
static char * hb_dvdread_name( char * path );
static int hb_dvdread_title_count( hb_dvd_t * d );
***********************************************************************
*
**********************************************************************/
-hb_dvd_t * hb_dvdread_init( char * path )
+hb_dvd_t * hb_dvdread_init( hb_handle_t * h, char * path )
{
hb_dvd_t * e;
hb_dvdread_t * d;
e = calloc( sizeof( hb_dvd_t ), 1 );
d = &(e->dvdread);
+ d->h = h;
/*
* Convert UTF-8 path to current code page on Windows
if ( d->cell_cur > d->cell_end )
{
hb_buffer_close( &b );
+ hb_set_work_error(d->h, HB_ERROR_READ);
return NULL;
}
d->in_cell = 0;
/* Wasn't a valid VOBU, try next block */
if( ++error > 1024 )
{
- hb_log( "dvd: couldn't find a VOBU after 1024 blocks" );
+ hb_error( "dvd: couldn't find a VOBU after 1024 blocks" );
hb_buffer_close( &b );
+ hb_set_work_error(d->h, HB_ERROR_READ);
return NULL;
}
return dvd_methods->name(path);
}
-hb_dvd_t * hb_dvd_init( char * path )
+hb_dvd_t * hb_dvd_init( hb_handle_t * h, char * path )
{
- return dvd_methods->init(path);
+ return dvd_methods->init(h, path);
}
int hb_dvd_title_count( hb_dvd_t * d )
int in_sync;
uint16_t cur_vob_id;
uint8_t cur_cell_id;
+ hb_handle_t * h;
};
struct hb_dvdnav_s
int cell;
hb_list_t * list_chapter;
int stopped;
+ hb_handle_t * h;
};
typedef struct hb_dvdnav_s hb_dvdnav_t;
struct hb_dvd_func_s
{
- hb_dvd_t * (* init) ( char * );
+ hb_dvd_t * (* init) ( hb_handle_t *, char * );
void (* close) ( hb_dvd_t ** );
char * (* name) ( char * );
int (* title_count) ( hb_dvd_t * );
#define DVD_READ_CACHE 1
static char * hb_dvdnav_name( char * path );
-static hb_dvd_t * hb_dvdnav_init( char * path );
+static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, char * path );
static int hb_dvdnav_title_count( hb_dvd_t * d );
static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * d, int t, uint64_t min_duration );
static int hb_dvdnav_start( hb_dvd_t * d, hb_title_t *title, int chapter );
***********************************************************************
*
**********************************************************************/
-static hb_dvd_t * hb_dvdnav_init( char * path )
+static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, char * path )
{
hb_dvd_t * e;
hb_dvdnav_t * d;
e = calloc( sizeof( hb_dvd_t ), 1 );
d = &(e->dvdnav);
+ d->h = h;
/*
* Convert UTF-8 path to current code page on Windows
hb_error( "dvd: dvdnav_sector_search failed - %s",
dvdnav_err_to_string(d->dvdnav) );
hb_buffer_close( &b );
+ hb_set_work_error(d->h, HB_ERROR_READ);
return NULL;
}
error_count++;
{
hb_error("dvdnav: Error, too many consecutive read errors");
hb_buffer_close( &b );
+ hb_set_work_error(d->h, HB_ERROR_READ);
return NULL;
}
continue;
{
// Transition to another title signals that we are done.
hb_buffer_close( &b );
+ hb_deep_log(2, "dvdnav: vts change, found next title");
return NULL;
}
}
{
// Transition to another title signals that we are done.
hb_buffer_close( &b );
+ hb_deep_log(2, "dvdnav: cell change, found next title");
return NULL;
}
c = FindChapterIndex(d->list_chapter, pgcn, pgn);
// Some titles end with a 'link' back to the beginning so
// a transition to an earlier chapter means we're done.
hb_buffer_close( &b );
+ hb_deep_log(2, "dvdnav: cell change, previous chapter");
return NULL;
}
chapter = d->chapter = c;
else if ( cell_event->cellN <= d->cell )
{
hb_buffer_close( &b );
+ hb_deep_log(2, "dvdnav: cell change, previous cell");
return NULL;
}
d->cell = cell_event->cellN;
*/
d->stopped = 1;
hb_buffer_close( &b );
+ hb_deep_log(2, "dvdnav: stop");
return NULL;
default:
hb_unlock( h->pause_lock );
}
+void hb_set_work_error( hb_handle_t * h, hb_error_code err )
+{
+ h->work_error = err;
+}
+
void hb_system_sleep_allow(hb_handle_t *h)
{
hb_system_sleep_private_enable(h->system_sleep_opaque);
**********************************************************************/
int hb_get_pid( hb_handle_t * );
void hb_set_state( hb_handle_t *, hb_state_t * );
+void hb_set_work_error( hb_handle_t * h, hb_error_code err );
void hb_job_setup_passes(hb_handle_t *h, hb_job_t *job, hb_list_t *list_pass);
/***********************************************************************
typedef union hb_dvd_s hb_dvd_t;
typedef struct hb_stream_s hb_stream_t;
-hb_dvd_t * hb_dvd_init( char * path );
+hb_dvd_t * hb_dvd_init( hb_handle_t * h, char * path );
int hb_dvd_title_count( hb_dvd_t * );
hb_title_t * hb_dvd_title_scan( hb_dvd_t *, int title, uint64_t min_duration );
int hb_dvd_start( hb_dvd_t *, hb_title_t *title, int chapter );
}
else if ( r->title->type == HB_DVD_TYPE )
{
- if ( !( r->dvd = hb_dvd_init( r->title->path ) ) )
+ if ( !( r->dvd = hb_dvd_init( r->h, r->title->path ) ) )
return 1;
}
else if ( r->title->type == HB_STREAM_TYPE ||
data->title_set->list_title );
}
}
- else if( ( data->dvd = hb_dvd_init( data->path ) ) )
+ else if( ( data->dvd = hb_dvd_init( data->h, data->path ) ) )
{
hb_log( "scan: DVD has %d title(s)",
hb_dvd_title_count( data->dvd ) );
if ( fread(stream->ts.packet, 1, stream->packetsize, stream->file_handle) !=
stream->packetsize )
{
+ int err;
+ if ((err = ferror(stream->file_handle)) != 0)
+ {
+ hb_error("next_packet: error (%d)", err);
+ hb_set_work_error(stream->h, HB_ERROR_READ);
+ }
return NULL;
}
if (buf[0] == 0x47)
}
else
{
+ int err;
+ if ((err = ferror(stream->file_handle)) != 0)
+ {
+ hb_error("align_to_next_packet: error (%d)", err);
+ hb_set_work_error(stream->h, HB_ERROR_READ);
+ }
return 0;
}
}
pos -= 4;
fseeko( stream->file_handle, -4, SEEK_CUR );
}
+
done:
// Parse packet for information we might need
funlockfile( stream->file_handle );
+
+ int err;
+ if ((err = ferror(stream->file_handle)) != 0)
+ {
+ hb_error("hb_ps_read_packet: error (%d)", err);
+ hb_set_work_error(stream->h, HB_ERROR_READ);
+ }
+
int len = pos - b->size;
b->size = pos;
#undef cp
// use M$ 'packed b-frames' and occasionally have negative
// sizes for the null frames these require.
if ( err != AVERROR(ENOMEM) || stream->ffmpeg_pkt->size >= 0 )
- // eof
+ {
+ // error or eof
+ if (err != AVERROR_EOF)
+ {
+ char errstr[80];
+ av_strerror(err, errstr, 80);
+ hb_error("av_read_frame error (%d): %s", err, errstr);
+ hb_set_work_error(stream->h, HB_ERROR_READ);
+ }
return NULL;
+ }
}
if ( stream->ffmpeg_pkt->stream_index == stream->ffmpeg_video_id )
{