summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorhandbrake <[email protected]>2006-01-14 13:24:23 +0000
committerhandbrake <[email protected]>2006-01-14 13:24:23 +0000
commit951be4e0b69aa652c992124025c862c4f1660937 (patch)
tree82935838e945a8aad290741b71aeeecc09058184 /core
parentdc8de40de13c3f3e643b980a95ef48ccafb542e3 (diff)
HandBrake 0.6.0-test2
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@11 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'core')
-rw-r--r--core/AviMux.c25
-rw-r--r--core/DVDRead.c10
-rw-r--r--core/FfmpegEnc.c3
-rw-r--r--core/Fifo.c30
-rw-r--r--core/Fifo.h5
-rw-r--r--core/Mp4Mux.c25
-rw-r--r--core/Thread.c64
-rw-r--r--core/Thread.h22
-rw-r--r--core/XvidEnc.c42
9 files changed, 162 insertions, 64 deletions
diff --git a/core/AviMux.c b/core/AviMux.c
index 71238425e..e106f8383 100644
--- a/core/AviMux.c
+++ b/core/AviMux.c
@@ -1,4 +1,4 @@
-/* $Id: AviMux.c,v 1.15 2004/02/18 17:07:20 titer Exp $
+/* $Id: AviMux.c,v 1.16 2004/02/18 19:36:35 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -162,15 +162,20 @@ void HBAviMuxClose( HBAviMux ** _a )
HBThreadClose( &a->thread );
file = fopen( a->title->file, "r" );
- fseek( file, 0, SEEK_END );
- size = ftell( file );
- fclose( file );
-
- HBLog( "HBAviMux: videoFrames=%lld, %lld bytes", videoFrames, videoBytes );
- HBLog( "HBAviMux: audioFrames=%lld, %lld bytes", audioFrames, audioBytes );
- HBLog( "HBAviMux: overhead=%.2f bytes / frame",
- ( (float) size - videoBytes - audioBytes ) /
- ( videoFrames + audioFrames ) );
+ if( file )
+ {
+ fseek( file, 0, SEEK_END );
+ size = ftell( file );
+ fclose( file );
+
+ HBLog( "HBAviMux: videoFrames=%lld, %lld bytes",
+ videoFrames, videoBytes );
+ HBLog( "HBAviMux: audioFrames=%lld, %lld bytes",
+ audioFrames, audioBytes );
+ HBLog( "HBAviMux: overhead=%.2f bytes / frame",
+ ( (float) size - videoBytes - audioBytes ) /
+ ( videoFrames + audioFrames ) );
+ }
free( a );
diff --git a/core/DVDRead.c b/core/DVDRead.c
index f90660948..08e5139f8 100644
--- a/core/DVDRead.c
+++ b/core/DVDRead.c
@@ -1,4 +1,4 @@
-/* $Id: DVDRead.c,v 1.9 2004/01/16 19:04:03 titer Exp $
+/* $Id: DVDRead.c,v 1.10 2004/02/29 11:21:34 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -89,7 +89,6 @@ static void DVDReadThread( void * _d )
HBDVDRead * d = (HBDVDRead*) _d;
HBTitle * title = d->title;
- uint8_t dummy[DVD_VIDEO_LB_LEN];
int i;
/* Open the device */
@@ -107,15 +106,12 @@ static void DVDReadThread( void * _d )
d->endPosition = dvdplay_title_end( d->vmg );
HBLog( "HBDVDRead: starting, blocks: %d to %d",
- d->beginPosition, d->endPosition );
-
- /* Lalala */
- dvdplay_read( d->vmg, dummy, 1 );
+ d->beginPosition, d->endPosition );
/* Do the job */
for( i = 0; i < ( title->twoPass ? 2 : 1 ); i++ )
{
- dvdplay_seek( d->vmg, 0 );
+ dvdplay_start( d->vmg, title->index );
HBLog( "HBDVDRead: starting pass %d of %d", i + 1,
title->twoPass ? 2 : 1 );
diff --git a/core/FfmpegEnc.c b/core/FfmpegEnc.c
index 4028dc5fb..7d909a7a3 100644
--- a/core/FfmpegEnc.c
+++ b/core/FfmpegEnc.c
@@ -1,4 +1,4 @@
-/* $Id: FfmpegEnc.c,v 1.18 2004/01/21 17:59:33 titer Exp $
+/* $Id: FfmpegEnc.c,v 1.19 2004/03/01 21:36:36 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -275,6 +275,7 @@ static void CloseAvcodec( HBFfmpegEnc * f )
if( f->title->esConfig )
{
free( f->title->esConfig );
+ f->title->esConfig = NULL;
f->title->esConfigLength = 0;
}
}
diff --git a/core/Fifo.c b/core/Fifo.c
index af6d90cfe..06aed08cb 100644
--- a/core/Fifo.c
+++ b/core/Fifo.c
@@ -1,4 +1,4 @@
-/* $Id: Fifo.c,v 1.8 2004/01/16 19:04:03 titer Exp $
+/* $Id: Fifo.c,v 1.9 2004/02/24 21:55:53 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -18,12 +18,25 @@ HBBuffer * HBBufferInit( int size )
b->alloc = size;
b->size = size;
- if( !( b->data = malloc( size ) ) )
+#if defined( HB_BEOS ) || defined( HB_LINUX )
+ if( !( b->data = memalign( 16, size ) ) )
{
HBLog( "HBBufferInit: malloc() failed, gonna crash" );
free( b );
return NULL;
}
+#elif defined( HB_MACOSX )
+ if( !( b->dataOrig = malloc( size + 15 ) ) )
+ {
+ HBLog( "HBBufferInit: malloc() failed, gonna crash" );
+ free( b );
+ return NULL;
+ }
+ b->data = b->dataOrig + 15;
+ b->data -= (long) b->data & 15;
+#elif defined( HB_CYGWIN )
+ /* TODO */
+#endif
b->position = 0.0;
@@ -33,7 +46,14 @@ HBBuffer * HBBufferInit( int size )
void HBBufferReAlloc( HBBuffer * b, int size )
{
b->alloc = size;
+#if defined( HB_BEOS ) || defined( HB_LINUX )
b->data = realloc( b->data, size );
+#elif defined( HB_MACOSX )
+ b->dataOrig = realloc( b->dataOrig, size );
+ b->data = b->dataOrig;
+#elif defined( HB_CYGWIN )
+ /* TODO */
+#endif
if( !b->data )
{
@@ -45,7 +65,13 @@ void HBBufferClose( HBBuffer ** _b )
{
HBBuffer * b = *_b;
+#if defined( HB_BEOS ) || defined( HB_LINUX )
free( b->data );
+#elif defined( HB_MACOSX )
+ free( b->dataOrig );
+#elif defined( HB_CYGWIN )
+ /* TODO */
+#endif
free( b );
*_b = NULL;
diff --git a/core/Fifo.h b/core/Fifo.h
index d9240fb25..daca41d0e 100644
--- a/core/Fifo.h
+++ b/core/Fifo.h
@@ -1,4 +1,4 @@
-/* $Id: Fifo.h,v 1.10 2004/01/16 19:04:04 titer Exp $
+/* $Id: Fifo.h,v 1.11 2004/02/24 21:55:53 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -16,6 +16,9 @@ struct HBBuffer
int alloc;
int size;
uint8_t * data;
+#if defined( HB_MACOSX )
+ uint8_t * dataOrig;
+#endif
float position;
int pass;
diff --git a/core/Mp4Mux.c b/core/Mp4Mux.c
index f780cab01..e1b8e9e64 100644
--- a/core/Mp4Mux.c
+++ b/core/Mp4Mux.c
@@ -1,4 +1,4 @@
-/* $Id: Mp4Mux.c,v 1.22 2004/02/18 17:07:20 titer Exp $
+/* $Id: Mp4Mux.c,v 1.23 2004/02/18 19:36:35 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -59,15 +59,20 @@ void HBMp4MuxClose( HBMp4Mux ** _m )
HBThreadClose( &m->thread );
file = fopen( m->title->file, "r" );
- fseek( file, 0, SEEK_END );
- size = ftell( file );
- fclose( file );
-
- HBLog( "HBMp4Mux: videoFrames=%lld, %lld bytes", videoFrames, videoBytes );
- HBLog( "HBMp4Mux: audioFrames=%lld, %lld bytes", audioFrames, audioBytes );
- HBLog( "HBMp4Mux: overhead=%.2f bytes / frame",
- ( (float) size - videoBytes - audioBytes ) /
- ( videoFrames + audioFrames ) );
+ if( file )
+ {
+ fseek( file, 0, SEEK_END );
+ size = ftell( file );
+ fclose( file );
+
+ HBLog( "HBMp4Mux: videoFrames=%lld, %lld bytes",
+ videoFrames, videoBytes );
+ HBLog( "HBMp4Mux: audioFrames=%lld, %lld bytes",
+ audioFrames, audioBytes );
+ HBLog( "HBMp4Mux: overhead=%.2f bytes / frame",
+ ( (float) size - videoBytes - audioBytes ) /
+ ( videoFrames + audioFrames ) );
+ }
free( m );
diff --git a/core/Thread.c b/core/Thread.c
index 01af1b0b6..413ff8b6e 100644
--- a/core/Thread.c
+++ b/core/Thread.c
@@ -1,4 +1,4 @@
-/* $Id: Thread.c,v 1.10 2004/01/14 21:37:25 titer Exp $
+/* $Id: Thread.c,v 1.11 2004/02/19 17:59:13 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -6,13 +6,22 @@
#include "Thread.h"
+/**********************************************************************
+ * HBThread implementation
+ **********************************************************************/
struct HBThread
{
+ /* User-friendly name */
char * name;
+
+ /* HB_(LOW|NORMAL)_PRIORITY */
int priority;
+
+ /* Thread function and argument */
void (*function) ( void * );
void * arg;
+ /* OS-specific thread id */
#if defined( HB_BEOS )
int thread;
#elif defined( HB_MACOSX ) || defined( HB_LINUX )
@@ -22,23 +31,45 @@ struct HBThread
#endif
};
-static void ThreadFunc( void * t );
+/* HBThreadInit actually starts this routine because
+ pthread_setschedparam() might fail if called from an external
+ thread (typically, because the thread exited immediatly. This isn't
+ really necessary, but I find it nicer that way */
+static void ThreadFunc( void * _t )
+{
+ HBThread * t = (HBThread*) _t;
+
+#if defined( HB_MACOSX )
+ /* Set the thread priority */
+ struct sched_param param;
+ memset( &param, 0, sizeof( struct sched_param ) );
+ param.sched_priority = t->priority;
+ if( pthread_setschedparam( pthread_self(), SCHED_OTHER, &param ) )
+ {
+ HBLog( "HBThreadInit: couldn't set thread priority" );
+ }
+#endif
+
+ /* Start the real routine */
+ t->function( t->arg );
+}
HBThread * HBThreadInit( char * name, void (* function)(void *),
void * arg, int priority )
{
+ /* Initializations */
HBThread * t;
if( !( t = malloc( sizeof( HBThread ) ) ) )
{
HBLog( "HBThreadInit: malloc() failed, gonna crash" );
return NULL;
}
-
t->name = strdup( name );
t->priority = priority;
t->function = function;
t->arg = arg;
+ /* Create and start the thread */
#if defined( HB_BEOS )
t->thread = spawn_thread( (int32 (*)( void * )) ThreadFunc,
name, priority, t );
@@ -57,27 +88,11 @@ HBThread * HBThreadInit( char * name, void (* function)(void *),
return t;
}
-static void ThreadFunc( void * _t )
-{
- HBThread * t = (HBThread*) _t;
-
-#if defined( HB_MACOSX )
- struct sched_param param;
- memset( &param, 0, sizeof( struct sched_param ) );
- param.sched_priority = t->priority;
- if( pthread_setschedparam( pthread_self(), SCHED_OTHER, &param ) )
- {
- HBLog( "HBThreadInit: couldn't set thread priority" );
- }
-#endif
-
- t->function( t->arg );
-}
-
void HBThreadClose( HBThread ** _t )
{
HBThread * t = *_t;
+ /* Join the thread */
#if defined( HB_BEOS )
long exitValue;
wait_for_thread( t->thread, &exitValue );
@@ -90,11 +105,16 @@ void HBThreadClose( HBThread ** _t )
HBLog( "HBThreadClose: thread %d stopped (\"%s\")",
t->thread, t->name );
+ /* Clean up */
free( t->name );
free( t );
*_t = NULL;
}
+
+/**********************************************************************
+ * HBLock implementation
+ **********************************************************************/
HBLock * HBLockInit()
{
HBLock * l;
@@ -131,6 +151,10 @@ void HBLockClose( HBLock ** _l )
*_l = NULL;
}
+
+/**********************************************************************
+ * HBCond implementation
+ **********************************************************************/
HBCond * HBCondInit()
{
HBCond * c = malloc( sizeof( HBCond ) );
diff --git a/core/Thread.h b/core/Thread.h
index 4d6288e5b..7f975d84b 100644
--- a/core/Thread.h
+++ b/core/Thread.h
@@ -1,4 +1,4 @@
-/* $Id: Thread.h,v 1.8 2004/01/14 21:37:25 titer Exp $
+/* $Id: Thread.h,v 1.9 2004/02/19 17:59:13 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -31,10 +31,13 @@
# define HB_NORMAL_PRIORITY 0
#endif
-/* Functions declarations */
-HBThread * HBThreadInit( char * name, void (* function)(void *),
- void * arg, int priority );
-void HBThreadClose( HBThread ** );
+/**********************************************************************
+ * HBThread/HBLock/HBCond declarations
+ **********************************************************************/
+HBThread * HBThreadInit( char * name,
+ void (* function)(void *),
+ void * arg, int priority );
+void HBThreadClose( HBThread ** );
HBLock * HBLockInit();
static inline void HBLockLock( HBLock * );
@@ -46,7 +49,10 @@ static inline void HBCondWait( HBCond *, HBLock * );
static inline void HBCondSignal( HBCond * );
void HBCondClose( HBCond ** );
-/* Inlined stuff */
+
+/**********************************************************************
+ * HBLock implementation (inline functions)
+ **********************************************************************/
struct HBLock
{
#if defined( HB_BEOS )
@@ -80,6 +86,10 @@ static inline void HBLockUnlock( HBLock * l )
#endif
}
+
+/**********************************************************************
+ * HBCond implementation (inline functions)
+ **********************************************************************/
struct HBCond
{
#if defined( HB_BEOS )
diff --git a/core/XvidEnc.c b/core/XvidEnc.c
index fe9e8ddbc..8bf841f36 100644
--- a/core/XvidEnc.c
+++ b/core/XvidEnc.c
@@ -1,4 +1,4 @@
-/* $Id: XvidEnc.c,v 1.18 2004/01/08 22:02:29 titer Exp $
+/* $Id: XvidEnc.c,v 1.20 2004/03/01 21:36:36 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -65,6 +65,12 @@ void HBXvidEncClose( HBWork ** _x )
x->pass );
xvid_encore( x->xvid, XVID_ENC_DESTROY, NULL, NULL);
}
+ if( x->title->esConfig )
+ {
+ free( x->title->esConfig );
+ x->title->esConfig = NULL;
+ x->title->esConfigLength = 0;
+ }
if( x->frames )
{
float bitrate = (float) x->bytes * x->title->rate / x->frames /
@@ -138,11 +144,10 @@ static int XvidEncWork( HBWork * w )
{
HBLog( "HBXvidEnc: closing libxvidcore (pass %d)",
x->pass );
-
xvid_encore( x->xvid, XVID_ENC_DESTROY, NULL, NULL);
}
- x->pass = scaledBuffer->pass;;
+ x->pass = scaledBuffer->pass;
HBLog( "HBXvidEnc: opening libxvidcore (pass %d)", x->pass );
memset( &xvid_gbl_init, 0, sizeof( xvid_gbl_init ) );
@@ -242,10 +247,33 @@ static int XvidEncWork( HBWork * w )
{
if( !title->esConfig )
{
- /* KLUDGE */
- title->esConfig = malloc( 15 );
- title->esConfigLength = 15;
- memcpy( title->esConfig, mpeg4Buffer->data + 4, 15 );
+ int volStart, vopStart;
+ for( volStart = 0; ; volStart++ )
+ {
+ if( mpeg4Buffer->data[volStart] == 0x0 &&
+ mpeg4Buffer->data[volStart+1] == 0x0 &&
+ mpeg4Buffer->data[volStart+2] == 0x1 &&
+ mpeg4Buffer->data[volStart+3] == 0x20 )
+ {
+ break;
+ }
+ }
+ for( vopStart = volStart + 4; ; vopStart++ )
+ {
+ if( mpeg4Buffer->data[vopStart] == 0x0 &&
+ mpeg4Buffer->data[vopStart+1] == 0x0 &&
+ mpeg4Buffer->data[vopStart+2] == 0x1 &&
+ mpeg4Buffer->data[vopStart+3] == 0xB6 )
+ {
+ break;
+ }
+ }
+
+ HBLog( "XvidEnc: VOL size is %d bytes", vopStart - volStart );
+ title->esConfig = malloc( vopStart - volStart );
+ title->esConfigLength = vopStart - volStart;
+ memcpy( title->esConfig, mpeg4Buffer->data + volStart,
+ vopStart - volStart );
}
x->frames++;
x->bytes += mpeg4Buffer->size;