diff options
author | handbrake <[email protected]> | 2006-01-14 12:49:29 +0000 |
---|---|---|
committer | handbrake <[email protected]> | 2006-01-14 12:49:29 +0000 |
commit | 939b35fc70bb688d38b086afebd8d14d8193d2c9 (patch) | |
tree | b9c30b1dfae122ed4081a0dba8d392bb74121d46 | |
parent | d8e695069746e98fb763392943e4de4ad072a3b9 (diff) |
HandBrake 0.2
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | HBAc3Decoder.cpp | 22 | ||||
-rw-r--r-- | HBAc3Decoder.h | 6 | ||||
-rw-r--r-- | HBAviMuxer.cpp | 12 | ||||
-rw-r--r-- | HBFifo.cpp | 4 | ||||
-rw-r--r-- | HBMp3Encoder.cpp | 52 | ||||
-rw-r--r-- | HBMp3Encoder.h | 14 | ||||
-rw-r--r-- | HBPictureWin.cpp | 88 | ||||
-rw-r--r-- | HBWindow.cpp | 5 | ||||
-rw-r--r-- | Jamfile | 4 | ||||
-rw-r--r-- | NEWS | 6 |
10 files changed, 123 insertions, 90 deletions
diff --git a/HBAc3Decoder.cpp b/HBAc3Decoder.cpp index 81753d899..b78097746 100644 --- a/HBAc3Decoder.cpp +++ b/HBAc3Decoder.cpp @@ -1,4 +1,4 @@ -/* $Id: HBAc3Decoder.cpp,v 1.6 2003/08/24 15:03:41 titer Exp $ */ +/* $Id: HBAc3Decoder.cpp,v 1.7 2003/08/25 19:47:14 titer Exp $ */ #include "HBCommon.h" #include "HBAc3Decoder.h" @@ -12,12 +12,12 @@ extern "C" { HBAc3Decoder::HBAc3Decoder( HBManager * manager, HBAudioInfo * audioInfo ) : HBThread( "ac3decoder" ) { - fManager = manager; - fAudioInfo = audioInfo; + fManager = manager; + fAudioInfo = audioInfo; - fAc3Buffer = NULL; - fAc3Frame = NULL; - fPosInAc3Buffer = 0; + fAc3Buffer = NULL; + fAc3Frame = NULL; + fPosInBuffer = 0; } void HBAc3Decoder::DoWork() @@ -108,18 +108,18 @@ bool HBAc3Decoder::GetBytes( uint32_t size ) { return false; } - fPosInAc3Buffer = 0; + fPosInBuffer = 0; } int willCopy = MIN( size - fAc3Frame->fSize, - fAc3Buffer->fSize - fPosInAc3Buffer ); + fAc3Buffer->fSize - fPosInBuffer ); memcpy( fAc3Frame->fData + fAc3Frame->fSize, - fAc3Buffer->fData + fPosInAc3Buffer, + fAc3Buffer->fData + fPosInBuffer, willCopy ); fAc3Frame->fSize += willCopy; - fPosInAc3Buffer += willCopy; + fPosInBuffer += willCopy; - if( fAc3Buffer->fSize == fPosInAc3Buffer ) + if( fAc3Buffer->fSize == fPosInBuffer ) { delete fAc3Buffer; fAc3Buffer = NULL; diff --git a/HBAc3Decoder.h b/HBAc3Decoder.h index 75e7553da..f9d6ad678 100644 --- a/HBAc3Decoder.h +++ b/HBAc3Decoder.h @@ -1,4 +1,4 @@ -/* $Id: HBAc3Decoder.h,v 1.5 2003/08/24 15:03:41 titer Exp $ */ +/* $Id: HBAc3Decoder.h,v 1.6 2003/08/25 19:47:14 titer Exp $ */ #ifndef HB_AC3_DECODER_H #define HB_AC3_DECODER_H @@ -21,9 +21,9 @@ class HBAc3Decoder : public HBThread HBManager * fManager; HBAudioInfo * fAudioInfo; - HBBuffer * fAc3Buffer; HBBuffer * fAc3Frame; - uint32_t fPosInAc3Buffer; + HBBuffer * fAc3Buffer; + uint32_t fPosInBuffer; }; #endif diff --git a/HBAviMuxer.cpp b/HBAviMuxer.cpp index 8c5d42176..cbe2f9578 100644 --- a/HBAviMuxer.cpp +++ b/HBAviMuxer.cpp @@ -1,4 +1,4 @@ -/* $Id: HBAviMuxer.cpp,v 1.21 2003/08/24 13:34:18 titer Exp $ */ +/* $Id: HBAviMuxer.cpp,v 1.24 2003/08/26 18:44:06 titer Exp $ */ #include "HBCommon.h" #include "HBAviMuxer.h" @@ -136,7 +136,10 @@ bool HBAviMuxer::AddVideoChunk() if( fIndex->fSize + 16 > fIndex->fAllocSize ) { /* Realloc if needed */ - fIndex->ReAlloc( fIndex->fSize + 1024 * 1024 ); + Log( "HBAviMuxer::AddVideoChunk() : reallocing index (%d -> %d MB)", + fIndex->fAllocSize / ( 1024 * 1024 ), + 1 + fIndex->fAllocSize / ( 1024 * 1024 ) ); + fIndex->ReAlloc( fIndex->fAllocSize + 1024 * 1024 ); } uint32_t flags = buffer->fKeyFrame ? AVIIF_KEYFRAME : 0; @@ -226,7 +229,10 @@ bool HBAviMuxer::AddAudioChunk( int which ) if( fIndex->fSize + 16 > fIndex->fAllocSize ) { /* Realloc if needed */ - fIndex->ReAlloc( fIndex->fSize + 1024 * 1024 ); + Log( "HBAviMuxer::AddAudioChunk() : reallocing index (%d -> %d MB)", + fIndex->fAllocSize / ( 1024 * 1024 ), + 1 + fIndex->fAllocSize / ( 1024 * 1024 ) ); + fIndex->ReAlloc( fIndex->fAllocSize + 1024 * 1024 ); } uint32_t flags = buffer->fKeyFrame ? AVIIF_KEYFRAME : 0; diff --git a/HBFifo.cpp b/HBFifo.cpp index fd79f734a..b85361c56 100644 --- a/HBFifo.cpp +++ b/HBFifo.cpp @@ -1,4 +1,4 @@ -/* $Id: HBFifo.cpp,v 1.10 2003/08/24 13:27:41 titer Exp $ */ +/* $Id: HBFifo.cpp,v 1.11 2003/08/26 07:48:36 titer Exp $ */ #include "HBCommon.h" #include "HBFifo.h" @@ -25,7 +25,7 @@ HBBuffer::~HBBuffer() void HBBuffer::ReAlloc( int size ) { - realloc( fData, size ); + fData = (uint8_t*) realloc( fData, size ); if( !fData ) { diff --git a/HBMp3Encoder.cpp b/HBMp3Encoder.cpp index 8cddd7615..cff6d6d66 100644 --- a/HBMp3Encoder.cpp +++ b/HBMp3Encoder.cpp @@ -1,4 +1,4 @@ -/* $Id: HBMp3Encoder.cpp,v 1.5 2003/08/24 20:50:49 titer Exp $ */ +/* $Id: HBMp3Encoder.cpp,v 1.6 2003/08/25 20:41:51 titer Exp $ */ #include "HBCommon.h" #include "HBMp3Encoder.h" @@ -10,15 +10,20 @@ HBMp3Encoder::HBMp3Encoder( HBManager * manager, HBAudioInfo * audioInfo ) : HBThread( "mp3encoder" ) { - fManager = manager; - fAudioInfo = audioInfo; + fManager = manager; + fAudioInfo = audioInfo; - fRawBuffer = NULL; + fRawBuffer = NULL; + fPosInBuffer = 0; + fLeftSamples = NULL; + fRightSamples = NULL; } void HBMp3Encoder::DoWork() { - while( !fAudioInfo->fRawFifo->Size() ) + /* Wait a first buffer so we are sure that + fAudioInfo->fInSampleRate (set the AC3 decoder) is not garbage */ + while( !fDie && !fAudioInfo->fRawFifo->Size() ) { snooze( 5000 ); } @@ -30,27 +35,33 @@ void HBMp3Encoder::DoWork() never get more than 1 frame at a time */ uint32_t count = ( 1152 * fAudioInfo->fInSampleRate ) / ( 2 * fAudioInfo->fOutSampleRate ); - fLeftSamples = (float*) malloc( count * sizeof( float ) ); - fRightSamples = (float*) malloc( count * sizeof( float ) ); /* Init libmp3lame */ lame_global_flags * globalFlags = lame_init(); lame_set_in_samplerate( globalFlags, fAudioInfo->fInSampleRate ); lame_set_out_samplerate( globalFlags, fAudioInfo->fOutSampleRate ); lame_set_brate( globalFlags, fAudioInfo->fOutBitrate ); - lame_init_params( globalFlags ); + + if( lame_init_params( globalFlags ) == -1 ) + { + Log( "HBMp3Encoder::DoWork() : lame_init_params() failed" ); + fManager->Error(); + return; + } - HBBuffer * mp3Buffer; + fLeftSamples = (float*) malloc( count * sizeof( float ) ); + fRightSamples = (float*) malloc( count * sizeof( float ) ); + + HBBuffer * mp3Buffer = new HBBuffer( LAME_MAXMP3BUFFER ); int ret; while( !fDie ) { /* Get new samples */ if( !GetSamples( count ) ) { - break; + continue; } - mp3Buffer = new HBBuffer( LAME_MAXMP3BUFFER ); ret = lame_encode_buffer_float( globalFlags, fLeftSamples, fRightSamples, count, mp3Buffer->fData, @@ -60,22 +71,25 @@ void HBMp3Encoder::DoWork() { /* Something wrong happened */ Log( "HBMp3Encoder : lame_encode_buffer_float() failed (%d)", ret ); - delete mp3Buffer; fManager->Error(); break; } - else if( !ret ) - { - delete mp3Buffer; - } else if( ret > 0 ) { /* We got something, send it to the muxer */ mp3Buffer->fSize = ret; mp3Buffer->fKeyFrame = true; fAudioInfo->fMp3Fifo->Push( mp3Buffer ); + mp3Buffer = new HBBuffer( LAME_MAXMP3BUFFER ); } } + + /* Clean up */ + delete mp3Buffer; + free( fLeftSamples ); + free( fRightSamples ); + + lame_close( globalFlags ); } bool HBMp3Encoder::GetSamples( uint32_t count ) @@ -86,14 +100,18 @@ bool HBMp3Encoder::GetSamples( uint32_t count ) { if( !fRawBuffer ) { - if( !( fRawBuffer = fAudioInfo->fRawFifo->Pop() ) ) + fRawBuffer = fAudioInfo->fRawFifo->Pop(); + + if( !fRawBuffer ) { return false; } + fPosInBuffer = 0; } int willCopy = MIN( count - samplesNb, 6 * 256 - fPosInBuffer ); + memcpy( fLeftSamples + samplesNb, (float*) fRawBuffer->fData + fPosInBuffer, willCopy * sizeof( float ) ); diff --git a/HBMp3Encoder.h b/HBMp3Encoder.h index 02e385224..d8f6ce3f9 100644 --- a/HBMp3Encoder.h +++ b/HBMp3Encoder.h @@ -1,4 +1,4 @@ -/* $Id: HBMp3Encoder.h,v 1.3 2003/08/23 19:22:59 titer Exp $ */ +/* $Id: HBMp3Encoder.h,v 1.4 2003/08/25 20:41:51 titer Exp $ */ #ifndef HB_MP3_ENCODER_H #define HB_MP3_ENCODER_H @@ -18,13 +18,13 @@ class HBMp3Encoder : public HBThread void DoWork(); bool GetSamples( uint32_t count ); - HBManager * fManager; - HBAudioInfo * fAudioInfo; + HBManager * fManager; + HBAudioInfo * fAudioInfo; - HBBuffer * fRawBuffer; - uint32_t fPosInBuffer; /* in samples */ - float * fLeftSamples; - float * fRightSamples; + HBBuffer * fRawBuffer; + uint32_t fPosInBuffer; /* in samples */ + float * fLeftSamples; + float * fRightSamples; }; #endif diff --git a/HBPictureWin.cpp b/HBPictureWin.cpp index 9849af010..8fd9e8405 100644 --- a/HBPictureWin.cpp +++ b/HBPictureWin.cpp @@ -1,4 +1,4 @@ -/* $Id: HBPictureWin.cpp,v 1.14 2003/08/24 20:50:49 titer Exp $ */ +/* $Id: HBPictureWin.cpp,v 1.15 2003/08/25 21:50:48 titer Exp $ */ #include "HBCommon.h" #include "HBPictureWin.h" @@ -13,6 +13,20 @@ #define UPDATE_BITMAP 'upbi' +/* Handy way to access HBTitleInfo members */ +#define fInWidth fTitleInfo->fInWidth +#define fInHeight fTitleInfo->fInHeight +#define fPixelWidth fTitleInfo->fPixelWidth +#define fPixelHeight fTitleInfo->fPixelHeight +#define fDeinterlace fTitleInfo->fDeinterlace +#define fOutWidth fTitleInfo->fOutWidth +#define fOutHeight fTitleInfo->fOutHeight +#define fTopCrop fTitleInfo->fTopCrop +#define fBottomCrop fTitleInfo->fBottomCrop +#define fLeftCrop fTitleInfo->fLeftCrop +#define fRightCrop fTitleInfo->fRightCrop +#define fPictures fTitleInfo->fPictures + HBPictureView::HBPictureView( BRect rect, BBitmap * bitmap ) : BView( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW ) { @@ -28,7 +42,7 @@ void HBPictureView::Draw( BRect rect ) } else { - Log( "HBPictureView::Draw : LockLooper() failed" ); + Log( "HBPictureView::Draw() : LockLooper() failed" ); } BView::Draw( rect ); @@ -42,13 +56,14 @@ HBPictureWin::HBPictureWin( HBTitleInfo * titleInfo ) { fTitleInfo = titleInfo; - fMaxOutWidth = fTitleInfo->fInWidth; - fMaxOutHeight = MULTIPLE_16( fTitleInfo->fInHeight * fTitleInfo->fPixelHeight / - fTitleInfo->fPixelWidth ); - fBitmap = new BBitmap( BRect( 0, 0, fMaxOutWidth, fMaxOutHeight ), + fMaxOutWidth = MULTIPLE_16( fInWidth ); + fMaxOutHeight = MULTIPLE_16( fInHeight * fPixelHeight / fPixelWidth ); + + /* Leave a one-pixel margin to draw the white line around the picture */ + fBitmap = new BBitmap( BRect( 0, 0, fMaxOutWidth + 1, fMaxOutHeight + 1 ), 0, B_RGB32 ); - ResizeTo( fMaxOutWidth + 40, fMaxOutHeight + 330 ); + ResizeTo( fMaxOutWidth + 40, fMaxOutHeight + 331 ); BRect r; @@ -59,25 +74,25 @@ HBPictureWin::HBPictureWin( HBTitleInfo * titleInfo ) AddChild( view ); /* First box : picture + slider */ - r = BRect( 10, 10, fMaxOutWidth + 30, fMaxOutHeight + 65 ); + r = BRect( 10, 10, fMaxOutWidth + 31, fMaxOutHeight + 68 ); BBox * pictureBox; pictureBox = new BBox( r, NULL ); pictureBox->SetLabel( "Preview" ); /* Picture view */ - r = BRect( 10, 15, fMaxOutWidth + 10, fMaxOutHeight + 15 ); + r = BRect( 10, 15, fMaxOutWidth + 11, fMaxOutHeight + 16 ); fPictureView = new HBPictureView( r, fBitmap ); pictureBox->AddChild( fPictureView ); /* Slider */ - r = BRect( 10, fMaxOutHeight + 25, fMaxOutWidth + 10, fMaxOutHeight + 55 ); + r = BRect( 10, fMaxOutHeight + 26, fMaxOutWidth + 10, fMaxOutHeight + 56 ); fPictureSlider = new BSlider( r, NULL, NULL, new BMessage( UPDATE_BITMAP ), 0, 9 ); pictureBox->AddChild( fPictureSlider ); view->AddChild( pictureBox ); /* Second box : resize & crop settings */ - r = BRect( 10, fMaxOutHeight + 75, fMaxOutWidth + 30, fMaxOutHeight + 320 ); + r = BRect( 10, fMaxOutHeight + 76, fMaxOutWidth + 30, fMaxOutHeight + 321 ); BBox * settingsBox; settingsBox = new BBox( r, NULL ); settingsBox->SetLabel( "Settings" ); @@ -93,28 +108,28 @@ HBPictureWin::HBPictureWin( HBTitleInfo * titleInfo ) r = BRect( 10, 55, fMaxOutWidth + 10, 85 ); fTopCropSlider = new BSlider( r, NULL, "Top cropping", new BMessage( UPDATE_BITMAP ), - 0, fTitleInfo->fInHeight / 4, + 0, fInHeight / 4, B_TRIANGLE_THUMB ); settingsBox->AddChild( fTopCropSlider ); r = BRect( 10, 95, fMaxOutWidth + 10, 125 ); fBottomCropSlider = new BSlider( r, NULL, "Bottom cropping", new BMessage( UPDATE_BITMAP ), - 0, fTitleInfo->fInHeight / 4, + 0, fInHeight / 4, B_TRIANGLE_THUMB ); settingsBox->AddChild( fBottomCropSlider ); r = BRect( 10, 135, fMaxOutWidth + 10, 165 ); fLeftCropSlider = new BSlider( r, NULL, "Left cropping", new BMessage( UPDATE_BITMAP ), - 0, fTitleInfo->fInWidth / 4, + 0, fInWidth / 4, B_TRIANGLE_THUMB ); settingsBox->AddChild( fLeftCropSlider ); r = BRect( 10, 175, fMaxOutWidth + 10, 205 ); fRightCropSlider = new BSlider( r, NULL, "Right cropping", new BMessage( UPDATE_BITMAP ), - 0, fTitleInfo->fInWidth / 4, + 0, fInWidth / 4, B_TRIANGLE_THUMB ); settingsBox->AddChild( fRightCropSlider ); @@ -164,19 +179,6 @@ void HBPictureWin::MessageReceived( BMessage * message ) void HBPictureWin::UpdateBitmap( int which ) { -#define fInWidth fTitleInfo->fInWidth -#define fInHeight fTitleInfo->fInHeight -#define fPixelWidth fTitleInfo->fPixelWidth -#define fPixelHeight fTitleInfo->fPixelHeight -#define fDeinterlace fTitleInfo->fDeinterlace -#define fOutWidth fTitleInfo->fOutWidth -#define fOutHeight fTitleInfo->fOutHeight -#define fTopCrop fTitleInfo->fTopCrop -#define fBottomCrop fTitleInfo->fBottomCrop -#define fLeftCrop fTitleInfo->fLeftCrop -#define fRightCrop fTitleInfo->fRightCrop -#define fPictures fTitleInfo->fPictures - fTopCrop = 2 * fTopCropSlider->Value(); fBottomCrop = 2 * fBottomCropSlider->Value(); fLeftCrop = 2 * fLeftCropSlider->Value(); @@ -222,15 +224,15 @@ void HBPictureWin::UpdateBitmap( int which ) img_convert( &pic4, PIX_FMT_RGBA32, &pic3, PIX_FMT_YUV420P, fOutWidth, fOutHeight ); /* Blank the bitmap */ - for( uint32_t i = 0; i < fMaxOutHeight; i++ ) + for( uint32_t i = 0; i < fMaxOutHeight + 2; i++ ) { memset( (uint8_t*) fBitmap->Bits() + i * fBitmap->BytesPerRow(), - 0, fMaxOutWidth * 4 ); + 0, ( fMaxOutWidth + 2 ) * 4 ); } /* Draw the picture (centered) */ - uint32_t leftOffset = ( fMaxOutWidth - fOutWidth ) / 2; - uint32_t topOffset = ( fMaxOutHeight - fOutHeight ) / 2; + uint32_t leftOffset = 1 + ( fMaxOutWidth - fOutWidth ) / 2; + uint32_t topOffset = 1 + ( fMaxOutHeight - fOutHeight ) / 2; for( uint32_t i = 0; i < fOutHeight; i++ ) { memcpy( (uint8_t*) fBitmap->Bits() + @@ -242,30 +244,30 @@ void HBPictureWin::UpdateBitmap( int which ) /* Draw the cropping zone */ memset( (uint8_t*) fBitmap->Bits() + - topOffset * fBitmap->BytesPerRow() + - leftOffset * 4, + ( topOffset - 1 ) * fBitmap->BytesPerRow() + + ( leftOffset - 1 ) * 4, 0xFF, - fOutWidth * 4 ); + ( fOutWidth + 2 ) * 4 ); - for( uint32_t i = 0; i < fOutHeight; i++ ) + for( uint32_t i = 0; i < fOutHeight + 2; i++ ) { memset( (uint8_t*) fBitmap->Bits() + - ( i + topOffset ) * fBitmap->BytesPerRow() + - leftOffset * 4, + ( i + ( topOffset - 1 ) ) * fBitmap->BytesPerRow() + + ( leftOffset - 1 ) * 4, 0xFF, 4 ); memset( (uint8_t*) fBitmap->Bits() + - ( i + topOffset ) * fBitmap->BytesPerRow() + - ( leftOffset + fOutWidth - 1 ) * 4, + ( i + ( topOffset - 1 ) ) * fBitmap->BytesPerRow() + + ( leftOffset + fOutWidth ) * 4, 0xFF, 4 ); } memset( (uint8_t*) fBitmap->Bits() + - ( topOffset + fOutHeight - 1 ) * fBitmap->BytesPerRow() + - leftOffset * 4, + ( topOffset + fOutHeight ) * fBitmap->BytesPerRow() + + ( leftOffset - 1 ) * 4, 0xFF, - fOutWidth * 4 ); + ( fOutWidth + 2 ) * 4 ); /* Clean up */ free( buf2 ); diff --git a/HBWindow.cpp b/HBWindow.cpp index 0d665ae45..9a6fcaa1d 100644 --- a/HBWindow.cpp +++ b/HBWindow.cpp @@ -1,4 +1,4 @@ -/* $Id: HBWindow.cpp,v 1.20 2003/08/24 20:50:49 titer Exp $ */ +/* $Id: HBWindow.cpp,v 1.21 2003/08/25 22:04:22 titer Exp $ */ #include "HBCommon.h" #include "HBWindow.h" @@ -399,6 +399,9 @@ void HBWindow::MessageReceived( BMessage * message ) fStatusBar->Update( pos - fStatusBar->CurrentValue(), text ); Enable( mode ); Unlock(); + + free( text ); + break; } @@ -1,6 +1,6 @@ -# $Id: Jamfile,v 1.15 2003/08/24 22:25:21 titer Exp $ +# $Id: Jamfile,v 1.17 2003/08/26 18:54:06 titer Exp $ -HB_VERSION = 0.1.1 ; +HB_VERSION = 0.2 ; C++FLAGS = $(CPPFLAGS) ; C++FLAGS += -g -Wall -Werror -Wno-multichar -O3 -funroll-loops ; @@ -1,4 +1,8 @@ -$Id: NEWS,v 1.5 2003/08/24 22:25:21 titer Exp $ +$Id: NEWS,v 1.6 2003/08/26 18:54:06 titer Exp $ + +Changes between 0.1.1 and 0.2 + - Fixed a major bug that made HandBrake probably crash after ~ 15 minutes encoded + - Fixed a few minor memory leaks Changes between 0.1 and 0.1.1 - Fixed a stupid bug that prevented to scan volumes correctly if |