diff options
author | maxd <[email protected]> | 2013-11-05 13:46:42 +0000 |
---|---|---|
committer | maxd <[email protected]> | 2013-11-05 13:46:42 +0000 |
commit | e7fa5d24cdd7275611ed738e3dfc909fe30ad317 (patch) | |
tree | f0478754e3d930d44782e313c3fa21cb465f6b22 | |
parent | a89397c1e3358b5f690b046481388ade19316fda (diff) |
RB626: return code support added
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5876 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/common.h | 16 | ||||
-rw-r--r-- | libhb/enc_qsv.c | 2 | ||||
-rw-r--r-- | libhb/encfaac.c | 2 | ||||
-rw-r--r-- | libhb/enctheora.c | 5 | ||||
-rw-r--r-- | libhb/encvorbis.c | 3 | ||||
-rw-r--r-- | libhb/hb.c | 1 | ||||
-rw-r--r-- | libhb/muxavformat.c | 3 | ||||
-rw-r--r-- | libhb/muxcommon.c | 1 | ||||
-rw-r--r-- | libhb/muxmkv.c | 8 | ||||
-rw-r--r-- | libhb/muxmp4.c | 16 | ||||
-rw-r--r-- | libhb/platform/macosx/encca_aac.c | 1 | ||||
-rw-r--r-- | libhb/work.c | 8 | ||||
-rw-r--r-- | test/test.c | 11 |
13 files changed, 68 insertions, 9 deletions
diff --git a/libhb/common.h b/libhb/common.h index 9244c981c..eed194cd7 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -101,6 +101,14 @@ typedef struct hb_filter_object_s hb_filter_object_t; typedef struct hb_buffer_s hb_buffer_t; typedef struct hb_fifo_s hb_fifo_t; 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_code; #include "ports.h" #ifdef __LIBHB__ @@ -553,6 +561,7 @@ struct hb_job_s /* Internal data */ hb_handle_t * h; hb_lock_t * pause; + volatile hb_error_code * done_error; volatile int * die; volatile int done; @@ -954,10 +963,7 @@ struct hb_state_s struct { /* HB_STATE_WORKDONE */ -#define HB_ERROR_NONE 0 -#define HB_ERROR_CANCELED 1 -#define HB_ERROR_UNKNOWN 2 - int error; + hb_error_code error; } workdone; struct @@ -1115,7 +1121,7 @@ int hb_use_dxva( hb_title_t * title ); #define OCLCHECK( method, ... )\ status = method( __VA_ARGS__ ); if( status != CL_SUCCESS ) {\ - printf( # method " error '%d'\n", status ); return status; } + hb_error("%s:%d (%s) error: %d\n", __FUNCTION__, __LINE__, #method, status); return status; } #define CL_FREE( buf )\ {\ diff --git a/libhb/enc_qsv.c b/libhb/enc_qsv.c index b45fe162e..9ddfeb5a8 100644 --- a/libhb/enc_qsv.c +++ b/libhb/enc_qsv.c @@ -263,6 +263,7 @@ int qsv_enc_init(av_qsv_context *qsv, hb_work_private_t *pv) if (sts < MFX_ERR_NONE) // ignore warnings { hb_error("qsv_enc_init: MFXVideoENCODE_QueryIOSurf failed (%d)", sts); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return -1; } @@ -320,6 +321,7 @@ int qsv_enc_init(av_qsv_context *qsv, hb_work_private_t *pv) if (sts < MFX_ERR_NONE) // ignore warnings { hb_error("qsv_enc_init: MFXVideoENCODE_Init failed (%d)", sts); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return -1; } diff --git a/libhb/encfaac.c b/libhb/encfaac.c index 551a7ea01..02b56cff9 100644 --- a/libhb/encfaac.c +++ b/libhb/encfaac.c @@ -116,6 +116,7 @@ int encfaacInit( hb_work_object_t * w, hb_job_t * job ) if( !faacEncSetConfiguration( pv->faac, cfg ) ) { hb_log( "faacEncSetConfiguration failed" ); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -123,6 +124,7 @@ int encfaacInit( hb_work_object_t * w, hb_job_t * job ) if( faacEncGetDecoderSpecificInfo( pv->faac, &bytes, &length ) < 0 ) { hb_log( "faacEncGetDecoderSpecificInfo failed" ); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } diff --git a/libhb/enctheora.c b/libhb/enctheora.c index d398f7717..48d130479 100644 --- a/libhb/enctheora.c +++ b/libhb/enctheora.c @@ -273,6 +273,7 @@ int enctheoraWork( hb_work_object_t * w, hb_buffer_t ** buf_in, if( bytes < 0 ) { hb_error("Error requesting stats size in second pass."); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return HB_WORK_DONE; } @@ -291,6 +292,7 @@ int enctheoraWork( hb_work_object_t * w, hb_buffer_t ** buf_in, fread( pv->stat_buf+pv->stat_fill, 1, size, pv->file ) < size ) { hb_error("Could not read frame data from two-pass data file!"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return HB_WORK_DONE; } @@ -304,6 +306,7 @@ int enctheoraWork( hb_work_object_t * w, hb_buffer_t ** buf_in, if( ret < 0 ) { hb_error("Error submitting pass data in second pass."); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return HB_WORK_DONE; } @@ -349,12 +352,14 @@ int enctheoraWork( hb_work_object_t * w, hb_buffer_t ** buf_in, if( bytes < 0 ) { fprintf(stderr,"Could not read two-pass data from encoder.\n"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return HB_WORK_DONE; } if( fwrite( buffer, 1, bytes, pv->file ) < bytes) { fprintf(stderr,"Unable to write to two-pass data file.\n"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return HB_WORK_DONE; } diff --git a/libhb/encvorbis.c b/libhb/encvorbis.c index c81b44d76..4d062c2c6 100644 --- a/libhb/encvorbis.c +++ b/libhb/encvorbis.c @@ -77,6 +77,7 @@ int encvorbisInit(hb_work_object_t *w, hb_job_t *job) audio->config.out.bitrate * 1000, -1)) { hb_error("encvorbis: vorbis_encode_setup_managed() failed"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return -1; } @@ -89,6 +90,7 @@ int encvorbisInit(hb_work_object_t *w, hb_job_t *job) audio->config.out.quality / 10)) { hb_error("encvorbis: vorbis_encode_setup_vbr() failed"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return -1; } @@ -98,6 +100,7 @@ int encvorbisInit(hb_work_object_t *w, hb_job_t *job) vorbis_encode_setup_init(&pv->vi)) { hb_error("encvorbis: vorbis_encode_ctl(ratemanage2_set) OR vorbis_encode_setup_init() failed"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return -1; } diff --git a/libhb/hb.c b/libhb/hb.c index 21f38a186..857ffa1d2 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -1499,6 +1499,7 @@ void hb_start( hb_handle_t * h ) h->paused = 0; h->work_die = 0; + h->work_error = HB_ERROR_NONE; h->work_thread = hb_work_init( h->jobs, &h->work_die, &h->work_error, &h->current_job ); } diff --git a/libhb/muxavformat.c b/libhb/muxavformat.c index 1121a352a..6aeb5122e 100644 --- a/libhb/muxavformat.c +++ b/libhb/muxavformat.c @@ -890,6 +890,7 @@ error: free(job->mux_data); job->mux_data = NULL; avformat_free_context(m->oc); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return -1; } @@ -1098,6 +1099,7 @@ static int avformatMux(hb_mux_object_t *m, hb_mux_data_t *track, hb_buffer_t *bu if (ret < 0) { hb_error("av_interleaved_write_frame failed!"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return -1; } @@ -1144,6 +1146,7 @@ static int avformatMux(hb_mux_object_t *m, hb_mux_data_t *track, hb_buffer_t *bu if (ret < 0 || m->oc->pb->error != 0) { hb_error("av_interleaved_write_frame failed!"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return -1; } diff --git a/libhb/muxcommon.c b/libhb/muxcommon.c index 91b83a7bb..b085bd769 100644 --- a/libhb/muxcommon.c +++ b/libhb/muxcommon.c @@ -477,6 +477,7 @@ hb_work_object_t * hb_muxer_init( hb_job_t * job ) #endif default: hb_error( "No muxer selected, exiting" ); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return NULL; } diff --git a/libhb/muxmkv.c b/libhb/muxmkv.c index 0a4cdd951..242415200 100644 --- a/libhb/muxmkv.c +++ b/libhb/muxmkv.c @@ -125,6 +125,7 @@ static int MKVInit( hb_mux_object_t * m ) { hb_error("Could not convert string, out of memory?"); job->mux_data = NULL; + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -136,6 +137,7 @@ static int MKVInit( hb_mux_object_t * m ) { hb_error( "Could not create output file, Disk Full?" ); job->mux_data = NULL; + *job->done_error = HB_ERROR_INIT; *job->die = 1; free(track); return 0; @@ -201,6 +203,7 @@ static int MKVInit( hb_mux_object_t * m ) } break; default: + *job->done_error = HB_ERROR_WRONG_INPUT; *job->die = 1; hb_error("muxmkv: Unknown video codec: %x", job->vcodec); free(track); @@ -310,6 +313,7 @@ static int MKVInit( hb_mux_object_t * m ) track->codecID = MK_ACODEC_AAC; break; default: + *job->done_error = HB_ERROR_WRONG_INPUT; *job->die = 1; hb_error("muxmkv: Unknown audio codec: %x", audio->config.out.codec); return 0; @@ -468,6 +472,7 @@ static int MKVInit( hb_mux_object_t * m ) if( mk_writeHeader( m->file, "HandBrake " HB_PROJECT_VERSION) < 0 ) { hb_error( "Failed to write to output file, disk full?"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; } if (track != NULL) @@ -523,6 +528,7 @@ static int MKVMux(hb_mux_object_t *m, hb_mux_data_t *mux_data, hb_buffer_t *buf) if( mk_startFrame(m->file, mux_data->track) < 0) { hb_error("Failed to write frame to output file, Disk Full?"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } uint64_t duration; @@ -548,6 +554,7 @@ static int MKVMux(hb_mux_object_t *m, hb_mux_data_t *mux_data, hb_buffer_t *buf) if( mk_startFrame(m->file, mux_data->track) < 0) { hb_error( "Failed to write frame to output file, Disk Full?" ); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } mk_addFrameData(m->file, mux_data->track, buf->data, buf->size); @@ -682,6 +689,7 @@ static int MKVEnd(hb_mux_object_t *m) if( mk_close(m->file) < 0 ) { hb_error( "Failed to flush the last frame and close the output file, Disk Full?" ); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c index ee082ac8b..4cc9d5d0f 100644 --- a/libhb/muxmp4.c +++ b/libhb/muxmp4.c @@ -66,6 +66,7 @@ static int MP4TuneTrackDurationPerChunk( hb_mux_object_t* m, MP4TrackId trackId if( !MP4SetTrackDurationPerChunk( m->file, trackId, dur )) { hb_error( "muxmp4.c: MP4SetTrackDurationPerChunk failed!" ); + *m->job->done_error = HB_ERROR_UNKNOWN; *m->job->die = 1; return 0; } @@ -111,6 +112,7 @@ static int MP4Init( hb_mux_object_t * m ) if (m->path == NULL) { hb_error("Could not convert string, out of memory?"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -131,6 +133,7 @@ static int MP4Init( hb_mux_object_t * m ) if (m->file == MP4_INVALID_FILE_HANDLE) { hb_error("muxmp4.c: MP4Create failed!"); + *job->done_error = HB_ERROR_WRONG_INPUT; *job->die = 1; return 0; } @@ -142,6 +145,7 @@ static int MP4Init( hb_mux_object_t * m ) if (!(MP4SetTimeScale( m->file, 90000 ))) { hb_error("muxmp4.c: MP4SetTimeScale failed!"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -159,6 +163,7 @@ static int MP4Init( hb_mux_object_t * m ) if ( mux_data->track == MP4_INVALID_TRACK_ID ) { hb_error( "muxmp4.c: MP4AddH264VideoTrack failed!" ); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -189,6 +194,7 @@ static int MP4Init( hb_mux_object_t * m ) if (mux_data->track == MP4_INVALID_TRACK_ID) { hb_error("muxmp4.c: MP4AddVideoTrack failed!"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -204,6 +210,7 @@ static int MP4Init( hb_mux_object_t * m ) job->config.mpeg4.bytes, job->config.mpeg4.length ))) { hb_error("muxmp4.c: MP4SetTrackESConfiguration failed!"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -216,6 +223,7 @@ static int MP4Init( hb_mux_object_t * m ) if (mux_data->track == MP4_INVALID_TRACK_ID) { hb_error("muxmp4.c: MP4AddVideoTrack failed!"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -231,6 +239,7 @@ static int MP4Init( hb_mux_object_t * m ) job->config.mpeg4.bytes, job->config.mpeg4.length ))) { hb_error("muxmp4.c: MP4SetTrackESConfiguration failed!"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -630,6 +639,7 @@ static int MP4Init( hb_mux_object_t * m ) (uint8_t*)palette, 16 * 4 ))) { hb_error("muxmp4.c: MP4SetTrackESConfiguration failed!"); + *job->done_error = HB_ERROR_INIT; *job->die = 1; return 0; } @@ -890,6 +900,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, dflags )) { hb_error("Failed to write to output file, disk full?"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } } @@ -930,6 +941,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, 1 )) { hb_error("Failed to write to output file, disk full?"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } mux_data->sum_dur += buf->s.start - mux_data->sum_dur; @@ -971,6 +983,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, 1 )) { hb_error("Failed to write to output file, disk full?"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } @@ -992,6 +1005,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, 1 )) { hb_error("Failed to write to output file, disk full?"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } mux_data->sum_dur += buf->s.start - mux_data->sum_dur; @@ -1005,6 +1019,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, 1 )) { hb_error("Failed to write to output file, disk full?"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } @@ -1025,6 +1040,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data, ( buf->s.frametype & HB_FRAME_KEY ) != 0 )) { hb_error("Failed to write to output file, disk full?"); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; } } diff --git a/libhb/platform/macosx/encca_aac.c b/libhb/platform/macosx/encca_aac.c index a5c7488a5..ded8205f7 100644 --- a/libhb/platform/macosx/encca_aac.c +++ b/libhb/platform/macosx/encca_aac.c @@ -200,6 +200,7 @@ int encCoreAudioInit(hb_work_object_t *w, hb_job_t *job, enum AAC_MODE mode) { hb_log("Error creating an AudioConverter err=%"PRId64" output.mBytesPerFrame=%"PRIu64"", (int64_t)err, (uint64_t)output.mBytesPerFrame); + *job->done_error = HB_ERROR_UNKNOWN; *job->die = 1; return -1; } diff --git a/libhb/work.c b/libhb/work.c index bdf2191ea..b63925359 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -91,14 +91,13 @@ static void work_func( void * _work ) { hb_list_rem( work->jobs, job ); job->die = work->die; + job->done_error = work->error; *(work->current_job) = job; InitWorkState( job->h ); do_job( job ); *(work->current_job) = NULL; } - *(work->error) = HB_ERROR_NONE; - free( work ); } @@ -1264,6 +1263,7 @@ static void do_job(hb_job_t *job) if ( ( w = hb_codec_decoder( audio->config.in.codec ) ) == NULL ) { hb_error("Invalid input codec: %d", audio->config.in.codec); + *job->done_error = HB_ERROR_WRONG_INPUT; *job->die = 1; goto cleanup; } @@ -1288,6 +1288,7 @@ static void do_job(hb_job_t *job) { hb_error("Invalid audio codec: %#x", audio->config.out.codec); w = NULL; + *job->done_error = HB_ERROR_WRONG_INPUT; *job->die = 1; goto cleanup; } @@ -1314,6 +1315,7 @@ static void do_job(hb_job_t *job) if ( reader->init( reader, job ) ) { hb_error( "Failure to initialise thread '%s'", reader->name ); + *job->done_error = HB_ERROR_INIT; *job->die = 1; goto cleanup; } @@ -1350,6 +1352,7 @@ static void do_job(hb_job_t *job) if( w->init( w, job ) ) { hb_error( "Failure to initialise thread '%s'", w->name ); + *job->done_error = HB_ERROR_INIT; *job->die = 1; goto cleanup; } @@ -1370,6 +1373,7 @@ static void do_job(hb_job_t *job) if( sync->init( w, job ) ) { hb_error( "Failure to initialise thread '%s'", w->name ); + *job->done_error = HB_ERROR_INIT; *job->die = 1; goto cleanup; } diff --git a/test/test.c b/test/test.c index fa67f6a95..d4c739b6d 100644 --- a/test/test.c +++ b/test/test.c @@ -147,6 +147,7 @@ static const char *qsv_preset = NULL; #endif /* Exit cleanly on Ctrl-C */ +static volatile hb_error_code done_error = HB_ERROR_NONE; static volatile int die = 0; static void SigHandler( int ); @@ -318,6 +319,7 @@ int main( int argc, char ** argv ) case 0x03: /* ctrl-c */ case 'q': fprintf( stdout, "\nEncoding Quit by user command\n" ); + done_error = HB_ERROR_CANCELED; die = 1; break; case 'p': @@ -369,6 +371,7 @@ int main( int argc, char ** argv ) { case 'q': fprintf( stdout, "\nEncoding Quit by user command\n" ); + done_error = HB_ERROR_CANCELED; die = 1; break; case 'p': @@ -437,7 +440,7 @@ int main( int argc, char ** argv ) fprintf(stdout, "\n"); fprintf(stderr, "HandBrake has exited.\n"); - return 0; + return done_error; } static void PrintTitleInfo( hb_title_t * title, int feature ) @@ -696,6 +699,7 @@ static int HandleEvents( hb_handle_t * h ) { /* No valid title, stop right there */ fprintf( stderr, "No title found.\n" ); + done_error = HB_ERROR_WRONG_INPUT; die = 1; break; } @@ -732,6 +736,7 @@ static int HandleEvents( hb_handle_t * h ) if( main_feature_pos == -1 ) { fprintf( stderr, "No main feature title found.\n" ); + done_error = HB_ERROR_WRONG_INPUT; die = 1; break; } @@ -3003,6 +3008,7 @@ static int HandleEvents( hb_handle_t * h ) fprintf( stderr, "\nEncode failed (error %x).\n", p.error ); } + done_error = p.error; die = 1; break; #undef p @@ -3016,6 +3022,7 @@ static int HandleEvents( hb_handle_t * h ) static volatile int64_t i_die_date = 0; void SigHandler( int i_signal ) { + done_error = HB_ERROR_CANCELED; if( die == 0 ) { die = 1; @@ -3026,7 +3033,7 @@ void SigHandler( int i_signal ) else if( i_die_date + 500 < hb_get_date() ) { fprintf( stderr, "Dying badly, files might remain in your /tmp\n" ); - exit( 1 ); + exit( done_error ); } } |