-/* $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"
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 );
}
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,
{
/* 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 )
{
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 ) );
-/* $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"
#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 )
{
}
else
{
- Log( "HBPictureView::Draw : LockLooper() failed" );
+ Log( "HBPictureView::Draw() : LockLooper() failed" );
}
BView::Draw( rect );
{
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;
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" );
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 );
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();
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() +
/* 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 );