From 8cbde553128c9c57986d5a2a60d9f1bf53c49460 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 14 Jan 2006 13:05:49 +0000 Subject: [PATCH] HandBrake 0.5 git-svn-id: svn://localhost/HandBrake/trunk@7 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- CREDITS | 220 ++++---- Jamfile | 53 +- NEWS | 6 +- TODO | 21 +- beos/{HandBrake.cpp => HBApp.cpp} | 6 +- beos/{HandBrake.h => HBApp.h} | 8 +- beos/MainWindow.cpp | 61 +- beos/MainWindow.h | 8 +- beos/PictureWin.cpp | 45 +- beos/PictureWin.h | 11 +- beos/RipView.cpp | 393 +++++++------ beos/RipView.h | 27 +- beos/ScanView.cpp | 50 +- beos/ScanView.h | 12 +- core/Ac3Dec.c | 219 ++++++++ core/Ac3Dec.h | 15 + core/Ac3Decoder.cpp | 204 ------- core/Ac3Decoder.h | 47 -- core/AviMux.c | 640 +++++++++++++++++++++ core/AviMux.h | 15 + core/AviMuxer.cpp | 481 ---------------- core/AviMuxer.h | 153 ----- core/Common.cpp | 288 ---------- core/Common.h | 215 -------- core/DVDRead.c | 328 +++++++++++ core/DVDRead.h | 16 + core/DVDReader.cpp | 99 ---- core/DVDReader.h | 25 - core/FfmpegEnc.c | 230 ++++++++ core/FfmpegEnc.h | 15 + core/Fifo.c | 105 ++++ core/Fifo.cpp | 120 ---- core/Fifo.h | 100 ++-- core/HandBrake.c | 767 ++++++++++++++++++++++++++ core/HandBrake.h | 55 ++ core/HandBrakeInternal.h | 35 ++ core/Languages.h | 6 +- core/MadDec.c | 9 + core/MadDec.h | 15 + core/Manager.cpp | 652 ---------------------- core/Manager.h | 64 --- core/Mp3Enc.c | 281 ++++++++++ core/Mp3Enc.h | 15 + core/Mp3Encoder.cpp | 185 ------- core/Mp3Encoder.h | 43 -- core/Mpeg2Dec.c | 195 +++++++ core/Mpeg2Dec.h | 15 + core/Mpeg2Decoder.cpp | 175 ------ core/Mpeg2Decoder.h | 40 -- core/Mpeg4Encoder.cpp | 181 ------ core/Mpeg4Encoder.h | 41 -- core/MpegDemux.cpp | 308 ----------- core/MpegDemux.h | 43 -- core/Resizer.cpp | 138 ----- core/Resizer.h | 38 -- core/Scale.c | 139 +++++ core/Scale.h | 15 + core/Scan.c | 395 +++++++++++++ core/Scan.h | 15 + core/Scanner.cpp | 303 ---------- core/Scanner.h | 27 - core/Thread.c | 138 +++++ core/Thread.cpp | 160 ------ core/Thread.h | 81 ++- core/Utils.c | 352 ++++++++++++ core/Utils.h | 213 +++++++ core/Work.c | 187 +++++++ core/Work.h | 27 + core/Worker.cpp | 150 ----- core/Worker.h | 28 - core/XvidEnc.c | 170 ++++++ core/XvidEnc.h | 15 + macosx/Controller.h | 17 +- macosx/Controller.mm | 657 +++++++++++----------- macosx/English.lproj/InfoPlist.strings | Bin 496 -> 488 bytes macosx/English.lproj/MainMenu.nib/classes.nib | 4 + macosx/English.lproj/MainMenu.nib/info.nib | 20 +- macosx/English.lproj/MainMenu.nib/objects.nib | Bin 17820 -> 18217 bytes macosx/HandBrake.pbproj/project.pbxproj | 146 +++-- macosx/PictureGLView.h | 24 +- macosx/PictureGLView.mm | 258 +++++++-- macosx/TargetSizeField.h | 6 +- macosx/TargetSizeField.mm | 12 +- macosx/main.mm | 4 +- test/Test.cpp | 265 --------- test/test.c | 237 ++++++++ 86 files changed, 6210 insertions(+), 5392 deletions(-) rename beos/{HandBrake.cpp => HBApp.cpp} (89%) rename beos/{HandBrake.h => HBApp.h} (72%) create mode 100644 core/Ac3Dec.c create mode 100644 core/Ac3Dec.h delete mode 100644 core/Ac3Decoder.cpp delete mode 100644 core/Ac3Decoder.h create mode 100644 core/AviMux.c create mode 100644 core/AviMux.h delete mode 100644 core/AviMuxer.cpp delete mode 100644 core/AviMuxer.h delete mode 100644 core/Common.cpp delete mode 100644 core/Common.h create mode 100644 core/DVDRead.c create mode 100644 core/DVDRead.h delete mode 100644 core/DVDReader.cpp delete mode 100644 core/DVDReader.h create mode 100644 core/FfmpegEnc.c create mode 100644 core/FfmpegEnc.h create mode 100644 core/Fifo.c delete mode 100644 core/Fifo.cpp create mode 100644 core/HandBrake.c create mode 100644 core/HandBrake.h create mode 100644 core/HandBrakeInternal.h create mode 100644 core/MadDec.c create mode 100644 core/MadDec.h delete mode 100644 core/Manager.cpp delete mode 100644 core/Manager.h create mode 100644 core/Mp3Enc.c create mode 100644 core/Mp3Enc.h delete mode 100644 core/Mp3Encoder.cpp delete mode 100644 core/Mp3Encoder.h create mode 100644 core/Mpeg2Dec.c create mode 100644 core/Mpeg2Dec.h delete mode 100644 core/Mpeg2Decoder.cpp delete mode 100644 core/Mpeg2Decoder.h delete mode 100644 core/Mpeg4Encoder.cpp delete mode 100644 core/Mpeg4Encoder.h delete mode 100644 core/MpegDemux.cpp delete mode 100644 core/MpegDemux.h delete mode 100644 core/Resizer.cpp delete mode 100644 core/Resizer.h create mode 100644 core/Scale.c create mode 100644 core/Scale.h create mode 100644 core/Scan.c create mode 100644 core/Scan.h delete mode 100644 core/Scanner.cpp delete mode 100644 core/Scanner.h create mode 100644 core/Thread.c delete mode 100644 core/Thread.cpp create mode 100644 core/Utils.c create mode 100644 core/Utils.h create mode 100644 core/Work.c create mode 100644 core/Work.h delete mode 100644 core/Worker.cpp delete mode 100644 core/Worker.h create mode 100644 core/XvidEnc.c create mode 100644 core/XvidEnc.h delete mode 100644 test/Test.cpp create mode 100644 test/test.c diff --git a/CREDITS b/CREDITS index 110e1cc0..4000b2dd 100644 --- a/CREDITS +++ b/CREDITS @@ -1,117 +1,123 @@ HandBrake uses a lot of cool libraries from the GNU/Linux world. Thank their authors ! -libdvdcss authors : +liba52 authors: + Aaron Holtzman + Michel Lespinasse + Gildas Bazin + Billy Biggs + Eduard Hasenleithner + Håkan Hjort + Charles M. Hannum + Chris Hodges + Michael Holzt + Angelos Keromytis + David I. Lehn + Don Mahurin + Jim Miller + Takefumi Sayo + Shoji Tokunaga -Billy Biggs -Stéphane Borel -Håkan Hjort -Samuel Hocevar -Eugenio Jarosiewicz -Jon Lech Johansen -Markus Kuespert -Pascal Levesque -Steven M. Schultz -David Siebörger -Alex Strelnikov -German Tischler -Gildas Bazin +libavcodec authors: + Fabrice Bellard + Alex Beregszaszi + Brian Foley + Arpad Gereoffy + Philip Gladstone + Falk Hueffner + Zdenek Kabelac + Nick Kurshev + Michael Niedermayer + François Revol + Dieter Shirley + Juan J. Sierralta + Lionel Ulmer -libdvdread authors : +libdvdcss authors: + Billy Biggs + Stéphane Borel + Håkan Hjort + Samuel Hocevar + Eugenio Jarosiewicz + Jon Lech Johansen + Markus Kuespert + Pascal Levesque + Steven M. Schultz + David Siebörger + Alex Strelnikov + German Tischler + Gildas Bazin -Björn Englund -Håkan Hjort -Billy Biggs -Christian Wolff +libdvdread authors: + Björn Englund + Håkan Hjort + Billy Biggs + Christian Wolff -libdvdplay authors : +libdvdplay authors: + Håkan Hjort + Martin Norbäck + Stéphane Borel -Håkan Hjort -Martin Norbäck -Stéphane Borel +libmp3lame authors: + Mike Cheng + Robert Hegemann + Frank Klemm + Alexander Leidinger + Naoki Shibata + Mark Taylor + Takehiro Tominiga + Iván Cavero Belaunde + Gabriel Bouvigne + Florian Bomers + CISC + John Dahlstrom + John Dee + Albert Faber + Peter Gubanov + Lars Magne Ingebrigtsen + Yosi Markovich + Zdenek Kabelac + Iwasa Kazmi + Guillaume Lessard + Steve Lhomme + Don Melton + Viral Shah + Acy Stapp + Roel VdB -mpeg2dec authors : +libmpeg2 authors: + Aaron Holtzman + Michel Lespinasse + Bruno Barreyra + Gildas Bazin + Alexander W. Chin + Stephen Crowley + Didier Gautheron + Ryan C. Gordon + Peter Gubanov + Håkan Hjort + Nicolas Joly + Gerd Knorr + David I. Lehn + Olie Lho + Rick Niles + Real Ouellet + Bajusz Peter + Franck Sicard + Brion Vibber + Martin Vogt + Fredrik Vraalsen -Aaron Holtzman -Michel Lespinasse -Bruno Barreyra -Gildas Bazin -Alexander W. Chin -Stephen Crowley -Didier Gautheron -Ryan C. Gordon -Peter Gubanov -Håkan Hjort -Nicolas Joly -Gerd Knorr -David I. Lehn -Olie Lho -Rick Niles -Real Ouellet -Bajusz Peter -Franck Sicard -Brion Vibber -Martin Vogt -Fredrik Vraalsen - -Ffmpeg authors : - -Fabrice Bellard -Alex Beregszaszi -Brian Foley -Arpad Gereoffy -Philip Gladstone -Falk Hueffner -Zdenek Kabelac -Nick Kurshev -Michael Niedermayer -François Revol -Dieter Shirley -Juan J. Sierralta -Lionel Ulmer - -a52dec authors : - -Aaron Holtzman -Michel Lespinasse -Gildas Bazin -Billy Biggs -Eduard Hasenleithner -Håkan Hjort -Charles M. Hannum -Chris Hodges -Michael Holzt -Angelos Keromytis -David I. Lehn -Don Mahurin -Jim Miller -Takefumi Sayo -Shoji Tokunaga - -lame authors : - -Mike Cheng -Robert Hegemann -Frank Klemm -Alexander Leidinger -Naoki Shibata -Mark Taylor -Takehiro Tominiga -Iván Cavero Belaunde -Gabriel Bouvigne -Florian Bomers -CISC -John Dahlstrom -John Dee -Albert Faber -Peter Gubanov -Lars Magne Ingebrigtsen -Yosi Markovich -Zdenek Kabelac -Iwasa Kazmi -Guillaume Lessard -Steve Lhomme -Don Melton -Viral Shah -Acy Stapp -Roel VdB +libxvidcore authors: + Christoph Lampert + Michael Militzer + Peter Ross + Benjamin Herrenschmidt + Daniel Smith + Dirk Knop + Edouard Gomez + Guillaume Morin + MinChen + Pascal Massimino + Radoslaw Czyz diff --git a/Jamfile b/Jamfile index 47147359..11dd9333 100644 --- a/Jamfile +++ b/Jamfile @@ -1,16 +1,20 @@ -# $Id: Jamfile,v 1.41 2003/10/16 13:46:32 titer Exp $ +# $Id: Jamfile,v 1.5 2003/11/07 22:28:30 titer Exp $ # # This file is part of the HandBrake source code. -# Homepage: . +# Homepage: . # It may be used under the terms of the GNU General Public License. -HB_VERSION = 0.4.1 ; +HB_VERSION = 0.5 ; # Compilers +CC = gcc ; C++ = g++ ; -LINK = g++ ; +LINK = gcc ; # Flags +CCFLAGS = $(CFLAGS) ; +CCFLAGS += -g -Wall -Werror ; +CCFLAGS += -DVERSION=\\\"$(HB_VERSION)\\\" -DSYS_$(OS) ; C++FLAGS = $(CPPFLAGS) ; C++FLAGS += -g -Wall -Werror ; C++FLAGS += -DVERSION=\\\"$(HB_VERSION)\\\" -DSYS_$(OS) ; @@ -18,15 +22,18 @@ LINKFLAGS = $(LDFLAGS) ; HDRS = core ; # Optims +CCFLAGS += -funroll-loops ; C++FLAGS += -funroll-loops ; OPTIM = -O3 ; # Libs -LINKLIBS = -ldvdplay -ldvdread -ldvdcss -lmpeg2 -lavcodec -la52 -lmp3lame ; +LINKLIBS = -ldvdplay -ldvdread -ldvdcss -lmpeg2 -lavcodec -la52 + -lmp3lame -lxvidcore ; # OS specific if $(OS) = BEOS { + CCFLAGS += -Wno-multichar ; C++FLAGS += -Wno-multichar ; LINKLIBS += -lbe -ltracker ; } @@ -36,9 +43,19 @@ else if $(OS) = LINUX } else if $(OS) = MACOSX { + CCFLAGS += -no-cpp-precomp ; + C++FLAGS += -no-cpp-precomp ; + LINKFLAGS += -multiply_defined suppress ; + # needed to clean HandBrake.app RM = rm -rf ; } +else if $(OS) = CYGWIN +{ + CCFLAGS += -mno-cygwin ; + C++FLAGS += -mno-cygwin ; + LINKFLAGS += -mno-cygwin ; +} # Do not remove temporary object files # There MUST be a cleaner way to do this @@ -46,36 +63,36 @@ actions quietly updated piecemeal together RmTemps { } -# Build HandBrake.app using ProjectBuilder +# Build HandBrake.app using Xcode rule OSXApp { - Clean clean : $(1) ; + Clean clean : $(1) macosx/build ; BuildOSXApp $(1) ; } actions BuildOSXApp { $(RM) HandBrake.app ; - ( cd macosx && pbxbuild ) && mv macosx/build/HandBrake.app . ; - $(RM) macosx/build ; + ( cd macosx && xcodebuild ) && cp -r macosx/build/HandBrake.app . ; } -Library core/libhb : core/Ac3Decoder.cpp core/AviMuxer.cpp - core/Common.cpp core/DVDReader.cpp core/Fifo.cpp - core/Manager.cpp core/Mp3Encoder.cpp - core/Mpeg2Decoder.cpp core/Mpeg4Encoder.cpp - core/MpegDemux.cpp core/Resizer.cpp - core/Scanner.cpp core/Thread.cpp core/Worker.cpp ; +Library core/libhb : core/Ac3Dec.c core/AviMux.c + core/Utils.c core/DVDRead.c core/Fifo.c + core/HandBrake.c core/Mp3Enc.c + core/Mpeg2Dec.c core/FfmpegEnc.c + core/MadDec.c core/Scale.c + core/Scan.c core/Thread.c core/Work.c + core/XvidEnc.c ; LinkLibraries HBTest : core/libhb.a ; -Main HBTest : test/Test.cpp ; +Main HBTest : test/test.c ; if $(OS) = BEOS { LinkLibraries HandBrake : core/libhb.a ; - Main HandBrake : beos/HandBrake.cpp beos/MainWindow.cpp + Main HandBrake : beos/HBApp.cpp beos/MainWindow.cpp beos/PictureWin.cpp beos/ScanView.cpp - beos/RipView.cpp ; + beos/RipView.cpp ; } if $(OS) = MACOSX diff --git a/NEWS b/NEWS index b3bc5cb2..f89ef3da 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,8 @@ -$Id: NEWS,v 1.11 2003/10/13 15:35:38 titer Exp $ +$Id: NEWS,v 1.3 2003/11/07 21:52:56 titer Exp $ + +Changes between 0.4 and 0.5 + - Bugfixes, rewrite of large parts of the core + - XviD encoding (1-pass only) Changes between 0.3 and 0.4 - Better multithreading diff --git a/TODO b/TODO index 127cc12a..080df325 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,17 @@ -- General - + Use the DVD name in popup and for the name of the created file - + Show the current pass +- Core + Should be able to boost the audio volume + + Allow the intf to preview the latest encoded picture + + Finish and test the MPEG audio decoder + + More encoding options: B-frames, type of estimation, + type of scaling, etc + + Subtitle support + + Finish xvid encoding support (2-pass, more tests) + + Allow the user to split the file in x parts + + AAC & vorbis encoding support + + mp4 & mkv muxing support + +- All interfaces + + Use the DVD name in popup and for the name of the created file -- OSX port - + Preview in a drawer - + Prompt before overwriting a file +- BeOS interface + + Redo the picture panel diff --git a/beos/HandBrake.cpp b/beos/HBApp.cpp similarity index 89% rename from beos/HandBrake.cpp rename to beos/HBApp.cpp index b5f13196..52afce81 100644 --- a/beos/HandBrake.cpp +++ b/beos/HBApp.cpp @@ -1,12 +1,12 @@ -/* $Id: HandBrake.cpp,v 1.8 2003/10/13 22:23:02 titer Exp $ +/* $Id: HBApp.cpp,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include -#include "HandBrake.h" +#include "HBApp.h" #include "MainWindow.h" void SigHandler( int signal ) diff --git a/beos/HandBrake.h b/beos/HBApp.h similarity index 72% rename from beos/HandBrake.h rename to beos/HBApp.h index 7035b548..fb5c41c3 100644 --- a/beos/HandBrake.h +++ b/beos/HBApp.h @@ -1,11 +1,11 @@ -/* $Id: HandBrake.h,v 1.7 2003/10/13 22:23:02 titer Exp $ +/* $Id: HBApp.h,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ -#ifndef HB_HANDBRAKE_H -#define HB_HANDBRAKE_H +#ifndef HB_HB_APP_H +#define HB_HB_APP_H #include diff --git a/beos/MainWindow.cpp b/beos/MainWindow.cpp index 613cf21d..bf52caa8 100644 --- a/beos/MainWindow.cpp +++ b/beos/MainWindow.cpp @@ -1,14 +1,13 @@ -/* $Id: MainWindow.cpp,v 1.19 2003/10/13 22:23:02 titer Exp $ +/* $Id: MainWindow.cpp,v 1.3 2003/11/07 21:52:56 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include #include #include -#include "Manager.h" #include "MainWindow.h" #include "ScanView.h" #include "RipView.h" @@ -17,17 +16,16 @@ MainWindow::MainWindow() : BWindow( BRect( 0,0,10,10 ), "HandBrake " VERSION, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE ) { - /* Init libhb & launch the manager thread */ - fManager = new HBManager( true ); + fHandle = HBInit( 1, 0 ); /* Add the scan view */ - fScanView = new ScanView( fManager ); - fRipView = new RipView( fManager ); + fScanView = new ScanView( fHandle ); + fRipView = new RipView( fHandle ); AddChild( fScanView ); /* Resize to fit */ ResizeTo( fScanView->Bounds().Width(), fScanView->Bounds().Height() ); - + BScreen screen; MoveTo( ( screen.Frame().Width() - fRipView->Bounds().Width() ) / 2, ( screen.Frame().Height() - fRipView->Bounds().Height() ) / 2 ); @@ -45,7 +43,7 @@ bool MainWindow::QuitRequested() fDie = true; long exit_value; wait_for_thread( fUpdateThread, &exit_value ); - delete fManager; + HBClose( &fHandle ); /* Stop the application */ be_app->PostMessage( B_QUIT_REQUESTED ); @@ -62,7 +60,7 @@ void MainWindow::MessageReceived( BMessage * message ) alert = new BAlert( "About HandBrake", "HandBrake " VERSION "\n\n" "by Eric Petit \n" - "Homepage : \n\n" + "Homepage : \n\n" "No, you don't want to know where this stupid app " "name comes from.\n\n" "Thanks to BGA for pointing out very cool bugs ;)", @@ -80,6 +78,7 @@ void MainWindow::MessageReceived( BMessage * message ) case B_SAVE_REQUESTED: case RIP_TITLE_POPUP: + case RIP_VIDEO_CODEC_POPUP: case RIP_BITRATE_RADIO: case RIP_TARGET_CONTROL: case RIP_CROP_BUTTON: @@ -88,7 +87,7 @@ void MainWindow::MessageReceived( BMessage * message ) case RIP_RIP_BUTTON: fRipView->MessageReceived( message ); break; - + default: BWindow::MessageReceived( message ); break; @@ -98,56 +97,64 @@ void MainWindow::MessageReceived( BMessage * message ) void MainWindow::UpdateInterface( MainWindow * _this ) { uint64_t time; + int64_t wait; while( !_this->fDie ) { /* Update every 0.1 sec */ time = system_time(); + _this->_UpdateInterface(); - snooze( 100000 - ( system_time() - time ) ); + + wait = 100000 - ( system_time() - time ); + if( wait > 0 ) + { + snooze( wait ); + } } } void MainWindow::_UpdateInterface() { - if( !fManager->NeedUpdate() ) - { - return; - } - - HBStatus status = fManager->GetStatus(); - if( !Lock() ) { fprintf( stderr, "Lock() failed\n" ); return; } + + int modeChanged; + HBStatus status; + + modeChanged = HBGetStatus( fHandle, &status ); - switch( status.fMode ) + switch( status.mode ) { case HB_MODE_UNDEF: - case HB_MODE_NEED_VOLUME: + case HB_MODE_NEED_DEVICE: break; - + case HB_MODE_SCANNING: - case HB_MODE_INVALID_VOLUME: - fScanView->UpdateIntf( status ); + case HB_MODE_INVALID_DEVICE: + fScanView->UpdateIntf( status, modeChanged ); break; case HB_MODE_READY_TO_RIP: + if( !modeChanged ) + break; + RemoveChild( fScanView ); ResizeTo( fRipView->Bounds().Width(), fRipView->Bounds().Height() ); AddChild( fRipView ); - fRipView->UpdateIntf( status ); + fRipView->UpdateIntf( status, modeChanged ); break; case HB_MODE_ENCODING: - case HB_MODE_SUSPENDED: + case HB_MODE_PAUSED: case HB_MODE_DONE: case HB_MODE_CANCELED: case HB_MODE_ERROR: - fRipView->UpdateIntf( status ); + fRipView->UpdateIntf( status, modeChanged ); break; default: diff --git a/beos/MainWindow.h b/beos/MainWindow.h index c4c32a71..5e50775b 100644 --- a/beos/MainWindow.h +++ b/beos/MainWindow.h @@ -1,7 +1,7 @@ -/* $Id: MainWindow.h,v 1.10 2003/10/10 01:08:42 titer Exp $ +/* $Id: MainWindow.h,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ @@ -12,7 +12,7 @@ class ScanView; class RipView; -#include "Common.h" +#include "HandBrake.h" class MainWindow : public BWindow { @@ -25,7 +25,7 @@ class MainWindow : public BWindow static void UpdateInterface( MainWindow * _this ); void _UpdateInterface(); - HBManager * fManager; + HBHandle * fHandle; int fUpdateThread; volatile bool fDie; diff --git a/beos/PictureWin.cpp b/beos/PictureWin.cpp index 23aabe7c..5667dbc3 100644 --- a/beos/PictureWin.cpp +++ b/beos/PictureWin.cpp @@ -1,7 +1,7 @@ -/* $Id: PictureWin.cpp,v 1.5 2003/09/30 14:38:15 titer Exp $ +/* $Id: PictureWin.cpp,v 1.2 2003/11/06 14:36:54 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include @@ -12,24 +12,23 @@ #include #include "PictureWin.h" -#include "Manager.h" #define UPDATE_BITMAP 'upbi' /* Handy way to access HBTitle members */ -#define fInWidth fTitle->fInWidth -#define fInHeight fTitle->fInHeight -#define fPixelWidth fTitle->fPixelWidth -#define fPixelHeight fTitle->fPixelHeight -#define fDeinterlace fTitle->fDeinterlace -#define fOutWidth fTitle->fOutWidth -#define fOutHeight fTitle->fOutHeight -#define fOutWidthMax fTitle->fOutWidthMax -#define fOutHeightMax fTitle->fOutHeightMax -#define fTopCrop fTitle->fTopCrop -#define fBottomCrop fTitle->fBottomCrop -#define fLeftCrop fTitle->fLeftCrop -#define fRightCrop fTitle->fRightCrop +#define fInWidth fTitle->inWidth +#define fInHeight fTitle->inHeight +#define fPixelWidth fTitle->pixelWidth +#define fPixelHeight fTitle->pixelHeight +#define fDeinterlace fTitle->deinterlace +#define fOutWidth fTitle->outWidth +#define fOutHeight fTitle->outHeight +#define fOutWidthMax fTitle->outWidthMax +#define fOutHeightMax fTitle->outHeightMax +#define fTopCrop fTitle->topCrop +#define fBottomCrop fTitle->bottomCrop +#define fLeftCrop fTitle->leftCrop +#define fRightCrop fTitle->rightCrop HBPictureView::HBPictureView( BRect rect, BBitmap * bitmap ) : BView( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW ) @@ -46,7 +45,7 @@ void HBPictureView::Draw( BRect rect ) } else { - Log( "HBPictureView::Draw() : LockLooper() failed" ); + fprintf( stderr, "LockLooper() failed\n" ); } BView::Draw( rect ); @@ -54,12 +53,12 @@ void HBPictureView::Draw( BRect rect ) /* Constructor */ -HBPictureWin::HBPictureWin( HBManager * manager, HBTitle * title ) +HBPictureWin::HBPictureWin( HBHandle * handle, HBTitle * title ) : BWindow( BRect( 0, 0, 0, 0 ), "Picture settings", B_FLOATING_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_CLOSABLE ) { - fManager = manager; + fHandle = handle; fTitle = title; /* Resize & center */ @@ -101,7 +100,7 @@ HBPictureWin::HBPictureWin( HBManager * manager, HBTitle * title ) view->AddChild( pictureBox ); - /* Second box : resize & crop settings */ + /* Second box : scale & crop settings */ r = BRect( 10, fOutHeightMax + 75, fOutWidthMax + 31, fOutHeightMax + 235 ); BBox * settingsBox; @@ -189,8 +188,8 @@ void HBPictureWin::UpdateBitmap( int image ) fRightCrop = 2 * fRightCropSlider->Value(); fDeinterlace = ( fDeinterlaceCheck->Value() != 0 ); - uint8_t * preview = fManager->GetPreview( fTitle, image ); - for( uint32_t i = 0; i < fOutHeightMax + 2; i++ ) + uint8_t * preview = HBGetPreview( fHandle, fTitle, image ); + for( int i = 0; i < fOutHeightMax + 2; i++ ) { memcpy( ((uint8_t*) fBitmap->Bits()) + i * fBitmap->BytesPerRow(), @@ -201,7 +200,7 @@ void HBPictureWin::UpdateBitmap( int image ) if( !Lock() ) { - Log( "HBPictureWin::UpdateBitmap() : cannot Lock()" ); + fprintf( stderr, "Lock() failed\n" ); return; } diff --git a/beos/PictureWin.h b/beos/PictureWin.h index 909e8ea5..265eb8ad 100644 --- a/beos/PictureWin.h +++ b/beos/PictureWin.h @@ -1,7 +1,7 @@ -/* $Id: PictureWin.h,v 1.3 2003/09/30 14:38:15 titer Exp $ +/* $Id: PictureWin.h,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #ifndef HB_PICTURE_WIN_H @@ -12,8 +12,7 @@ class BSlider; class BCheckBox; -/* libhb headers */ -#include "Common.h" +#include "HandBrake.h" class HBPictureView : public BView { @@ -28,14 +27,14 @@ class HBPictureView : public BView class HBPictureWin : public BWindow { public: - HBPictureWin( HBManager * manager, HBTitle * title ); + HBPictureWin( HBHandle * handle, HBTitle * title ); virtual void MessageReceived( BMessage * message ); void UpdateBitmap( int which ); private: - HBManager * fManager; + HBHandle * fHandle; HBTitle * fTitle; /* GUI */ diff --git a/beos/RipView.cpp b/beos/RipView.cpp index 180ba23f..75609051 100644 --- a/beos/RipView.cpp +++ b/beos/RipView.cpp @@ -1,7 +1,7 @@ -/* $Id: RipView.cpp,v 1.6 2003/10/13 23:42:03 titer Exp $ +/* $Id: RipView.cpp,v 1.3 2003/11/07 21:52:56 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include @@ -19,14 +19,13 @@ #include "RipView.h" #include "PictureWin.h" -#include "Manager.h" #define DEFAULT_FILE "/boot/home/Desktop/Movie.avi" -RipView::RipView( HBManager * manager ) +RipView::RipView( HBHandle * handle ) : BView( BRect( 0,0,400,480 ), NULL, B_FOLLOW_ALL, B_WILL_DRAW ) { - fManager = manager; + fHandle = handle; BRect r; SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); @@ -85,7 +84,7 @@ RipView::RipView( HBManager * manager ) /* Crop */ r = BRect( fVideoBox->Bounds().Width() - 120, 120, fVideoBox->Bounds().Width() - 10, 140 ); - fCropButton = new BButton( r, NULL, "Crop & Resize...", + fCropButton = new BButton( r, NULL, "Crop & Scale...", new BMessage( RIP_CROP_BUTTON ) ); fVideoBox->AddChild( fCropButton ); @@ -172,7 +171,10 @@ RipView::RipView( HBManager * manager ) AddChild( fStartButton ); /* Fill popups */ - fVideoCodecPopUp->AddItem( new BMenuItem( "MPEG-4", NULL ) ); + fVideoCodecPopUp->AddItem( new BMenuItem( "MPEG-4 (Ffmpeg)", + new BMessage( RIP_VIDEO_CODEC_POPUP ) ) ); + fVideoCodecPopUp->AddItem( new BMenuItem( "MPEG-4 (XviD)", + new BMessage( RIP_VIDEO_CODEC_POPUP ) ) ); fVideoCodecPopUp->ItemAt( 0 )->SetMarked( true ); fAudioCodecPopUp->AddItem( new BMenuItem( "MP3", NULL ) ); fAudioCodecPopUp->ItemAt( 0 )->SetMarked( true ); @@ -208,7 +210,7 @@ void RipView::MessageReceived( BMessage * message ) case RIP_TITLE_POPUP: { int index = fTitlePopUp->IndexOf( fTitlePopUp->FindMarked() ); - HBTitle * title = (HBTitle*) fTitleList->ItemAt( index ); + HBTitle * title = (HBTitle*) HBListItemAt( fTitleList, index ); /* Empty current popups */ BMenuItem * item; @@ -225,13 +227,13 @@ void RipView::MessageReceived( BMessage * message ) /* Show new languages */ HBAudio * audio; - for( uint32_t i = 0; i < title->fAudioList->CountItems(); i++ ) + for( int i = 0; i < HBListCountItems( title->audioList ); i++ ) { - audio = (HBAudio*) title->fAudioList->ItemAt( i ); + audio = (HBAudio*) HBListItemAt( title->audioList, i ); fLanguagePopUp->AddItem( - new BMenuItem( audio->fDescription, NULL ) ); + new BMenuItem( audio->language, NULL ) ); fSecondaryLanguagePopUp->AddItem( - new BMenuItem( audio->fDescription, + new BMenuItem( audio->language, new BMessage( RIP_TARGET_CONTROL ) ) ); } fLanguagePopUp->ItemAt( 0 )->SetMarked( true ); @@ -241,11 +243,25 @@ void RipView::MessageReceived( BMessage * message ) fSecondaryLanguagePopUp->CountItems() - 1 )->SetMarked( true ); fSecondaryLanguageField->SetEnabled( - ( title->fAudioList->CountItems() > 1 ) ); + ( HBListCountItems( title->audioList ) > 1 ) ); break; } + case RIP_VIDEO_CODEC_POPUP: + { + if( fVideoCodecPopUp->IndexOf( fVideoCodecPopUp->FindMarked() ) ) + { + fTwoPassCheck->SetValue( 0 ); + fTwoPassCheck->SetEnabled( false ); + } + else + { + fTwoPassCheck->SetEnabled( true ); + } + break; + } + case RIP_BITRATE_RADIO: { if( fCustomBitrateRadio->Value() ) @@ -271,7 +287,7 @@ void RipView::MessageReceived( BMessage * message ) int64_t available; int index = fTitlePopUp->IndexOf( fTitlePopUp->FindMarked() ); - HBTitle * title = (HBTitle*) fTitleList->ItemAt( index ); + HBTitle * title = (HBTitle*) HBListItemAt( fTitleList, index ); available = (int64_t) 1024 * 1024 * atoi( fTargetSizeControl->Text() ); @@ -281,16 +297,16 @@ void RipView::MessageReceived( BMessage * message ) /* Video chunk headers (8 bytes / frame) and and index (16 bytes / frame) */ - available -= 24 * title->fLength * title->fRate / - title->fScale; + available -= 24 * title->length * title->rate / + title->rateBase; /* Audio tracks */ available -= ( strcmp( fSecondaryLanguagePopUp->FindMarked()->Label(), "None" ) ? 2 : 1 ) * - ( title->fLength * + ( title->length * atoi( fAudioBitratePopUp->FindMarked()->Label() ) * 128 + - 24 * title->fLength * 44100 / 1152 ); + 24 * title->length * 44100 / 1152 ); char string[1024]; memset( string, 0, 1024 ); if( available < 0 ) @@ -300,7 +316,7 @@ void RipView::MessageReceived( BMessage * message ) else { sprintf( string, "%lld", available / - ( 128 * title->fLength ) ); + ( 128 * title->length ) ); } fCustomBitrateControl->SetText( string ); break; @@ -309,10 +325,10 @@ void RipView::MessageReceived( BMessage * message ) case RIP_CROP_BUTTON: { int index = fTitlePopUp->IndexOf( fTitlePopUp->FindMarked() ); - HBTitle * title = (HBTitle*) fTitleList->ItemAt( index ); + HBTitle * title = (HBTitle*) HBListItemAt( fTitleList, index ); HBPictureWin * win; - win = new HBPictureWin( fManager, title ); + win = new HBPictureWin( fHandle, title ); win->Show(); break; } @@ -341,11 +357,11 @@ void RipView::MessageReceived( BMessage * message ) { if( strcmp( fSuspendButton->Label(), "Suspend" ) ) { - fManager->ResumeRip(); + HBResumeRip( fHandle ); } else { - fManager->SuspendRip(); + HBPauseRip( fHandle ); } break; @@ -355,7 +371,7 @@ void RipView::MessageReceived( BMessage * message ) { if( strcmp( fStartButton->Label(), "Rip !" ) ) { - fManager->StopRip(); + HBStopRip( fHandle ); } else { @@ -363,29 +379,32 @@ void RipView::MessageReceived( BMessage * message ) /* Get asked title & languages */ index = fTitlePopUp->IndexOf( fTitlePopUp->FindMarked() ); - HBTitle * title = (HBTitle*) fTitleList->ItemAt( index ); + HBTitle * title = (HBTitle*) HBListItemAt( fTitleList, index ); index = fLanguagePopUp->IndexOf( fLanguagePopUp->FindMarked() ); HBAudio * audio1 = - (HBAudio*) title->fAudioList->ItemAt( index ); + (HBAudio*) HBListItemAt( title->audioList, index ); index = fSecondaryLanguagePopUp->IndexOf( fSecondaryLanguagePopUp->FindMarked() ); HBAudio * audio2 = - (HBAudio*) title->fAudioList->ItemAt( index ); + (HBAudio*) HBListItemAt( title->audioList, index ); /* Use user settings */ - title->fBitrate = atoi( fCustomBitrateControl->Text() ); - title->fTwoPass = ( fTwoPassCheck->Value() != 0 ); - audio1->fOutBitrate = + title->file = strdup( fFileControl->Text() ); + title->bitrate = atoi( fCustomBitrateControl->Text() ); + title->twoPass = ( fTwoPassCheck->Value() != 0 ); + title->codec = fVideoCodecPopUp->IndexOf( + fVideoCodecPopUp->FindMarked() ) ? HB_CODEC_XVID : + HB_CODEC_FFMPEG; + audio1->outBitrate = atoi( fAudioBitratePopUp->FindMarked()->Label() ); if( audio2 ) { - audio2->fOutBitrate = + audio2->outBitrate = atoi( fAudioBitratePopUp->FindMarked()->Label() ); } /* Let libhb do the job */ - fManager->StartRip( title, audio1, audio2, - (char*) fFileControl->Text() ); + HBStartRip( fHandle, title, audio1, audio2 ); } break; } @@ -396,23 +415,26 @@ void RipView::MessageReceived( BMessage * message ) } } -void RipView::UpdateIntf( HBStatus status ) +void RipView::UpdateIntf( HBStatus status, int modeChanged ) { - switch( status.fMode ) + switch( status.mode ) { case HB_MODE_READY_TO_RIP: { - fTitleList = status.fTitleList; + if( !modeChanged ) + break; + + fTitleList = status.titleList; HBTitle * title; - for( uint32_t i = 0; i < fTitleList->CountItems(); i++ ) + for( int i = 0; i < HBListCountItems( fTitleList ); i++ ) { - title = (HBTitle*) fTitleList->ItemAt( i ); + title = (HBTitle*) HBListItemAt( fTitleList, i ); char string[1024]; memset( string, 0, 1024 ); - sprintf( string, "%d (%02lld:%02lld:%02lld)", - title->fIndex, title->fLength / 3600, - ( title->fLength % 3600 ) / 60, - title->fLength % 60 ); + sprintf( string, "%d (%02d:%02d:%02d)", + title->index, title->length / 3600, + ( title->length % 3600 ) / 60, + title->length % 60 ); fTitlePopUp->AddItem( new BMenuItem( string, new BMessage( RIP_TITLE_POPUP ) ) ); } @@ -423,23 +445,30 @@ void RipView::UpdateIntf( HBStatus status ) case HB_MODE_ENCODING: { - fTitleField->SetEnabled( false ); - fVideoCodecField->SetEnabled( false ); - fCustomBitrateRadio->SetEnabled( false ); - fCustomBitrateControl->SetEnabled( false ); - fTargetSizeRadio->SetEnabled( false ); - fTargetSizeControl->SetEnabled( false ); - fTwoPassCheck->SetEnabled( false ); - fCropButton->SetEnabled( false ); - fLanguageField->SetEnabled( false ); - fSecondaryLanguageField->SetEnabled( false ); - fAudioCodecField->SetEnabled( false ); - fAudioBitrateField->SetEnabled( false ); - fFileFormatField->SetEnabled( false ); - fFileControl->SetEnabled( false ); - fFileButton->SetEnabled( false ); - - if( !status.fPosition ) + if( modeChanged ) + { + fTitleField->SetEnabled( false ); + fVideoCodecField->SetEnabled( false ); + fCustomBitrateRadio->SetEnabled( false ); + fCustomBitrateControl->SetEnabled( false ); + fTargetSizeRadio->SetEnabled( false ); + fTargetSizeControl->SetEnabled( false ); + fTwoPassCheck->SetEnabled( false ); + fCropButton->SetEnabled( false ); + fLanguageField->SetEnabled( false ); + fSecondaryLanguageField->SetEnabled( false ); + fAudioCodecField->SetEnabled( false ); + fAudioBitrateField->SetEnabled( false ); + fFileFormatField->SetEnabled( false ); + fFileControl->SetEnabled( false ); + fFileButton->SetEnabled( false ); + fSuspendButton->SetLabel( "Suspend" ); + fSuspendButton->SetEnabled( true ); + fStartButton->SetLabel( "Cancel" ); + fStartButton->SetEnabled( true ); + } + + if( !status.position ) { fStatusBar->Update( - fStatusBar->CurrentValue(), "Starting..." ); @@ -449,163 +478,175 @@ void RipView::UpdateIntf( HBStatus status ) char string[1024]; memset( string, 0, 1024 ); sprintf( string, "Encoding: %.2f %% (%.2f fps, " "%02d:%02d:%02d remaining)", - 100 * status.fPosition, - status.fFrameRate, - status.fRemainingTime / 3600, - ( status.fRemainingTime % 3600 ) / 60, - status.fRemainingTime % 60 ); - fStatusBar->Update( 100 * status.fPosition - + 100 * status.position, + status.frameRate, + status.remainingTime / 3600, + ( status.remainingTime % 3600 ) / 60, + status.remainingTime % 60 ); + fStatusBar->Update( 100 * status.position - fStatusBar->CurrentValue(), string ); } - - fSuspendButton->SetLabel( "Suspend" ); - fSuspendButton->SetEnabled( true ); - fStartButton->SetLabel( "Cancel" ); - fStartButton->SetEnabled( true ); break; } - case HB_MODE_SUSPENDED: + case HB_MODE_PAUSED: { - fTitleField->SetEnabled( false ); - fVideoCodecField->SetEnabled( false ); - fCustomBitrateRadio->SetEnabled( false ); - fCustomBitrateControl->SetEnabled( false ); - fTargetSizeRadio->SetEnabled( false ); - fTargetSizeControl->SetEnabled( false ); - fTwoPassCheck->SetEnabled( false ); - fCropButton->SetEnabled( false ); - fLanguageField->SetEnabled( false ); - fSecondaryLanguageField->SetEnabled( false ); - fAudioCodecField->SetEnabled( false ); - fAudioBitrateField->SetEnabled( false ); - fFileFormatField->SetEnabled( false ); - fFileControl->SetEnabled( false ); - fFileButton->SetEnabled( false ); - - fStatusBar->Update( 100 * status.fPosition - - fStatusBar->CurrentValue(), "Suspended" ); + if( modeChanged ) + { + fTitleField->SetEnabled( false ); + fVideoCodecField->SetEnabled( false ); + fCustomBitrateRadio->SetEnabled( false ); + fCustomBitrateControl->SetEnabled( false ); + fTargetSizeRadio->SetEnabled( false ); + fTargetSizeControl->SetEnabled( false ); + fTwoPassCheck->SetEnabled( false ); + fCropButton->SetEnabled( false ); + fLanguageField->SetEnabled( false ); + fSecondaryLanguageField->SetEnabled( false ); + fAudioCodecField->SetEnabled( false ); + fAudioBitrateField->SetEnabled( false ); + fFileFormatField->SetEnabled( false ); + fFileControl->SetEnabled( false ); + fFileButton->SetEnabled( false ); + fSuspendButton->SetLabel( "Resume" ); + fSuspendButton->SetEnabled( true ); + fStartButton->SetLabel( "Cancel" ); + fStartButton->SetEnabled( true ); + } - fSuspendButton->SetLabel( "Resume" ); - fSuspendButton->SetEnabled( true ); - fStartButton->SetLabel( "Cancel" ); - fStartButton->SetEnabled( true ); + fStatusBar->Update( 100 * status.position - + fStatusBar->CurrentValue(), "Suspended" ); break; } case HB_MODE_STOPPING: { - fTitleField->SetEnabled( false ); - fVideoCodecField->SetEnabled( false ); - fCustomBitrateRadio->SetEnabled( false ); - fCustomBitrateControl->SetEnabled( false ); - fTargetSizeRadio->SetEnabled( false ); - fTargetSizeControl->SetEnabled( false ); - fTwoPassCheck->SetEnabled( false ); - fCropButton->SetEnabled( false ); - fLanguageField->SetEnabled( false ); - fSecondaryLanguageField->SetEnabled( false ); - fAudioCodecField->SetEnabled( false ); - fAudioBitrateField->SetEnabled( false ); - fFileFormatField->SetEnabled( false ); - fFileControl->SetEnabled( false ); - fFileButton->SetEnabled( false ); + if( modeChanged ) + { + fTitleField->SetEnabled( false ); + fVideoCodecField->SetEnabled( false ); + fCustomBitrateRadio->SetEnabled( false ); + fCustomBitrateControl->SetEnabled( false ); + fTargetSizeRadio->SetEnabled( false ); + fTargetSizeControl->SetEnabled( false ); + fTwoPassCheck->SetEnabled( false ); + fCropButton->SetEnabled( false ); + fLanguageField->SetEnabled( false ); + fSecondaryLanguageField->SetEnabled( false ); + fAudioCodecField->SetEnabled( false ); + fAudioBitrateField->SetEnabled( false ); + fFileFormatField->SetEnabled( false ); + fFileControl->SetEnabled( false ); + fFileButton->SetEnabled( false ); + fSuspendButton->SetLabel( "Suspend" ); + fSuspendButton->SetEnabled( false ); + fStartButton->SetLabel( "Cancel" ); + fStartButton->SetEnabled( false ); + } fStatusBar->Update( - fStatusBar->CurrentValue(), "Stopping..." ); - - fSuspendButton->SetLabel( "Suspend" ); - fSuspendButton->SetEnabled( false ); - fStartButton->SetLabel( "Cancel" ); - fStartButton->SetEnabled( false ); break; } case HB_MODE_DONE: { - fTitleField->SetEnabled( true ); - fVideoCodecField->SetEnabled( true ); - fCustomBitrateRadio->SetEnabled( true ); - fCustomBitrateControl->SetEnabled( fCustomBitrateRadio->Value() ); - fTargetSizeRadio->SetEnabled( true ); - fTargetSizeControl->SetEnabled( fTargetSizeRadio->Value() ); - fTwoPassCheck->SetEnabled( true ); - fCropButton->SetEnabled( true ); - fLanguageField->SetEnabled( true ); - fSecondaryLanguageField->SetEnabled( - ( fSecondaryLanguagePopUp->CountItems() > 2 ) ); - fAudioCodecField->SetEnabled( true ); - fAudioBitrateField->SetEnabled( true ); - fFileFormatField->SetEnabled( true ); - fFileControl->SetEnabled( true ); - fFileButton->SetEnabled( true ); + if( modeChanged ) + { + fTitleField->SetEnabled( true ); + fVideoCodecField->SetEnabled( true ); + fCustomBitrateRadio->SetEnabled( true ); + fCustomBitrateControl->SetEnabled( + fCustomBitrateRadio->Value() ); + fTargetSizeRadio->SetEnabled( true ); + fTargetSizeControl->SetEnabled( fTargetSizeRadio->Value() ); + fTwoPassCheck->SetEnabled( true ); + fCropButton->SetEnabled( true ); + fLanguageField->SetEnabled( true ); + fSecondaryLanguageField->SetEnabled( + ( fSecondaryLanguagePopUp->CountItems() > 2 ) ); + fAudioCodecField->SetEnabled( true ); + fAudioBitrateField->SetEnabled( true ); + fFileFormatField->SetEnabled( true ); + fFileControl->SetEnabled( true ); + fFileButton->SetEnabled( true ); + + fSuspendButton->SetLabel( "Suspend" ); + fSuspendButton->SetEnabled( false ); + fStartButton->SetLabel( "Rip !" ); + fStartButton->SetEnabled( true ); + MessageReceived( new BMessage( RIP_VIDEO_CODEC_POPUP ) ); + } fStatusBar->Update( 100.0 - fStatusBar->CurrentValue(), "Done." ); - - fSuspendButton->SetLabel( "Suspend" ); - fSuspendButton->SetEnabled( false ); - fStartButton->SetLabel( "Rip !" ); - fStartButton->SetEnabled( true ); break; } case HB_MODE_CANCELED: { - fTitleField->SetEnabled( true ); - fVideoCodecField->SetEnabled( true ); - fCustomBitrateRadio->SetEnabled( true ); - fCustomBitrateControl->SetEnabled( fCustomBitrateRadio->Value() ); - fTargetSizeRadio->SetEnabled( true ); - fTargetSizeControl->SetEnabled( fTargetSizeRadio->Value() ); - fTwoPassCheck->SetEnabled( true ); - fCropButton->SetEnabled( true ); - fLanguageField->SetEnabled( true ); - fSecondaryLanguageField->SetEnabled( - ( fSecondaryLanguagePopUp->CountItems() > 2 ) ); - fAudioCodecField->SetEnabled( true ); - fAudioBitrateField->SetEnabled( true ); - fFileFormatField->SetEnabled( true ); - fFileControl->SetEnabled( true ); - fFileButton->SetEnabled( true ); + if( modeChanged ) + { + fTitleField->SetEnabled( true ); + fVideoCodecField->SetEnabled( true ); + fCustomBitrateRadio->SetEnabled( true ); + fCustomBitrateControl->SetEnabled( + fCustomBitrateRadio->Value() ); + fTargetSizeRadio->SetEnabled( true ); + fTargetSizeControl->SetEnabled( fTargetSizeRadio->Value() ); + fTwoPassCheck->SetEnabled( true ); + fCropButton->SetEnabled( true ); + fLanguageField->SetEnabled( true ); + fSecondaryLanguageField->SetEnabled( + ( fSecondaryLanguagePopUp->CountItems() > 2 ) ); + fAudioCodecField->SetEnabled( true ); + fAudioBitrateField->SetEnabled( true ); + fFileFormatField->SetEnabled( true ); + fFileControl->SetEnabled( true ); + fFileButton->SetEnabled( true ); + fSuspendButton->SetLabel( "Suspend" ); + fSuspendButton->SetEnabled( false ); + fStartButton->SetLabel( "Rip !" ); + fStartButton->SetEnabled( true ); + MessageReceived( new BMessage( RIP_VIDEO_CODEC_POPUP ) ); + } fStatusBar->Update( - fStatusBar->CurrentValue(), "Canceled." ); - - fSuspendButton->SetLabel( "Suspend" ); - fSuspendButton->SetEnabled( false ); - fStartButton->SetLabel( "Rip !" ); - fStartButton->SetEnabled( true ); break; } case HB_MODE_ERROR: { - fTitleField->SetEnabled( true ); - fVideoCodecField->SetEnabled( true ); - fCustomBitrateRadio->SetEnabled( true ); - fCustomBitrateControl->SetEnabled( fCustomBitrateRadio->Value() ); - fTargetSizeRadio->SetEnabled( true ); - fTargetSizeControl->SetEnabled( fTargetSizeRadio->Value() ); - fTwoPassCheck->SetEnabled( true ); - fCropButton->SetEnabled( true ); - fLanguageField->SetEnabled( true ); - fSecondaryLanguageField->SetEnabled( - ( fSecondaryLanguagePopUp->CountItems() > 2 ) ); - fAudioCodecField->SetEnabled( true ); - fAudioBitrateField->SetEnabled( true ); - fFileFormatField->SetEnabled( true ); - fFileControl->SetEnabled( true ); - fFileButton->SetEnabled( true ); + if( modeChanged ) + { + fTitleField->SetEnabled( true ); + fVideoCodecField->SetEnabled( true ); + fCustomBitrateRadio->SetEnabled( true ); + fCustomBitrateControl->SetEnabled( + fCustomBitrateRadio->Value() ); + fTargetSizeRadio->SetEnabled( true ); + fTargetSizeControl->SetEnabled( fTargetSizeRadio->Value() ); + fTwoPassCheck->SetEnabled( true ); + fCropButton->SetEnabled( true ); + fLanguageField->SetEnabled( true ); + fSecondaryLanguageField->SetEnabled( + ( fSecondaryLanguagePopUp->CountItems() > 2 ) ); + fAudioCodecField->SetEnabled( true ); + fAudioBitrateField->SetEnabled( true ); + fFileFormatField->SetEnabled( true ); + fFileControl->SetEnabled( true ); + fFileButton->SetEnabled( true ); + fSuspendButton->SetLabel( "Suspend" ); + fSuspendButton->SetEnabled( false ); + fStartButton->SetLabel( "Rip !" ); + fStartButton->SetEnabled( true ); + MessageReceived( new BMessage( RIP_VIDEO_CODEC_POPUP ) ); + } fStatusBar->Update( - fStatusBar->CurrentValue(), "Error." ); - - fSuspendButton->SetLabel( "Suspend" ); - fSuspendButton->SetEnabled( false ); - fStartButton->SetLabel( "Rip !" ); - fStartButton->SetEnabled( true ); break; } diff --git a/beos/RipView.h b/beos/RipView.h index d487b2b9..27d9831a 100644 --- a/beos/RipView.h +++ b/beos/RipView.h @@ -1,7 +1,7 @@ -/* $Id: RipView.h,v 1.5 2003/10/13 22:23:02 titer Exp $ +/* $Id: RipView.h,v 1.3 2003/11/07 21:52:56 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ @@ -19,25 +19,26 @@ class BRadioButton; class BStatusBar; class BTextControl; -#include "Common.h" +#include "HandBrake.h" -#define RIP_TITLE_POPUP 'rtip' -#define RIP_BITRATE_RADIO 'rbir' -#define RIP_TARGET_CONTROL 'rtac' -#define RIP_CROP_BUTTON 'rcrb' -#define RIP_BROWSE_BUTTON 'rbrb' -#define RIP_SUSPEND_BUTTON 'rsub' -#define RIP_RIP_BUTTON 'rrib' +#define RIP_TITLE_POPUP 'rtip' +#define RIP_VIDEO_CODEC_POPUP 'rvcp' +#define RIP_BITRATE_RADIO 'rbir' +#define RIP_TARGET_CONTROL 'rtac' +#define RIP_CROP_BUTTON 'rcrb' +#define RIP_BROWSE_BUTTON 'rbrb' +#define RIP_SUSPEND_BUTTON 'rsub' +#define RIP_RIP_BUTTON 'rrib' class RipView : public BView { public: - RipView( HBManager * manager ); + RipView( HBHandle * handle ); void MessageReceived( BMessage * message ); - void UpdateIntf( HBStatus status ); + void UpdateIntf( HBStatus status, int modeChanged ); private: - HBManager * fManager; + HBHandle * fHandle; HBList * fTitleList; BBox * fVideoBox; diff --git a/beos/ScanView.cpp b/beos/ScanView.cpp index fb5d722e..24c66db7 100644 --- a/beos/ScanView.cpp +++ b/beos/ScanView.cpp @@ -1,7 +1,7 @@ -/* $Id: ScanView.cpp,v 1.4 2003/10/13 23:42:03 titer Exp $ +/* $Id: ScanView.cpp,v 1.2 2003/11/06 14:36:54 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include @@ -21,13 +21,12 @@ #include #include -#include "Manager.h" #include "ScanView.h" -ScanView::ScanView( HBManager * manager ) +ScanView::ScanView( HBHandle * handle ) : BView( BRect( 0,0,400,190 ), NULL, B_FOLLOW_ALL, B_WILL_DRAW ) { - fManager = manager; + fHandle = handle; BRect r; SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); @@ -125,12 +124,14 @@ void ScanView::MessageReceived( BMessage * message ) { if( fRadioDetected->Value() ) { - fManager->ScanVolumes( (char*) - fPopUp->FindMarked()->Label() ); + HBScanDevice( fHandle, + (char*) fPopUp->FindMarked()->Label(), + 0 ); } else { - fManager->ScanVolumes( (char*) fFolderControl->Text() ); + HBScanDevice( fHandle, + (char*) fFolderControl->Text(), 0 ); } break; } @@ -140,36 +141,41 @@ void ScanView::MessageReceived( BMessage * message ) } } -void ScanView::UpdateIntf( HBStatus status ) +void ScanView::UpdateIntf( HBStatus status, int modeChanged ) { - switch( status.fMode ) + switch( status.mode ) { case HB_MODE_SCANNING: { - fRadioDetected->SetEnabled( false ); - fRadioFolder->SetEnabled( false ); - fField->SetEnabled( false ); - fFolderControl->SetEnabled( false ); - fBrowseButton->SetEnabled( false ); - fOpenButton->SetEnabled( false ); + if( modeChanged ) + { + fRadioDetected->SetEnabled( false ); + fRadioFolder->SetEnabled( false ); + fField->SetEnabled( false ); + fFolderControl->SetEnabled( false ); + fBrowseButton->SetEnabled( false ); + fOpenButton->SetEnabled( false ); + } char string[1024]; memset( string, 0, 1024 ); - if( !status.fScannedTitle ) + if( !status.scannedTitle ) { - sprintf( string, "Opening %s...", - status.fScannedVolume ); + sprintf( string, "Opening device..." ); } else { - sprintf( string, "Scanning %s, title %d...", - status.fScannedVolume, status.fScannedTitle ); + sprintf( string, "Scanning title %d...", + status.scannedTitle ); } fStatusString->SetText( string ); break; } - case HB_MODE_INVALID_VOLUME: + case HB_MODE_INVALID_DEVICE: { + if( !modeChanged ) + break; + fRadioDetected->SetEnabled( true ); fRadioFolder->SetEnabled( true ); diff --git a/beos/ScanView.h b/beos/ScanView.h index 5e2514b5..11ed342c 100644 --- a/beos/ScanView.h +++ b/beos/ScanView.h @@ -1,7 +1,7 @@ -/* $Id: ScanView.h,v 1.2 2003/10/13 22:23:02 titer Exp $ +/* $Id: ScanView.h,v 1.2 2003/11/06 14:36:54 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #ifndef HB_SCAN_VIEW_H @@ -16,7 +16,7 @@ class BRadioButton; class BStringView; class BTextControl; -#include "Common.h" +#include "HandBrake.h" #define SCAN_RADIO 'scra' #define SCAN_BROWSE_BUTTON 'sbrb' @@ -25,14 +25,14 @@ class BTextControl; class ScanView : public BView { public: - ScanView( HBManager * manager ); + ScanView( HBHandle * handle ); void MessageReceived( BMessage * message ); - void UpdateIntf( HBStatus status ); + void UpdateIntf( HBStatus status, int modeChanged ); private: void DetectVolumes(); - HBManager * fManager; + HBHandle * fHandle; BRadioButton * fRadioDetected; BRadioButton * fRadioFolder; diff --git a/core/Ac3Dec.c b/core/Ac3Dec.c new file mode 100644 index 00000000..d5430d49 --- /dev/null +++ b/core/Ac3Dec.c @@ -0,0 +1,219 @@ +/* $Id: Ac3Dec.c,v 1.4 2003/11/04 20:16:44 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Ac3Dec.h" +#include "Fifo.h" +#include "Work.h" + +#include + +/* Local prototypes */ +static int Ac3DecWork( HBWork * ); +static int GetBytes( HBAc3Dec *, int ); + +struct HBAc3Dec +{ + HB_WORK_COMMON_MEMBERS + + HBHandle * handle; + HBAudio * audio; + + /* liba52 stuff */ + a52_state_t * state; + int inFlags; + int outFlags; + float sampleLevel; + + /* Buffers */ + uint8_t ac3Frame[3840]; /* Max size of a A52 frame */ + int ac3FrameSize; /* In bytes */ + HBBuffer * ac3Buffer; + int ac3BufferPos; /* In bytes */ + int nextFrameSize; /* In bytes */ + float position; + HBBuffer * rawBuffer; +}; + +HBAc3Dec * HBAc3DecInit( HBHandle * handle, HBAudio * audio ) +{ + HBAc3Dec * a; + if( !( a = malloc( sizeof( HBAc3Dec ) ) ) ) + { + HBLog( "HBAc3DecInit: malloc() failed, gonna crash" ); + return NULL; + } + + a->name = strdup( "Ac3Dec" ); + a->work = Ac3DecWork; + + a->handle = handle; + a->audio = audio; + + /* Init liba52 */ + a->state = a52_init( 0 ); + a->inFlags = 0; + + /* Let it do the downmixing */ + a->outFlags = A52_STEREO; + + /* Lame wants samples from -32768 to 32768 */ + a->sampleLevel = 32768.0; + + a->ac3FrameSize = 0; + a->ac3Buffer = NULL; + a->ac3BufferPos = 0; + a->nextFrameSize = 0; + a->position = 0.0; + a->rawBuffer = NULL; + + return a; +} + +void HBAc3DecClose( HBAc3Dec ** _a ) +{ + HBAc3Dec * a = *_a; + + if( a->ac3Buffer ) HBBufferClose( &a->ac3Buffer ); + if( a->rawBuffer ) HBBufferClose( &a->rawBuffer ); + a52_free( a->state ); + free( a->name ); + free( a ); + + *_a = NULL; +} + +static int Ac3DecWork( HBWork * w ) +{ + HBAc3Dec * a = (HBAc3Dec*) w; + HBAudio * audio = a->audio; + + int didSomething = 0; + + /* Push decoded buffer */ + if( a->rawBuffer ) + { + if( HBFifoPush( audio->rawFifo, &a->rawBuffer ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + } + + /* Get a frame header (7 bytes) */ + if( a->ac3FrameSize < 7 ) + { + if( GetBytes( a, 7 ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + + a->nextFrameSize = a52_syncinfo( a->ac3Frame, &a->inFlags, + &audio->inSampleRate, + &audio->inBitrate ); + + if( !a->nextFrameSize ) + { + HBLog( "HBAc3Dec: a52_syncinfo() failed" ); + HBErrorOccured( a->handle, HB_ERROR_A52_SYNC ); + return didSomething; + } + } + + /* Get the whole frame */ + if( a->ac3FrameSize >= 7 ) + { + sample_t * samples; + HBBuffer * rawBuffer; + int i; + + if( GetBytes( a, a->nextFrameSize ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + + /* Feed liba52 */ + a52_frame( a->state, a->ac3Frame, &a->outFlags, + &a->sampleLevel, 0 ); + a->ac3FrameSize = 0; + + /* 6 blocks per frame, 256 samples per block, 2 channels */ + rawBuffer = HBBufferInit( 12 * 256 * sizeof( float ) ); + rawBuffer->position = a->position; + + for( i = 0; i < 6; i++ ) + { + /* Decode a block */ + a52_block( a->state ); + + /* Get a pointer to the raw data */ + samples = a52_samples( a->state ); + + /* Copy left channel data */ + memcpy( rawBuffer->data + i * 256 * sizeof( float ), + samples, + 256 * sizeof( float ) ); + + /* Copy right channel data */ + memcpy( rawBuffer->data + ( 6 + i ) * 256 * sizeof( float ), + samples + 256, + 256 * sizeof( float ) ); + } + + a->rawBuffer = rawBuffer; + } + + return didSomething; +} + +static int GetBytes( HBAc3Dec * a, int size ) +{ + int i; + + while( a->ac3FrameSize < size ) + { + if( !a->ac3Buffer ) + { + if( !( a->ac3Buffer = HBFifoPop( a->audio->ac3Fifo ) ) ) + { + return 0; + } + a->ac3BufferPos = 0; + a->position = a->ac3Buffer->position; + + if( a->ac3Buffer->last ) + { + HBDone( a->handle ); + } + } + + i = MIN( size - a->ac3FrameSize, + a->ac3Buffer->size - a->ac3BufferPos ); + memcpy( a->ac3Frame + a->ac3FrameSize, + a->ac3Buffer->data + a->ac3BufferPos, + i ); + a->ac3FrameSize += i; + a->ac3BufferPos += i; + + if( a->ac3BufferPos == a->ac3Buffer->size ) + { + HBBufferClose( &a->ac3Buffer ); + } + } + + return 1; +} + diff --git a/core/Ac3Dec.h b/core/Ac3Dec.h new file mode 100644 index 00000000..a1ecaff6 --- /dev/null +++ b/core/Ac3Dec.h @@ -0,0 +1,15 @@ +/* $Id: Ac3Dec.h,v 1.1 2003/11/03 12:08:00 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_AC3_DEC_H +#define HB_AC3_DEC_H + +#include "HandBrakeInternal.h" + +HBAc3Dec * HBAc3DecInit( HBHandle *, HBAudio * ); +void HBAc3DecClose( HBAc3Dec ** ); + +#endif diff --git a/core/Ac3Decoder.cpp b/core/Ac3Decoder.cpp deleted file mode 100644 index 663184e4..00000000 --- a/core/Ac3Decoder.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* $Id: Ac3Decoder.cpp,v 1.21 2003/10/14 14:35:20 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Ac3Decoder.h" -#include "Fifo.h" -#include "Manager.h" - -extern "C" { -#include -} - -HBAc3Decoder::HBAc3Decoder( HBManager * manager, HBAudio * audio ) -{ - fManager = manager; - fAudio = audio; - - fLock = new HBLock(); - fUsed = false; - - /* Init liba52 */ - fState = a52_init( 0 ); - fInFlags = 0; - fOutFlags = A52_STEREO; - - /* Lame wants samples from -32768 to 32768 */ - fSampleLevel = 32768.0; - - /* Max size for a A52 frame is 3840 bytes */ - fAc3Frame = new HBBuffer( 3840 ); - fAc3Frame->fSize = 0; - fAc3Buffer = NULL; - fPosInAc3Buffer = 0; - fRawBuffer = NULL; -} - -HBAc3Decoder::~HBAc3Decoder() -{ - if( fRawBuffer ) delete fRawBuffer; - if( fAc3Buffer ) delete fAc3Buffer; - delete fAc3Frame; - a52_free( fState ); - delete fLock; -} - -bool HBAc3Decoder::Work() -{ - if( !Lock() ) - { - return false; - } - - /* Push the latest decoded buffer */ - if( fRawBuffer ) - { - if( fAudio->fRawFifo->Push( fRawBuffer ) ) - { - fRawBuffer = NULL; - } - else - { - Unlock(); - return false; - } - } - - /* Get a frame header (7 bytes) */ - if( fAc3Frame->fSize < 7 ) - { - if( GetBytes( 7 ) ) - { - /* Get the size of the coming frame */ - fFrameSize = a52_syncinfo( fAc3Frame->fData, &fInFlags, - &fAudio->fInSampleRate, - &fAudio->fInBitrate ); - if( !fFrameSize ) - { - Log( "HBAc3Decoder: a52_syncinfo failed" ); - fManager->Error( HB_ERROR_A52_SYNC ); - return false; - } - } - else - { - Unlock(); - return false; - } - } - - /* In case the audio should start later than the video, - insert some silence */ - if( fAudio->fDelay > 3 * 256 * 1000 / fAudio->fInSampleRate ) - { - fRawBuffer = new HBBuffer( 12 * 256 * sizeof( float ) ); - for( uint32_t i = 0; i < 12 * 256; i++ ) - { - ((float*)fRawBuffer->fData)[i] = 0; - } - fAudio->fDelay -= 6 * 256 * 1000 / fAudio->fInSampleRate; - - Unlock(); - return true; - } - - if( fAc3Frame->fSize >= 7 ) - { - /* Get the whole frame */ - if( GetBytes( (uint32_t) fFrameSize ) ) - { - /* Feed liba52 */ - a52_frame( fState, fAc3Frame->fData, &fOutFlags, - &fSampleLevel, 0 ); - fAc3Frame->fSize = 0; - - /* 6 blocks per frame, 256 samples per block */ - fRawBuffer = new HBBuffer( 12 * 256 * sizeof( float ) ); - fRawBuffer->fPosition = fPosition; - - sample_t * samples; - for( int i = 0; i < 6; i++ ) - { - /* Decode a block */ - a52_block( fState ); - - /* Get a pointer to the raw data */ - samples = a52_samples( fState ); - - /* Copy left channel data */ - memcpy( (float*) fRawBuffer->fData + i * 256, - samples, - 256 * sizeof( float ) ); - - /* Copy right channel data */ - memcpy( (float*) fRawBuffer->fData + ( 6 + i ) * 256, - samples + 256, - 256 * sizeof( float ) ); - } - } - else - { - Unlock(); - return false; - } - } - - Unlock(); - return true; -} - -bool HBAc3Decoder::Lock() -{ - fLock->Lock(); - if( fUsed ) - { - fLock->Unlock(); - return false; - } - fUsed = true; - fLock->Unlock(); - return true; -} - -void HBAc3Decoder::Unlock() -{ - fLock->Lock(); - fUsed = false; - fLock->Unlock(); -} - -/* GetBytes() : pops buffers from the AC3 fifo until fAc3Frame - contains bytes */ -bool HBAc3Decoder::GetBytes( uint32_t size ) -{ - while( fAc3Frame->fSize < size ) - { - if( !fAc3Buffer ) - { - if( !( fAc3Buffer = fAudio->fAc3Fifo->Pop() ) ) - { - return false; - } - fPosInAc3Buffer = 0; - fPosition = fAc3Buffer->fPosition; - } - - int willCopy = MIN( size - fAc3Frame->fSize, - fAc3Buffer->fSize - fPosInAc3Buffer ); - memcpy( fAc3Frame->fData + fAc3Frame->fSize, - fAc3Buffer->fData + fPosInAc3Buffer, - willCopy ); - fAc3Frame->fSize += willCopy; - fPosInAc3Buffer += willCopy; - - if( fAc3Buffer->fSize == fPosInAc3Buffer ) - { - delete fAc3Buffer; - fAc3Buffer = NULL; - } - } - - return true; -} diff --git a/core/Ac3Decoder.h b/core/Ac3Decoder.h deleted file mode 100644 index f63206b1..00000000 --- a/core/Ac3Decoder.h +++ /dev/null @@ -1,47 +0,0 @@ -/* $Id: Ac3Decoder.h,v 1.11 2003/10/14 14:35:20 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_AC3_DECODER_H -#define HB_AC3_DECODER_H - -#include "Common.h" - -class HBAc3Decoder -{ - public: - HBAc3Decoder( HBManager * manager, - HBAudio * audio ); - ~HBAc3Decoder(); - bool Work(); - - private: - bool Lock(); - void Unlock(); - bool GetBytes( uint32_t size ); - - HBManager * fManager; - HBAudio * fAudio; - - HBLock * fLock; - bool fUsed; - - /* liba52 */ - a52_state_t * fState; - int fInFlags; - int fOutFlags; - float fSampleLevel; - - /* buffers */ - HBBuffer * fAc3Frame; - HBBuffer * fAc3Buffer; - uint32_t fPosInAc3Buffer; - HBBuffer * fRawBuffer; - - float fPosition; - int fFrameSize; -}; - -#endif diff --git a/core/AviMux.c b/core/AviMux.c new file mode 100644 index 00000000..bd055121 --- /dev/null +++ b/core/AviMux.c @@ -0,0 +1,640 @@ +/* $Id: AviMux.c,v 1.5 2003/11/06 18:35:53 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "AviMux.h" +#include "Fifo.h" +#include "Thread.h" + +/* Local structures */ +typedef struct AviMainHeader AviMainHeader; +typedef struct AviStreamHeader AviStreamHeader; +typedef struct BitmapInfo BitmapInfo; +typedef struct WaveFormatEx WaveFormatEx; + +/* Local prototypes */ +static void AviMuxThread( void * ); +static void InitAviHeaders( HBAviMux * ); +static void AddChunk( HBAviMux *, HBBuffer **, uint32_t, + AviStreamHeader * ); +static void AddIndex( HBAviMux * ); +static void WriteInt8( FILE *, uint8_t ); +static void WriteInt16( FILE *, uint16_t ); +static void WriteInt32( FILE *, uint32_t ); +static void WriteBuffer( FILE *, HBBuffer * ); +static void WriteMainHeader( FILE *, AviMainHeader * ); +static void WriteStreamHeader( FILE *, AviStreamHeader * ); +static void WriteBitmapInfo( FILE *, BitmapInfo * ); +static void WriteWaveFormatEx( FILE *, WaveFormatEx * ); +static void IndexAddInt32( HBBuffer * buffer, uint32_t ); +static HBBuffer * Pop( HBAviMux *, HBFifo * ); + +#define AVIF_HASINDEX 0x10 +#define AVIIF_KEYFRAME 0x10 +#define FOURCC(a) ((a[3]<<24)|(a[2]<<16)|(a[1]<<8)|a[0]) + +/* Structures definitions */ +struct __attribute__((__packed__)) AviMainHeader +{ + uint32_t FourCC; + uint32_t BytesCount; + uint32_t MicroSecPerFrame; + uint32_t MaxBytesPerSec; + uint32_t PaddingGranularity; + uint32_t Flags; + uint32_t TotalFrames; + uint32_t InitialFrames; + uint32_t Streams; + uint32_t SuggestedBufferSize; + uint32_t Width; + uint32_t Height; + uint32_t Reserved[4]; +}; + +struct __attribute__((__packed__)) AviStreamHeader +{ + uint32_t FourCC; + uint32_t BytesCount; + uint32_t Type; + uint32_t Handler; + uint32_t Flags; + uint16_t Priority; + uint16_t Language; + uint32_t InitialFrames; + uint32_t Scale; + uint32_t Rate; + uint32_t Start; + uint32_t Length; + uint32_t SuggestedBufferSize; + uint32_t Quality; + uint32_t SampleSize; + int16_t Left; + int16_t Top; + int16_t Right; + int16_t Bottom; +}; + +struct __attribute__((__packed__)) BitmapInfo +{ + uint32_t FourCC; + uint32_t BytesCount; + uint32_t Size; + uint32_t Width; + uint32_t Height; + uint16_t Planes; + uint16_t BitCount; + uint32_t Compression; + uint32_t SizeImage; + uint32_t XPelsPerMeter; + uint32_t YPelsPerMeter; + uint32_t ClrUsed; + uint32_t ClrImportant; + uint8_t Blue; + uint8_t Green; + uint8_t Red; + uint8_t Reserved; +}; + +struct __attribute__((__packed__)) WaveFormatEx +{ + uint32_t FourCC; + uint32_t BytesCount; + uint16_t FormatTag; + uint16_t Channels; + uint32_t SamplesPerSec; + uint32_t AvgBytesPerSec; + uint16_t BlockAlign; + uint16_t BitsPerSample; + uint16_t Size; + + /* mp3 specific */ + uint16_t Id; + uint32_t Flags; + uint16_t BlockSize; + uint16_t FramesPerBlock; + uint16_t CodecDelay; +}; + +struct HBAviMux +{ + HBHandle * handle; + HBTitle * title; + HBAudio * audio; + HBAudio * optAudio; + + AviMainHeader mainHeader; + AviStreamHeader videoHeader; + BitmapInfo videoFormat; + AviStreamHeader audioHeader; + WaveFormatEx audioFormat; + AviStreamHeader optAudioHeader; + WaveFormatEx optAudioFormat; + + /* Data size in bytes, not including headers */ + unsigned size; + FILE * file; + HBBuffer * index; + + int die; + HBThread * thread; +}; + +HBAviMux * HBAviMuxInit( HBHandle * handle, HBTitle * title, + HBAudio * audio, HBAudio * optAudio ) +{ + HBAviMux * a; + if( !( a = malloc( sizeof( HBAviMux ) ) ) ) + { + HBLog( "HBAviMuxInit: malloc() failed, gonna crash" ); + return NULL; + } + + a->handle = handle; + a->title = title; + a->audio = audio; + a->optAudio = optAudio; + + a->size = 0; + a->file = NULL; + a->index = HBBufferInit( 1024 * 1024 ); + a->index->size = 0; + + a->die = 0; + a->thread = HBThreadInit( "avi muxer", AviMuxThread, a, + HB_NORMAL_PRIORITY ); + return a; +} + +void HBAviMuxClose( HBAviMux ** _a ) +{ + HBAviMux * a = *_a; + + a->die = 1; + HBThreadClose( &a->thread ); + free( a ); + + *_a = NULL; +} + +static void AviMuxThread( void * _a ) +{ + HBAviMux * a = (HBAviMux*) _a; + HBTitle * title = a->title; + HBAudio * audio = a->audio; + HBAudio * optAudio = a->optAudio; + + HBBuffer * videoBuffer = NULL; + HBBuffer * audioBuffer = NULL; + HBBuffer * optAudioBuffer = NULL; + + /* Open destination file */ + HBLog( "HBAviMux: opening %s", title->file ); + if( !( a->file = fopen( title->file, "w" ) ) ) + { + HBLog( "HBAviMux: fopen() failed" ); + HBErrorOccured( a->handle, HB_ERROR_AVI_WRITE ); + return; + } + + /* Get a buffer for each track */ + videoBuffer = Pop( a, title->mpeg4Fifo ); + audioBuffer = Pop( a, audio->mp3Fifo ); + if( optAudio ) + { + optAudioBuffer = Pop( a, optAudio->mp3Fifo ); + } + + /* Failed ? Then forget it */ + if( !videoBuffer || !audioBuffer || + ( optAudio && !optAudioBuffer ) ) + { + fclose( a->file ); + a->file = NULL; + + HBLog( "HBAviMux: deleting %s", title->file ); + unlink( title->file ); + return; + } + + InitAviHeaders( a ); + + for( ;; ) + { + /* Get a buffer for each track */ + if( !videoBuffer ) + { + videoBuffer = Pop( a, title->mpeg4Fifo ); + } + if( !audioBuffer ) + { + audioBuffer = Pop( a, audio->mp3Fifo ); + } + if( optAudio && !optAudioBuffer ) + { + optAudioBuffer = Pop( a, optAudio->mp3Fifo ); + } + + if( !videoBuffer && !audioBuffer && !optAudioBuffer ) + { + /* Couldn't get anything -> must exit NOW */ + break; + } + + /* Interleave frames in the same order than they were in the + original MPEG stream */ + if( videoBuffer && + ( !audioBuffer || + videoBuffer->position < audioBuffer->position ) && + ( !optAudioBuffer || + videoBuffer->position < optAudioBuffer->position ) ) + { + AddChunk( a, &videoBuffer, FOURCC( "00dc" ), + &a->videoHeader ); + } + else if( audioBuffer && + ( !optAudioBuffer || + audioBuffer->position < optAudioBuffer->position ) ) + { + AddChunk( a, &audioBuffer, FOURCC( "01wb" ), + &a->audioHeader ); + } + else + { + AddChunk( a, &optAudioBuffer, FOURCC( "02wb" ), + &a->optAudioHeader ); + } + } + + AddIndex( a ); + + HBLog( "HBAviMux: closing %s", title->file ); + fclose( a->file ); +} + +static void InitAviHeaders( HBAviMux * a ) +{ + HBTitle * title = a->title; + HBAudio * audio = a->audio; + HBAudio * optAudio = a->optAudio; + AviMainHeader * mainHeader = &a->mainHeader; + AviStreamHeader * videoHeader = &a->videoHeader; + BitmapInfo * videoFormat = &a->videoFormat; + AviStreamHeader * audioHeader = &a->audioHeader; + WaveFormatEx * audioFormat = &a->audioFormat; + AviStreamHeader * optAudioHeader = &a->optAudioHeader; + WaveFormatEx * optAudioFormat = &a->optAudioFormat; + FILE * file = a->file; + int hdrlBytes; + int i; + + /* AVI main header */ + memset( mainHeader, 0, sizeof( AviMainHeader ) ); + mainHeader->FourCC = FOURCC( "avih" ); + mainHeader->BytesCount = sizeof( AviMainHeader ) - 8; + mainHeader->MicroSecPerFrame = (uint64_t) 1000000 * + title->rateBase / title->rate; + mainHeader->Streams = optAudio ? 3 : 2; + mainHeader->Width = title->outWidth; + mainHeader->Height = title->outHeight; + + /* Video stream header */ + memset( videoHeader, 0, sizeof( AviStreamHeader ) ); + videoHeader->FourCC = FOURCC( "strh" ); + videoHeader->BytesCount = sizeof( AviStreamHeader ) - 8; + videoHeader->Type = FOURCC( "vids" ); + + if( title->codec == HB_CODEC_FFMPEG ) + videoHeader->Handler = FOURCC( "divx" ); + else if( title->codec == HB_CODEC_XVID ) + videoHeader->Handler = FOURCC( "xvid" ); + + videoHeader->Scale = title->rateBase; + videoHeader->Rate = title->rate; + + /* Video stream format */ + memset( videoFormat, 0, sizeof( BitmapInfo ) ); + videoFormat->FourCC = FOURCC( "strf" ); + videoFormat->BytesCount = sizeof( BitmapInfo ) - 8; + videoFormat->Size = sizeof( BitmapInfo ) - 8; + videoFormat->Width = title->outWidth; + videoFormat->Height = title->outHeight; + videoFormat->Planes = 1; + videoFormat->BitCount = 24; + if( title->codec == HB_CODEC_FFMPEG ) + videoFormat->Compression = FOURCC( "DX50" ); + else if( title->codec == HB_CODEC_XVID ) + videoFormat->Compression = FOURCC( "XVID" ); + + /* Audio stream header */ + memset( audioHeader, 0, sizeof( AviStreamHeader ) ); + audioHeader->FourCC = FOURCC( "strh" ); + audioHeader->BytesCount = sizeof( AviStreamHeader ) - 8; + audioHeader->Type = FOURCC( "auds" ); + audioHeader->InitialFrames = 1; + audioHeader->Scale = 1152; + audioHeader->Rate = audio->outSampleRate; + audioHeader->Quality = 0xFFFFFFFF; + + /* Audio stream format */ + memset( audioFormat, 0, sizeof( WaveFormatEx ) ); + audioFormat->FourCC = FOURCC( "strf" ); + audioFormat->BytesCount = sizeof( WaveFormatEx ) - 8; + audioFormat->FormatTag = 0x55; + audioFormat->Channels = 2; + audioFormat->SamplesPerSec = audio->outSampleRate; + audioFormat->AvgBytesPerSec = audio->outBitrate * 1024 / 8; + audioFormat->BlockAlign = 1152; + audioFormat->Size = 12; + audioFormat->Id = 1; + audioFormat->Flags = 2; + audioFormat->BlockSize = 1152; + audioFormat->FramesPerBlock = 1; + audioFormat->CodecDelay = 1393; + + if( optAudio ) + { + /* optAudio stream header */ + memset( optAudioHeader, 0, sizeof( AviStreamHeader ) ); + optAudioHeader->FourCC = FOURCC( "strh" ); + optAudioHeader->BytesCount = sizeof( AviStreamHeader ) - 8; + optAudioHeader->Type = FOURCC( "auds" ); + optAudioHeader->InitialFrames = 1; + optAudioHeader->Scale = 1152; + optAudioHeader->Rate = optAudio->outSampleRate; + optAudioHeader->Quality = 0xFFFFFFFF; + + /* optAudio stream format */ + memset( optAudioFormat, 0, sizeof( WaveFormatEx ) ); + optAudioFormat->FourCC = FOURCC( "strf" ); + optAudioFormat->BytesCount = sizeof( WaveFormatEx ) - 8; + optAudioFormat->FormatTag = 0x55; + optAudioFormat->Channels = 2; + optAudioFormat->SamplesPerSec = optAudio->outSampleRate; + optAudioFormat->AvgBytesPerSec = optAudio->outBitrate * 1024 / 8; + optAudioFormat->BlockAlign = 1152; + optAudioFormat->Size = 12; + optAudioFormat->Id = 1; + optAudioFormat->Flags = 2; + optAudioFormat->BlockSize = 1152; + optAudioFormat->FramesPerBlock = 1; + optAudioFormat->CodecDelay = 1393; + } + + hdrlBytes = 4 + sizeof( AviMainHeader ) + + ( optAudio ? 3 : 2 ) * ( 12 + sizeof( AviStreamHeader ) ) + + sizeof( BitmapInfo ) + + ( optAudio ? 2 : 1 ) * sizeof( WaveFormatEx ); + + /* Here we really start to write into the file */ + + WriteInt32( file, FOURCC( "RIFF" ) ); + WriteInt32( file, 2040 ); + WriteInt32( file, FOURCC( "AVI " ) ); + WriteInt32( file, FOURCC( "LIST" ) ); + WriteInt32( file, hdrlBytes ); + WriteInt32( file, FOURCC( "hdrl" ) ); + WriteMainHeader( file, mainHeader ); + WriteInt32( file, FOURCC( "LIST" ) ); + WriteInt32( file, 4 + sizeof( AviStreamHeader ) + + sizeof( BitmapInfo ) ); + WriteInt32( file, FOURCC( "strl" ) ); + WriteStreamHeader( file, videoHeader ); + WriteBitmapInfo( file, videoFormat ); + WriteInt32( file, FOURCC( "LIST" ) ); + WriteInt32( file, 4 + sizeof( AviStreamHeader ) + + sizeof( WaveFormatEx ) ); + WriteInt32( file, FOURCC( "strl" ) ); + WriteStreamHeader( file, audioHeader ); + WriteWaveFormatEx( file, audioFormat ); + if( optAudio ) + { + WriteInt32( file, FOURCC( "LIST" ) ); + WriteInt32( file, 4 + sizeof( AviStreamHeader ) + + sizeof( WaveFormatEx ) ); + WriteInt32( file, FOURCC( "strl" ) ); + WriteStreamHeader( file, optAudioHeader ); + WriteWaveFormatEx( file, optAudioFormat ); + } + WriteInt32( file, FOURCC( "JUNK" ) ); + WriteInt32( file, 2008 - hdrlBytes ); + for( i = 0; i < 2008 - hdrlBytes; i++ ) + { + WriteInt8( file, 0 ); + } + WriteInt32( file, FOURCC( "LIST" ) ); + WriteInt32( file, 4 ); + WriteInt32( file, FOURCC( "movi" ) ); +} + +static void AddChunk( HBAviMux * a, HBBuffer ** _buffer, + uint32_t fourCC, AviStreamHeader * header ) +{ + HBBuffer * buffer = *_buffer; + + /* Update index */ + IndexAddInt32( a->index, fourCC ); + IndexAddInt32( a->index, buffer->keyFrame ? AVIIF_KEYFRAME : 0 ); + IndexAddInt32( a->index, 4 + a->size ); + IndexAddInt32( a->index, buffer->size ); + + /* Write the chunk to the file */ + fseek( a->file, 0, SEEK_END ); + WriteInt32( a->file, fourCC ); + WriteInt32( a->file, buffer->size ); + WriteBuffer( a->file, buffer ); + + /* Chunks must be 2-bytes aligned */ + if( buffer->size & 1 ) + { + WriteInt8( a->file, 0 ); + } + + /* Update headers */ + a->size += 8 + EVEN( buffer->size ); + header->Length++; + + /* RIFF size */ + fseek( a->file, 4, SEEK_SET ); + WriteInt32( a->file, 2040 + a->size ); + + /* AviStreamHeader's length */ + fseek( a->file, 140, SEEK_SET ); + WriteInt32( a->file, a->videoHeader.Length ); + fseek( a->file, 268, SEEK_SET ); + WriteInt32( a->file, a->audioHeader.Length ); + if( a->optAudio ) + { + fseek( a->file, 382, SEEK_SET ); + WriteInt32( a->file, a->optAudioHeader.Length ); + } + + /* movi size */ + fseek( a->file, 2040, SEEK_SET ); + WriteInt32( a->file, 4 + a->size ); + + HBBufferClose( _buffer ); +} + +static void AddIndex( HBAviMux * a ) +{ + fseek( a->file, 0, SEEK_END ); + + WriteInt32( a->file, FOURCC( "idx1" ) ); + WriteInt32( a->file, a->index->size ); + WriteBuffer( a->file, a->index ); + + a->size += 8 + a->index->size; + fseek( a->file, 4, SEEK_SET ); + WriteInt32( a->file, 2040 + a->size ); + a->mainHeader.Flags |= AVIF_HASINDEX; + fseek( a->file, 24, SEEK_SET ); + WriteMainHeader( a->file, &a->mainHeader ); +} + +static void WriteInt8( FILE * file, uint8_t val ) +{ + fputc( val, file ); +} + +static void WriteInt16( FILE * file, uint16_t val ) +{ + fputc( val & 0xFF, file ); + fputc( val >> 8, file ); +} + +static void WriteInt32( FILE * file, uint32_t val ) +{ + fputc( val & 0xFF, file ); + fputc( ( val >> 8 ) & 0xFF, file ); + fputc( ( val >> 16 ) & 0xFF, file ); + fputc( val >> 24, file ); +} + +static void WriteBuffer( FILE * file, HBBuffer * buffer ) +{ + fwrite( buffer->data, buffer->size, 1, file ); +} + +static void WriteBitmapInfo( FILE * file, BitmapInfo * bitmapInfo ) +{ + WriteInt32( file, bitmapInfo->FourCC ); + WriteInt32( file, bitmapInfo->BytesCount ); + WriteInt32( file, bitmapInfo->Size ); + WriteInt32( file, bitmapInfo->Width ); + WriteInt32( file, bitmapInfo->Height ); + WriteInt16( file, bitmapInfo->Planes ); + WriteInt16( file, bitmapInfo->BitCount ); + WriteInt32( file, bitmapInfo->Compression ); + WriteInt32( file, bitmapInfo->SizeImage ); + WriteInt32( file, bitmapInfo->XPelsPerMeter ); + WriteInt32( file, bitmapInfo->YPelsPerMeter ); + WriteInt32( file, bitmapInfo->ClrUsed ); + WriteInt32( file, bitmapInfo->ClrImportant ); + WriteInt8( file, bitmapInfo->Blue ); + WriteInt8( file, bitmapInfo->Green ); + WriteInt8( file, bitmapInfo->Red ); + WriteInt8( file, bitmapInfo->Reserved ); +} + +static void WriteWaveFormatEx( FILE * file, WaveFormatEx * waveFormatEx ) +{ + WriteInt32( file, waveFormatEx->FourCC ); + WriteInt32( file, waveFormatEx->BytesCount ); + WriteInt16( file, waveFormatEx->FormatTag ); + WriteInt16( file, waveFormatEx->Channels ); + WriteInt32( file, waveFormatEx->SamplesPerSec ); + WriteInt32( file, waveFormatEx->AvgBytesPerSec ); + WriteInt16( file, waveFormatEx->BlockAlign ); + WriteInt16( file, waveFormatEx->BitsPerSample ); + WriteInt16( file, waveFormatEx->Size ); + WriteInt16( file, waveFormatEx->Id ); + WriteInt32( file, waveFormatEx->Flags ); + WriteInt16( file, waveFormatEx->BlockSize ); + WriteInt16( file, waveFormatEx->FramesPerBlock ); + WriteInt16( file, waveFormatEx->CodecDelay ); +} + +static void WriteMainHeader( FILE * file, AviMainHeader * mainHeader ) +{ + WriteInt32( file, mainHeader->FourCC ); + WriteInt32( file, mainHeader->BytesCount ); + WriteInt32( file, mainHeader->MicroSecPerFrame ); + WriteInt32( file, mainHeader->MaxBytesPerSec ); + WriteInt32( file, mainHeader->PaddingGranularity ); + WriteInt32( file, mainHeader->Flags ); + WriteInt32( file, mainHeader->TotalFrames ); + WriteInt32( file, mainHeader->InitialFrames ); + WriteInt32( file, mainHeader->Streams ); + WriteInt32( file, mainHeader->SuggestedBufferSize ); + WriteInt32( file, mainHeader->Width ); + WriteInt32( file, mainHeader->Height ); + WriteInt32( file, mainHeader->Reserved[0] ); + WriteInt32( file, mainHeader->Reserved[1] ); + WriteInt32( file, mainHeader->Reserved[2] ); + WriteInt32( file, mainHeader->Reserved[3] ); +} + +static void WriteStreamHeader( FILE * file, AviStreamHeader * streamHeader ) +{ + WriteInt32( file, streamHeader->FourCC ); + WriteInt32( file, streamHeader->BytesCount ); + WriteInt32( file, streamHeader->Type ); + WriteInt32( file, streamHeader->Handler ); + WriteInt32( file, streamHeader->Flags ); + WriteInt16( file, streamHeader->Priority ); + WriteInt16( file, streamHeader->Language ); + WriteInt32( file, streamHeader->InitialFrames ); + WriteInt32( file, streamHeader->Scale ); + WriteInt32( file, streamHeader->Rate ); + WriteInt32( file, streamHeader->Start ); + WriteInt32( file, streamHeader->Length ); + WriteInt32( file, streamHeader->SuggestedBufferSize ); + WriteInt32( file, streamHeader->Quality ); + WriteInt32( file, streamHeader->SampleSize ); + WriteInt16( file, streamHeader->Left ); + WriteInt16( file, streamHeader->Top ); + WriteInt16( file, streamHeader->Right ); + WriteInt16( file, streamHeader->Bottom ); +} + +static void IndexAddInt32( HBBuffer * b, uint32_t val ) +{ + if( b->size + 16 > b->alloc ) + { + HBLog( "HBAviMux: reallocing index (%d MB)", + 1 + b->alloc / 1024 / 1024 ); + HBBufferReAlloc( b, b->alloc + 1024 + 1024 ); + } + + b->data[b->size++] = val & 0xFF; + b->data[b->size++] = ( val >> 8 ) & 0xFF; + b->data[b->size++] = ( val >> 16 ) & 0xFF; + b->data[b->size++] = val >> 24; +} + +static HBBuffer * Pop( HBAviMux * a, HBFifo * fifo ) +{ + HBBuffer * buffer; + + for( ;; ) + { + HBCheckPaused( a->handle ); + + if( ( buffer = HBFifoPop( fifo ) ) ) + { + return buffer; + } + + if( a->die ) + { + break; + } + + HBSnooze( 10000 ); + } + + return NULL; +} + diff --git a/core/AviMux.h b/core/AviMux.h new file mode 100644 index 00000000..1fccbe97 --- /dev/null +++ b/core/AviMux.h @@ -0,0 +1,15 @@ +/* $Id: AviMux.h,v 1.1 2003/11/03 12:08:00 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_AVI_MUX_H +#define HB_AVI_MUX_H + +#include "HandBrakeInternal.h" + +HBAviMux * HBAviMuxInit( HBHandle *, HBTitle *, HBAudio *, HBAudio * ); +void HBAviMuxClose( HBAviMux ** ); + +#endif diff --git a/core/AviMuxer.cpp b/core/AviMuxer.cpp deleted file mode 100644 index 4a84fe8b..00000000 --- a/core/AviMuxer.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/* $Id: AviMuxer.cpp,v 1.17 2003/10/09 23:33:36 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "AviMuxer.h" -#include "Manager.h" - -#define AVIF_HASINDEX 0x10 -#define AVIIF_KEYFRAME 0x10 - -#define FOURCC(a) ( ( a[3] << 24 ) | ( a[2] << 16 ) | ( a[1] << 8 ) | a[0] ) - -/* TODO : check return values from fputc/fwrite in case disk is full - or something */ - -void WriteInt8( FILE * file, uint8_t val ) -{ - fputc( val, file ); -} - -void WriteInt16( FILE * file, uint16_t val ) -{ - fputc( val & 0xFF, file ); - fputc( val >> 8, file ); -} - -void WriteInt32( FILE * file, uint32_t val ) -{ - fputc( val & 0xFF, file ); - fputc( ( val >> 8 ) & 0xFF, file ); - fputc( ( val >> 16 ) & 0xFF, file ); - fputc( val >> 24, file ); -} - -void WriteBuffer( FILE * file, HBBuffer * buffer ) -{ - fwrite( buffer->fData, buffer->fSize, 1, file ); -} - -void WriteBitmapInfo( FILE * file, BitmapInfo * bitmapInfo ) -{ - WriteInt32( file, bitmapInfo->FourCC ); - WriteInt32( file, bitmapInfo->BytesCount ); - WriteInt32( file, bitmapInfo->Size ); - WriteInt32( file, bitmapInfo->Width ); - WriteInt32( file, bitmapInfo->Height ); - WriteInt16( file, bitmapInfo->Planes ); - WriteInt16( file, bitmapInfo->BitCount ); - WriteInt32( file, bitmapInfo->Compression ); - WriteInt32( file, bitmapInfo->SizeImage ); - WriteInt32( file, bitmapInfo->XPelsPerMeter ); - WriteInt32( file, bitmapInfo->YPelsPerMeter ); - WriteInt32( file, bitmapInfo->ClrUsed ); - WriteInt32( file, bitmapInfo->ClrImportant ); - WriteInt8( file, bitmapInfo->Blue ); - WriteInt8( file, bitmapInfo->Green ); - WriteInt8( file, bitmapInfo->Red ); - WriteInt8( file, bitmapInfo->Reserved ); -} - -void WriteWaveFormatEx( FILE * file, WaveFormatEx * waveFormatEx ) -{ - WriteInt32( file, waveFormatEx->FourCC ); - WriteInt32( file, waveFormatEx->BytesCount ); - WriteInt16( file, waveFormatEx->FormatTag ); - WriteInt16( file, waveFormatEx->Channels ); - WriteInt32( file, waveFormatEx->SamplesPerSec ); - WriteInt32( file, waveFormatEx->AvgBytesPerSec ); - WriteInt16( file, waveFormatEx->BlockAlign ); - WriteInt16( file, waveFormatEx->BitsPerSample ); - WriteInt16( file, waveFormatEx->Size ); - WriteInt16( file, waveFormatEx->Id ); - WriteInt32( file, waveFormatEx->Flags ); - WriteInt16( file, waveFormatEx->BlockSize ); - WriteInt16( file, waveFormatEx->FramesPerBlock ); - WriteInt16( file, waveFormatEx->CodecDelay ); -} - -void WriteMainHeader( FILE * file, AviMainHeader * mainHeader ) -{ - WriteInt32( file, mainHeader->FourCC ); - WriteInt32( file, mainHeader->BytesCount ); - WriteInt32( file, mainHeader->MicroSecPerFrame ); - WriteInt32( file, mainHeader->MaxBytesPerSec ); - WriteInt32( file, mainHeader->PaddingGranularity ); - WriteInt32( file, mainHeader->Flags ); - WriteInt32( file, mainHeader->TotalFrames ); - WriteInt32( file, mainHeader->InitialFrames ); - WriteInt32( file, mainHeader->Streams ); - WriteInt32( file, mainHeader->SuggestedBufferSize ); - WriteInt32( file, mainHeader->Width ); - WriteInt32( file, mainHeader->Height ); - WriteInt32( file, mainHeader->Reserved[0] ); - WriteInt32( file, mainHeader->Reserved[1] ); - WriteInt32( file, mainHeader->Reserved[2] ); - WriteInt32( file, mainHeader->Reserved[3] ); -} - -void WriteStreamHeader( FILE * file, AviStreamHeader * streamHeader ) -{ - WriteInt32( file, streamHeader->FourCC ); - WriteInt32( file, streamHeader->BytesCount ); - WriteInt32( file, streamHeader->Type ); - WriteInt32( file, streamHeader->Handler ); - WriteInt32( file, streamHeader->Flags ); - WriteInt16( file, streamHeader->Priority ); - WriteInt16( file, streamHeader->Language ); - WriteInt32( file, streamHeader->InitialFrames ); - WriteInt32( file, streamHeader->Scale ); - WriteInt32( file, streamHeader->Rate ); - WriteInt32( file, streamHeader->Start ); - WriteInt32( file, streamHeader->Length ); - WriteInt32( file, streamHeader->SuggestedBufferSize ); - WriteInt32( file, streamHeader->Quality ); - WriteInt32( file, streamHeader->SampleSize ); - WriteInt16( file, streamHeader->Left ); - WriteInt16( file, streamHeader->Top ); - WriteInt16( file, streamHeader->Right ); - WriteInt16( file, streamHeader->Bottom ); -} - -HBAviIndex::HBAviIndex( uint32_t size ) - : HBBuffer( size ) -{ - fSize = 0; -} - -void HBAviIndex::WriteInt32( uint32_t val ) -{ - if( fSize + 16 > fAllocSize ) - { - /* Realloc if needed */ - Log( "HBAviIndex::WriteInt32() : reallocing index (%d -> %d MB)", - fAllocSize / ( 1024 * 1024 ), - 1 + fAllocSize / ( 1024 * 1024 ) ); - ReAlloc( fAllocSize + 1024 * 1024 ); - } - - fData[fSize] = val & 0xFF; - fData[fSize + 1] = ( val >> 8 ) & 0xFF; - fData[fSize + 2] = ( val >> 16 ) & 0xFF; - fData[fSize + 3] = val >> 24; - - fSize += 4; -} - -HBAviMuxer::HBAviMuxer( HBManager * manager, HBTitle * title, - HBAudio * audio1, HBAudio * audio2, - char * fileName ) - : HBThread( "avimuxer", HB_NORMAL_PRIORITY ) -{ - fManager = manager; - fTitle = title; - fAudio1 = audio1; - fAudio2 = audio2; - fFileName = strdup( fileName ); - - fVideoBuffer = NULL; - fAudio1Buffer = NULL; - fAudio2Buffer = NULL; - - fRiffBytesCount = 2040; - fMoviBytesCount = 4; - - Run(); -} - -void HBAviMuxer::DoWork() -{ - /* Open the destination file */ - if( !( fFile = fopen( fFileName, "w" ) ) ) - { - Log( "HBAviMuxer: fopen failed" ); - fManager->Error( HB_ERROR_AVI_WRITE ); - return; - } - - /* Initializations */ - memset( &fMainHeader, 0, sizeof( AviMainHeader ) ); - memset( &fVideoStreamHeader, 0, sizeof( AviStreamHeader ) ); - memset( &fAudio1StreamHeader, 0, sizeof( AviStreamHeader ) ); - memset( &fAudio2StreamHeader, 0, sizeof( AviStreamHeader ) ); - memset( &fVideoStreamFormat, 0, sizeof( BitmapInfo ) ); - memset( &fAudio1StreamFormat, 0, sizeof( WaveFormatEx ) ); - memset( &fAudio2StreamFormat, 0, sizeof( WaveFormatEx ) ); - - /* Alloc an 1 MB index (to be realloced later if needed) */ - fIndex = new HBAviIndex( 1024 * 1024 ); - - /* Main loop */ - for( ;; ) - { - while( fSuspend ) - { - Snooze( 10000 ); - } - - if( !fVideoBuffer ) - { - fVideoBuffer = Pop( fTitle->fMpeg4Fifo ); - } - if( fAudio1 && !fAudio1Buffer ) - { - fAudio1Buffer = Pop( fAudio1->fMp3Fifo ); - } - if( fAudio2 && !fAudio2Buffer ) - { - fAudio2Buffer = Pop( fAudio2->fMp3Fifo ); - } - - if( !fVideoBuffer && !fAudio1Buffer && !fAudio2Buffer ) - { - break; - } - - if( fVideoBuffer && - ( !fAudio1Buffer || - fVideoBuffer->fPosition < fAudio1Buffer->fPosition ) && - ( !fAudio2Buffer || - fVideoBuffer->fPosition < fAudio2Buffer->fPosition ) ) - { - AddVideoChunk(); - } - else if( fAudio1Buffer && - ( !fAudio2Buffer || - fAudio1Buffer->fPosition < fAudio2Buffer->fPosition ) ) - { - AddAudioChunk( 1 ); - } - else - { - AddAudioChunk( 2 ); - } - } - - /* Write the index */ - fseek( fFile, 0, SEEK_END ); - WriteInt32( fFile, FOURCC( "idx1" ) ); - WriteInt32( fFile, fIndex->fSize ); - WriteBuffer( fFile, fIndex ); - - /* Update the headers */ - fRiffBytesCount += 8 + fIndex->fSize; - fMainHeader.Flags |= AVIF_HASINDEX; - UpdateMainHeader(); - - delete fIndex; - - fclose( fFile ); -} - -bool HBAviMuxer::AddVideoChunk() -{ - fRiffBytesCount += 8 + EVEN( fVideoBuffer->fSize ); - fMoviBytesCount += 8 + EVEN( fVideoBuffer->fSize ); - - fMainHeader.MicroSecPerFrame = 1000000 * (uint64_t) fTitle->fScale / - fTitle->fRate; - fMainHeader.TotalFrames++; - fMainHeader.Width = fTitle->fOutWidth; - fMainHeader.Height = fTitle->fOutHeight; - - fVideoStreamHeader.FourCC = FOURCC( "strh" ); - fVideoStreamHeader.BytesCount = AVI_STREAM_HEADER_SIZE - 8; - fVideoStreamHeader.Type = FOURCC( "vids" ); - fVideoStreamHeader.Handler = FOURCC( "DIVX" ); - fVideoStreamHeader.Scale = fTitle->fScale; - fVideoStreamHeader.Rate = fTitle->fRate; - fVideoStreamHeader.Length++; - - fVideoStreamFormat.FourCC = FOURCC( "strf" ); - fVideoStreamFormat.BytesCount = BITMAP_INFO_SIZE - 8; - fVideoStreamFormat.Size = BITMAP_INFO_SIZE - 8; - fVideoStreamFormat.Width = fTitle->fOutWidth; - fVideoStreamFormat.Height = fTitle->fOutHeight; - fVideoStreamFormat.Planes = 1; - fVideoStreamFormat.BitCount = 24; - fVideoStreamFormat.Compression = FOURCC( "DIVX" );; - - UpdateMainHeader(); - - fseek( fFile, 0, SEEK_END ); - - /* Update the index */ - fIndex->WriteInt32( FOURCC( "00dc" ) ); - fIndex->WriteInt32( fVideoBuffer->fKeyFrame ? AVIIF_KEYFRAME : 0 ); - fIndex->WriteInt32( ftell( fFile ) - 2044 ); - fIndex->WriteInt32( fVideoBuffer->fSize ); - - /* Write the chunk */ - WriteInt32( fFile, FOURCC( "00dc" ) ); - WriteInt32( fFile, fVideoBuffer->fSize ); - WriteBuffer( fFile, fVideoBuffer ); - - /* Chunks must be 2-bytes aligned */ - if( fVideoBuffer->fSize & 1 ) - { - WriteInt8( fFile, 0 ); - } - - delete fVideoBuffer; - fVideoBuffer = NULL; - - return true; -} - -bool HBAviMuxer::AddAudioChunk( int track ) -{ - HBAudio * info; - HBBuffer * buffer; - AviStreamHeader * streamHeader; - WaveFormatEx * streamFormat; - - if( track == 1 ) - { - info = fAudio1; - buffer = fAudio1Buffer; - streamHeader = &fAudio1StreamHeader; - streamFormat = &fAudio1StreamFormat; - } - else - { - info = fAudio2; - buffer = fAudio2Buffer; - streamHeader = &fAudio2StreamHeader; - streamFormat = &fAudio2StreamFormat; - } - - fRiffBytesCount += 8 + EVEN( buffer->fSize ); - fMoviBytesCount += 8 + EVEN( buffer->fSize ); - - streamHeader->FourCC = FOURCC( "strh" ); - streamHeader->BytesCount = AVI_STREAM_HEADER_SIZE - 8; - streamHeader->Type = FOURCC( "auds" ); - streamHeader->InitialFrames = 1; - streamHeader->Scale = 1152; - streamHeader->Rate = info->fOutSampleRate; - streamHeader->Length++; - streamHeader->Quality = 0xFFFFFFFF; - - - streamFormat->FourCC = FOURCC( "strf" ); - streamFormat->BytesCount = WAVE_FORMAT_EX_SIZE - 8; - streamFormat->FormatTag = 0x55; - streamFormat->Channels = 2; - streamFormat->SamplesPerSec = info->fOutSampleRate; - streamFormat->AvgBytesPerSec = info->fOutBitrate * 1024 / 8; - streamFormat->BlockAlign = 1152; - - /* stolen from libavformat/wav.c */ - streamFormat->Size = 12; - streamFormat->Id = 1; - streamFormat->Flags = 2; - streamFormat->BlockSize = 1152; - streamFormat->FramesPerBlock = 1; - streamFormat->CodecDelay = 1393; - - UpdateMainHeader(); - - fseek( fFile, 0, SEEK_END ); - - /* Update the index */ - if( track == 1 ) - { - fIndex->WriteInt32( FOURCC( "01wb" ) ); - } - else - { - fIndex->WriteInt32( FOURCC( "02wb" ) ); - } - fIndex->WriteInt32( buffer->fKeyFrame ? AVIIF_KEYFRAME : 0 ); - fIndex->WriteInt32( ftell( fFile ) - 2044 ); - fIndex->WriteInt32( buffer->fSize ); - - /* Write the chunk */ - WriteInt32( fFile, - ( track == 1 ) ? FOURCC( "01wb" ) : FOURCC( "02wb" ) ); - WriteInt32( fFile, buffer->fSize ); - WriteBuffer( fFile, buffer ); - - /* Chunks must be 2-bytes aligned */ - if( buffer->fSize & 1 ) - { - WriteInt8( fFile, 0 ); - } - - delete buffer; - if( track == 1 ) - { - fAudio1Buffer = NULL; - } - else - { - fAudio2Buffer = NULL; - } - - return true; -} - -void HBAviMuxer::UpdateMainHeader() -{ - fMainHeader.FourCC = FOURCC( "avih" ); - fMainHeader.BytesCount = AVI_MAIN_HEADER_SIZE - 8; - fMainHeader.Streams = 1 + ( fAudio1 ? 1 : 0 ) + - ( fAudio2 ? 1 : 0 ); - - fHdrlBytesCount = 4 + AVI_MAIN_HEADER_SIZE + 12 + - AVI_STREAM_HEADER_SIZE + BITMAP_INFO_SIZE; - - if( fAudio1 ) - { - fHdrlBytesCount += 12 + AVI_STREAM_HEADER_SIZE + - WAVE_FORMAT_EX_SIZE; - } - if( fAudio2 ) - { - fHdrlBytesCount += 12 + AVI_STREAM_HEADER_SIZE + - WAVE_FORMAT_EX_SIZE; - } - - fseek( fFile, 0, SEEK_SET ); - WriteInt32( fFile, FOURCC( "RIFF" ) ); - WriteInt32( fFile, fRiffBytesCount ); - WriteInt32( fFile, FOURCC( "AVI " ) ); - WriteInt32( fFile, FOURCC( "LIST" ) ); - WriteInt32( fFile, fHdrlBytesCount ); - WriteInt32( fFile, FOURCC( "hdrl" ) ); - - WriteMainHeader( fFile, &fMainHeader ); - - int strlSize; - strlSize = 4 + AVI_STREAM_HEADER_SIZE + BITMAP_INFO_SIZE; - WriteInt32( fFile, FOURCC( "LIST" ) ); - WriteInt32( fFile, strlSize ); - WriteInt32( fFile, FOURCC( "strl" ) ); - - WriteStreamHeader( fFile, &fVideoStreamHeader ); - WriteBitmapInfo( fFile, &fVideoStreamFormat ); - - if( fAudio1 ) - { - strlSize = 4 + AVI_STREAM_HEADER_SIZE + WAVE_FORMAT_EX_SIZE; - WriteInt32( fFile, FOURCC( "LIST" ) ); - WriteInt32( fFile, strlSize ); - WriteInt32( fFile, FOURCC( "strl" ) ); - WriteStreamHeader( fFile, &fAudio1StreamHeader ); - WriteWaveFormatEx( fFile, &fAudio1StreamFormat ); - } - - if( fAudio2 ) - { - strlSize = 4 + AVI_STREAM_HEADER_SIZE + WAVE_FORMAT_EX_SIZE; - WriteInt32( fFile, FOURCC( "LIST" ) ); - WriteInt32( fFile, strlSize ); - WriteInt32( fFile, FOURCC( "strl" ) ); - WriteStreamHeader( fFile, &fAudio2StreamHeader ); - WriteWaveFormatEx( fFile, &fAudio2StreamFormat ); - } - - /* a JUNK chunk to fill the free space. - size = 2048 -/ - 12 ("RIFFxxxxAVI ") - - 8 (hdrl's "LIS1Txxxx") - - fHdrlBytesCount - - 8 ("JUNKxxxx") - - 12 ("LISTxxxxmovi) */ - int junkSize = 2008 - fHdrlBytesCount; - WriteInt32( fFile, FOURCC( "JUNK" ) ); - WriteInt32( fFile, junkSize ); - for( uint32_t i = 0; i < 2008 - fHdrlBytesCount; i++ ) - { - WriteInt8( fFile, 0 ); - } - - /* movi list */ - WriteInt32( fFile, FOURCC( "LIST" ) ); - WriteInt32( fFile, fMoviBytesCount ); - WriteInt32( fFile, FOURCC( "movi" ) ); -} diff --git a/core/AviMuxer.h b/core/AviMuxer.h deleted file mode 100644 index 842f7a87..00000000 --- a/core/AviMuxer.h +++ /dev/null @@ -1,153 +0,0 @@ -/* $Id: AviMuxer.h,v 1.10 2003/09/30 14:38:15 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_AVI_MUXER_H -#define HB_AVI_MUXER_H - -#include "Common.h" -#include "Fifo.h" -#include "Thread.h" - -/* Misc structures used in AVI headers */ -#define BITMAP_INFO_SIZE 52 -typedef struct BitmapInfo -{ - uint32_t FourCC; - uint32_t BytesCount; - uint32_t Size; - uint32_t Width; - uint32_t Height; - uint16_t Planes; - uint16_t BitCount; - uint32_t Compression; - uint32_t SizeImage; - uint32_t XPelsPerMeter; - uint32_t YPelsPerMeter; - uint32_t ClrUsed; - uint32_t ClrImportant; - uint8_t Blue; - uint8_t Green; - uint8_t Red; - uint8_t Reserved; -} BitmapInfo; - -#define WAVE_FORMAT_EX_SIZE 38 -typedef struct WaveFormatEx -{ - uint32_t FourCC; - uint32_t BytesCount; - uint16_t FormatTag; - uint16_t Channels; - uint32_t SamplesPerSec; - uint32_t AvgBytesPerSec; - uint16_t BlockAlign; - uint16_t BitsPerSample; - uint16_t Size; - - /* mp3 specific */ - uint16_t Id; - uint32_t Flags; - uint16_t BlockSize; - uint16_t FramesPerBlock; - uint16_t CodecDelay; -} WaveFormatEx; - -#define AVI_STREAM_HEADER_SIZE 64 -typedef struct AviStreamHeader -{ - uint32_t FourCC; - uint32_t BytesCount; - uint32_t Type; - uint32_t Handler; - uint32_t Flags; - uint16_t Priority; - uint16_t Language; - uint32_t InitialFrames; - uint32_t Scale; - uint32_t Rate; - uint32_t Start; - uint32_t Length; - uint32_t SuggestedBufferSize; - uint32_t Quality; - uint32_t SampleSize; - int16_t Left; - int16_t Top; - int16_t Right; - int16_t Bottom; -} AviStreamHeader; - -#define AVI_MAIN_HEADER_SIZE 64 -typedef struct AviMainHeader -{ - uint32_t FourCC; - uint32_t BytesCount; - uint32_t MicroSecPerFrame; - uint32_t MaxBytesPerSec; - uint32_t PaddingGranularity; - uint32_t Flags; - uint32_t TotalFrames; - uint32_t InitialFrames; - uint32_t Streams; - uint32_t SuggestedBufferSize; - uint32_t Width; - uint32_t Height; - uint32_t Reserved[4]; -} AviMainHeader; - -class HBAviIndex : public HBBuffer -{ - public: - HBAviIndex( uint32_t size ); - void WriteInt32( uint32_t val ); -}; - -class HBAviMuxer : public HBThread -{ - public: - HBAviMuxer( HBManager * manager, - HBTitle * title, HBAudio * audio1, - HBAudio * audio2, - char * fileName ); - - private: - void DoWork(); - bool AddVideoChunk(); - bool AddAudioChunk( int track ); - void UpdateMainHeader(); - - HBManager * fManager; - HBTitle * fTitle; - HBAudio * fAudio1; - HBAudio * fAudio2; - char * fFileName; - - FILE * fFile; - HBBuffer * fVideoBuffer; - HBBuffer * fAudio1Buffer; - HBBuffer * fAudio2Buffer; - - /* The main header */ - AviMainHeader fMainHeader; - - /* The video track */ - AviStreamHeader fVideoStreamHeader; - BitmapInfo fVideoStreamFormat; - - /* The audio tracks */ - AviStreamHeader fAudio1StreamHeader; - WaveFormatEx fAudio1StreamFormat; - AviStreamHeader fAudio2StreamHeader; - WaveFormatEx fAudio2StreamFormat; - - uint32_t fRiffBytesCount; - uint32_t fHdrlBytesCount; - uint32_t fMoviBytesCount; - - HBAviIndex * fIndex; - -}; - -#endif diff --git a/core/Common.cpp b/core/Common.cpp deleted file mode 100644 index 4087a001..00000000 --- a/core/Common.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* $Id: Common.cpp,v 1.31 2003/10/07 22:48:31 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#if defined( SYS_BEOS ) -# include -#endif - -#include "Common.h" -#include "Fifo.h" -#include "MpegDemux.h" -#include "Languages.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { -#include -} - -void Snooze( uint64_t time ) -{ -#if defined( SYS_BEOS ) - snooze( time ); -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - usleep( time ); -#endif -} - -void Log( char * log, ... ) -{ - if( !getenv( "HB_DEBUG" ) ) - { - return; - } - - char string[1024]; - - /* Show the time */ - time_t _now = time( NULL ); - struct tm * now = localtime( &_now ); - sprintf( string, "[%02d:%02d:%02d] ", - now->tm_hour, now->tm_min, now->tm_sec ); - - /* Convert the message to a string */ - va_list args; - va_start( args, log ); - int ret = vsnprintf( string + 11, 1011, log, args ); - va_end( args ); - - /* Add the end of line */ - string[ret+11] = '\n'; - string[ret+12] = '\0'; - - /* Print it */ - fprintf( stderr, "%s", string ); -} - -char * LanguageForCode( int code ) -{ - char codeString[2]; - codeString[0] = ( code >> 8 ) & 0xFF; - codeString[1] = code & 0xFF; - - iso639_lang_t * lang; - for( lang = languages; lang->engName; lang++ ) - { - if( !strncmp( lang->iso639_1, codeString, 2 ) ) - { - if( *lang->nativeName ) - return lang->nativeName; - - return lang->engName; - } - } - - return "Unknown"; -} - -uint64_t GetDate() -{ - struct timeval tv; - gettimeofday( &tv, NULL ); - return( (uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec ); -} - -int GetCPUCount() -{ - int CPUCount = 1; - -#if defined( SYS_BEOS ) - system_info info; - get_system_info( &info ); - CPUCount = info.cpu_count; - -#elif defined( SYS_MACOSX ) - FILE * info; - char buffer[256]; - - if( ( info = popen( "/usr/sbin/sysctl hw.ncpu", "r" ) ) ) - { - if( fgets( buffer, 256, info ) ) - { - int count; - if( sscanf( buffer, "hw.ncpu: %d", &count ) == 1 ) - { - CPUCount = count; - } - else - { - Log( "GetCPUCount: sscanf() failed" ); - } - } - else - { - Log( "GetCPUCount: fgets() failed" ); - } - fclose( info ); - } - else - { - Log( "GetCPUCount: popen() failed" ); - } - -#elif defined( SYS_LINUX ) - FILE * info; - char buffer[256]; - - if( ( info = fopen( "/proc/cpuinfo", "r" ) ) ) - { - int count = 0; - while( fgets( buffer, 256, info ) ) - { - if( !memcmp( buffer, "processor", - sizeof( "processor" ) - 1 ) ) - { - count++; - } - } - CPUCount = count; - fclose( info ); - } - else - { - Log( "GetCPUCount: fopen() failed" ); - } - -#endif - CPUCount = MAX( 1, CPUCount ); - CPUCount = MIN( CPUCount, 8 ); - - return CPUCount; -} - -#define HBLIST_DEFAULT_SIZE 20 - -HBList::HBList() -{ - fItems = (void**) malloc( HBLIST_DEFAULT_SIZE * sizeof( void* ) ); - fAllocItems = HBLIST_DEFAULT_SIZE; - fNbItems = 0; -} - -HBList::~HBList() -{ - free( fItems ); -} - -uint32_t HBList::CountItems() -{ - return fNbItems; -} - -void HBList::AddItem( void * item ) -{ - if( !item ) - { - return; - } - - if( fNbItems == fAllocItems ) - { - fAllocItems += HBLIST_DEFAULT_SIZE; - fItems = (void**) realloc( fItems, fAllocItems * sizeof( void* ) ); - } - - fItems[fNbItems] = item; - - fNbItems++; -} - -void HBList::RemoveItem( void * item ) -{ - if( !item || !fNbItems ) - { - return; - } - - uint32_t i; - for( i = 0; i < fNbItems; i++ ) - { - if( fItems[i] == item ) - { - break; - } - } - - if( fItems[i] != item ) - { - Log( "HBList::RemoveItem() : item not in the list" ); - return; - } - - for( ; i < fNbItems - 1; i++ ) - { - fItems[i] = fItems[i+1]; - } - - fNbItems--; -} - -void * HBList::ItemAt( uint32_t index ) -{ - if( index < fNbItems ) - { - return fItems[index]; - } - - return NULL; -} - -HBTitle::HBTitle( char * device, int index ) -{ - fDevice = strdup( device ); - fIndex = index; - - fAudioList = new HBList(); - fPSFifo = NULL; - fMpeg2Fifo = NULL; - fRawFifo = NULL; - fMpeg4Fifo = NULL; - - fTopCrop = 0; - fBottomCrop = 0; - fLeftCrop = 0; - fRightCrop = 0; - fBitrate = 1024; - fDeinterlace = false; - fTwoPass = false; -} - -HBTitle::~HBTitle() -{ - HBAudio * audio; - - while( ( audio = (HBAudio*) fAudioList->ItemAt( 0 ) ) ) - { - fAudioList->RemoveItem( audio ); - delete audio; - } - delete fAudioList; -} - -/* Audio track */ -HBAudio::HBAudio( int id, char * description ) -{ - fId = id; - fDescription = strdup( description ); - fOutSampleRate = 44100; - fOutBitrate = 128; - - fAc3Fifo = NULL; - fRawFifo = NULL; - fMp3Fifo = NULL; -} - -HBAudio::~HBAudio() -{ - free( fDescription ); -} diff --git a/core/Common.h b/core/Common.h deleted file mode 100644 index 3c138e2a..00000000 --- a/core/Common.h +++ /dev/null @@ -1,215 +0,0 @@ -/* $Id: Common.h,v 1.34 2003/10/13 17:49:58 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_COMMON_H -#define HB_COMMON_H - -/* Standard headers */ -#include -#include -#include -#include -#include -typedef uint8_t byte_t; - -/* Misc structures */ -typedef struct a52_state_s a52_state_t; -typedef struct lame_global_struct lame_global_flags; -typedef struct dvdplay_s * dvdplay_ptr; -typedef struct mpeg2dec_s mpeg2dec_t; -typedef struct AVPicture AVPicture; -typedef struct AVFrame AVFrame; -typedef struct AVCodecContext AVCodecContext; -typedef struct ImgReSampleContext ImgReSampleContext; - -/* Classes */ -class HBAc3Decoder; -class HBAudio; -class HBAviIndex; -class HBAviMuxer; -class HBBuffer; -class HBDVDReader; -class HBFifo; -class HBList; -class HBLock; -class HBManager; -class HBMp3Encoder; -class HBMpeg2Decoder; -class HBMpeg4Encoder; -class HBMpegDemux; -class HBResizer; -class HBScanner; -class HBStatus; -class HBThread; -class HBTitle; -class HBWorker; - -/* Handy macros */ -#ifndef MIN -# define MIN( a, b ) ( ( (a) > (b) ) ? (b) : (a) ) -#endif -#ifndef MAX -# define MAX( a, b ) ( ( (a) > (b) ) ? (a) : (b) ) -#endif -#define EVEN( a ) ( ( (a) & 0x1 ) ? ( (a) + 1 ) : (a) ) -#define MULTIPLE_16( a ) ( 16 * ( ( (a) + 8 ) / 16 ) ) - -#define VOUT_ASPECT_FACTOR 432000 - -/* Global prototypes */ -void Snooze( uint64_t time ); -void Log( char * log, ... ); -char * LanguageForCode( int code ); -uint64_t GetDate(); -int GetCPUCount(); - -/* Possible states */ -typedef enum -{ - HB_MODE_UNDEF = 00000, - HB_MODE_NEED_VOLUME = 00001, - HB_MODE_SCANNING = 00002, - HB_MODE_INVALID_VOLUME = 00004, - HB_MODE_READY_TO_RIP = 00010, - HB_MODE_ENCODING = 00020, - HB_MODE_SUSPENDED = 00040, - HB_MODE_STOPPING = 00100, - HB_MODE_DONE = 00200, - HB_MODE_CANCELED = 00400, - HB_MODE_ERROR = 01000 -} HBMode; - -/* Possible errors */ -typedef enum -{ - HB_ERROR_A52_SYNC = 0, - HB_ERROR_AVI_WRITE, - HB_ERROR_DVD_OPEN, - HB_ERROR_DVD_READ, - HB_ERROR_MP3_INIT, - HB_ERROR_MP3_ENCODE, - HB_ERROR_MPEG4_INIT -} HBError; - -class HBStatus -{ - public: - HBMode fMode; - - /* HB_MODE_SCANNING */ - char * fScannedVolume; - int fScannedTitle; - - /* HB_MODE_SCANDONE */ - HBList * fTitleList; - - /* HB_MODE_ENCODING || HB_MODE_SUSPENDED */ - float fPosition; - float fFrameRate; - uint32_t fFrames; - uint64_t fStartDate; - uint32_t fRemainingTime; /* in seconds */ - uint64_t fSuspendDate; - - /* HB_MODE_ERROR */ - HBError fError; -}; - -class HBList -{ - public: - HBList(); - ~HBList(); - uint32_t CountItems(); - void AddItem( void * item ); - void RemoveItem( void * item ); - void * ItemAt( uint32_t index ); - - private: - void ** fItems; - uint32_t fAllocItems; - uint32_t fNbItems; -}; - -class HBAudio -{ - public: - HBAudio( int id, char * description ); - ~HBAudio(); - - /* Ident */ - uint32_t fId; - char * fDescription; - - /* Settings */ - int fInSampleRate; - int fOutSampleRate; - int fInBitrate; - int fOutBitrate; - - int64_t fDelay; /* in ms */ - - /* Fifos */ - HBFifo * fAc3Fifo; - HBFifo * fRawFifo; - HBFifo * fMp3Fifo; - - /* Threads */ - HBAc3Decoder * fAc3Decoder; - HBMp3Encoder * fMp3Encoder; -}; - -class HBTitle -{ - public: - HBTitle( char * device, int index ); - ~HBTitle(); - - char * fDevice; - int fIndex; - uint64_t fLength; - - /* Video input */ - uint32_t fInWidth; - uint32_t fInHeight; - uint32_t fAspect; - uint32_t fRate; - uint32_t fScale; - - /* Video output */ - bool fDeinterlace; - uint32_t fOutWidth; - uint32_t fOutHeight; - uint32_t fOutWidthMax; - uint32_t fOutHeightMax; - uint32_t fTopCrop; - uint32_t fBottomCrop; - uint32_t fLeftCrop; - uint32_t fRightCrop; - uint32_t fBitrate; - bool fTwoPass; - - /* Audio infos */ - HBList * fAudioList; - - /* Fifos */ - HBFifo * fPSFifo; - HBFifo * fMpeg2Fifo; - HBFifo * fRawFifo; - HBFifo * fResizedFifo; - HBFifo * fMpeg4Fifo; - - /* Threads */ - HBDVDReader * fDVDReader; - HBMpegDemux * fMpegDemux; - HBMpeg2Decoder * fMpeg2Decoder; - HBResizer * fResizer; - HBMpeg4Encoder * fMpeg4Encoder; - HBAviMuxer * fAviMuxer; - HBWorker * fWorkers[4]; -}; - -#endif diff --git a/core/DVDRead.c b/core/DVDRead.c new file mode 100644 index 00000000..58e8f103 --- /dev/null +++ b/core/DVDRead.c @@ -0,0 +1,328 @@ +/* $Id: DVDRead.c,v 1.4 2003/11/06 13:03:19 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "DVDRead.h" +#include "Fifo.h" +#include "Thread.h" + +#include +#include +#include +#include +#include + +/* Local prototypes */ +static void DVDReadThread( void * ); +static int DoPass( HBDVDRead * ); +static int Demux( HBDVDRead * ); +static int Push( HBDVDRead *, HBFifo * fifo, HBBuffer ** buffer ); + +struct HBDVDRead +{ + HBHandle * handle; + + dvdplay_ptr vmg; + HBTitle * title; + HBAudio * audio; + HBAudio * optAudio; + int beginPosition; + int endPosition; + int pass; + HBBuffer * psBuffer; + HBList * esBufferList; + HBBuffer * videoBuf; + HBBuffer * audioBuf; + HBBuffer * optAudioBuf; + int videoStart; + int audioStart; + int optAudioStart; + + int die; + HBThread * thread; +}; + +HBDVDRead * HBDVDReadInit( HBHandle * handle, HBTitle * t, + HBAudio * a1, HBAudio * a2 ) +{ + HBDVDRead * d; + if( !( d = malloc( sizeof( HBDVDRead ) ) ) ) + { + HBLog( "HBDVDReadInit: malloc() failed, gonna crash" ); + return NULL; + } + + /* Initializations */ + d->handle = handle; + d->vmg = NULL; + d->title = t; + d->audio = a1; + d->optAudio = a2; + d->beginPosition = 0; + d->endPosition = 0; + d->pass = 0; + d->psBuffer = NULL; + d->esBufferList = HBListInit(); + d->videoBuf = NULL; + d->audioBuf = NULL; + d->optAudioBuf = NULL; + d->videoStart = -1; + d->audioStart = -1; + d->optAudioStart = -1; + + /* Launch the thread */ + d->die = 0; + d->thread = HBThreadInit( "dvd reader", DVDReadThread, d, + HB_NORMAL_PRIORITY ); + + return d; +} + +void HBDVDReadClose( HBDVDRead ** _d ) +{ + HBBuffer * buffer; + + HBDVDRead * d = *_d; + + /* Stop the thread */ + d->die = 1; + HBThreadClose( &d->thread ); + + /* Clean up */ + while( ( buffer = (HBBuffer*) HBListItemAt( d->esBufferList, 0 ) ) ) + { + HBListRemove( d->esBufferList, buffer ); + HBBufferClose( &buffer ); + } + HBListClose( &d->esBufferList ) ; + free( d ); + + (*_d) = NULL; +} + +static void DVDReadThread( void * _d ) +{ + HBDVDRead * d = (HBDVDRead*) _d; + uint8_t dummy[DVD_VIDEO_LB_LEN]; + int i; + + /* Open the device */ + d->vmg = dvdplay_open( d->title->device, NULL, NULL ); + if( !d->vmg ) + { + HBLog( "HBDVDRead: dvdplay_open() failed" ); + HBErrorOccured( d->handle, HB_ERROR_DVD_OPEN ); + return; + } + + /* Open the title */ + dvdplay_start( d->vmg, d->title->index ); + d->beginPosition = dvdplay_title_first( d->vmg ); + 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 ); + + /* Do the job */ + for( i = 0; i < ( d->title->twoPass ? 2 : 1 ); i++ ) + { + dvdplay_seek( d->vmg, 0 ); + + HBLog( "HBDVDRead: starting pass %d of %d", i + 1, + d->title->twoPass ? 2 : 1 ); + + d->pass = d->title->twoPass ? ( i + 1 ) : 0; + + if( !DoPass( d ) ) + { + break; + } + } + + /* Flag the latest buffers so we know when we're done */ + if( !d->die ) + { + HBLog( "HBDVDRead: done" ); + + if( d->videoBuf ) + { + d->videoBuf->last = 1; + Push( d, d->title->mpeg2Fifo, &d->videoBuf ); + } + if( d->audioBuf ) + { + d->audioBuf->last = 1; + Push( d, d->audio->ac3Fifo, &d->audioBuf ); + } + if( d->optAudioBuf ) + { + d->optAudioBuf->last = 1; + Push( d, d->optAudio->ac3Fifo, &d->optAudioBuf ); + } + } + + /* Clean up */ + dvdplay_close( d->vmg ); +} + + +static int DoPass( HBDVDRead * d ) +{ + int i; + + for( i = 0; i < d->endPosition - d->beginPosition; i++ ) + { + d->psBuffer = HBBufferInit( DVD_VIDEO_LB_LEN ); + d->psBuffer->position = + (float) i / ( d->endPosition - d->beginPosition ); + + if( d->pass ) + { + d->psBuffer->position /= 2; + + if( d->pass == 2 ) + { + d->psBuffer->position += 0.5; + } + } + d->psBuffer->pass = d->pass; + + if( dvdplay_read( d->vmg, d->psBuffer->data, 1 ) < 0 ) + { + HBLog( "HBDVDRead: dvdplay_read() failed" ); + HBErrorOccured( d->handle, HB_ERROR_DVD_READ ); + HBBufferClose( &d->psBuffer ); + return 0; + } + + if( !Demux( d ) ) + { + return 0; + } + } + + return 1; +} + +static int Demux( HBDVDRead * d ) +{ + HBBuffer * esBuffer; + + /* Demux */ + HBPStoES( &d->psBuffer, d->esBufferList ); + + /* Push buffers */ + while( ( esBuffer = (HBBuffer*) HBListItemAt( d->esBufferList, 0 ) ) ) + { + /* First pass: trash audio buffers */ + if( d->pass == 1 && esBuffer->streamId != 0xE0 ) + { + HBListRemove( d->esBufferList, esBuffer ); + HBBufferClose( &esBuffer ); + continue; + } + + if( esBuffer->streamId == 0xE0 ) + { + if( d->videoStart < 0 ) + { + d->videoStart = esBuffer->pts / 90; + HBLog( "HBDVDRead: got first 0xE0 packet (%d)", + d->videoStart ); + } + + if( d->videoBuf ) + { + d->videoBuf->last = 0; + if( !Push( d, d->title->mpeg2Fifo, &d->videoBuf ) ) + { + return 0; + } + } + + HBListRemove( d->esBufferList, esBuffer ); + d->videoBuf = esBuffer; + } + else if( esBuffer->streamId == d->audio->id ) + { + if( d->audioStart < 0 ) + { + d->audioStart = esBuffer->pts / 90; + HBLog( "HBDVDRead: got first 0x%x packet (%d)", + d->audio->id, d->audioStart ); + + d->audio->delay = d->audioStart - d->videoStart; + } + + if( d->audioBuf ) + { + d->audioBuf->last = 0; + if( !Push( d, d->audio->ac3Fifo, &d->audioBuf ) ) + { + return 0; + } + } + + HBListRemove( d->esBufferList, esBuffer ); + d->audioBuf = esBuffer; + } + else if( d->optAudio && esBuffer->streamId == d->optAudio->id ) + { + if( d->optAudioStart < 0 ) + { + d->optAudioStart = esBuffer->pts / 90; + HBLog( "HBDVDRead: got first 0x%x packet (%d)", + d->optAudio->id, d->optAudioStart ); + + d->optAudio->delay = d->optAudioStart - d->videoStart; + } + + if( d->optAudioBuf ) + { + d->optAudioBuf->last = 0; + if( !Push( d, d->optAudio->ac3Fifo, &d->optAudioBuf ) ) + { + return 0; + } + } + + HBListRemove( d->esBufferList, esBuffer ); + d->optAudioBuf = esBuffer; + } + else + { + HBListRemove( d->esBufferList, esBuffer ); + HBBufferClose( &esBuffer ); + } + } + + return 1; +} + +static int Push( HBDVDRead * d, HBFifo * fifo, HBBuffer ** buffer ) +{ + for( ;; ) + { + HBCheckPaused( d->handle ); + + if( HBFifoPush( fifo, buffer ) ) + { + return 1; + } + + if( d->die ) + { + break; + } + + HBSnooze( 10000 ); + } + + return 0; +} + diff --git a/core/DVDRead.h b/core/DVDRead.h new file mode 100644 index 00000000..7a9aa7e2 --- /dev/null +++ b/core/DVDRead.h @@ -0,0 +1,16 @@ +/* $Id: DVDRead.h,v 1.1 2003/11/03 12:08:00 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_DVD_READ_H +#define HB_DVD_READ_H + +#include "HandBrakeInternal.h" + +HBDVDRead * HBDVDReadInit( HBHandle *, HBTitle *, + HBAudio *, HBAudio * ); +void HBDVDReadClose( HBDVDRead ** ); + +#endif diff --git a/core/DVDReader.cpp b/core/DVDReader.cpp deleted file mode 100644 index c3c0e6f3..00000000 --- a/core/DVDReader.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* $Id: DVDReader.cpp,v 1.18 2003/10/16 13:39:13 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "DVDReader.h" -#include "Manager.h" -#include "Fifo.h" - -#include -#include -#include -#include -#include - -HBDVDReader::HBDVDReader( HBManager * manager, HBTitle * title ) - : HBThread( "dvdreader", HB_NORMAL_PRIORITY ) -{ - fManager = manager; - fTitle = title; - - Run(); -} - -void HBDVDReader::DoWork() -{ - /* Open the device */ - dvdplay_ptr vmg; - vmg = dvdplay_open( fTitle->fDevice, NULL, NULL ); - if( !vmg ) - { - Log( "HBDVDReader: dvdplay_open() failed" ); - fManager->Error( HB_ERROR_DVD_OPEN ); - return; - } - - bool die = false; - for( int i = 0; i < ( fTitle->fTwoPass ? 2 : 1 ); i++ ) - { - /* Open the title */ - dvdplay_start( vmg, fTitle->fIndex ); - - /* Read */ - HBBuffer * dvdBuffer; - int beginPosition = dvdplay_position( vmg ); - int endPosition = dvdplay_title_end( vmg ); - - while( dvdplay_position( vmg ) < endPosition ) - { - while( fSuspend ) - { - Snooze( 10000 ); - } - - dvdBuffer = new HBBuffer( DVD_VIDEO_LB_LEN ); - dvdBuffer->fPosition = (float) ( dvdplay_position( vmg ) - - beginPosition ) / - (float) ( endPosition - beginPosition ) ; - if( fTitle->fTwoPass ) - { - dvdBuffer->fPosition /= 2; - if( i == 1 ) - { - dvdBuffer->fPosition += 0.5; - } - } - dvdBuffer->fPass = fTitle->fTwoPass ? ( i + 1 ) : 0; - - if( dvdplay_read( vmg, dvdBuffer->fData, 1 ) < 0 ) - { - Log( "HBDVDReader: dvdplay_read() failed" ); - delete dvdBuffer; - fManager->Error( HB_ERROR_DVD_READ ); - die = true; - break; - } - - if( !Push( fTitle->fPSFifo, dvdBuffer ) ) - { - die = true; - break; - } - } - - if( die ) - { - break; - } - } - - if( !die ) - { - fManager->Done(); - } - - /* Clean up */ - dvdplay_close( vmg ); -} diff --git a/core/DVDReader.h b/core/DVDReader.h deleted file mode 100644 index b76f5756..00000000 --- a/core/DVDReader.h +++ /dev/null @@ -1,25 +0,0 @@ -/* $Id: DVDReader.h,v 1.5 2003/09/30 14:38:15 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_DVD_READER_H -#define HB_DVD_READER_H - -#include "Common.h" -#include "Thread.h" - -class HBDVDReader : public HBThread -{ - public: - HBDVDReader( HBManager * manager, HBTitle * title ); - - private: - void DoWork(); - - HBManager * fManager; - HBTitle * fTitle; -}; - -#endif diff --git a/core/FfmpegEnc.c b/core/FfmpegEnc.c new file mode 100644 index 00000000..2118c29d --- /dev/null +++ b/core/FfmpegEnc.c @@ -0,0 +1,230 @@ +/* $Id: FfmpegEnc.c,v 1.5 2003/11/06 13:03:19 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "FfmpegEnc.h" +#include "Fifo.h" +#include "Work.h" + +#include + +/* Extern functions */ +void HBSetPosition( HBHandle *, float ); + +/* Local prototypes */ +static int FfmpegEncWork( HBWork * ); + +struct HBFfmpegEnc +{ + HB_WORK_COMMON_MEMBERS + + HBHandle * handle; + HBTitle * title; + + HBBuffer * mpeg4Buffer; + int pass; + AVCodecContext * context; + FILE * file; +}; + +HBFfmpegEnc * HBFfmpegEncInit( HBHandle * handle, HBTitle * title ) +{ + HBFfmpegEnc * f; + if( !( f = malloc( sizeof( HBFfmpegEnc ) ) ) ) + { + HBLog( "HBFfmpegEncInit: malloc() failed, gonna crash" ); + return NULL; + } + + f->name = strdup( "FfmpegEnc" ); + f->work = FfmpegEncWork; + + f->handle = handle; + f->title = title; + + f->mpeg4Buffer = NULL; + f->pass = 42; + f->context = NULL; + f->file = NULL; + + return f; +} + +void HBFfmpegEncClose( HBFfmpegEnc ** _f ) +{ + HBFfmpegEnc * f = *_f; + + if( f->context ) + { + HBLog( "HBFfmpegEnc: closing libavcodec (pass %d)", + f->pass ); + + avcodec_close( f->context ); + if( f->file ) + { + fclose( f->file ); + f->file = NULL; + } + } + free( f->name ); + free( f ); + + *_f = NULL; +} + +static int FfmpegEncWork( HBWork * w ) +{ + HBFfmpegEnc * f = (HBFfmpegEnc*) w; + HBTitle * title = f->title; + + HBBuffer * scaledBuffer; + HBBuffer * mpeg4Buffer; + AVFrame * frame; + + int didSomething = 0; + + if( f->mpeg4Buffer ) + { + if( HBFifoPush( title->mpeg4Fifo, &f->mpeg4Buffer ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + } + + if( ( scaledBuffer = HBFifoPop( title->scaledFifo ) ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + + /* Init or re-init if needed */ + if( scaledBuffer->pass != f->pass ) + { + AVCodec * codec; + AVCodecContext * context; + + if( f->context ) + { + HBLog( "HBFfmpegEnc: closing libavcodec (pass %d)", + f->pass ); + + avcodec_close( f->context ); + if( f->file ) + { + fclose( f->file ); + f->file = NULL; + } + } + + f->pass = scaledBuffer->pass; + + HBLog( "HBFfmpegEnc: opening libavcodec (pass %d)", f->pass ); + codec = avcodec_find_encoder( CODEC_ID_MPEG4 ); + if( !codec ) + { + HBLog( "HBFfmpegEnc: avcodec_find_encoder() failed" ); + HBErrorOccured( f->handle, HB_ERROR_MPEG4_INIT ); + return didSomething; + } + + context = avcodec_alloc_context(); + context->bit_rate = 1024 * title->bitrate; + context->bit_rate_tolerance = 10240 * title->bitrate; + context->width = title->outWidth; + context->height = title->outHeight; + context->frame_rate = title->rate; + context->frame_rate_base = title->rateBase; + context->gop_size = 10 * title->rate / + title->rateBase; + + if( f->pass ) + { + char fileName[1024]; memset( fileName, 0, 1024 ); + sprintf( fileName, "/tmp/HB.%d.ffmpeg.log", + HBGetPid( f->handle ) ); + + if( f->pass == 1 ) + { + f->file = fopen( fileName, "w" ); + + context->flags |= CODEC_FLAG_PASS1; + } + else + { + FILE * file; + int size; + char * log; + + file = fopen( fileName, "r" ); + fseek( file, 0, SEEK_END ); + size = ftell( file ); + fseek( file, 0, SEEK_SET ); + if( !( log = malloc( size + 1 ) ) ) + { + HBLog( "HBFfmpegEnc: malloc() failed, gonna crash" ); + } + log[size] = '\0'; + fread( log, size, 1, file ); + fclose( file ); + + context->flags |= CODEC_FLAG_PASS2; + context->stats_in = log; + } + } + + if( avcodec_open( context, codec ) < 0 ) + { + HBLog( "HBFfmpegEnc: avcodec_open() failed" ); + HBErrorOccured( f->handle, HB_ERROR_MPEG4_INIT ); + return didSomething; + } + + f->context = context; + } + + frame = avcodec_alloc_frame(); + frame->data[0] = scaledBuffer->data; + frame->data[1] = frame->data[0] + title->outWidth * + title->outHeight; + frame->data[2] = frame->data[1] + title->outWidth * + title->outHeight / 4; + frame->linesize[0] = title->outWidth; + frame->linesize[1] = title->outWidth / 2; + frame->linesize[2] = title->outWidth / 2; + + mpeg4Buffer = HBBufferInit( 3 * title->outWidth * + title->outHeight / 2 ); + mpeg4Buffer->position = scaledBuffer->position; + mpeg4Buffer->size = + avcodec_encode_video( f->context, mpeg4Buffer->data, + mpeg4Buffer->alloc, frame ); + mpeg4Buffer->keyFrame = f->context->coded_frame->key_frame; + + /* Inform the GUI about the current position */ + HBPosition( f->handle, scaledBuffer->position ); + + if( f->pass == 1 ) + { + if( f->context->stats_out ) + { + fprintf( f->file, "%s", f->context->stats_out ); + } + HBBufferClose( &mpeg4Buffer ); + } + + HBBufferClose( &scaledBuffer ); + free( frame ); + + f->mpeg4Buffer = mpeg4Buffer; + + return didSomething; +} diff --git a/core/FfmpegEnc.h b/core/FfmpegEnc.h new file mode 100644 index 00000000..8ab62201 --- /dev/null +++ b/core/FfmpegEnc.h @@ -0,0 +1,15 @@ +/* $Id: FfmpegEnc.h,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_FFMPEG_ENC_H +#define HB_FFMPEG_ENC_H + +#include "HandBrakeInternal.h" + +HBFfmpegEnc * HBFfmpegEncInit( HBHandle *, HBTitle * ); +void HBFfmpegEncClose( HBFfmpegEnc ** ); + +#endif diff --git a/core/Fifo.c b/core/Fifo.c new file mode 100644 index 00000000..a8f6034c --- /dev/null +++ b/core/Fifo.c @@ -0,0 +1,105 @@ +/* $Id: Fifo.c,v 1.2 2003/11/05 19:14:37 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Fifo.h" + +HBBuffer * HBBufferInit( int size ) +{ + HBBuffer * b; + if( !( b = malloc( sizeof( HBBuffer ) ) ) ) + { + HBLog( "HBBufferInit: malloc() failed, gonna crash" ); + return NULL; + } + + b->alloc = size; + b->size = size; + + if( !( b->data = malloc( size ) ) ) + { + HBLog( "HBBufferInit: malloc() failed, gonna crash" ); + free( b ); + return NULL; + } + + b->position = 0.0; + b->streamId = 0; + b->keyFrame = 0; + b->pts = 0; + b->pass = 0; + b->last = 0; + + return b; +} + +void HBBufferReAlloc( HBBuffer * b, int size ) +{ + b->alloc = size; + b->data = realloc( b->data, size ); + + if( !b->data ) + { + HBLog( "HBBufferReAlloc: realloc() failed, gonna crash soon" ); + } +} + +void HBBufferClose( HBBuffer ** b ) +{ + free( (*b)->data ); + (*b) = NULL; +} + +HBFifo * HBFifoInit( int capacity ) +{ + HBFifo * f; + if( !( f = malloc( sizeof( HBFifo ) ) ) ) + { + HBLog( "HBFifoInit: malloc() failed, gonna crash" ); + return NULL; + } + + f->capacity = capacity; + f->whereToPush = 0; + f->whereToPop = 0; + + if( !( f->buffers = malloc( ( capacity + 1 ) * sizeof( void* ) ) ) ) + { + HBLog( "HBFifoInit: malloc() failed, gonna crash" ); + free( f ); + return NULL; + } + + f->lock = HBLockInit(); + + return f; +} + +int HBFifoSize( HBFifo * f ) +{ + return ( f->capacity + 1 + f->whereToPush - f->whereToPop ) % + ( f->capacity + 1 ); +} + +void HBFifoClose( HBFifo ** _f ) +{ + HBFifo * f = (*_f); + + HBLog( "HBFifoClose: trashing %d buffer%s", + HBFifoSize( f ), ( HBFifoSize( f ) > 1 ) ? "s" : "" ); + + while( f->whereToPush != f->whereToPop ) + { + HBBufferClose( &(f->buffers[f->whereToPop]) ); + f->whereToPop++; + f->whereToPop %= ( f->capacity + 1 ); + } + + HBLockClose( &f->lock ); + free( f->buffers ); + free( f ); + (*_f) = NULL; +} + diff --git a/core/Fifo.cpp b/core/Fifo.cpp deleted file mode 100644 index d1d051c3..00000000 --- a/core/Fifo.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* $Id: Fifo.cpp,v 1.15 2003/10/13 14:12:18 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Fifo.h" -#include "Thread.h" - -HBBuffer::HBBuffer( uint32_t size ) -{ - fAllocSize = size; - fSize = size; - fKeyFrame = false; - fData = (uint8_t*) malloc( size ); - fPosition = 0; - - if( !fData ) - { - Log( "HBBuffer::HBBuffer() : malloc() failed, gonna crash soon" ); - } -} - -HBBuffer::~HBBuffer() -{ - free( fData ); -} - -void HBBuffer::ReAlloc( uint32_t size ) -{ - fData = (uint8_t*) realloc( fData, size ); - - if( !fData ) - { - Log( "HBBuffer::ReAlloc() : realloc() failed, gonna crash soon" ); - } - - fAllocSize = size; -} - -/* Constructor */ -HBFifo::HBFifo( int capacity ) -{ - fCapacity = capacity; - - fWhereToPush = 0; - fWhereToPop = 0; - fBuffers = (HBBuffer**) malloc( ( fCapacity + 1 ) * sizeof( void* ) ); - fLock = new HBLock(); -} - -HBFifo::~HBFifo() -{ - Log( "HBFifo::~HBFifo: trashing %d buffer%s", - Size(), Size() ? "s" : "" ); - - /* Empty the fifo */ - while( fWhereToPush != fWhereToPop ) - { - HBBuffer * buffer = fBuffers[fWhereToPop]; - fWhereToPop++; - fWhereToPop %= ( fCapacity + 1 ); - delete buffer; - } - - /* Cleaning */ - free( fBuffers ); - - delete fLock; -} - -/* Size() : returns how much the fifo is currently filled */ -int HBFifo::Size() -{ - return ( fCapacity + 1 + fWhereToPush - fWhereToPop ) % - ( fCapacity + 1 ); -} - -/* Capacity() : simply returns the fifo capacity... */ -int HBFifo::Capacity() -{ - return fCapacity; -} - -/* Push() - returns immediatly (true if successful, false otherwise ) */ -bool HBFifo::Push( HBBuffer * buffer ) -{ - fLock->Lock(); - - if( Size() < fCapacity ) - { - fBuffers[fWhereToPush] = buffer; - fWhereToPush++; - fWhereToPush %= ( fCapacity + 1 ); - fLock->Unlock(); - return true; - } - - fLock->Unlock(); - return false; -} - -/* Pop() - returns immediatly (a pointer to a buffer if successful, - NULL otherwise ) */ -HBBuffer * HBFifo::Pop() -{ - fLock->Lock(); - - if( fWhereToPush != fWhereToPop ) - { - HBBuffer * buffer = fBuffers[fWhereToPop]; - fWhereToPop++; - fWhereToPop %= ( fCapacity + 1 ); - fLock->Unlock(); - return buffer; - } - - fLock->Unlock(); - return NULL; -} diff --git a/core/Fifo.h b/core/Fifo.h index 69200d30..758125eb 100644 --- a/core/Fifo.h +++ b/core/Fifo.h @@ -1,49 +1,81 @@ -/* $Id: Fifo.h,v 1.11 2003/09/30 14:38:15 titer Exp $ +/* $Id: Fifo.h,v 1.3 2003/11/06 13:07:52 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #ifndef HB_FIFO_H #define HB_FIFO_H -#include "Common.h" +#include "Utils.h" +#include "Thread.h" -class HBBuffer +struct HBBuffer { - public: - HBBuffer( uint32_t size ); - ~HBBuffer(); - void ReAlloc( uint32_t size ); - - uint32_t fAllocSize; - uint32_t fSize; - uint8_t * fData; - - float fPosition; - uint32_t fStreamId; - bool fKeyFrame; - uint64_t fPTS; - uint32_t fPass; + int alloc; + int size; + uint8_t * data; + + float position; + int streamId; + int keyFrame; + uint64_t pts; + int pass; + int last; }; -class HBFifo +HBBuffer * HBBufferInit( int size ); +void HBBufferReAlloc( HBBuffer *, int size ); +void HBBufferClose( HBBuffer ** ); + +struct HBFifo { - public: - HBFifo( int capacity = 32 ); - ~HBFifo(); - - int Size(); - int Capacity(); - bool Push( HBBuffer * buffer ); - HBBuffer * Pop(); - - private: - int fCapacity; - int fWhereToPush; - int fWhereToPop; - HBBuffer ** fBuffers; - HBLock * fLock; + int capacity; + int whereToPush; + int whereToPop; + HBBuffer ** buffers; + HBLock * lock; }; +HBFifo * HBFifoInit( int capacity ); +int HBFifoSize( HBFifo * ); +static inline int HBFifoPush( HBFifo *, HBBuffer ** ); +static inline HBBuffer * HBFifoPop( HBFifo * ); +void HBFifoClose( HBFifo ** ); + +static inline int HBFifoPush( HBFifo * f, HBBuffer ** b ) +{ + HBLockLock( f->lock ); + + if( HBFifoSize( f ) < f->capacity ) + { + f->buffers[f->whereToPush] = *b; + f->whereToPush++; + f->whereToPush %= ( f->capacity + 1 ); + HBLockUnlock( f->lock ); + *b = NULL; + return 1; + } + + HBLockUnlock( f->lock ); + return 0; +} + +static inline HBBuffer * HBFifoPop( HBFifo * f ) +{ + HBLockLock( f->lock ); + + if( f->whereToPush != f->whereToPop ) + { + HBBuffer * b = f->buffers[f->whereToPop]; + f->whereToPop++; + f->whereToPop %= ( f->capacity + 1 ); + HBLockUnlock( f->lock ); + return b; + } + + HBLockUnlock( f->lock ); + return NULL; +} + #endif diff --git a/core/HandBrake.c b/core/HandBrake.c new file mode 100644 index 00000000..3f84a575 --- /dev/null +++ b/core/HandBrake.c @@ -0,0 +1,767 @@ +/* $Id: HandBrake.c,v 1.15 2003/11/07 21:52:57 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "HandBrakeInternal.h" + +#include + +#include "Ac3Dec.h" +#include "AviMux.h" +#include "DVDRead.h" +#include "FfmpegEnc.h" +#include "Fifo.h" +#include "Mp3Enc.h" +#include "Mpeg2Dec.h" +#include "Scale.h" +#include "Scan.h" +#include "Thread.h" +#include "Work.h" +#include "XvidEnc.h" + +/* Local prototypes */ +static void HandBrakeThread( void * ); +static void _StopRip( HBHandle * ); +static void FixPictureSettings( HBTitle * ); +static int GetCPUCount(); + +struct HBHandle +{ + HBThread * thread; + int die; + int pid; + + int cpuCount; + + int stopScan; + int stopRip; + int ripDone; + int error; + + HBScan * scan; + + HBLock * lock; + HBStatus status; + int modeChanged; + HBTitle * curTitle; + HBAudio * curAudio; + HBAudio * curOptAudio; + + int frames; + uint64_t beginDate; + int framesSinceFpsUpdate; + uint64_t lastFpsUpdate; + uint64_t pauseDate; + + HBLock * pauseLock; +}; + +HBHandle * HBInit( int debug, int cpuCount ) +{ + HBHandle * h; + if( !( h = malloc( sizeof( HBHandle ) ) ) ) + { + HBLog( "HBInit: malloc() failed, gonna crash" ); + return NULL; + } + + /* See HBLog() in Utils.cpp */ + if( debug ) + { + putenv( "HB_DEBUG=1" ); + } + + /* Init libavcodec */ + avcodec_init(); + register_avcodec( &mpeg4_encoder ); + + /* Check CPU count */ + if( !cpuCount ) + { + h->cpuCount = GetCPUCount(); + HBLog( "HBInit: %d CPU%s detected", h->cpuCount, + ( h->cpuCount > 1 ) ? "s" : "" ); + } + else + { + if( cpuCount < 1 ) + { + HBLog( "HBInit: invalid CPU count (%d), using 1", + cpuCount ); + h->cpuCount = 1; + } + else if( cpuCount > 8 ) + { + HBLog( "HBInit: invalid CPU count (%d), using 8", + cpuCount ); + h->cpuCount = 8; + } + else + { + HBLog( "HBInit: user specified %d CPU%s", + cpuCount, ( cpuCount > 1 ) ? "s" : "" ); + h->cpuCount = cpuCount; + } + } + + /* Initializations */ + h->stopScan = 0; + h->stopRip = 0; + h->ripDone = 0; + h->error = 0; + + h->scan = NULL; + + h->lock = HBLockInit(); + h->modeChanged = 1; + h->status.mode = HB_MODE_NEED_DEVICE; + h->curTitle = NULL; + h->curAudio = NULL; + h->curOptAudio = NULL; + + h->pauseLock = HBLockInit(); + + h->die = 0; + h->thread = HBThreadInit( "libhb", HandBrakeThread, h, + HB_NORMAL_PRIORITY ); + + return h; +} + +int HBGetStatus( HBHandle * h, HBStatus * status ) +{ + HBLockLock( h->lock ); + memcpy( status, &h->status, sizeof( HBStatus ) ); + + if( !h->modeChanged ) + { + HBLockUnlock( h->lock ); + return 0; + } + + h->modeChanged = 0; + HBLockUnlock( h->lock ); + return 1; +} + +void HBScanDevice( HBHandle * h, char * device, int title ) +{ + if( !( h->status.mode & ( HB_MODE_NEED_DEVICE | + HB_MODE_INVALID_DEVICE ) ) ) + { + HBLog( "HBScanDevice: current mode is %d, aborting", + h->status.mode ); + return; + } + + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HB_MODE_SCANNING; + h->status.scannedTitle = 0; + HBLockUnlock( h->lock ); + + h->scan = HBScanInit( h, device, title ); +} + +void HBStartRip( HBHandle * h, HBTitle * t, + HBAudio * a1, HBAudio * a2 ) +{ + int i; + + if( !( h->status.mode & ( HB_MODE_READY_TO_RIP | HB_MODE_DONE | + HB_MODE_CANCELED | HB_MODE_ERROR ) ) ) + { + HBLog( "HBStartRip: current mode is %d, aborting", + h->status.mode ); + return; + } + + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HB_MODE_ENCODING; + h->status.position = 0.0; + h->status.pass = 1; + h->status.passCount = t->twoPass ? 2 : 1; + h->frames = 0; + h->framesSinceFpsUpdate = 0; + HBLockUnlock( h->lock ); + + FixPictureSettings( t ); + + /* Create fifos */ + t->mpeg2Fifo = HBFifoInit( 512 ); + t->rawFifo = HBFifoInit( 1 ); + t->scaledFifo = HBFifoInit( 1 ); + t->mpeg4Fifo = HBFifoInit( 1 ); + a1->ac3Fifo = HBFifoInit( 512 ); + a1->rawFifo = HBFifoInit( 1 ); + a1->mp3Fifo = HBFifoInit( 1 ); + if( a2 ) + { + a2->ac3Fifo = HBFifoInit( 512 ); + a2->rawFifo = HBFifoInit( 1 ); + a2->mp3Fifo = HBFifoInit( 1 ); + } + + /* Create work objects */ + t->mpeg2Dec = HBMpeg2DecInit( h, t ); + t->scale = HBScaleInit( h, t ); + + if( t->codec == HB_CODEC_FFMPEG ) + t->ffmpegEnc = HBFfmpegEncInit( h, t ); + else if( t->codec == HB_CODEC_XVID ) + t->xvidEnc = HBXvidEncInit( h, t ); + + a1->ac3Dec = HBAc3DecInit( h, a1 ); + a1->mp3Enc = HBMp3EncInit( h, a1 ); + if( a2 ) + { + a2->ac3Dec = HBAc3DecInit( h, a2 ); + a2->mp3Enc = HBMp3EncInit( h, a2 ); + } + + /* Create threads */ + t->dvdRead = HBDVDReadInit( h, t, a1, a2 ); + t->aviMux = HBAviMuxInit( h, t, a1, a2 ); + for( i = 0; i < h->cpuCount; i++ ) + { + t->workThreads[i] = HBWorkThreadInit( h, t, a1, a2, i ? 0 : 1 ); + } + + h->curTitle = t; + h->curAudio = a1; + h->curOptAudio = a2; +} + +void HBPauseRip( HBHandle * h ) +{ + if( h->status.mode != HB_MODE_ENCODING ) + { + HBLog( "HBPauseRip: current mode is %d, aborting", + h->status.mode ); + return; + } + + h->pauseDate = HBGetDate(); + HBLockLock( h->pauseLock ); + HBLockLock( h->lock ); + h->status.mode = HB_MODE_PAUSED; + h->modeChanged = 1; + HBLockUnlock( h->lock ); +} + +void HBResumeRip( HBHandle * h ) +{ + if( h->status.mode != HB_MODE_PAUSED ) + { + HBLog( "HBResumeRip: current mode is %d, aborting", + h->status.mode ); + return; + } + + h->beginDate += HBGetDate() - h->pauseDate; + h->lastFpsUpdate += HBGetDate() - h->pauseDate; + HBLockUnlock( h->pauseLock ); + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HB_MODE_ENCODING; + HBLockUnlock( h->lock ); +} + +void HBStopRip( HBHandle * h ) +{ + if( !( h->status.mode & ( HB_MODE_ENCODING | HB_MODE_PAUSED ) ) ) + { + HBLog( "HBStopRip: current mode is %d, aborting", + h->status.mode ); + return; + } + + if( h->status.mode & HB_MODE_PAUSED ) + { + HBLockUnlock( h->pauseLock ); + } + + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HB_MODE_STOPPING; + HBLockUnlock( h->lock ); + h->stopRip = 1; +} + +uint8_t * HBGetPreview( HBHandle * h, HBTitle * t, int picture ) +{ + AVPicture pic1, pic2, pic3, pic4; + uint8_t * buf1, * buf2, * buf3, * buf4; + char fileName[1024]; + FILE * file; + ImgReSampleContext * resampleContext; + int8_t * preview, * pen; + int i; + + FixPictureSettings( t ); + + buf1 = malloc( 3 * t->inWidth * t->inHeight / 2 ); + buf2 = malloc( 3 * t->inWidth * t->inHeight / 2 ); + buf3 = malloc( 3 * t->outWidth * t->outHeight / 2 ); + buf4 = malloc( 4 * t->outWidth * t->outHeight ); + + if( !buf1 || !buf2 || !buf3 || !buf4 ) + { + HBLog( "HBGetPreview: malloc() failed, gonna crash" ); + return NULL; + } + + /* Original YUV picture */ + avpicture_fill( &pic1, buf1, PIX_FMT_YUV420P, t->inWidth, + t->inHeight ); + + /* Deinterlaced YUV picture */ + avpicture_fill( &pic2, buf2, PIX_FMT_YUV420P, + t->inWidth, t->inHeight ); + + /* Scaled YUV picture */ + avpicture_fill( &pic3, buf3, PIX_FMT_YUV420P, t->outWidth, + t->outHeight ); + + /* Scaled RGB picture ) */ + avpicture_fill( &pic4, buf4, PIX_FMT_RGBA32, t->outWidth, + t->outHeight ); + + /* Get the original image from the temp file */ + memset( fileName, 0, 1024 ); + sprintf( fileName, "/tmp/HB.%d.%d.%d", h->pid, t->index, + picture ); + file = fopen( fileName, "r" ); + if( file ) + { + fread( buf1, 3 * t->inWidth * t->inHeight / 2, 1, file ); + fclose( file ); + } + else + { + HBLog( "HBGetPreview: could not open %s", fileName ); + memset( buf1, 0, 3 * t->inWidth * t->inHeight / 2 ); + } + + /* Deinterlace if needed, and scale */ + resampleContext = + img_resample_full_init( t->outWidth, t->outHeight, + t->inWidth, t->inHeight, + t->topCrop, t->bottomCrop, + t->leftCrop, t->rightCrop ); + if( t->deinterlace ) + { + avpicture_deinterlace( &pic2, &pic1, PIX_FMT_YUV420P, + t->inWidth, t->inHeight ); + img_resample( resampleContext, &pic3, &pic2 ); + } + else + { + img_resample( resampleContext, &pic3, &pic1 ); + } + + /* Convert to RGB */ + img_convert( &pic4, PIX_FMT_RGBA32, &pic3, PIX_FMT_YUV420P, + t->outWidth, t->outHeight ); + + /* Create the final preview */ + preview = malloc( 4 * ( t->outWidthMax + 2 ) * + ( t->outHeightMax + 2 ) ); + + if( !preview ) + { + HBLog( "HBGetPreview: malloc() failed, gonna crash" ); + return NULL; + } + + /* Blank it */ + memset( preview, 0x80, + 4 * ( t->outWidthMax + 2 ) * ( t->outHeightMax + 2 ) ); + + /* Draw the picture (centered) and draw the cropping zone */ + pen = preview + ( t->outHeightMax - t->outHeight ) * + ( t->outWidthMax + 2 ) * 2 + + ( t->outWidthMax - t->outWidth ) * 2; + + memset( pen, 0xFF, 4 * ( t->outWidth + 2 ) ); + pen += 4 * ( t->outWidthMax + 2 ); + + for( i = 0; i < t->outHeight; i++ ) + { + uint8_t * nextLine = pen + 4 * ( t->outWidthMax + 2 ); + + memset( pen, 0xFF, 4 ); + pen += 4; + memcpy( pen, buf4 + 4 * t->outWidth * i, 4 * t->outWidth ); + pen += 4 * t->outWidth; + memset( pen, 0xFF, 4 ); + + pen = nextLine; + } + + memset( pen, 0xFF, 4 * ( t->outWidth + 2 ) ); + + /* Free memory */ + free( buf1 ); + free( buf2 ); + free( buf3 ); + free( buf4 ); + + return preview; + return NULL; +} + +void HBClose( HBHandle ** _h ) +{ + char command[1024]; + + HBHandle * h = *_h; + + h->die = 1; + HBThreadClose( &h->thread ); + + if( h->status.mode == HB_MODE_SCANNING ) + { + HBScanClose( &h->scan ); + } + else if( h->status.mode == HB_MODE_PAUSED ) + { + HBLockUnlock( h->pauseLock ); + _StopRip( h ); + } + else if( h->status.mode == HB_MODE_ENCODING ) + { + _StopRip( h ); + } + + memset( command, 0, 1024 ); + sprintf( command, "rm -f /tmp/HB.%d.*", h->pid ); + system( command ); + + if( h->status.titleList ) + { + HBTitle * title; + while( ( title = HBListItemAt( h->status.titleList, 0 ) ) ) + { + HBListRemove( h->status.titleList, title ); + HBTitleClose( &title ); + } + HBListClose( &h->status.titleList ); + } + + HBLockClose( &h->lock ); + HBLockClose( &h->pauseLock ); + free( h ); + + *_h = NULL; +} + +/* Following functions are called by libhb's internal threads */ +void HBCheckPaused( HBHandle * h ) +{ + HBLockLock( h->pauseLock ); + HBLockUnlock( h->pauseLock ); +} + +void HBScanning( HBHandle * h, int title ) +{ + HBLockLock( h->lock ); + h->status.scannedTitle = title; + HBLockUnlock( h->lock ); +} + +void HBScanDone( HBHandle * h, HBList * titleList ) +{ + h->status.titleList = titleList; + h->stopScan = 1; +} + +int HBGetPid( HBHandle * h ) +{ + return h->pid; +} + +void HBDone( HBHandle * h ) +{ + h->ripDone = 1; +} + +void HBPosition( HBHandle * h, float position ) +{ + if( !h->frames ) + { + h->beginDate = HBGetDate(); + h->lastFpsUpdate = h->beginDate; + } + + h->frames++; + h->framesSinceFpsUpdate++; + + HBLockLock( h->lock ); + if( position - h->status.position > 0.0001 || h->frames == 2 ) + { + HBLog( "Progress: %.2f %%", 100.0 * position ); + h->status.position = position; + + if( h->curTitle->twoPass ) + h->status.pass = ( position < 0.5 ) ? 1 : 2; + else + h->status.pass = 1; + } + if( HBGetDate() - h->lastFpsUpdate > 1000000 ) + { + h->status.frameRate = 1000000.0 * h->framesSinceFpsUpdate / + ( HBGetDate() - h->lastFpsUpdate ); + h->status.avFrameRate = 1000000.0 * h->frames / + ( HBGetDate() - h->beginDate ); + h->status.remainingTime = ( 1.0 - h->status.position ) * + ( HBGetDate() - h->beginDate ) / + h->status.position / 1000000; + + HBLog( "Speed: %.2f fps (average: %.2f fps, " + "remaining: %02d:%02d:%02d)", + h->status.frameRate, h->status.avFrameRate, + h->status.remainingTime / 3600, + ( h->status.remainingTime / 60 ) % 60, + h->status.remainingTime % 60 ); + + h->lastFpsUpdate = HBGetDate(); + h->framesSinceFpsUpdate = 0; + } + HBLockUnlock( h->lock ); +} + +void HBErrorOccured( HBHandle * h, HBError error ) +{ + if( !( h->status.mode & ( HB_MODE_ENCODING | HB_MODE_PAUSED ) ) ) + { + return; + } + + h->status.error = error; + h->error = 1; +} + +/* Local functions */ +static void HandBrakeThread( void * _h ) +{ + HBHandle * h = (HBHandle*) _h; + + h->pid = getpid(); + + while( !h->die ) + { + if( h->stopScan ) + { + HBScanClose( &h->scan ); + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HBListCountItems( h->status.titleList ) ? + HB_MODE_READY_TO_RIP : HB_MODE_INVALID_DEVICE; + HBLockUnlock( h->lock ); + h->stopScan = 0; + } + + if( h->stopRip ) + { + _StopRip( h ); + + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HB_MODE_CANCELED; + HBLockUnlock( h->lock ); + + h->stopRip = 0; + } + + if( h->ripDone ) + { + /* Wait a bit */ + HBSnooze( 500000 ); + + _StopRip( h ); + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HB_MODE_DONE; + HBLockUnlock( h->lock ); + + h->ripDone = 0; + } + + if( h->error ) + { + _StopRip( h ); + + HBLockLock( h->lock ); + h->modeChanged = 1; + h->status.mode = HB_MODE_ERROR; + HBLockUnlock( h->lock ); + + h->error = 0; + } + + HBSnooze( 10000 ); + } +} + +static void _StopRip( HBHandle * h ) +{ + int i; + + /* Stop threads */ + HBDVDReadClose( &h->curTitle->dvdRead ); + HBAviMuxClose( &h->curTitle->aviMux ); + for( i = 0; i < h->cpuCount; i++ ) + { + HBWorkThreadClose( &h->curTitle->workThreads[h->cpuCount-i-1] ); + } + + /* Clean up */ + HBMpeg2DecClose( &h->curTitle->mpeg2Dec ); + HBScaleClose( &h->curTitle->scale ); + + if( h->curTitle->codec == HB_CODEC_FFMPEG ) + HBFfmpegEncClose( &h->curTitle->ffmpegEnc ); + else if( h->curTitle->codec == HB_CODEC_XVID ) + HBXvidEncClose( &h->curTitle->xvidEnc ); + + HBAc3DecClose( &h->curAudio->ac3Dec ); + HBMp3EncClose( &h->curAudio->mp3Enc ); + if( h->curOptAudio ) + { + HBAc3DecClose( &h->curOptAudio->ac3Dec ); + HBMp3EncClose( &h->curOptAudio->mp3Enc ); + } + + /* Destroy fifos */ + HBFifoClose( &h->curTitle->mpeg2Fifo ); + HBFifoClose( &h->curTitle->rawFifo ); + HBFifoClose( &h->curTitle->scaledFifo ); + HBFifoClose( &h->curTitle->mpeg4Fifo ); + HBFifoClose( &h->curAudio->ac3Fifo ); + HBFifoClose( &h->curAudio->rawFifo ); + HBFifoClose( &h->curAudio->mp3Fifo ); + if( h->curOptAudio ) + { + HBFifoClose( &h->curOptAudio->ac3Fifo ); + HBFifoClose( &h->curOptAudio->rawFifo ); + HBFifoClose( &h->curOptAudio->mp3Fifo ); + } +} + +static void FixPictureSettings( HBTitle * t ) +{ + /* Sanity checks */ + t->topCrop = EVEN( t->topCrop ); + t->bottomCrop = EVEN( t->bottomCrop ); + t->leftCrop = EVEN( t->leftCrop ); + t->rightCrop = EVEN( t->rightCrop ); + + t->outWidth = MIN( t->outWidth, t->outWidthMax ); + t->outWidth = MAX( 16, t->outWidth ); + + t->outHeight = + MULTIPLE_16( (uint64_t) t->outWidth * t->inWidth * + ( t->inHeight - t->topCrop - t->bottomCrop ) * + VOUT_ASPECT_FACTOR / + ( (uint64_t) t->inHeight * + ( t->inWidth - t->leftCrop - t->rightCrop ) * + t->aspect ) ); + t->outHeight = MAX( 16, t->outHeight ); + + if( t->outHeight > t->outHeightMax ) + { + t->outHeight = t->outHeightMax; + t->outWidth = + MULTIPLE_16( (uint64_t) t->outHeight * t->inHeight * + ( t->inWidth - t->leftCrop - t->rightCrop ) * + t->aspect / + ( (uint64_t) t->inWidth * + ( t->inHeight - t->topCrop - t->bottomCrop ) * + VOUT_ASPECT_FACTOR ) ); + t->outWidth = MIN( t->outWidth, t->outWidthMax ); + t->outWidth = MAX( 16, t->outWidth ); + } +} + +static int GetCPUCount() +{ + int CPUCount = 1; + +#if defined( SYS_BEOS ) + system_info info; + get_system_info( &info ); + CPUCount = info.cpu_count; + +#elif defined( SYS_MACOSX ) + FILE * info; + char buffer[256]; + + if( ( info = popen( "/usr/sbin/sysctl hw.ncpu", "r" ) ) ) + { + if( fgets( buffer, 256, info ) ) + { + int count; + if( sscanf( buffer, "hw.ncpu: %d", &count ) == 1 ) + { + CPUCount = count; + } + else + { + HBLog( "GetCPUCount: sscanf() failed" ); + } + } + else + { + HBLog( "GetCPUCount: fgets() failed" ); + } + fclose( info ); + } + else + { + HBLog( "GetCPUCount: popen() failed" ); + } + +#elif defined( SYS_LINUX ) + FILE * info; + char buffer[256]; + + if( ( info = popen( "grep -c '^processor' /proc/cpuinfo", "r" ) ) ) + { + if( fgets( buffer, 256, info ) ) + { + int count; + if( sscanf( buffer, "%d", &count ) == 1 ) + { + CPUCount = count; + } + else + { + HBLog( "GetCPUCount: sscanf() failed" ); + } + } + else + { + HBLog( "GetCPUCount: fgets() failed" ); + } + fclose( info ); + } + else + { + HBLog( "GetCPUCount: fopen() failed" ); + } + +#elif defined( SYS_CYGWIN ) + /* TODO */ + CPUCount = 1; + +#endif + CPUCount = MAX( 1, CPUCount ); + CPUCount = MIN( CPUCount, 8 ); + + return CPUCount; +} + diff --git a/core/HandBrake.h b/core/HandBrake.h new file mode 100644 index 00000000..35ec0fc0 --- /dev/null +++ b/core/HandBrake.h @@ -0,0 +1,55 @@ +/* $Id: HandBrake.h,v 1.3 2003/11/06 13:03:19 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_HANDBRAKE_H +#define HB_HANDBRAKE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "Utils.h" + +/* Init libhb. Set debug to 0 to see no output, 1 to see all libhb logs. + Set cpuCount to 0 if you want libhb to autodetect */ +HBHandle * HBInit( int debug, int cpuCount ); + +/* Fills the HBStatus * argument with infos about the current status. + Returns 1 if mode has changed, 0 otherwise */ +int HBGetStatus( HBHandle *, HBStatus * ); + +/* Launch a thread which scans the specified device and title. Use + title = 0 to scan all titles. Returns immediately */ +void HBScanDevice( HBHandle *, char * device, int title ); + +/* Start ripping the specified title with specified audio tracks. + Returns immediatly */ +void HBStartRip( HBHandle *, HBTitle *, HBAudio *, HBAudio * ); + +/* Suspend rip. Returns immediatly */ +void HBPauseRip( HBHandle * ); + +/* Resume rip. Returns immediatly */ +void HBResumeRip( HBHandle * ); + +/* Cancel rip. Returns immediatly */ +void HBStopRip( HBHandle * ); + +/* Calculate preview for the specified picture of the specified title, + taking care of the current cropping & scaling settings. Returns a + pointer to raw RGBA data. It includes the white border around the + picture, so the size of the picture is ( maxWidth + 2 ) x + ( maxHeight + 2 ) */ +uint8_t * HBGetPreview( HBHandle *, HBTitle *, int picture ); + +/* Clean up things */ +void HBClose( HBHandle ** ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/core/HandBrakeInternal.h b/core/HandBrakeInternal.h new file mode 100644 index 00000000..7c10512c --- /dev/null +++ b/core/HandBrakeInternal.h @@ -0,0 +1,35 @@ +/* $Id: HandBrakeInternal.h,v 1.2 2003/11/04 15:44:24 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_HANDBRAKE_INTERNAL_H +#define HB_HANDBRAKE_INTERNAL_H + +#include "HandBrake.h" + +/* Called by HBScan to tell the GUI how far we are */ +void HBScanning( HBHandle *, int title ); + +/* Called by HBScan. titleList is a list of all valid titles which + should be shown on the interface */ +void HBScanDone( HBHandle *, HBList * titleList ); + +/* Used to create temporary files (/tmp/HB.pid.whatever) */ +int HBGetPid( HBHandle * ); + +/* Called by every thread involved in the rip process. Returns + immediately is rip isn't paused, blocks if it is */ +void HBCheckPaused( HBHandle * ); + +/* Called by the decoders when the last packet is being proceeded */ +void HBDone( HBHandle * ); + +/* Called by the video encoder to update the GUI progress */ +void HBPosition( HBHandle *, float ); + +/* Called by any thread which couldn't continue and ask to stop */ +void HBErrorOccured( HBHandle *, HBError ); + +#endif diff --git a/core/Languages.h b/core/Languages.h index 21a5e148..7949688c 100644 --- a/core/Languages.h +++ b/core/Languages.h @@ -1,7 +1,7 @@ -/* $Id: Languages.h,v 1.2 2003/09/30 14:38:15 titer Exp $ +/* $Id: Languages.h,v 1.1 2003/11/03 12:08:01 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #ifndef HB_LANGUAGES_H @@ -14,7 +14,7 @@ typedef struct iso639_lang_t char * iso639_1; /* ISO-639-1 (2 characters) code */ } iso639_lang_t; -iso639_lang_t languages[] = +static iso639_lang_t languages[] = { { "Afar", "", "aa" }, { "Abkhazian", "", "ab" }, { "Afrikaans", "", "af" }, diff --git a/core/MadDec.c b/core/MadDec.c new file mode 100644 index 00000000..deecfeeb --- /dev/null +++ b/core/MadDec.c @@ -0,0 +1,9 @@ +/* $Id: MadDec.c,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "MadDec.h" +#include "Fifo.h" + diff --git a/core/MadDec.h b/core/MadDec.h new file mode 100644 index 00000000..b1624338 --- /dev/null +++ b/core/MadDec.h @@ -0,0 +1,15 @@ +/* $Id: MadDec.h,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_MAD_DEC_H +#define HB_MAD_DEC_H + +#include "HandBrakeInternal.h" + +HBMadDec * HBMadDecInit( HBHandle *, HBAudio * ); +void HBMadDecClose( HBMadDec * ); + +#endif diff --git a/core/Manager.cpp b/core/Manager.cpp deleted file mode 100644 index 908aa08f..00000000 --- a/core/Manager.cpp +++ /dev/null @@ -1,652 +0,0 @@ -/* $Id: Manager.cpp,v 1.70 2003/10/16 13:36:17 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Ac3Decoder.h" -#include "AviMuxer.h" -#include "DVDReader.h" -#include "Fifo.h" -#include "Manager.h" -#include "Mp3Encoder.h" -#include "Mpeg2Decoder.h" -#include "Mpeg4Encoder.h" -#include "MpegDemux.h" -#include "Resizer.h" -#include "Scanner.h" -#include "Worker.h" - -#include - -/* Public methods */ - -HBManager::HBManager( bool debug, int cpuCount ) - : HBThread( "manager", HB_NORMAL_PRIORITY ) -{ - /* See Log() in Common.cpp */ - if( debug ) - { - putenv( "HB_DEBUG=1" ); - } - - /* Check CPU count */ - if( !cpuCount ) - { - fCPUCount = GetCPUCount(); - Log( "HBManager::HBManager: %d CPU%s detected", fCPUCount, - ( fCPUCount > 1 ) ? "s" : "" ); - } - else - { - fCPUCount = cpuCount; - if( fCPUCount < 1 ) - { - Log( "HBManager::HBManager: invalid CPU count (%d), " - "using 1", fCPUCount ); - fCPUCount = 1; - } - else if( fCPUCount > 8 ) - { - Log( "HBManager::HBManager: invalid CPU count (%d), " - "using 8", fCPUCount ); - fCPUCount = 8; - } - Log( "HBManager::HBManager: user specified %d CPU%s", - fCPUCount, ( fCPUCount > 1 ) ? "s" : "" ); - } - - /* Init ffmpeg's libavcodec */ - avcodec_init(); -// register_avcodec( &mpeg4_encoder ); - avcodec_register_all(); - - /* Initialization */ - fStopScan = false; - fStopRip = false; - fRipDone = false; - fError = false; - - fScanner = NULL; - - fStatusLock = new HBLock(); - fStatus.fMode = HB_MODE_NEED_VOLUME; - fNeedUpdate = true; - - fCurTitle = NULL; - fCurAudio1 = NULL; - fCurAudio2 = NULL; - - Run(); -} - -HBManager::~HBManager() -{ - /* Stop ripping if needed */ - fStatusLock->Lock(); - if( fStatus.fMode == HB_MODE_ENCODING ) - { - fStatusLock->Unlock(); - - StopRip(); - while( fStopRip ) - { - Snooze( 10000 ); - } - } - else - { - fStatusLock->Unlock(); - } - - /* Stop scanning if needed */ - if( fScanner ) - { - delete fScanner; - } - - /* Remove temp files */ - char command[1024]; memset( command, 0, 1024 ); - sprintf( command, "rm -f /tmp/HB.%d.*", GetPid() ); - system( command ); - - delete fStatusLock; -} - -void HBManager::DoWork() -{ - while( !fDie ) - { - if( fStopScan ) - { - /* Destroy the thread */ - delete fScanner; - fScanner = NULL; - - /* Update interface */ - fStatusLock->Lock(); - if( fStatus.fTitleList && fStatus.fTitleList->CountItems() ) - { - fStatus.fMode = HB_MODE_READY_TO_RIP; - } - else - { - fStatus.fMode = HB_MODE_INVALID_VOLUME; - } - fNeedUpdate = true; - fStatusLock->Unlock(); - - fStopScan = false; - } - - if( fStopRip || fError || fRipDone ) - { - if( fRipDone ) - { - /* Wait a bit */ - while( fCurTitle->fPSFifo->Size() ) - { - Snooze( 10000 ); - } - while( fCurTitle->fMpeg2Fifo->Size() && - ( !fCurAudio1 || fCurAudio1->fAc3Fifo->Size() ) && - ( !fCurAudio2 || fCurAudio2->fAc3Fifo->Size() ) ) - { - Snooze( 10000 ); - } - Snooze( 500000 ); - } - else - { - fStatusLock->Lock(); - fStatus.fMode = HB_MODE_STOPPING; - fNeedUpdate = true; - fStatusLock->Unlock(); - } - - /* Stop threads */ - delete fCurTitle->fDVDReader; - delete fCurTitle->fAviMuxer; - for( int i = 0; i < fCPUCount; i++ ) - { - delete fCurTitle->fWorkers[i]; - } - - /* Clean up */ - delete fCurTitle->fMpegDemux; - delete fCurTitle->fMpeg2Decoder; - delete fCurTitle->fResizer; - delete fCurTitle->fMpeg4Encoder; - - if( fCurAudio1 ) - { - delete fCurAudio1->fAc3Decoder; - delete fCurAudio1->fMp3Encoder; - } - - if( fCurAudio2 ) - { - delete fCurAudio2->fAc3Decoder; - delete fCurAudio2->fMp3Encoder; - } - - /* Destroy fifos */ - delete fCurTitle->fPSFifo; - delete fCurTitle->fMpeg2Fifo; - delete fCurTitle->fRawFifo; - delete fCurTitle->fResizedFifo; - delete fCurTitle->fMpeg4Fifo; - - if( fCurAudio1 ) - { - delete fCurAudio1->fAc3Fifo; - delete fCurAudio1->fRawFifo; - delete fCurAudio1->fMp3Fifo; - } - - if( fCurAudio2 ) - { - delete fCurAudio2->fAc3Fifo; - delete fCurAudio2->fRawFifo; - delete fCurAudio2->fMp3Fifo; - } - - /* Update interface */ - fStatusLock->Lock(); - fStatus.fMode = fStopRip ? HB_MODE_CANCELED : - ( fError ? HB_MODE_ERROR : HB_MODE_DONE ); - fNeedUpdate = true; - fStatusLock->Unlock(); - - fStopRip = false; - fError = false; - fRipDone = false; - } - - Snooze( 10000 ); - } -} - -bool HBManager::NeedUpdate() -{ - fStatusLock->Lock(); - if( fNeedUpdate ) - { - fNeedUpdate = false; - fStatusLock->Unlock(); - return true; - } - fStatusLock->Unlock(); - - return false; -} - -HBStatus HBManager::GetStatus() -{ - fStatusLock->Lock(); - HBStatus status = fStatus; - fStatusLock->Unlock(); - - return status; -} - -void HBManager::ScanVolumes( char * device ) -{ - if( !( fStatus.fMode & - ( HB_MODE_NEED_VOLUME | HB_MODE_INVALID_VOLUME ) ) ) - { - Log( "HBManager::ScanVolumes : current mode is %d, aborting", - fStatus.fMode ); - return; - } - - fScanner = new HBScanner( this, device ); - - fStatusLock->Lock(); - fStatus.fMode = HB_MODE_SCANNING; - fStatus.fScannedVolume = strdup( device ); - fStatus.fScannedTitle = 0; - fNeedUpdate = true; - fStatusLock->Unlock(); -} - -void HBManager::StartRip( HBTitle * title, HBAudio * audio1, - HBAudio * audio2, char * file ) -{ - if( !title || !file ) - { - Log( "HBManager::StartRip : error (title = %p, file = %s)", - title, file ); - return; - } - - if( !( fStatus.fMode & ( HB_MODE_READY_TO_RIP | HB_MODE_DONE | - HB_MODE_CANCELED | HB_MODE_ERROR ) ) ) - { - Log( "HBManager::StartRip : current mode is %d, aborting", - fStatus.fMode ); - return; - } - - FixPictureSettings( title ); - - Log( "HBManager::StartRip:" ); - Log( "- device: %s, title: %d", title->fDevice, title->fIndex ); - Log( "- video: %dx%d->%dx%d, bitrate=%d, 2-pass=%s, deinterlace=%s", - title->fInWidth, title->fInHeight, - title->fOutWidth, title->fOutHeight, - title->fBitrate, title->fTwoPass ? "yes" : "no", - title->fDeinterlace ? "yes" : "no" ); - Log( "- cropping: top=%d, bottom=%d, left=%d, right=%d", - title->fTopCrop, title->fBottomCrop, - title->fLeftCrop, title->fRightCrop ); - if( audio1 ) - { - Log( "- audio 1: lang = %s (%x), bitrate = %d", - audio1->fDescription, audio1->fId, audio1->fOutBitrate ); - } - if( audio2 ) - { - Log( "- audio 2: lang = %s (%x), bitrate = %d", - audio2->fDescription, audio2->fId, audio2->fOutBitrate ); - } - - /* Create fifos */ - title->fPSFifo = new HBFifo( 256 ); - title->fMpeg2Fifo = new HBFifo( 256 ); - title->fRawFifo = new HBFifo( 4 ); - title->fResizedFifo = new HBFifo( 4 ); - title->fMpeg4Fifo = new HBFifo( 4 ); - if( audio1 ) - { - audio1->fAc3Fifo = new HBFifo( 256 ); - audio1->fRawFifo = new HBFifo( 4 ); - audio1->fMp3Fifo = new HBFifo( 4 ); - } - if( audio2 ) - { - audio2->fAc3Fifo = new HBFifo( 256 ); - audio2->fRawFifo = new HBFifo( 4 ); - audio2->fMp3Fifo = new HBFifo( 4 ); - } - - /* Create decoders & encoders objects */ - title->fMpegDemux = new HBMpegDemux( this, title, audio1, - audio2 ); - title->fMpeg2Decoder = new HBMpeg2Decoder( this, title ); - title->fResizer = new HBResizer( this, title ); - title->fMpeg4Encoder = new HBMpeg4Encoder( this, title ); - if( audio1 ) - { - audio1->fAc3Decoder = new HBAc3Decoder( this, audio1 ); - audio1->fMp3Encoder = new HBMp3Encoder( this, audio1 ); - } - if( audio2 ) - { - audio2->fAc3Decoder = new HBAc3Decoder( this, audio2 ); - audio2->fMp3Encoder = new HBMp3Encoder( this, audio2 ); - } - - /* Create and launch the threads */ - title->fDVDReader = new HBDVDReader( this, title ); - title->fAviMuxer = new HBAviMuxer( this, title, audio1, audio2, - file ); - for( int i = 0; i < fCPUCount; i++ ) - { - title->fWorkers[i] = new HBWorker( title, audio1, audio2 ); - } - - fCurTitle = title; - fCurAudio1 = audio1; - fCurAudio2 = audio2; - - fStatusLock->Lock(); - fStatus.fMode = HB_MODE_ENCODING; - fStatus.fPosition = 0; - fStatus.fFrameRate = 0; - fStatus.fFrames = 0; - fStatus.fStartDate = 0; - fStatus.fRemainingTime = 0; - fStatus.fSuspendDate = 0; - fNeedUpdate = true; - fStatusLock->Unlock(); -} - -void HBManager::SuspendRip() -{ - if( fStatus.fMode != HB_MODE_ENCODING ) - { - Log( "HBManager::SuspendRip : current mode is %d, aborting", - fStatus.fMode ); - return; - } - - fCurTitle->fDVDReader->Suspend(); - fCurTitle->fAviMuxer->Suspend(); - for( int i = 0; i < fCPUCount; i++ ) - { - fCurTitle->fWorkers[i]->Suspend(); - } - - fStatusLock->Lock(); - fStatus.fMode = HB_MODE_SUSPENDED; - fStatus.fSuspendDate = GetDate(); - fNeedUpdate = true; - fStatusLock->Unlock(); -} - -void HBManager::ResumeRip() -{ - if( fStatus.fMode != HB_MODE_SUSPENDED ) - { - Log( "HBManager::ResumeRip : current mode is %d, aborting", - fStatus.fMode ); - return; - } - - fCurTitle->fDVDReader->Resume(); - fCurTitle->fAviMuxer->Resume(); - for( int i = 0; i < fCPUCount; i++ ) - { - fCurTitle->fWorkers[i]->Resume(); - } - - fStatusLock->Lock(); - fStatus.fMode = HB_MODE_ENCODING; - fStatus.fStartDate += GetDate() - fStatus.fSuspendDate; - fNeedUpdate = true; - fStatusLock->Unlock(); -} - -void HBManager::StopRip() -{ - if( !( fStatus.fMode & ( HB_MODE_ENCODING | HB_MODE_SUSPENDED ) ) ) - { - Log( "HBManager::StopRip : current mode is %d, aborting", - fStatus.fMode ); - return; - } - - /* Stop the threads */ - fStopRip = true; -} - -#define fInWidth title->fInWidth -#define fInHeight title->fInHeight -#define fAspect title->fAspect -#define fDeinterlace title->fDeinterlace -#define fOutWidth title->fOutWidth -#define fOutHeight title->fOutHeight -#define fOutWidthMax title->fOutWidthMax -#define fOutHeightMax title->fOutHeightMax -#define fTopCrop title->fTopCrop -#define fBottomCrop title->fBottomCrop -#define fLeftCrop title->fLeftCrop -#define fRightCrop title->fRightCrop - -void HBManager::FixPictureSettings( HBTitle * title ) -{ - /* Sanity checks */ - fTopCrop = EVEN( fTopCrop ); - fBottomCrop = EVEN( fBottomCrop ); - fLeftCrop = EVEN( fLeftCrop ); - fRightCrop = EVEN( fRightCrop ); - - fOutWidth = MIN( fOutWidth, fOutWidthMax ); - fOutWidth = MAX( 16, fOutWidth ); - - fOutHeight = MULTIPLE_16( (uint64_t) fOutWidth * fInWidth * - ( fInHeight - fTopCrop - fBottomCrop ) * - VOUT_ASPECT_FACTOR / - ( (uint64_t) fInHeight * - ( fInWidth - fLeftCrop - fRightCrop ) * - fAspect ) ); - fOutHeight = MAX( 16, fOutHeight ); - - if( fOutHeight > fOutHeightMax ) - { - fOutHeight = fOutHeightMax; - fOutWidth = MULTIPLE_16( (uint64_t) fOutHeight * fInHeight * - ( fInWidth - fLeftCrop - fRightCrop ) * - fAspect / - ( (uint64_t) fInWidth * - ( fInHeight - fTopCrop - fBottomCrop ) * - VOUT_ASPECT_FACTOR ) ); - fOutWidth = MIN( fOutWidth, fOutWidthMax ); - fOutWidth = MAX( 16, fOutWidth ); - } -} - -uint8_t * HBManager::GetPreview( HBTitle * title, uint32_t image ) -{ - FixPictureSettings( title ); - - AVPicture pic1, pic2, pic3, pic4; - uint8_t * buf1, * buf2, * buf3, * buf4; - - /* Original YUV picture */ - buf1 = (uint8_t*) malloc( 3 * fInWidth * fInHeight / 2 ); - avpicture_fill( &pic1, buf1, PIX_FMT_YUV420P, fInWidth, - fInHeight ); - - /* Deinterlaced YUV picture */ - buf2 = (uint8_t*) malloc( 3 * fInWidth * fInHeight / 2 ); - avpicture_fill( &pic2, buf2, PIX_FMT_YUV420P, - fInWidth, fInHeight ); - - /* Resized YUV picture */ - buf3 = (uint8_t*) malloc( 3 * fOutWidth * fOutHeight / 2 ); - avpicture_fill( &pic3, buf3, PIX_FMT_YUV420P, fOutWidth, - fOutHeight ); - - /* Resized RGB picture ) */ - buf4 = (uint8_t*) malloc( 4 * fOutWidth * fOutHeight ); - avpicture_fill( &pic4, buf4, PIX_FMT_RGBA32, fOutWidth, - fOutHeight ); - - /* Get the original image from the temp file */ - char fileName[1024]; memset( fileName, 0, 1024 ); - sprintf( fileName, "/tmp/HB.%d.%x.%d", GetPid(), (uint32_t) title, - image); - FILE * file = fopen( fileName, "r" ); - fread( buf1, 3 * fInWidth * fInHeight / 2, 1, file ); - fclose( file ); - - /* Deinterlace if needed, and resize */ - ImgReSampleContext * resampleContext = - img_resample_full_init( fOutWidth, fOutHeight, - fInWidth, fInHeight, - fTopCrop, fBottomCrop, - fLeftCrop, fRightCrop ); - if( fDeinterlace ) - { - avpicture_deinterlace( &pic2, &pic1, PIX_FMT_YUV420P, - fInWidth, fInHeight ); - img_resample( resampleContext, &pic3, &pic2 ); - } - else - { - img_resample( resampleContext, &pic3, &pic1 ); - } - - /* Convert to RGB */ - img_convert( &pic4, PIX_FMT_RGBA32, &pic3, PIX_FMT_YUV420P, - fOutWidth, fOutHeight ); - - /* Create the final preview */ - uint8_t * preview = (uint8_t*) malloc( 4 * ( fOutWidthMax + 2 ) * - ( fOutHeightMax + 2 ) ); - - /* Blank it */ - memset( preview, 0, - 4 * ( fOutWidthMax + 2 ) * ( fOutHeightMax + 2 ) ); - - /* Draw the picture (centered) and draw the cropping zone */ - uint32_t leftOffset = 1 + ( fOutWidthMax - fOutWidth ) / 2; - uint32_t topOffset = 1 + ( fOutHeightMax - fOutHeight ) / 2; - - memset( preview + 4 * ( ( fOutWidthMax + 2 ) * ( topOffset - 1 ) + - leftOffset - 1 ), - 0xFF, 4 * ( fOutWidth + 2 ) ); - - for( uint32_t i = 0; i < fOutHeight; i++ ) - { - memset( preview + 4 * ( ( fOutWidthMax + 2 ) * - ( i + topOffset ) + leftOffset - 1 ), - 0xFF, 4 ); - memcpy( preview + 4 * ( ( fOutWidthMax + 2 ) * - ( i + topOffset ) + leftOffset ), - buf4 + 4 * fOutWidth * i, - 4 * fOutWidth ); - memset( preview + 4 * ( ( fOutWidthMax + 2 ) * - ( i + topOffset ) + leftOffset + - fOutWidth ), - 0xFF, 4 ); - } - - memset( preview + 4 * ( ( fOutWidthMax + 2 ) * - ( topOffset + fOutHeight ) + - leftOffset - 1 ), - 0xFF, 4 * ( fOutWidth + 2 ) ); - - /* Free memory */ - free( buf1 ); - free( buf2 ); - free( buf3 ); - free( buf4 ); - - return preview; -} - -#undef fInWidth -#undef fInHeight -#undef fAspect -#undef fDeinterlace -#undef fOutWidth -#undef fOutHeight -#undef fOutWidthMax -#undef fOutHeightMax -#undef fTopCrop -#undef fBottomCrop -#undef fLeftCrop -#undef fRightCrop - -void HBManager::Scanning( char * volume, int title ) -{ - fStatusLock->Lock(); - fStatus.fMode = HB_MODE_SCANNING; - fStatus.fScannedVolume = volume; - fStatus.fScannedTitle = title; - fNeedUpdate = true; - fStatusLock->Unlock(); -} - -void HBManager::ScanDone( HBList * titleList ) -{ - fStatus.fTitleList = titleList;; - fStopScan = true; -} - -/* Called by the DVD reader */ -void HBManager::Done() -{ - fRipDone = true; -} - -void HBManager::Error( HBError error ) -{ - if( fStatus.fMode != HB_MODE_ENCODING ) - { - return; - } - - fStatus.fError = error; - fError = true; -} - -void HBManager::SetPosition( float pos ) -{ - if( !fStatus.fStartDate ) - { - fStatus.fStartDate = GetDate(); - } - - fStatus.fFrames++; - - if( ( pos - fStatus.fPosition ) * 10000 < 1 ) - { - return; - } - - fStatusLock->Lock(); - fStatus.fPosition = pos; - fStatus.fFrameRate = (float) fStatus.fFrames / - ( ( (float) ( GetDate() - fStatus.fStartDate ) ) / 1000000 ) ; - fStatus.fRemainingTime = - (uint32_t) ( (float) ( GetDate() - fStatus.fStartDate ) * - ( 1 - fStatus.fPosition ) / - ( 1000000 * fStatus.fPosition ) ); - fNeedUpdate = true; - fStatusLock->Unlock(); -} - diff --git a/core/Manager.h b/core/Manager.h deleted file mode 100644 index dc885e5f..00000000 --- a/core/Manager.h +++ /dev/null @@ -1,64 +0,0 @@ -/* $Id: Manager.h,v 1.32 2003/10/08 22:20:36 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_MANAGER_H -#define HB_MANAGER_H - -#include "Common.h" -#include "Thread.h" - -class HBManager : public HBThread -{ - public: - HBManager( bool debug = false, - int cpuCount = 0 ); - ~HBManager(); - void DoWork(); - - /* Methods called by the interface */ - bool NeedUpdate(); - HBStatus GetStatus(); - void ScanVolumes( char * device ); - void StartRip( HBTitle * title, HBAudio * audio1, - HBAudio * audio2, char * file ); - void SuspendRip(); - void ResumeRip(); - void StopRip(); - uint8_t * GetPreview( HBTitle * title, uint32_t image ); - - /* Methods called by the working threads */ - void Scanning( char * volume, int title ); - void ScanDone( HBList * titleList ); - void Done(); - void Error( HBError error ); - void SetPosition( float pos ); - - private: - void FixPictureSettings( HBTitle * title ); - - int fPid; - int fCPUCount; - - /* Booleans used in DoWork() */ - bool fStopScan; - volatile bool fStopRip; - bool fRipDone; - bool fError; - - /* Scanner thread */ - HBScanner * fScanner; - - /* Status infos */ - HBLock * fStatusLock; - bool fNeedUpdate; - HBStatus fStatus; - - HBTitle * fCurTitle; - HBAudio * fCurAudio1; - HBAudio * fCurAudio2; -}; - -#endif diff --git a/core/Mp3Enc.c b/core/Mp3Enc.c new file mode 100644 index 00000000..70693467 --- /dev/null +++ b/core/Mp3Enc.c @@ -0,0 +1,281 @@ +/* $Id: Mp3Enc.c,v 1.5 2003/11/07 21:52:57 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Fifo.h" +#include "Mp3Enc.h" +#include "Work.h" + +#include + +/* Local prototypes */ +static int Mp3EncWork( HBWork * ); +static int GetBytes( HBMp3Enc * ); + +struct HBMp3Enc +{ + HB_WORK_COMMON_MEMBERS + + HBHandle * handle; + HBAudio * audio; + lame_global_flags * globalFlags; + HBBuffer * rawBuffer; + int rawBufferPos; + float position; + int samplesNeeded; + int samplesGot; + float * left; + float * right; + HBBuffer * mp3Buffer; +}; + +HBMp3Enc * HBMp3EncInit( HBHandle * handle, HBAudio * audio ) +{ + HBMp3Enc * m; + if( !( m = malloc( sizeof( HBMp3Enc ) ) ) ) + { + HBLog( "HBMp3EncInit: malloc() failed, gonna crash" ); + return NULL; + } + + m->name = strdup( "Mp3Enc" ); + m->work = Mp3EncWork; + + m->handle = handle; + m->audio = audio; + m->globalFlags = NULL; + m->rawBuffer = NULL; + m->rawBufferPos = 0; + m->position = 0.0; + m->samplesNeeded = 0; + m->samplesGot = 0; + m->left = NULL; + m->right = NULL; + m->mp3Buffer = NULL; + + return m; +} + +void HBMp3EncClose( HBMp3Enc ** _m ) +{ + HBMp3Enc * m = *_m; + + if( m->globalFlags ) lame_close( m->globalFlags ); + if( m->rawBuffer ) HBBufferClose( &m->rawBuffer ); + if( m->left ) free( m->left ); + if( m->right ) free( m->right ); + if( m->mp3Buffer ) HBBufferClose( &m->mp3Buffer ); + free( m->name ); + free( m ); + + *_m = NULL; +} + +static int Mp3EncWork( HBWork * w ) +{ + HBMp3Enc * m = (HBMp3Enc*) w; + HBAudio * audio = m->audio; + + HBBuffer * mp3Buffer; + int ret; + + int didSomething = 0; + + if( !m->globalFlags ) + { + int i; + + /* Get a first buffer so we know that audio->inSampleRate is + correct */ + if( ( m->rawBuffer = HBFifoPop( audio->rawFifo ) ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + m->rawBufferPos = 0; + m->position = m->rawBuffer->position; + + /* The idea is to have exactly one mp3 frame (i.e. 1152 samples) by + output buffer. As we are resampling from inSampleRate to + outSampleRate, we will give ( 1152 * inSampleRate ) / + ( 2 * outSampleRate ) samples to libmp3lame so we are sure we + will never get more than 1 frame at a time */ + m->samplesNeeded = 1152 * audio->inSampleRate / + audio->outSampleRate / 2; + + HBLog( "HBMp3Enc: opening lame (%d->%d Hz, %d kbps)", + audio->inSampleRate, audio->outSampleRate, + audio->outBitrate ); + m->globalFlags = lame_init(); + lame_set_in_samplerate( m->globalFlags, audio->inSampleRate ); + lame_set_out_samplerate( m->globalFlags, audio->outSampleRate ); + lame_set_brate( m->globalFlags, audio->outBitrate ); + + if( lame_init_params( m->globalFlags ) == -1 ) + { + HBLog( "HBMp3Enc: lame_init_params() failed" ); + HBErrorOccured( m->handle, HB_ERROR_MP3_INIT ); + return didSomething; + } + + m->left = malloc( m->samplesNeeded * sizeof( float ) ); + m->right = malloc( m->samplesNeeded * sizeof( float ) ); + + if( !m->left || !m->right ) + { + HBLog( "HBMp3Enc: malloc() failed, gonna crash" ); + } + + for( i = 0; i < m->samplesNeeded; i++ ) + { + m->left[i] = 0.0; + m->right[i] = 0.0; + } + } + + /* Push encoded buffer */ + if( m->mp3Buffer ) + { + if( HBFifoPush( audio->mp3Fifo, &m->mp3Buffer ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + } + + /* A/V synchro fix in case audio doesn't start at the same time + than video */ + if( audio->delay > 0 ) + { + /* Audio starts later - insert some silence */ + int length = m->samplesNeeded * 1000 / audio->inSampleRate; + + if( audio->delay > length ) + { + HBLog( "HBMp3Enc: adding %d ms of silence", length ); + m->samplesGot = m->samplesNeeded; + audio->delay -= length; + } + else + { + audio->delay = 0; + } + } + else if( audio->delay < 0 ) + { + /* Audio starts sooner - trash some */ + int length = m->samplesNeeded * 1000 / audio->inSampleRate; + + if( - audio->delay > length ) + { + if( GetBytes( m ) ) + { + didSomething = 1; + HBLog( "HBMp3Enc: trashing %d ms", length ); + m->samplesGot = 0; + audio->delay += length; + return didSomething; + } + else + { + return didSomething; + } + } + else + { + audio->delay = 0; + } + } + + /* Get new samples */ + if( GetBytes( m ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + + m->samplesGot = 0; + + mp3Buffer = HBBufferInit( LAME_MAXMP3BUFFER ); + ret = lame_encode_buffer_float( m->globalFlags, m->left, + m->right, m->samplesNeeded, + mp3Buffer->data, + mp3Buffer->size ); + + if( ret < 0 ) + { + /* Error */ + HBLog( "HBMp3Enc: lame_encode_buffer_float() failed (%d)", + ret ); + HBErrorOccured( m->handle, HB_ERROR_MP3_ENCODE ); + HBBufferClose( &mp3Buffer ); + } + else if( ret == 0 ) + { + /* No error, but nothing encoded */ + HBBufferClose( &mp3Buffer ); + } + else + { + /* Encoding was successful */ + mp3Buffer->size = ret; + mp3Buffer->keyFrame = 1; + mp3Buffer->position = m->position; + + m->mp3Buffer = mp3Buffer; + } + + return didSomething; +} + +static int GetBytes( HBMp3Enc * m ) +{ + while( m->samplesGot < m->samplesNeeded ) + { + int i; + + if( !m->rawBuffer ) + { + if( !( m->rawBuffer = HBFifoPop( m->audio->rawFifo ) ) ) + { + return 0; + } + + m->rawBufferPos = 0; + m->position = m->rawBuffer->position; + } + + i = MIN( m->samplesNeeded - m->samplesGot, + ( m->rawBuffer->size / 2 - + m->rawBufferPos ) / sizeof( float ) ); + + memcpy( m->left + m->samplesGot, + m->rawBuffer->data + m->rawBufferPos, + i * sizeof( float ) ); + memcpy( m->right + m->samplesGot, + m->rawBuffer->data + m->rawBuffer->size / 2 + + m->rawBufferPos, + i * sizeof( float ) ); + + m->samplesGot += i; + m->rawBufferPos += i * sizeof( float ); + + if( m->rawBufferPos == m->rawBuffer->size / 2 ) + { + HBBufferClose( &m->rawBuffer ); + } + } + + return 1; +} diff --git a/core/Mp3Enc.h b/core/Mp3Enc.h new file mode 100644 index 00000000..db02f4f4 --- /dev/null +++ b/core/Mp3Enc.h @@ -0,0 +1,15 @@ +/* $Id: Mp3Enc.h,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_MP3_ENCODER_H +#define HB_MP3_ENCODER_H + +#include "HandBrakeInternal.h" + +HBMp3Enc * HBMp3EncInit( HBHandle *, HBAudio * ); +void HBMp3EncClose( HBMp3Enc ** ); + +#endif diff --git a/core/Mp3Encoder.cpp b/core/Mp3Encoder.cpp deleted file mode 100644 index 96ae8c56..00000000 --- a/core/Mp3Encoder.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* $Id: Mp3Encoder.cpp,v 1.14 2003/10/14 14:35:20 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Mp3Encoder.h" -#include "Manager.h" -#include "Fifo.h" - -#include - -HBMp3Encoder::HBMp3Encoder( HBManager * manager, HBAudio * audio ) -{ - fManager = manager; - fAudio = audio; - - fLock = new HBLock(); - fUsed = false; - - fRawBuffer = NULL; - fPosInBuffer = 0; - fSamplesNb = 0; - fLeftSamples = NULL; - fRightSamples = NULL; - - fPosition = 0; - fInitDone = false; - fMp3Buffer = NULL; -} - -bool HBMp3Encoder::Work() -{ - if( !Lock() ) - { - return false; - } - - if( !fInitDone ) - { - /* Wait for a first buffer so we know fAudio->fInSampleRate - is correct */ - if( !fAudio->fRawFifo->Size() ) - { - Unlock(); - return false; - } - - /* The idea is to have exactly one mp3 frame (i.e. 1152 samples) by - output buffer. As we are resampling from fInSampleRate to - fOutSampleRate, we will give ( 1152 * fInSampleRate ) / - ( 2 * fOutSampleRate ) to libmp3lame so we are sure we will - never get more than 1 frame at a time */ - fCount = ( 1152 * fAudio->fInSampleRate ) / - ( 2 * fAudio->fOutSampleRate ); - - /* Init libmp3lame */ - fGlobalFlags = lame_init(); - lame_set_in_samplerate( fGlobalFlags, fAudio->fInSampleRate ); - lame_set_out_samplerate( fGlobalFlags, fAudio->fOutSampleRate ); - lame_set_brate( fGlobalFlags, fAudio->fOutBitrate ); - - if( lame_init_params( fGlobalFlags ) == -1 ) - { - Log( "HBMp3Encoder: lame_init_params() failed" ); - fManager->Error( HB_ERROR_MP3_INIT ); - return false; - } - - fLeftSamples = (float*) malloc( fCount * sizeof( float ) ); - fRightSamples = (float*) malloc( fCount * sizeof( float ) ); - - fInitDone = true; - } - - if( fMp3Buffer ) - { - if( fAudio->fMp3Fifo->Push( fMp3Buffer ) ) - { - fMp3Buffer = NULL; - } - else - { - Unlock(); - return false; - } - } - - /* Get new samples */ - if( GetSamples() ) - { - fSamplesNb = 0; - - fMp3Buffer = new HBBuffer( LAME_MAXMP3BUFFER ); - int ret = lame_encode_buffer_float( fGlobalFlags, fLeftSamples, - fRightSamples, fCount, - fMp3Buffer->fData, - fMp3Buffer->fSize ); - - if( ret < 0 ) - { - Log( "HBMp3Encoder: lame_encode_buffer_float() failed " - "(%d)", ret ); - fManager->Error( HB_ERROR_MP3_ENCODE ); - return false; - } - else if( ret > 0 ) - { - /* We got something, send it to the muxer */ - fMp3Buffer->fSize = ret; - fMp3Buffer->fKeyFrame = true; - fMp3Buffer->fPosition = fPosition; - } - else - { - delete fMp3Buffer; - fMp3Buffer = NULL; - } - } - else - { - Unlock(); - return false; - } - - Unlock(); - return true; -} - -bool HBMp3Encoder::Lock() -{ - fLock->Lock(); - if( fUsed ) - { - fLock->Unlock(); - return false; - } - fUsed = true; - fLock->Unlock(); - return true; -} - -void HBMp3Encoder::Unlock() -{ - fLock->Lock(); - fUsed = false; - fLock->Unlock(); -} - -bool HBMp3Encoder::GetSamples() -{ - while( fSamplesNb < fCount ) - { - if( !fRawBuffer ) - { - if( !( fRawBuffer = fAudio->fRawFifo->Pop() ) ) - { - return false; - } - - fPosInBuffer = 0; - fPosition = fRawBuffer->fPosition; - } - - int willCopy = MIN( fCount - fSamplesNb, 6 * 256 - fPosInBuffer ); - - memcpy( fLeftSamples + fSamplesNb, - (float*) fRawBuffer->fData + fPosInBuffer, - willCopy * sizeof( float ) ); - memcpy( fRightSamples + fSamplesNb, - (float*) fRawBuffer->fData + 6 * 256 + fPosInBuffer, - willCopy * sizeof( float ) ); - - fSamplesNb += willCopy; - fPosInBuffer += willCopy; - - if( fPosInBuffer == 6 * 256 ) - { - delete fRawBuffer; - fRawBuffer = NULL; - } - } - - return true; -} diff --git a/core/Mp3Encoder.h b/core/Mp3Encoder.h deleted file mode 100644 index fb834896..00000000 --- a/core/Mp3Encoder.h +++ /dev/null @@ -1,43 +0,0 @@ -/* $Id: Mp3Encoder.h,v 1.9 2003/10/07 22:48:31 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_MP3_ENCODER_H -#define HB_MP3_ENCODER_H - -#include "Common.h" - -class HBMp3Encoder -{ - public: - HBMp3Encoder( HBManager * manager, - HBAudio * audio ); - bool Work(); - - private: - bool Lock(); - void Unlock(); - bool GetSamples(); - - HBManager * fManager; - HBAudio * fAudio; - - HBLock * fLock; - bool fUsed; - - HBBuffer * fRawBuffer; - uint32_t fPosInBuffer; /* in samples */ - uint32_t fSamplesNb; - float * fLeftSamples; - float * fRightSamples; - - float fPosition; - lame_global_flags * fGlobalFlags; - bool fInitDone; - HBBuffer * fMp3Buffer; - uint32_t fCount; -}; - -#endif diff --git a/core/Mpeg2Dec.c b/core/Mpeg2Dec.c new file mode 100644 index 00000000..d6ce22b3 --- /dev/null +++ b/core/Mpeg2Dec.c @@ -0,0 +1,195 @@ +/* $Id: Mpeg2Dec.c,v 1.3 2003/11/06 12:33:11 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Fifo.h" +#include "Mpeg2Dec.h" +#include "Work.h" + +#include + +/* Local prototypes */ +static int Mpeg2DecWork( HBWork * ); + +struct HBMpeg2Dec +{ + HB_WORK_COMMON_MEMBERS + + HBHandle * handle; + HBTitle * title; + HBList * rawBufferList; + int pass; + mpeg2dec_t * libmpeg2; + const mpeg2_info_t * info; + int lateField; +}; + +HBMpeg2Dec * HBMpeg2DecInit( HBHandle * handle, HBTitle * title ) +{ + HBMpeg2Dec * m ; + if( !( m = malloc( sizeof( HBMpeg2Dec ) ) ) ) + { + HBLog( "HBMpeg2Dec: malloc() failed, gonna crash" ); + return NULL; + } + + m->name = strdup( "Mpeg2Dec" ); + m->work = Mpeg2DecWork; + + m->handle = handle; + m->title = title; + + m->rawBufferList = HBListInit(); + m->pass = 42; + m->libmpeg2 = NULL; + m->info = NULL; + m->lateField = 0; + + return m; +} + +void HBMpeg2DecClose( HBMpeg2Dec ** _m ) +{ + HBBuffer * buffer; + + HBMpeg2Dec * m = *_m; + + if( m->libmpeg2 ) + { + HBLog( "HBMpeg2Dec: closing libmpeg2 (pass %d)", m->pass ); + mpeg2_close( m->libmpeg2 ); + } + while( ( buffer = HBListItemAt( m->rawBufferList, 0 ) ) ) + { + HBListRemove( m->rawBufferList, buffer ); + HBBufferClose( &buffer ); + } + HBListClose( &m->rawBufferList ); + free( m->name ); + free( m ); + + *_m = NULL; +} + +static int Mpeg2DecWork( HBWork * w ) +{ + HBMpeg2Dec * m = (HBMpeg2Dec*) w; + HBTitle * title = m->title; + HBBuffer * mpeg2Buffer; + HBBuffer * rawBuffer; + HBBuffer * tmpBuffer; + mpeg2_state_t state; + + int didSomething = 0; + + /* Push decoded buffers */ + while( ( rawBuffer = (HBBuffer*) + HBListItemAt( m->rawBufferList, 0 ) ) ) + { + tmpBuffer = rawBuffer; + if( HBFifoPush( title->rawFifo, &rawBuffer ) ) + { + didSomething = 1; + HBListRemove( m->rawBufferList, tmpBuffer ); + } + else + { + return didSomething; + } + } + + /* Get a new buffer to decode */ + if( ( mpeg2Buffer = HBFifoPop( title->mpeg2Fifo ) ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + + /* Init or re-init if needed */ + if( mpeg2Buffer->pass != m->pass ) + { + if( m->libmpeg2 ) + { + HBLog( "HBMpeg2Dec: closing libmpeg2 (pass %d)", m->pass ); + mpeg2_close( m->libmpeg2 ); + } + + m->pass = mpeg2Buffer->pass; + + HBLog( "HBMpeg2Dec: opening libmpeg2 (pass %d)", m->pass ); + m->libmpeg2 = mpeg2_init(); + m->info = mpeg2_info( m->libmpeg2 ); + m->lateField = 0; + } + + /* Decode */ + mpeg2_buffer( m->libmpeg2, mpeg2Buffer->data, + mpeg2Buffer->data + mpeg2Buffer->size ); + + for( ;; ) + { + state = mpeg2_parse( m->libmpeg2 ); + + if( state == STATE_BUFFER ) + { + break; + } + else if( ( state == STATE_SLICE || state == STATE_END ) && + m->info->display_fbuf ) + { + rawBuffer = HBBufferInit( 3 * title->inWidth * + title->outWidth ); + + /* TODO: make libmpeg2 write directly in our buffer */ + memcpy( rawBuffer->data, m->info->display_fbuf->buf[0], + title->inWidth * title->inHeight ); + memcpy( rawBuffer->data + title->inWidth * title->inHeight, + m->info->display_fbuf->buf[1], + title->inWidth * title->inHeight / 4 ); + memcpy( rawBuffer->data + title->inWidth * title->inHeight + + title->inWidth * title->inHeight / 4, + m->info->display_fbuf->buf[2], + title->inWidth * title->inHeight / 4 ); + + rawBuffer->position = mpeg2Buffer->position; + rawBuffer->pass = mpeg2Buffer->pass; + + HBListAdd( m->rawBufferList, rawBuffer ); + + /* NTSC pulldown kludge */ + if( m->info->display_picture->nb_fields == 3 ) + { + if( m->lateField ) + { + tmpBuffer = HBBufferInit( rawBuffer->size ); + tmpBuffer->position = rawBuffer->position; + tmpBuffer->pass = rawBuffer->pass; + tmpBuffer->last = rawBuffer->last; + memcpy( tmpBuffer->data, rawBuffer->data, + tmpBuffer->size ); + HBListAdd( m->rawBufferList, tmpBuffer ); + } + m->lateField = !m->lateField; + } + } + else if( state == STATE_INVALID ) + { + /* Shouldn't happen on a DVD */ + HBLog( "HBMpeg2Dec: STATE_INVALID" ); + } + } + + if( mpeg2Buffer->last ) + { + HBDone( m->handle ); + } + + HBBufferClose( &mpeg2Buffer ); + + return didSomething; +} diff --git a/core/Mpeg2Dec.h b/core/Mpeg2Dec.h new file mode 100644 index 00000000..af7f18c4 --- /dev/null +++ b/core/Mpeg2Dec.h @@ -0,0 +1,15 @@ +/* $Id: Mpeg2Dec.h,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_MPEG2_DEC_H +#define HB_MPEG2_DEC_H + +#include "HandBrakeInternal.h" + +HBMpeg2Dec * HBMpeg2DecInit( HBHandle *, HBTitle * ); +void HBMpeg2DecClose( HBMpeg2Dec ** ); + +#endif diff --git a/core/Mpeg2Decoder.cpp b/core/Mpeg2Decoder.cpp deleted file mode 100644 index a9b6a537..00000000 --- a/core/Mpeg2Decoder.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* $Id: Mpeg2Decoder.cpp,v 1.22 2003/10/14 14:35:20 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Mpeg2Decoder.h" -#include "Manager.h" -#include "Fifo.h" - -extern "C" { -#include -} -#include - -HBMpeg2Decoder::HBMpeg2Decoder( HBManager * manager, HBTitle * title ) -{ - fManager = manager; - fTitle = title; - - fLock = new HBLock(); - fUsed = false; - - fPass = 42; - fRawBuffer = NULL; - fRawBufferList = new HBList(); - fHandle = NULL; -} - -bool HBMpeg2Decoder::Work() -{ - if( !Lock() ) - { - return false; - } - - /* Push decoded buffers */ - while( ( fRawBuffer = - (HBBuffer*) fRawBufferList->ItemAt( 0 ) ) ) - { - if( fTitle->fRawFifo->Push( fRawBuffer ) ) - { - fRawBufferList->RemoveItem( fRawBuffer ); - } - else - { - Unlock(); - return false; - } - } - - /* Get a new buffer to decode */ - if( ( fMpeg2Buffer = fTitle->fMpeg2Fifo->Pop() ) ) - { - /* (Re)init if needed */ - if( fMpeg2Buffer->fPass != fPass ) - { - fPass = fMpeg2Buffer->fPass; - Init(); - } - - /* Do the job */ - DecodeBuffer(); - } - else - { - Unlock(); - return false; - } - - Unlock(); - return true; -} - -bool HBMpeg2Decoder::Lock() -{ - fLock->Lock(); - if( fUsed ) - { - fLock->Unlock(); - return false; - } - fUsed = true; - fLock->Unlock(); - return true; -} - -void HBMpeg2Decoder::Unlock() -{ - fLock->Lock(); - fUsed = false; - fLock->Unlock(); -} - -void HBMpeg2Decoder::Init() -{ - if( fHandle ) - { - mpeg2_close( fHandle ); - } - - fLateField = false; - - fHandle = mpeg2_init(); -} - -void HBMpeg2Decoder::DecodeBuffer() -{ - const mpeg2_info_t * info = mpeg2_info( fHandle ); - - /* Feed libmpeg2 */ - mpeg2_buffer( fHandle, fMpeg2Buffer->fData, - fMpeg2Buffer->fData + fMpeg2Buffer->fSize ); - - mpeg2_state_t state; - for( ;; ) - { - state = mpeg2_parse( fHandle ); - - if( state == STATE_BUFFER ) - { - break; - } - else if( ( state == STATE_SLICE || state == STATE_END ) && - info->display_fbuf ) - { - fRawBuffer = new HBBuffer( 3 * fTitle->fInWidth * - fTitle->fInHeight / 2 ); - - /* TODO : make libmpeg2 write directly in our buffer */ - memcpy( fRawBuffer->fData, - info->display_fbuf->buf[0], - fTitle->fInWidth * fTitle->fInHeight ); - memcpy( fRawBuffer->fData + fTitle->fInWidth * - fTitle->fInHeight, - info->display_fbuf->buf[1], - fTitle->fInWidth * fTitle->fInHeight / 4 ); - memcpy( fRawBuffer->fData + fTitle->fInWidth * - fTitle->fInHeight + fTitle->fInWidth * - fTitle->fInHeight / 4, - info->display_fbuf->buf[2], - fTitle->fInWidth * fTitle->fInHeight / 4 ); - - fRawBuffer->fPosition = fMpeg2Buffer->fPosition; - fRawBuffer->fPass = fMpeg2Buffer->fPass; - - fRawBufferList->AddItem( fRawBuffer ); - - /* NTSC pulldown kludge */ - if( info->display_picture->nb_fields == 3 ) - { - if( fLateField ) - { - HBBuffer * pulldownBuffer; - pulldownBuffer = new HBBuffer( fRawBuffer->fSize ); - pulldownBuffer->fPosition = fRawBuffer->fPosition; - pulldownBuffer->fPass = fRawBuffer->fPass; - memcpy( pulldownBuffer->fData, fRawBuffer->fData, - pulldownBuffer->fSize ); - fRawBufferList->AddItem( pulldownBuffer ); - } - fLateField = !fLateField; - } - } - else if( state == STATE_INVALID ) - { - /* Shouldn't happen on a DVD */ - Log( "HBMpeg2Decoder: STATE_INVALID" ); - } - } - - delete fMpeg2Buffer; - fMpeg2Buffer = NULL; -} - diff --git a/core/Mpeg2Decoder.h b/core/Mpeg2Decoder.h deleted file mode 100644 index 6e20509a..00000000 --- a/core/Mpeg2Decoder.h +++ /dev/null @@ -1,40 +0,0 @@ -/* $Id: Mpeg2Decoder.h,v 1.16 2003/10/14 14:35:20 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_MPEG2_DECODER_H -#define HB_MPEG2_DECODER_H - -#include "Common.h" - -class HBMpeg2Decoder -{ - public: - HBMpeg2Decoder( HBManager * manager, - HBTitle * title ); - bool Work(); - - private: - bool Lock(); - void Unlock(); - - void Init(); - void DecodeBuffer(); - - HBManager * fManager; - HBTitle * fTitle; - - HBLock * fLock; - bool fUsed; - - uint32_t fPass; - HBBuffer * fMpeg2Buffer; - HBBuffer * fRawBuffer; - HBList * fRawBufferList; - mpeg2dec_t * fHandle; - bool fLateField; -}; - -#endif diff --git a/core/Mpeg4Encoder.cpp b/core/Mpeg4Encoder.cpp deleted file mode 100644 index bf5821a4..00000000 --- a/core/Mpeg4Encoder.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* $Id: Mpeg4Encoder.cpp,v 1.25 2003/10/14 15:23:56 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Mpeg4Encoder.h" -#include "Manager.h" -#include "Fifo.h" - -#include - -HBMpeg4Encoder::HBMpeg4Encoder( HBManager * manager, HBTitle * title ) -{ - fManager = manager; - fTitle = title; - - fLock = new HBLock(); - fUsed = false; - - fPass = 42; - fMpeg4Buffer = NULL; - fFile = NULL; - fFrame = avcodec_alloc_frame(); - fLog = NULL; -} - -bool HBMpeg4Encoder::Work() -{ - if( !Lock() ) - { - return false; - } - - if( fMpeg4Buffer ) - { - if( fTitle->fMpeg4Fifo->Push( fMpeg4Buffer ) ) - { - fMpeg4Buffer = NULL; - } - else - { - Unlock(); - return false; - } - } - - if( ( fResizedBuffer = fTitle->fResizedFifo->Pop() ) ) - { - if( fResizedBuffer->fPass != fPass ) - { - fPass = fResizedBuffer->fPass; - Init(); - } - - fManager->SetPosition( fResizedBuffer->fPosition ); - EncodeBuffer(); - } - else - { - Unlock(); - return false; - } - - Unlock(); - return true; -} - -bool HBMpeg4Encoder::Lock() -{ - fLock->Lock(); - if( fUsed ) - { - fLock->Unlock(); - return false; - } - fUsed = true; - fLock->Unlock(); - return true; -} - -void HBMpeg4Encoder::Unlock() -{ - fLock->Lock(); - fUsed = false; - fLock->Unlock(); -} - -void HBMpeg4Encoder::Init() -{ - /* Clean up if needed */ - if( fFile ) - { - fclose( fFile ); - } - - AVCodec * codec = avcodec_find_encoder( CODEC_ID_MPEG4 ); - if( !codec ) - { - Log( "HBMpeg4Encoder: avcodec_find_encoder() failed" ); - fManager->Error( HB_ERROR_MPEG4_INIT ); - return; - } - - fContext = avcodec_alloc_context(); - fContext->bit_rate = 1024 * fTitle->fBitrate; - fContext->bit_rate_tolerance = 10240 * fTitle->fBitrate; - fContext->width = fTitle->fOutWidth; - fContext->height = fTitle->fOutHeight; - fContext->frame_rate = fTitle->fRate; - fContext->frame_rate_base = fTitle->fScale; - fContext->gop_size = 10 * fTitle->fRate / fTitle->fScale; - - if( fPass == 1 ) - { - fContext->flags |= CODEC_FLAG_PASS1; - - char fileName[1024]; memset( fileName, 0, 1024 ); - sprintf( fileName, "/tmp/HB.%d.ffmpeg.log", fManager->GetPid() ); - fFile = fopen( fileName, "w" ); - } - else if( fPass == 2 ) - { - fContext->flags |= CODEC_FLAG_PASS2; - - char fileName[1024]; memset( fileName, 0, 1024 ); - sprintf( fileName, "/tmp/HB.%d.ffmpeg.log", fManager->GetPid() ); - fFile = fopen( fileName, "r" ); - fseek( fFile, 0, SEEK_END ); - uint32_t size = ftell( fFile ); - fLog = (char*) malloc( size + 1 ); - fseek( fFile, 0, SEEK_SET ); - fread( fLog, size, 1, fFile ); - fclose( fFile ); - fLog[size] = '\0'; - fContext->stats_in = fLog; - } - - if( avcodec_open( fContext, codec ) < 0 ) - { - Log( "HBMpeg4Encoder: avcodec_open() failed" ); - fManager->Error( HB_ERROR_MPEG4_INIT ); - return; - } -} - -void HBMpeg4Encoder::EncodeBuffer() -{ - fFrame->data[0] = fResizedBuffer->fData; - fFrame->data[1] = fFrame->data[0] + fTitle->fOutWidth * - fTitle->fOutHeight; - fFrame->data[2] = fFrame->data[1] + fTitle->fOutWidth * - fTitle->fOutHeight / 4; - fFrame->linesize[0] = fTitle->fOutWidth; - fFrame->linesize[1] = fTitle->fOutWidth / 2; - fFrame->linesize[2] = fTitle->fOutWidth / 2; - - fMpeg4Buffer = new HBBuffer( 3 * fTitle->fOutWidth * - fTitle->fOutHeight / 2 ); - /* Should be really too much... */ - - fMpeg4Buffer->fPosition = fResizedBuffer->fPosition; - fMpeg4Buffer->fSize = - avcodec_encode_video( fContext, fMpeg4Buffer->fData, - fMpeg4Buffer->fAllocSize, fFrame ); - fMpeg4Buffer->fKeyFrame = ( fContext->coded_frame->key_frame != 0 ); - - if( fResizedBuffer->fPass == 1 ) - { - if( fContext->stats_out ) - { - fprintf( fFile, "%s", fContext->stats_out ); - } - delete fMpeg4Buffer; - fMpeg4Buffer = NULL; - } - - delete fResizedBuffer; - fResizedBuffer = NULL; -} - diff --git a/core/Mpeg4Encoder.h b/core/Mpeg4Encoder.h deleted file mode 100644 index 3d20f315..00000000 --- a/core/Mpeg4Encoder.h +++ /dev/null @@ -1,41 +0,0 @@ -/* $Id: Mpeg4Encoder.h,v 1.11 2003/10/08 11:56:40 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_MPEG4_ENCODER_H -#define HB_MPEG4_ENCODER_H - -#include "Common.h" - -class HBMpeg4Encoder -{ - public: - HBMpeg4Encoder( HBManager * manager, - HBTitle * title ); - bool Work(); - - private: - bool Lock(); - void Unlock(); - - void Init(); - void EncodeBuffer(); - - HBManager * fManager; - HBTitle * fTitle; - - HBLock * fLock; - bool fUsed; - - uint32_t fPass; - HBBuffer * fResizedBuffer; - AVCodecContext * fContext; - AVFrame * fFrame; - FILE * fFile; - char * fLog; - HBBuffer * fMpeg4Buffer; -}; - -#endif diff --git a/core/MpegDemux.cpp b/core/MpegDemux.cpp deleted file mode 100644 index 249ee273..00000000 --- a/core/MpegDemux.cpp +++ /dev/null @@ -1,308 +0,0 @@ -/* $Id: MpegDemux.cpp,v 1.20 2003/10/16 13:36:17 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "MpegDemux.h" -#include "Manager.h" -#include "Fifo.h" - -extern "C" { -#include -} - -HBMpegDemux::HBMpegDemux( HBManager * manager, HBTitle * title, - HBAudio * audio1, HBAudio * audio2 ) -{ - fManager = manager; - fTitle = title; - fAudio1 = audio1; - fAudio2 = audio2; - - fLock = new HBLock(); - fUsed = false; - - fPSBuffer = NULL; - fESBuffer = NULL; - fESBufferList = NULL; - - fFirstVideoPTS = -1; - fFirstAudio1PTS = -1; - fFirstAudio2PTS = -1; -} - -HBMpegDemux::~HBMpegDemux() -{ - /* Free memory */ - if( fESBufferList ) - { - while( ( fESBuffer = (HBBuffer*) fESBufferList->ItemAt( 0 ) ) ) - { - fESBufferList->RemoveItem( fESBuffer ); - delete fESBuffer; - } - } - delete fLock; -} - -bool HBMpegDemux::Work() -{ - if( !Lock() ) - { - return false; - } - - /* Push waiting buffers */ - if( fESBufferList ) - { - for( uint32_t i = 0; i < fESBufferList->CountItems(); ) - { - fESBuffer = (HBBuffer*) fESBufferList->ItemAt( i ); - - if( fESBuffer->fPass == 1 && fESBuffer->fStreamId != 0xE0 ) - { - fESBufferList->RemoveItem( fESBuffer ); - delete fESBuffer; - continue; - } - - /* Look for a decoder for this ES */ - - if( fESBuffer->fStreamId == 0xE0 ) - { - if( fFirstVideoPTS < 0 ) - { - fFirstVideoPTS = fESBuffer->fPTS; - Log( "HBMpegDemux: got first 0xE0 packet (%lld)", - fFirstVideoPTS ); - } - if( fTitle->fMpeg2Fifo->Push( fESBuffer ) ) - { - fESBufferList->RemoveItem( fESBuffer ); - } - else - { - i++; - } - } - else if( fAudio1 && - fESBuffer->fStreamId == fAudio1->fId ) - { - if( fFirstAudio1PTS < 0 ) - { - fFirstAudio1PTS = fESBuffer->fPTS; - Log( "HBMpegDemux: got first 0x%x packet (%lld)", - fAudio1->fId, fFirstAudio1PTS ); - - fAudio1->fDelay = - ( fFirstAudio1PTS - fFirstVideoPTS ) / 90; - } - if( fAudio1->fAc3Fifo->Push( fESBuffer ) ) - { - fESBufferList->RemoveItem( fESBuffer ); - } - else - { - i++; - } - } - else if( fAudio2 && - fESBuffer->fStreamId == fAudio2->fId ) - { - if( fFirstAudio2PTS < 0 ) - { - fFirstAudio2PTS = fESBuffer->fPTS; - Log( "HBMpegDemux: got first 0x%x packet (%lld)", - fAudio2->fId, fFirstAudio2PTS ); - - fAudio2->fDelay = - ( fFirstAudio2PTS - fFirstVideoPTS ) / 90; - } - if( fAudio2->fAc3Fifo->Push( fESBuffer ) ) - { - fESBufferList->RemoveItem( fESBuffer ); - } - else - { - i++; - } - } - else - { - fESBufferList->RemoveItem( fESBuffer ); - delete fESBuffer; - } - } - - if( !fESBufferList->CountItems() ) - { - delete fESBufferList; - fESBufferList = NULL; - } - else - { - Unlock(); - return false; - } - } - - /* Get a PS packet */ - if( ( fPSBuffer = fTitle->fPSFifo->Pop() ) ) - { - /* Get the ES data in it */ - PStoES( fPSBuffer, &fESBufferList ); - } - else - { - Unlock(); - return false; - } - - Unlock(); - return true; -} - -bool HBMpegDemux::Lock() -{ - fLock->Lock(); - if( fUsed ) - { - fLock->Unlock(); - return false; - } - fUsed = true; - fLock->Unlock(); - return true; -} - -void HBMpegDemux::Unlock() -{ - fLock->Lock(); - fUsed = false; - fLock->Unlock(); -} - -bool PStoES( HBBuffer * psBuffer, HBList ** _esBufferList ) -{ -#define psData (psBuffer->fData) - - uint32_t pos = 0; - - /* pack_header */ - if( psData[pos] != 0 || psData[pos+1] != 0 || - psData[pos+2] != 0x1 || psData[pos+3] != 0xBA ) - { - Log( "PStoES: not a PS packet (%02x%02x%02x%02x)", - psData[pos] << 24, psData[pos+1] << 16, - psData[pos+2] << 8, psData[pos+3] ); - delete psBuffer; - (*_esBufferList) = NULL; - return false; - } - pos += 4; /* pack_start_code */ - pos += 9; /* pack_header */ - pos += 1 + ( psData[pos] & 0x7 ); /* stuffing bytes */ - - /* system_header */ - if( psData[pos] == 0 && psData[pos+1] == 0 && - psData[pos+2] == 0x1 && psData[pos+3] == 0xBB ) - { - uint32_t header_length; - - pos += 4; /* system_header_start_code */ - header_length = ( psData[pos] << 8 ) + psData[pos+1]; - pos += 2 + header_length; - } - - HBList * esBufferList = new HBList(); - HBBuffer * esBuffer; - - /* PES */ - while( pos + 6 < psBuffer->fSize && - psData[pos] == 0 && psData[pos+1] == 0 && psData[pos+2] == 0x1 ) - { - uint32_t streamId; - uint32_t PES_packet_length; - uint32_t PES_packet_end; - uint32_t PES_header_data_length; - uint32_t PES_header_end; - bool hasPTS; - uint64_t PTS = 0; - - pos += 3; /* packet_start_code_prefix */ - streamId = psData[pos]; - pos += 1; - - PES_packet_length = ( psData[pos] << 8 ) + psData[pos+1]; - pos += 2; /* PES_packet_length */ - PES_packet_end = pos + PES_packet_length; - - if( streamId != 0xE0 && streamId != 0xBD ) - { - /* Not interesting */ - pos = PES_packet_end; - continue; - } - - hasPTS = ( ( psData[pos+1] >> 6 ) & 0x2 ); - pos += 2; /* Required headers */ - - PES_header_data_length = psData[pos]; - pos += 1; - PES_header_end = pos + PES_header_data_length; - - if( hasPTS ) - { - PTS = ( ( ( (uint64_t) psData[pos] >> 1 ) & 0x7 ) << 30 ) + - ( psData[pos+1] << 22 ) + - ( ( psData[pos+2] >> 1 ) << 15 ) + - ( psData[pos+3] << 7 ) + - ( psData[pos+4] >> 1 ); - } - - pos = PES_header_end; - - if( streamId == 0xBD ) - { - /* A52: don't ask */ - streamId |= ( psData[pos] << 8 ); - pos += 4; - } - - /* Sanity check */ - if( pos >= PES_packet_end ) - { - Log( "PStoES: pos >= PES_packet_end" ); - pos = PES_packet_end; - continue; - } - - /* Here we hit we ES payload */ - esBuffer = new HBBuffer( PES_packet_end - pos ); - - esBuffer->fPosition = psBuffer->fPosition; - esBuffer->fPass = psBuffer->fPass; - esBuffer->fStreamId = streamId; - esBuffer->fPTS = PTS; - memcpy( esBuffer->fData, psBuffer->fData + pos, - PES_packet_end - pos ); - - esBufferList->AddItem( esBuffer ); - - pos = PES_packet_end; - } - - delete psBuffer; - - if( !esBufferList->CountItems() ) - { - delete esBufferList; - esBufferList = NULL; - } - - (*_esBufferList) = esBufferList; - return true; - -#undef psData -} diff --git a/core/MpegDemux.h b/core/MpegDemux.h deleted file mode 100644 index 187a08de..00000000 --- a/core/MpegDemux.h +++ /dev/null @@ -1,43 +0,0 @@ -/* $Id: MpegDemux.h,v 1.11 2003/10/09 13:24:48 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_MPEG_DEMUX_H -#define HB_MPEG_DEMUX_H - -#include "Common.h" - -bool PStoES( HBBuffer * psBuffer, HBList ** _esBufferList ); - -class HBMpegDemux -{ - public: - HBMpegDemux( HBManager * manager, HBTitle * title, - HBAudio * audio1, HBAudio * audio2 ); - ~HBMpegDemux(); - bool Work(); - - private: - bool Lock(); - void Unlock(); - - HBManager * fManager; - HBTitle * fTitle; - HBAudio * fAudio1; - HBAudio * fAudio2; - - HBLock * fLock; - bool fUsed; - - HBBuffer * fPSBuffer; - HBBuffer * fESBuffer; - HBList * fESBufferList; - - int64_t fFirstVideoPTS; - int64_t fFirstAudio1PTS; - int64_t fFirstAudio2PTS; -}; - -#endif diff --git a/core/Resizer.cpp b/core/Resizer.cpp deleted file mode 100644 index c49a39bf..00000000 --- a/core/Resizer.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* $Id: Resizer.cpp,v 1.9 2003/10/14 14:35:20 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Resizer.h" -#include "Manager.h" -#include "Fifo.h" - -#include - -HBResizer::HBResizer( HBManager * manager, HBTitle * title ) -{ - fManager = manager; - fTitle = title; - - /* Lock */ - fLock = new HBLock(); - fUsed = false; - - /* Init libavcodec */ - fResampleContext = - img_resample_full_init( fTitle->fOutWidth, fTitle->fOutHeight, - fTitle->fInWidth, fTitle->fInHeight, - fTitle->fTopCrop, fTitle->fBottomCrop, - fTitle->fLeftCrop, fTitle->fRightCrop ); - - /* Buffers & pictures */ - fRawBuffer = NULL; - fDeinterlacedBuffer = new HBBuffer( 3 * fTitle->fInWidth * - fTitle->fInHeight / 2 ); - fResizedBuffer = NULL; - fRawPicture = (AVPicture*) malloc( sizeof( AVPicture ) ); - fDeinterlacedPicture = (AVPicture*) malloc( sizeof( AVPicture ) ); - fResizedPicture = (AVPicture*) malloc( sizeof( AVPicture ) ); - - avpicture_fill( fDeinterlacedPicture, fDeinterlacedBuffer->fData, - PIX_FMT_YUV420P, fTitle->fInWidth, - fTitle->fInHeight ); -} - -HBResizer::~HBResizer() -{ - /* Free memory */ - free( fResizedPicture ); - free( fDeinterlacedPicture ); - free( fRawPicture ); - if( fResizedBuffer ) delete fResizedBuffer; - delete fDeinterlacedBuffer; - img_resample_close( fResampleContext ); - delete fLock; -} - -bool HBResizer::Work() -{ - if( !Lock() ) - { - return false; - } - - /* Push the latest resized buffer */ - if( fResizedBuffer ) - { - if( fTitle->fResizedFifo->Push( fResizedBuffer ) ) - { - fResizedBuffer = NULL; - } - else - { - Unlock(); - return false; - } - } - - /* Get a new raw picture */ - if( ( fRawBuffer = fTitle->fRawFifo->Pop() ) ) - { - /* Do the job */ - avpicture_fill( fRawPicture, fRawBuffer->fData, - PIX_FMT_YUV420P, fTitle->fInWidth, - fTitle->fInHeight ); - - fResizedBuffer = new HBBuffer( 3 * fTitle->fOutWidth * - fTitle->fOutHeight / 2 ); - fResizedBuffer->fPosition = fRawBuffer->fPosition; - fResizedBuffer->fPass = fRawBuffer->fPass; - avpicture_fill( fResizedPicture, fResizedBuffer->fData, - PIX_FMT_YUV420P, fTitle->fOutWidth, - fTitle->fOutHeight ); - - if( fTitle->fDeinterlace ) - { - avpicture_deinterlace( fDeinterlacedPicture, fRawPicture, - PIX_FMT_YUV420P, - fTitle->fInWidth, - fTitle->fInHeight ); - img_resample( fResampleContext, fResizedPicture, - fDeinterlacedPicture ); - } - else - { - img_resample( fResampleContext, fResizedPicture, - fRawPicture ); - } - delete fRawBuffer; - fRawBuffer = NULL; - } - else - { - Unlock(); - return false; - } - - Unlock(); - return true; -} - -bool HBResizer::Lock() -{ - fLock->Lock(); - if( fUsed ) - { - fLock->Unlock(); - return false; - } - fUsed = true; - fLock->Unlock(); - return true; -} - -void HBResizer::Unlock() -{ - fLock->Lock(); - fUsed = false; - fLock->Unlock(); -} - diff --git a/core/Resizer.h b/core/Resizer.h deleted file mode 100644 index f6d4a456..00000000 --- a/core/Resizer.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $Id: Resizer.h,v 1.5 2003/10/07 22:48:31 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_RESIZER_H -#define HB_RESIZER_H - -#include "Common.h" - -class HBResizer -{ - public: - HBResizer( HBManager * manager, HBTitle * title ); - ~HBResizer(); - bool Work(); - - private: - bool Lock(); - void Unlock(); - - HBManager * fManager; - HBTitle * fTitle; - - HBLock * fLock; - bool fUsed; - - ImgReSampleContext * fResampleContext; - HBBuffer * fRawBuffer; - HBBuffer * fDeinterlacedBuffer; - HBBuffer * fResizedBuffer; - AVPicture * fRawPicture; - AVPicture * fDeinterlacedPicture; - AVPicture * fResizedPicture; -}; - -#endif diff --git a/core/Scale.c b/core/Scale.c new file mode 100644 index 00000000..7e929596 --- /dev/null +++ b/core/Scale.c @@ -0,0 +1,139 @@ +/* $Id: Scale.c,v 1.4 2003/11/06 13:03:19 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Fifo.h" +#include "Scale.h" +#include "Work.h" + +#include + +/* Local prototypes */ +static int ScaleWork( HBWork * ); + +struct HBScale +{ + HB_WORK_COMMON_MEMBERS + + HBHandle * handle; + HBTitle * title; + + ImgReSampleContext * context; + AVPicture rawPicture; + HBBuffer * deintBuffer; + AVPicture deintPicture; + HBBuffer * scaledBuffer; + AVPicture scaledPicture; +}; + +HBScale * HBScaleInit( HBHandle * handle, HBTitle * title ) +{ + HBScale * s; + if( !( s = malloc( sizeof( HBScale ) ) ) ) + { + HBLog( "HBScaleInit: malloc() failed, gonna crash" ); + return NULL; + } + + s->name = strdup( "Scale" ); + s->work = ScaleWork; + + s->handle = handle; + s->title = title; + + /* Init libavcodec */ + s->context = + img_resample_full_init( title->outWidth, title->outHeight, + title->inWidth, title->inHeight, + title->topCrop, title->bottomCrop, + title->leftCrop, title->rightCrop ); + + /* Allocate a constant buffer used for deinterlacing */ + s->deintBuffer = HBBufferInit( 3 * title->inWidth * + title->inHeight / 2 ); + avpicture_fill( &s->deintPicture, s->deintBuffer->data, + PIX_FMT_YUV420P, title->inWidth, title->inHeight ); + + s->scaledBuffer = NULL; + + return s; +} + +void HBScaleClose( HBScale ** _s ) +{ + HBScale * s = *_s; + + img_resample_close( s->context ); + HBBufferClose( &s->deintBuffer ); + free( s->name ); + free( s ); + + *_s = NULL; +} + +static int ScaleWork( HBWork * w ) +{ + HBScale * s = (HBScale*) w; + HBTitle * title = s->title; + HBBuffer * rawBuffer; + + int didSomething = 0; + + /* Push scaled buffer */ + if( s->scaledBuffer ) + { + if( HBFifoPush( title->scaledFifo, &s->scaledBuffer ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + } + + /* Get a new raw picture */ + if( ( rawBuffer = HBFifoPop( title->rawFifo ) ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + + /* Allocate new buffer for the scaled picture */ + s->scaledBuffer = HBBufferInit( 3 * title->outWidth * + title->outHeight / 2 ); + s->scaledBuffer->position = rawBuffer->position; + s->scaledBuffer->pass = rawBuffer->pass; + + /* libavcodec stuff */ + avpicture_fill( &s->rawPicture, rawBuffer->data, PIX_FMT_YUV420P, + title->inWidth, title->inHeight ); + avpicture_fill( &s->scaledPicture, s->scaledBuffer->data, + PIX_FMT_YUV420P, title->outWidth, + title->outHeight ); + + /* Do the job */ + if( title->deinterlace ) + { + avpicture_deinterlace( &s->deintPicture, &s->rawPicture, + PIX_FMT_YUV420P, title->inWidth, + title->inHeight ); + img_resample( s->context, &s->scaledPicture, + &s->deintPicture ); + } + else + { + img_resample( s->context, &s->scaledPicture, &s->rawPicture ); + } + + /* Free memory */ + HBBufferClose( &rawBuffer ); + + return didSomething; +} + diff --git a/core/Scale.h b/core/Scale.h new file mode 100644 index 00000000..cf06ad66 --- /dev/null +++ b/core/Scale.h @@ -0,0 +1,15 @@ +/* $Id: Scale.h,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_SCALE_H +#define HB_SCALE_H + +#include "HandBrakeInternal.h" + +HBScale * HBScaleInit( HBHandle *, HBTitle * ); +void HBScaleClose( HBScale ** ); + +#endif diff --git a/core/Scan.c b/core/Scan.c new file mode 100644 index 00000000..83f2fc09 --- /dev/null +++ b/core/Scan.c @@ -0,0 +1,395 @@ +/* $Id: Scan.c,v 1.4 2003/11/06 13:03:19 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Fifo.h" +#include "Languages.h" +#include "Scan.h" +#include "Thread.h" + +#include +#include +#include +#include +#include + +#include + +/* Local prototypes */ +static void ScanThread( void * ); +static HBTitle * ScanTitle( HBScan *, dvdplay_ptr vmg, int index ); +static int DecodeFrame( HBScan * s, dvdplay_ptr vmg, + HBTitle * title, int which ); +static char * LanguageForCode( int code ); + +struct HBScan +{ + HBHandle * handle; + char * device; + int title; + int die; + HBThread * thread; +}; + +HBScan * HBScanInit( HBHandle * handle, char * device, int title ) +{ + HBScan * s; + if( !( s = malloc( sizeof( HBScan ) ) ) ) + { + HBLog( "HBScanInit: malloc() failed, gonna crash" ); + return NULL; + } + + s->handle = handle; + s->device = strdup( device ); + s->title = title; + s->die = 0; + s->thread = HBThreadInit( "scan", ScanThread, s, + HB_NORMAL_PRIORITY ); + + return s; +} + +void HBScanClose( HBScan ** _s ) +{ + HBScan * s = *_s; + + s->die = 1; + HBThreadClose( &s->thread ); + + free( s->device ); + free( s ); + *_s = NULL; +} + +static void ScanThread( void * _s ) +{ + HBScan * s = (HBScan*) _s; + dvdplay_ptr vmg; + HBList * titleList = HBListInit(); + HBTitle * title; + int i; + + HBLog( "HBScan: opening device %s", s->device ); + HBScanning( s->handle, 0 ); + + vmg = dvdplay_open( s->device, NULL, NULL ); + if( !vmg ) + { + HBLog( "HBScan: dvdplay_open() failed (%s)", s->device ); + HBScanDone( s->handle, titleList ); + return; + } + + /* Detect titles */ + for( i = ( s->title ? s->title - 1 : 0 ); + i < ( s->title ? s->title : dvdplay_title_nr( vmg ) ); + i++ ) + { + if( s->die ) + { + break; + } + + if( !( title = ScanTitle( s, vmg, i + 1 ) ) ) + { + continue; + } + + HBListAdd( titleList, title ); + } + + HBLog( "HBScan: closing device %s", s->device ); + dvdplay_close( vmg ); + + HBScanDone( s->handle, titleList ); +} + +static HBTitle * ScanTitle( HBScan * s, dvdplay_ptr vmg, int index ) +{ + HBTitle * title; + int audio_nr, foo; + audio_attr_t * attr; + HBAudio * audio; + int i; + uint8_t dummy[DVD_VIDEO_LB_LEN]; + + HBLog( "HBScan: scanning title %d", index ); + HBScanning( s->handle, index ); + + title = HBTitleInit( s->device, index ); + dvdplay_start( vmg, index ); + + /* Length */ + title->length = dvdplay_title_time( vmg ); + HBLog( "HBScan: title length is %d seconds", title->length ); + + /* Discard titles under 10 seconds */ + if( title->length < 10 ) + { + HBLog( "HBScan: ignoring title %d (too short)", index ); + HBTitleClose( &title ); + return NULL; + } + + /* Detect languages */ + dvdplay_audio_info( vmg, &audio_nr, &foo ); + + for( i = 0; i < audio_nr; i++ ) + { + int id; + int j; + + if( s->die ) + { + break; + } + + id = dvdplay_audio_id( vmg, i ); + + if( id < 1 ) + { + continue; + } + + if( ( id & 0xFF ) != 0xBD ) + { + HBLog( "HBScan: non-AC3 audio track detected, ignoring" ); + continue; + } + + /* Check if we don't already found an track with the same id */ + audio = NULL; + for( j = 0; j < HBListCountItems( title->audioList ); j++ ) + { + audio = (HBAudio*) HBListItemAt( title->audioList, j ); + if( id == audio->id ) + { + break; + } + else + { + audio = NULL; + } + } + + if( audio ) + { + HBLog( "HBScan: discarding duplicate track %x", id ); + continue; + } + + attr = dvdplay_audio_attr( vmg, j ); + audio = HBAudioInit( id, LanguageForCode( attr->lang_code ) ); + HBLog( "HBScan: new language (%x, %s)", id, audio->language ); + HBListAdd( title->audioList, audio ); + } + + /* Discard titles with no audio tracks */ + if( !HBListCountItems( title->audioList ) ) + { + HBLog( "HBScan: ignoring title %d (no audio track)", index ); + HBTitleClose( &title ); + return NULL; + } + + /* Kludge : libdvdplay wants we to read a first block before seeking */ + dvdplay_read( vmg, dummy, 1 ); + + + for( i = 0; i < 10; i++ ) + { + if( s->die ) + { + break; + } + + if( !DecodeFrame( s, vmg, title, i ) ) + { + HBLog( "HBScan: ignoring title %d (could not decode)", + index ); + HBTitleClose( &title ); + return NULL; + } + } + + if( title->inHeight * title->aspect > + title->inWidth * VOUT_ASPECT_FACTOR ) + { + title->outWidthMax = title->inWidth; + title->outHeightMax = MULTIPLE_16( (uint64_t)title->inWidth * + VOUT_ASPECT_FACTOR / title->aspect ); + } + else + { + title->outWidthMax = MULTIPLE_16( (uint64_t)title->inHeight * + title->aspect / VOUT_ASPECT_FACTOR ); + title->outHeightMax = title->inHeight; + } + + /* Default picture size */ + title->outWidth = title->outWidthMax; + title->outHeight = title->outHeightMax; + + return title; +} + +static int DecodeFrame( HBScan * s, dvdplay_ptr vmg, + HBTitle * title, int which ) +{ + int titleFirst = dvdplay_title_first( vmg ); + int titleEnd = dvdplay_title_end( vmg ); + int pictureStart = ( which + 1 ) * ( titleEnd - titleFirst ) / 11; + int pictureEnd = titleFirst + ( which + 2 ) * + ( titleEnd - titleFirst ) / 11; + + mpeg2dec_t * handle; + const mpeg2_info_t * info; + mpeg2_state_t state; + char fileName[1024]; + FILE * file; + + HBList * esBufferList = HBListInit(); + HBBuffer * psBuffer = NULL; + HBBuffer * esBuffer = NULL; + + /* Seek to the right place */ + dvdplay_seek( vmg, pictureStart ); + + /* Init libmpeg2 */ + handle = mpeg2_init(); + info = mpeg2_info( handle ); + + /* Init the destination file */ + memset( fileName, 0, 1024 ); + sprintf( fileName, "/tmp/HB.%d.%d.%d", HBGetPid( s->handle ), + title->index, which ); + file = fopen( fileName, "w" ); + +#define CLEANUP \ + while( ( esBuffer = (HBBuffer*) HBListItemAt( esBufferList, 0 ) ) ) \ + { \ + HBListRemove( esBufferList, esBuffer ); \ + HBBufferClose( &esBuffer ); \ + } \ + HBListClose( &esBufferList ); \ + if( psBuffer ) HBBufferClose( &psBuffer ); \ + if( esBuffer ) HBBufferClose( &esBuffer ); \ + mpeg2_close( handle ); \ + fclose( file ) + + for( ;; ) + { + state = mpeg2_parse( handle ); + + if( state == STATE_BUFFER ) + { + /* Free the previous buffer */ + if( esBuffer ) + { + HBBufferClose( &esBuffer ); + } + + /* Get a new one */ + while( !esBuffer ) + { + while( !HBListCountItems( esBufferList ) ) + { + psBuffer = HBBufferInit( DVD_VIDEO_LB_LEN ); + if( dvdplay_read( vmg, psBuffer->data, 1 ) != 1 || + !HBPStoES( &psBuffer, esBufferList ) ) + { + HBLog( "HBScan: failed to get a valid PS " + "packet" ); + CLEANUP; + return 0; + } + + if( dvdplay_position( vmg ) >= pictureEnd ) + { + HBLog( "HBScan: gone too far, aborting" ); + CLEANUP; + return 0; + } + } + + esBuffer = (HBBuffer*) HBListItemAt( esBufferList, 0 ); + HBListRemove( esBufferList, esBuffer ); + + if( esBuffer->streamId != 0xE0 ) + { + HBBufferClose( &esBuffer ); + } + } + + /* Feed libmpeg2 */ + mpeg2_buffer( handle, esBuffer->data, + esBuffer->data + esBuffer->size ); + } + else if( state == STATE_SEQUENCE ) + { + /* Get size & framerate info */ + title->inWidth = info->sequence->width; + title->inHeight = info->sequence->height; + title->aspect = (uint64_t)info->sequence->display_width * + info->sequence->pixel_width * VOUT_ASPECT_FACTOR / + ( info->sequence->display_height * + info->sequence->pixel_height ); + title->rate = 27000000; + title->rateBase = info->sequence->frame_period; + } + else if( ( state == STATE_SLICE || state == STATE_END ) && + ( info->display_fbuf ) && + ( info->display_picture->flags & PIC_MASK_CODING_TYPE ) + == PIC_FLAG_CODING_TYPE_I ) + { + /* Write the raw picture to a file */ + fwrite( info->display_fbuf->buf[0], + title->inWidth * title->inHeight, 1, file ); + fwrite( info->display_fbuf->buf[1], + title->inWidth * title->inHeight / 4, 1, file ); + fwrite( info->display_fbuf->buf[2], + title->inWidth * title->inHeight / 4, 1, file ); + break; + } + else if( state == STATE_INVALID ) + { + /* Reset libmpeg2 */ + mpeg2_close( handle ); + handle = mpeg2_init(); + } + } + + CLEANUP; + + return 1; + +#undef CLEANUP +} + +static char * LanguageForCode( int code ) +{ + char codeString[2]; + iso639_lang_t * lang; + + codeString[0] = ( code >> 8 ) & 0xFF; + codeString[1] = code & 0xFF; + + for( lang = languages; lang->engName; lang++ ) + { + if( !strncmp( lang->iso639_1, codeString, 2 ) ) + { + if( *lang->nativeName ) + { + return lang->nativeName; + } + + return lang->engName; + } + } + + return "Unknown"; +} + diff --git a/core/Scan.h b/core/Scan.h new file mode 100644 index 00000000..5cc8542e --- /dev/null +++ b/core/Scan.h @@ -0,0 +1,15 @@ +/* $Id: Scan.h,v 1.2 2003/11/06 13:03:19 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_SCAN_H +#define HB_SCAN_H + +#include "HandBrakeInternal.h" + +HBScan * HBScanInit( HBHandle *, char * device, int title ); +void HBScanClose( HBScan ** ); + +#endif diff --git a/core/Scanner.cpp b/core/Scanner.cpp deleted file mode 100644 index 44ff6be3..00000000 --- a/core/Scanner.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* $Id: Scanner.cpp,v 1.23 2003/10/13 14:12:18 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Scanner.h" -#include "Manager.h" -#include "Fifo.h" -#include "MpegDemux.h" - -#include -#include -#include -#include -#include - -extern "C" { -#include -} - -HBScanner::HBScanner( HBManager * manager, char * device ) - : HBThread( "scanner", HB_NORMAL_PRIORITY ) -{ - fManager = manager; - fDevice = strdup( device ); - - Run(); -} - -void HBScanner::DoWork() -{ - Log( "HBScanner: opening device %s", fDevice ); - - dvdplay_ptr vmg; - vmg = dvdplay_open( fDevice, NULL, NULL ); - if( !vmg ) - { - Log( "HBScanner: dvdplay_open() failed (%s)", - fDevice ); - fManager->ScanDone( NULL ); - return; - } - - /* Detect titles */ - HBList * titleList = new HBList(); - HBTitle * title; - for( int i = 0; i < dvdplay_title_nr( vmg ); i++ ) - { - if( fDie ) - { - break; - } - - Log( "HBScanner: scanning title %d", i + 1 ); - fManager->Scanning( fDevice, i + 1 ); - - title = new HBTitle( fDevice, i + 1 ); - - if( ScanTitle( title, vmg ) ) - { - titleList->AddItem( title ); - } - else - { - Log( "HBScanner: ignoring title %d", i + 1 ); - delete title; - } - } - - Log( "HBScanner: closing device %s", fDevice ); - dvdplay_close( vmg ); - - fManager->ScanDone( titleList ); -} - -bool HBScanner::ScanTitle( HBTitle * title, dvdplay_ptr vmg ) -{ - dvdplay_start( vmg, title->fIndex ); - - /* Length */ - title->fLength = dvdplay_title_time( vmg ); - Log( "HBScanner::ScanTitle: title length is %lld seconds", - title->fLength ); - - /* Discard titles under 10 seconds */ - if( title->fLength < 10 ) - { - return false; - } - - /* Detect languages */ - int audio_nr, foo; - dvdplay_audio_info( vmg, &audio_nr, &foo ); - - audio_attr_t * attr; - HBAudio * audio; - for( int i = 0; i < audio_nr; i++ ) - { - if( fDie ) - { - break; - } - - int id = dvdplay_audio_id( vmg, i ); - - if( id < 1 ) - { - continue; - } - - if( ( id & 0xFF ) != 0xBD ) - { - Log( "HBScanner::ScanTitle: non-AC3 audio track " - "detected, ignoring" ); - continue; - } - - /* Check if we don't already found an track with the same id */ - audio = NULL; - for( uint32_t j = 0; j < title->fAudioList->CountItems(); j++ ) - { - audio = (HBAudio*) title->fAudioList->ItemAt( j ); - if( (uint32_t) id == audio->fId ) - { - break; - } - else - { - audio = NULL; - } - } - - if( audio ) - { - Log( "HBScanner::ScanTitle: discarding duplicate track %x", - id ); - continue; - } - - attr = dvdplay_audio_attr( vmg, i ); - audio = new HBAudio( id, LanguageForCode( attr->lang_code ) ); - Log( "HBScanner::ScanTitle: new language (%x, %s)", - id, audio->fDescription ); - title->fAudioList->AddItem( audio ); - } - - /* Discard titles with no audio tracks */ - if( !title->fAudioList->CountItems() ) - { - return false; - } - - /* Kludge : libdvdplay wants we to read a first block before seeking */ - uint8_t dummyBuf[DVD_VIDEO_LB_LEN]; - dvdplay_read( vmg, dummyBuf, 1 ); - - for( int i = 0; i < 10; i++ ) - { - if( fDie ) - { - break; - } - - if( !DecodeFrame( title, vmg, i ) ) - { - return false; - } - } - - if( title->fInHeight * title->fAspect > - title->fInWidth * VOUT_ASPECT_FACTOR ) - { - title->fOutWidthMax = title->fInWidth; - title->fOutHeightMax = MULTIPLE_16( (uint64_t)title->fInWidth * - VOUT_ASPECT_FACTOR / title->fAspect ); - } - else - { - title->fOutWidthMax = MULTIPLE_16( (uint64_t)title->fInHeight * - title->fAspect / VOUT_ASPECT_FACTOR ); - title->fOutHeightMax = title->fInHeight; - } - - /* Default picture size */ - title->fOutWidth = title->fOutWidthMax; - title->fOutHeight = title->fOutHeightMax; - - return true; -} -bool HBScanner::DecodeFrame( HBTitle * title, dvdplay_ptr vmg, int i ) -{ - /* Seek to the right place */ - int titleFirst = dvdplay_title_first ( vmg ); - int titleEnd = dvdplay_title_end( vmg ); - - dvdplay_seek( vmg, ( i + 1 ) * ( titleEnd - titleFirst ) / 11 ) ; - - /* Init libmpeg2 */ - mpeg2dec_t * handle = mpeg2_init(); - const mpeg2_info_t * info = mpeg2_info( handle ); - mpeg2_state_t state; - - /* Init the destination file */ - char fileName[1024]; - memset( fileName, 0, 1024 ); - sprintf( fileName, "/tmp/HB.%d.%x.%d", fManager->GetPid(), - (uint32_t) title, i ); - FILE * file = fopen( fileName, "w" ); - - HBList * esBufferList = NULL; - HBBuffer * psBuffer = NULL; - HBBuffer * esBuffer = NULL; - - for( ;; ) - { - state = mpeg2_parse( handle ); - - if( state == STATE_BUFFER ) - { - /* Free the previous buffer */ - if( esBuffer ) - { - delete esBuffer; - esBuffer = NULL; - } - - /* Get a new one */ - while( !esBuffer ) - { - while( !esBufferList ) - { - psBuffer = new HBBuffer( DVD_VIDEO_LB_LEN ); - if( dvdplay_read( vmg, psBuffer->fData, 1 ) != 1 || - !PStoES( psBuffer, &esBufferList ) ) - { - Log( "HBScanner::DecodeFrame: failed to get " - "a valid PS packet" ); - mpeg2_close( handle ); - fclose( file ); - return false; - } - } - - esBuffer = (HBBuffer*) esBufferList->ItemAt( 0 ); - esBufferList->RemoveItem( esBuffer ); - if( !esBufferList->CountItems() ) - { - delete esBufferList; - esBufferList = NULL; - } - - if( esBuffer->fStreamId != 0xE0 ) - { - delete esBuffer; - esBuffer = NULL; - } - } - - /* Feed libmpeg2 */ - mpeg2_buffer( handle, esBuffer->fData, - esBuffer->fData + esBuffer->fSize ); - } - else if( state == STATE_SEQUENCE ) - { - /* Get size & framerate info */ - title->fInWidth = info->sequence->width; - title->fInHeight = info->sequence->height; - title->fAspect = (uint64_t)info->sequence->display_width * - info->sequence->pixel_width * VOUT_ASPECT_FACTOR / - ( info->sequence->display_height * - info->sequence->pixel_height ); - title->fRate = 27000000; - title->fScale = info->sequence->frame_period; - } - else if( ( state == STATE_SLICE || state == STATE_END ) && - ( info->display_fbuf ) && - ( info->display_picture->flags & PIC_MASK_CODING_TYPE ) - == PIC_FLAG_CODING_TYPE_I ) - { - /* Write the raw picture to a file */ - fwrite( info->display_fbuf->buf[0], - title->fInWidth * title->fInHeight, 1, file ); - fwrite( info->display_fbuf->buf[1], - title->fInWidth * title->fInHeight / 4, 1, file ); - fwrite( info->display_fbuf->buf[2], - title->fInWidth * title->fInHeight / 4, 1, file ); - break; - } - else if( state == STATE_INVALID ) - { - /* Reset libmpeg2 */ - mpeg2_close( handle ); - handle = mpeg2_init(); - } - } - - mpeg2_close( handle ); - - fclose( file ); - - return true; -} diff --git a/core/Scanner.h b/core/Scanner.h deleted file mode 100644 index dbdb587c..00000000 --- a/core/Scanner.h +++ /dev/null @@ -1,27 +0,0 @@ -/* $Id: Scanner.h,v 1.5 2003/09/30 21:21:32 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_SCANNER_H -#define HB_SCANNER_H - -#include "Common.h" -#include "Thread.h" - -class HBScanner : public HBThread -{ - public: - HBScanner( HBManager * manager, char * device ); - - private: - void DoWork(); - bool ScanTitle( HBTitle * title, dvdplay_ptr vmg ); - bool DecodeFrame( HBTitle * title, dvdplay_ptr vmg, int i ); - - HBManager * fManager; - char * fDevice; -}; - -#endif diff --git a/core/Thread.c b/core/Thread.c new file mode 100644 index 00000000..77caa0ee --- /dev/null +++ b/core/Thread.c @@ -0,0 +1,138 @@ +/* $Id: Thread.c,v 1.4 2003/11/06 15:51:36 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Thread.h" + +struct HBThread +{ + char * name; + int priority; + void (*function) ( void * ); + void * arg; + +#if defined( SYS_BEOS ) + int thread; +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) + pthread_t thread; +#elif defined( SYS_CYGWIN ) + /* TODO */ + int thread; +#endif +}; + +#ifndef SYS_CYGWIN +static void ThreadFunc( void * t ); +#endif + +HBThread * HBThreadInit( char * name, void (* function)(void *), + void * arg, int priority ) +{ + 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; + +#if defined( SYS_BEOS ) + t->thread = spawn_thread( (int32 (*)( void * )) ThreadFunc, + name, priority, t ); + resume_thread( t->thread ); +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) + pthread_create( &t->thread, NULL, + (void * (*)( void * )) ThreadFunc, t ); +#elif defined( SYS_CYGWIN ) + /* TODO */ + t->thread = 0; +#endif + + HBLog( "HBThreadInit: thread %d started (\"%s\")", + t->thread, t->name ); + + return t; +} + +#ifndef SYS_CYGWIN +static void ThreadFunc( void * _t ) +{ + HBThread * t = (HBThread*) _t; + +#if defined( SYS_MACOSX ) + struct sched_param param; + memset( ¶m, 0, sizeof( struct sched_param ) ); + param.sched_priority = t->priority; + if( pthread_setschedparam( pthread_self(), SCHED_OTHER, ¶m ) ) + { + HBLog( "HBThreadInit: couldn't set thread priority" ); + } +#endif + + t->function( t->arg ); +} +#endif + +void HBThreadClose( HBThread ** _t ) +{ + HBThread * t = *_t; + +#if defined( SYS_BEOS ) + long exitValue; + wait_for_thread( t->thread, &exitValue ); +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) + pthread_join( t->thread, NULL ); +#elif defined( SYS_CYGWIN ) + /* TODO */ +#endif + + HBLog( "HBThreadClose: thread %d stopped (\"%s\")", + t->thread, t->name ); + + free( t->name ); + free( t ); + *_t = NULL; +} + +HBLock * HBLockInit() +{ + HBLock * l; + if( !( l = malloc( sizeof( HBLock ) ) ) ) + { + HBLog( "HBLockInit: malloc() failed, gonna crash" ); + return NULL; + } + +#if defined( SYS_BEOS ) + l->sem = create_sem( 1, "sem" ); +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) + pthread_mutex_init( &l->mutex, NULL ); +#elif defined( SYS_CYGWIN ) + /* TODO */ +#endif + + return l; +} + +void HBLockClose( HBLock ** _l ) +{ + HBLock * l = *_l; + +#if defined( SYS_BEOS ) + delete_sem( l->sem ); +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) + pthread_mutex_destroy( &l->mutex ); +#elif defined( SYS_CYGWIN ) + /* TODO */ +#endif + free( l ); + + *_l = NULL; +} + diff --git a/core/Thread.cpp b/core/Thread.cpp deleted file mode 100644 index c52f7506..00000000 --- a/core/Thread.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* $Id: Thread.cpp,v 1.24 2003/10/14 14:35:20 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#if defined( SYS_BEOS ) -# include -# include -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) -# include -#endif - -#include "Thread.h" -#include "Fifo.h" - -HBThread::HBThread( char * name, int priority ) -{ - fName = strdup( name ); - fPriority = priority; - fDie = false; - fSuspend = false; -} - -HBThread::~HBThread() -{ - fDie = true; - fSuspend = false; - -#if defined( SYS_BEOS ) - long exit_value; - wait_for_thread( fThread, &exit_value ); -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_join( fThread, NULL ); -#endif - - Log( "HBThread: thread %d stopped (\"%s\")", fThread, fName ); - free( fName ); -} - -void HBThread::Suspend() -{ - fSuspend = true; -} - -void HBThread::Resume() -{ - fSuspend = false; -} - -int HBThread::GetPid() -{ - return fPid; -} - -void HBThread::Run() -{ -#if defined( SYS_BEOS ) - fThread = spawn_thread( (int32 (*)(void *)) ThreadFunc, - fName, fPriority, this ); - resume_thread( fThread ); -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_create( &fThread, NULL, - (void * (*)(void *)) ThreadFunc, this ); -#endif - - Log( "HBThread: thread %d started (\"%s\")", - fThread, fName ); -} - -bool HBThread::Push( HBFifo * fifo, HBBuffer * buffer ) -{ - while( !fDie ) - { - if( fifo->Push( buffer ) ) - { - return true; - } - - Snooze( 10000 ); - } - - delete buffer; - return false; -} - -HBBuffer * HBThread::Pop( HBFifo * fifo ) -{ - HBBuffer * buffer; - - while( !fDie ) - { - if( ( buffer = fifo->Pop() ) ) - { - return buffer; - } - - Snooze( 10000 ); - } - - return NULL; -} - -void HBThread::ThreadFunc( HBThread * _this ) -{ -#if defined( SYS_MACOSX ) - struct sched_param param; - memset( ¶m, 0, sizeof( struct sched_param ) ); - param.sched_priority = _this->fPriority; - if ( pthread_setschedparam( pthread_self(), SCHED_OTHER, ¶m ) ) - { - Log( "HBThread: couldn't set thread priority" ); - } -#endif - - _this->fPid = (int) getpid(); - - _this->DoWork(); -} - -void HBThread::DoWork() -{ -} - - -HBLock::HBLock() -{ -#if defined( SYS_BEOS ) - fLocker = new BLocker(); -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_mutex_init( &fMutex, NULL ); -#endif -} - -HBLock::~HBLock() -{ -#if defined( SYS_BEOS ) - delete fLocker; -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_mutex_destroy( &fMutex ); -#endif -} - -void HBLock::Lock() -{ -#if defined( SYS_BEOS ) - fLocker->Lock(); -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_mutex_lock( &fMutex ); -#endif -} - -void HBLock::Unlock() -{ -#if defined( SYS_BEOS ) - fLocker->Unlock(); -#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_mutex_unlock( &fMutex ); -#endif -} diff --git a/core/Thread.h b/core/Thread.h index 0a09fabc..58700aae 100644 --- a/core/Thread.h +++ b/core/Thread.h @@ -1,13 +1,19 @@ -/* $Id: Thread.h,v 1.19 2003/10/09 16:03:51 titer Exp $ +/* $Id: Thread.h,v 1.3 2003/11/06 15:51:36 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #ifndef HB_THREAD_H #define HB_THREAD_H -#include "Common.h" +#if defined( SYS_BEOS ) +# include +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) +# include +#endif + +#include "Utils.h" #if defined( SYS_BEOS ) # define HB_LOW_PRIORITY 5 @@ -15,63 +21,52 @@ #elif defined( SYS_MACOSX ) # define HB_LOW_PRIORITY 0 # define HB_NORMAL_PRIORITY 31 -#elif defined( SYS_LINUX ) +#elif defined( SYS_LINUX ) || defined( SYS_CYGWIN ) /* Actually unused */ # define HB_LOW_PRIORITY 0 # define HB_NORMAL_PRIORITY 0 #endif -class HBThread -{ - public: - HBThread( char * name, - int priority = HB_LOW_PRIORITY ); - virtual ~HBThread(); - void Suspend(); - void Resume(); - int GetPid(); - - protected: - void Run(); - bool Push( HBFifo * fifo, HBBuffer * buffer ); - HBBuffer * Pop( HBFifo * fifo ); - - volatile bool fDie; - volatile bool fSuspend; - - private: - static void ThreadFunc( HBThread * _this ); - virtual void DoWork(); - - char * fName; - int fPriority; +HBThread * HBThreadInit( char * name, void (* function)(void *), + void * arg, int priority ); +void HBThreadClose( HBThread ** ); +struct HBLock +{ #if defined( SYS_BEOS ) - int fThread; + sem_id sem; #elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_t fThread; + pthread_mutex_t mutex; +#elif defined( SYS_CYGWIN ) + /* TODO */ #endif - int fPid; }; +HBLock * HBLockInit(); +static inline void HBLockLock( HBLock * ); +static inline void HBLockUnlock( HBLock * ); +void HBLockClose( HBLock ** ); + +static inline void HBLockLock( HBLock * l ) +{ #if defined( SYS_BEOS ) -class BLocker; + acquire_sem( l->sem ); +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) + pthread_mutex_lock( &l->mutex ); +#elif defined( SYS_CYGWIN ) + /* TODO */ #endif +} -class HBLock +static inline void HBLockUnlock( HBLock * l ) { - public: - HBLock(); - ~HBLock(); - void Lock(); - void Unlock(); - - private: #if defined( SYS_BEOS ) - BLocker * fLocker; + release_sem( l->sem ); #elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) - pthread_mutex_t fMutex; + pthread_mutex_unlock( &l->mutex ); +#elif defined( SYS_CYGWIN ) + /* TODO */ #endif -}; +} #endif diff --git a/core/Utils.c b/core/Utils.c new file mode 100644 index 00000000..5f35ec3a --- /dev/null +++ b/core/Utils.c @@ -0,0 +1,352 @@ +/* $Id: Utils.c,v 1.6 2003/11/06 15:51:36 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include +#include +#include + +#include "Utils.h" +#include "Fifo.h" + +struct HBList +{ + void ** items; + int allocItems; + int nbItems; +}; + +void HBSnooze( int time ) +{ +#if defined( SYS_BEOS ) + snooze( time ); +#elif defined( SYS_MACOSX ) || defined( SYS_LINUX ) + usleep( time ); +#elif defined( SYS_CYGWIN ) + /* TODO */ +#endif +} + +void HBLog( char * log, ... ) +{ + char string[81]; + time_t _now; + struct tm * now; + va_list args; + int ret; + + if( !getenv( "HB_DEBUG" ) ) + { + return; + } + + /* Show the time */ + _now = time( NULL ); + now = localtime( &_now ); + sprintf( string, "[%02d:%02d:%02d] ", + now->tm_hour, now->tm_min, now->tm_sec ); + + /* Convert the message to a string */ + va_start( args, log ); + ret = vsnprintf( string + 11, 68, log, args ); + va_end( args ); + + /* Add the end of line */ + string[ret+11] = '\n'; + string[ret+12] = '\0'; + + /* Print it */ + fprintf( stderr, "%s", string ); +} + +uint64_t HBGetDate() +{ +#ifndef SYS_CYGWIN + struct timeval tv; + gettimeofday( &tv, NULL ); + return( (uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec ); +#else + return 0; +#endif +} + +/* Basic MPEG demuxer - only works with DVDs ! (2048 bytes packets) */ +int HBPStoES( HBBuffer ** _psBuffer, HBList * esBufferList ) +{ + HBBuffer * psBuffer = *_psBuffer; + HBBuffer * esBuffer; + int pos = 0; + +#define d (psBuffer->data) + + /* pack_header */ + if( d[pos] != 0 || d[pos+1] != 0 || + d[pos+2] != 0x1 || d[pos+3] != 0xBA ) + { + HBLog( "HBPStoES: not a PS packet (%02x%02x%02x%02x)", + d[pos] << 24, d[pos+1] << 16, + d[pos+2] << 8, d[pos+3] ); + HBBufferClose( _psBuffer ); + return 0; + } + pos += 4; /* pack_start_code */ + pos += 9; /* pack_header */ + pos += 1 + ( d[pos] & 0x7 ); /* stuffing bytes */ + + /* system_header */ + if( d[pos] == 0 && d[pos+1] == 0 && + d[pos+2] == 0x1 && d[pos+3] == 0xBB ) + { + int header_length; + + pos += 4; /* system_header_start_code */ + header_length = ( d[pos] << 8 ) + d[pos+1]; + pos += 2 + header_length; + } + + /* PES */ + while( pos + 6 < psBuffer->size && + d[pos] == 0 && d[pos+1] == 0 && d[pos+2] == 0x1 ) + { + uint32_t streamId; + uint32_t PES_packet_length; + uint32_t PES_packet_end; + uint32_t PES_header_d_length; + uint32_t PES_header_end; + int hasPTS; + uint64_t PTS = 0; + + pos += 3; /* packet_start_code_prefix */ + streamId = d[pos]; + pos += 1; + + PES_packet_length = ( d[pos] << 8 ) + d[pos+1]; + pos += 2; /* PES_packet_length */ + PES_packet_end = pos + PES_packet_length; + + if( streamId != 0xE0 && streamId != 0xBD ) + { + /* Not interesting */ + pos = PES_packet_end; + continue; + } + + hasPTS = ( ( d[pos+1] >> 6 ) & 0x2 ) ? 1 : 0; + pos += 2; /* Required headers */ + + PES_header_d_length = d[pos]; + pos += 1; + PES_header_end = pos + PES_header_d_length; + + if( hasPTS ) + { + PTS = ( ( ( (uint64_t) d[pos] >> 1 ) & 0x7 ) << 30 ) + + ( d[pos+1] << 22 ) + + ( ( d[pos+2] >> 1 ) << 15 ) + + ( d[pos+3] << 7 ) + + ( d[pos+4] >> 1 ); + } + + pos = PES_header_end; + + if( streamId == 0xBD ) + { + /* A52: don't ask */ + streamId |= ( d[pos] << 8 ); + pos += 4; + } + + /* Sanity check */ + if( pos >= PES_packet_end ) + { + HBLog( "HBPStoES: pos >= PES_packet_end" ); + pos = PES_packet_end; + continue; + } + + /* Here we hit we ES payload */ + esBuffer = HBBufferInit( PES_packet_end - pos ); + + esBuffer->position = psBuffer->position; + esBuffer->pass = psBuffer->pass; + esBuffer->streamId = streamId; + esBuffer->pts = PTS; + memcpy( esBuffer->data, d + pos, + PES_packet_end - pos ); + + HBListAdd( esBufferList, esBuffer ); + + pos = PES_packet_end; + } + + HBBufferClose( _psBuffer ); + + return 1; +} + +#define HBLIST_DEFAULT_SIZE 20 +HBList * HBListInit() +{ + HBList * l; + if( !( l = malloc( sizeof( HBList ) ) ) ) + { + HBLog( "HBListInit: malloc() failed, gonna crash" ); + return NULL; + } + + if( !( l->items = malloc( HBLIST_DEFAULT_SIZE * sizeof( void* ) ) ) ) + { + HBLog( "HBListInit: malloc() failed, gonna crash" ); + free( l ); + return NULL; + } + + l->allocItems = HBLIST_DEFAULT_SIZE; + l->nbItems = 0; + + return l; +} + +int HBListCountItems( HBList * l ) +{ + return l->nbItems; +} + +void HBListAdd( HBList * l, void * item ) +{ + if( !item ) + { + return; + } + + if( l->nbItems == l->allocItems ) + { + l->allocItems += HBLIST_DEFAULT_SIZE; + l->items = realloc( l->items, + l->allocItems * sizeof( void* ) ); + } + + l->items[l->nbItems] = item; + (l->nbItems)++; +} + +void HBListRemove( HBList * l, void * item ) +{ + int i; + + if( !item || !l->nbItems ) + { + return; + } + + for( i = 0; i < l->nbItems; i++ ) + { + if( l->items[i] == item ) + { + break; + } + } + + if( l->items[i] != item ) + { + HBLog( "HBListRemove: specified item is not in the list" ); + return; + } + + for( ; i < l->nbItems - 1; i++ ) + { + l->items[i] = l->items[i+1]; + } + + (l->nbItems)--; +} + +void * HBListItemAt( HBList * l, int index ) +{ + if( index < 0 || index >= l->nbItems ) + { + return NULL; + } + + return l->items[index]; +} + +void HBListClose( HBList ** _l ) +{ + HBList * l = *_l; + + free( l->items ); + free( l ); + + *_l = NULL; +} + +HBTitle * HBTitleInit( char * device, int index ) +{ + HBTitle * t = calloc( sizeof( HBTitle ), 1 ); + + t->device = strdup( device ); + t->index = index; + + t->codec = HB_CODEC_FFMPEG; + t->bitrate = 1024; + + t->audioList = HBListInit(); + + return t; +} + +void HBTitleClose( HBTitle ** _t ) +{ + HBTitle * t = *_t; + + HBAudio * audio; + while( ( audio = HBListItemAt( t->audioList, 0 ) ) ) + { + HBListRemove( t->audioList, audio ); + HBAudioClose( &audio ); + } + HBListClose( &t->audioList ); + + if( t->file ) free( t->file ); + free( t->device ); + free( t ); + + *_t = NULL; +} + +HBAudio * HBAudioInit( int id, char * language ) +{ + HBAudio * a; + if( !( a = malloc( sizeof( HBAudio ) ) ) ) + { + HBLog( "HBAudioInit: malloc() failed, gonna crash" ); + return NULL; + } + + a->id = id; + a->language = strdup( language ); + a->inSampleRate = 0; + a->outSampleRate = 44100; + a->delay = 0; + a->ac3Fifo = NULL; + a->rawFifo = NULL; + a->mp3Fifo = NULL; + a->ac3Dec = NULL; + a->mp3Enc = NULL; + + return a; +} + +void HBAudioClose( HBAudio ** _a ) +{ + HBAudio * a = *_a; + + free( a->language ); + free( a ); + + *_a = NULL; +} + diff --git a/core/Utils.h b/core/Utils.h new file mode 100644 index 00000000..ba1a9101 --- /dev/null +++ b/core/Utils.h @@ -0,0 +1,213 @@ +/* $Id: Utils.h,v 1.6 2003/11/07 21:22:17 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_UTILS_H +#define HB_UTILS_H + +/* Standard headers */ +#include +#include +#include +#include +#include +typedef uint8_t byte_t; +#ifdef SYS_BEOS +# include +#endif + +/* Handy macros */ +#ifndef MIN +#define MIN( a, b ) ( ( (a) > (b) ) ? (b) : (a) ) +#endif +#ifndef MAX +#define MAX( a, b ) ( ( (a) > (b) ) ? (a) : (b) ) +#endif +#ifndef EVEN +#define EVEN( a ) ( ( (a) & 0x1 ) ? ( (a) + 1 ) : (a) ) +#endif +#ifndef MULTIPLE_16 +#define MULTIPLE_16( a ) ( 16 * ( ( (a) + 8 ) / 16 ) ) +#endif +#ifndef VOUT_ASPECT_FACTOR +#define VOUT_ASPECT_FACTOR 432000 +#endif + +typedef struct HBAc3Dec HBAc3Dec; +typedef struct HBAudio HBAudio; +typedef struct HBAviMux HBAviMux; +typedef struct HBBuffer HBBuffer; +typedef struct HBDVDRead HBDVDRead; +typedef struct HBFifo HBFifo; +typedef struct HBList HBList; +typedef struct HBLock HBLock; +typedef struct HBHandle HBHandle; +typedef struct HBMp3Enc HBMp3Enc; +typedef struct HBMpeg2Dec HBMpeg2Dec; +typedef struct HBFfmpegEnc HBFfmpegEnc; +typedef struct HBMadDec HBMadDec; +typedef struct HBScale HBScale; +typedef struct HBScan HBScan; +typedef struct HBStatus HBStatus; +typedef struct HBThread HBThread; +typedef struct HBTitle HBTitle; +typedef struct HBWork HBWork; +typedef struct HBWorkThread HBWorkThread; +typedef struct HBXvidEnc HBXvidEnc; + +/* Misc functions which may be used from anywhere */ +void HBSnooze( int time ); +void HBLog( char * log, ... ); +uint64_t HBGetDate(); +int HBPStoES( HBBuffer ** psBuffer, HBList * esBufferList ); + +/* HBList functions */ +HBList * HBListInit(); +int HBListCountItems( HBList * ); +void HBListAdd( HBList *, void * item ); +void HBListRemove( HBList *, void * item ); +void * HBListItemAt( HBList *, int index ); +void HBListClose( HBList ** ); + +/* HBTitle function */ +HBTitle * HBTitleInit(); +void HBTitleClose( HBTitle ** ); + +/* HBAudio functions */ +HBAudio * HBAudioInit( int id, char * language ); +void HBAudioClose( HBAudio ** ); + +/* Possible states */ +typedef enum +{ + HB_MODE_UNDEF = 00000, + HB_MODE_NEED_DEVICE = 00001, + HB_MODE_SCANNING = 00002, + HB_MODE_INVALID_DEVICE = 00004, + HB_MODE_READY_TO_RIP = 00010, + HB_MODE_ENCODING = 00020, + HB_MODE_PAUSED = 00040, + HB_MODE_STOPPING = 00100, + HB_MODE_DONE = 00200, + HB_MODE_CANCELED = 00400, + HB_MODE_ERROR = 01000, + HB_MODE_EXITING = 02000 +} HBMode; + +/* Possible errors */ +typedef enum +{ + HB_ERROR_A52_SYNC = 0, + HB_ERROR_AVI_WRITE, + HB_ERROR_DVD_OPEN, + HB_ERROR_DVD_READ, + HB_ERROR_MP3_INIT, + HB_ERROR_MP3_ENCODE, + HB_ERROR_MPEG4_INIT +} HBError; + +/* Possible codecs */ +typedef enum +{ + HB_CODEC_FFMPEG = 0, + HB_CODEC_XVID +} HBCodec; + +struct HBStatus +{ + HBMode mode; + + /* HB_MODE_SCANNING */ + int scannedTitle; + + /* HB_MODE_SCANDONE */ + HBList * titleList; + + /* HB_MODE_ENCODING || HB_MODE_PAUSED */ + float position; + int pass; + int passCount; + float frameRate; + float avFrameRate; + uint32_t remainingTime; /* in seconds */ + + /* HB_MODE_ERROR */ + HBError error; +}; + +struct HBTitle +{ + char * device; + int index; + int length; + char * file; + + /* Video input */ + int inWidth; + int inHeight; + int aspect; + int rate; + int rateBase; + + /* Video output */ + int outWidth; + int outHeight; + int outWidthMax; + int outHeightMax; + int topCrop; + int bottomCrop; + int leftCrop; + int rightCrop; + int deinterlace; + HBCodec codec; + int bitrate; + int twoPass; + + /* Audio infos */ + HBList * audioList; + + /* Fifos */ + HBFifo * mpeg2Fifo; + HBFifo * rawFifo; + HBFifo * scaledFifo; + HBFifo * mpeg4Fifo; + + /* Threads */ + HBDVDRead * dvdRead; + HBMpeg2Dec * mpeg2Dec; + HBScale * scale; + HBFfmpegEnc * ffmpegEnc; + HBXvidEnc * xvidEnc; + HBAviMux * aviMux; + HBWorkThread * workThreads[8]; +}; + +struct HBAudio +{ + /* Ident */ + uint32_t id; + char * language; + + /* Settings */ + int inSampleRate; + int outSampleRate; + int inBitrate; + int outBitrate; + + int delay; /* in ms */ + + /* Fifos */ + HBFifo * ac3Fifo; + HBFifo * rawFifo; + HBFifo * mp3Fifo; + + /* Threads */ + HBAc3Dec * ac3Dec; + HBMp3Enc * mp3Enc; +}; + + + +#endif diff --git a/core/Work.c b/core/Work.c new file mode 100644 index 00000000..b15e5083 --- /dev/null +++ b/core/Work.c @@ -0,0 +1,187 @@ +/* $Id: Work.c,v 1.4 2003/11/06 12:33:11 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "Thread.h" +#include "Work.h" + +/* Local prototypes */ +static void WorkThread( void * t ); + +struct HBWork +{ + HB_WORK_COMMON_MEMBERS +}; + +struct HBWorkThread +{ + HBHandle * handle; + + HBList * workList; + int firstThread; + + int die; + HBThread * thread; +}; + +HBWorkThread * HBWorkThreadInit( HBHandle * handle, HBTitle * title, + HBAudio * audio, HBAudio * optAudio, + int firstThread ) +{ + int i; + HBWork * w; + + HBWorkThread * t; + if( !( t = malloc( sizeof( HBWorkThread ) ) ) ) + { + HBLog( "HBWorkThreadInit: malloc() failed, gonna crash" ); + return NULL; + } + + t->handle = handle; + + /* Build a list of work objects. They all include + HB_WORK_COMMON_MEMBERS, so we'll be able to do the job without + knowing what each one actually do */ + t->workList = HBListInit(); + HBListAdd( t->workList, title->mpeg2Dec ); + HBListAdd( t->workList, title->scale ); + + if( title->codec == HB_CODEC_FFMPEG ) + HBListAdd( t->workList, title->ffmpegEnc ); + else if( title->codec == HB_CODEC_XVID ) + HBListAdd( t->workList, title->xvidEnc ); + + HBListAdd( t->workList, audio->ac3Dec ); + HBListAdd( t->workList, audio->mp3Enc ); + if( optAudio ) + { + HBListAdd( t->workList, optAudio->ac3Dec ); + HBListAdd( t->workList, optAudio->mp3Enc ); + } + + t->firstThread = firstThread; + + /* Work objects are not thread-safe, so let's init locks so each + one can not be called anymore when it's doing something. This + is done by the first worker thread (see HBStartRip) */ + if( t->firstThread ) + { + for( i = 0; i < HBListCountItems( t->workList ); i++ ) + { + w = (HBWork*) HBListItemAt( t->workList, i ); + w->lock = HBLockInit(); + w->used = 0; + w->time = 0; + } + } + + /* Actually launch the thread */ + t->die = 0; + t->thread = HBThreadInit( "work thread", WorkThread, t, + HB_LOW_PRIORITY ); + + return t; +} + +void HBWorkThreadClose( HBWorkThread ** _t ) +{ + HBWorkThread * t = (*_t); + HBWork * w; + + /* Stop the thread */ + t->die = 1; + HBThreadClose( &t->thread ); + + /* Destroy locks, show stats */ + if( t->firstThread ) + { + int i; + uint64_t total = 0; + + for( i = 0; i < HBListCountItems( t->workList ); i++ ) + { + w = (HBWork*) HBListItemAt( t->workList, i ); + HBLockClose( &w->lock ); + total += w->time; + } + + for( i = 0; i < HBListCountItems( t->workList ); i++ ) + { + w = (HBWork*) HBListItemAt( t->workList, i ); + HBLog( "HBWorkThreadClose: %- 9s = %05.2f %%", w->name, + 100.0 * w->time / total ); + } + + } + + /* Free memory */ + HBListClose( &t->workList ); + free( t ); + + (*_t) = NULL; +} + +static void WorkThread( void * _t ) +{ + HBWorkThread * t = (HBWorkThread*) _t; + HBWork * w; + int didSomething, i; + uint64_t date; + + for( ;; ) + { + HBCheckPaused( t->handle ); + + didSomething = 0; + + for( i = 0; i < HBListCountItems( t->workList ); i++ ) + { + if( t->die ) + { + break; + } + + w = (HBWork*) HBListItemAt( t->workList, i ); + + /* Check if another thread isn't using this work object. + If not, lock it */ + HBLockLock( w->lock ); + if( w->used ) + { + HBLockUnlock( w->lock ); + continue; + } + w->used = 1; + HBLockUnlock( w->lock ); + + /* Actually do the job */ + date = HBGetDate(); + if( w->work( w ) ) + { + w->time += HBGetDate() - date; + didSomething = 1; + } + + /* Unlock */ + HBLockLock( w->lock ); + w->used = 0; + HBLockUnlock( w->lock ); + } + + if( t->die ) + { + break; + } + + /* If nothing could be done, wait a bit to prevent a useless + CPU-consuming loop */ + if( !didSomething ) + { + HBSnooze( 10000 ); + } + } +} + diff --git a/core/Work.h b/core/Work.h new file mode 100644 index 00000000..8d3cfba1 --- /dev/null +++ b/core/Work.h @@ -0,0 +1,27 @@ +/* $Id: Work.h,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_WORK_H +#define HB_WORK_H + +#include "HandBrakeInternal.h" + +#define HB_WORK_COMMON_MEMBERS \ + char * name; \ + HBLock * lock; \ + int used; \ + uint64_t time; \ + int (*work) ( HBWork * ); + +void HBWorkLock( HBWork * ); +void HBWorkWork( HBWork * ); +void HBWorkUnlock( HBWork * ); + +HBWorkThread * HBWorkThreadInit( HBHandle *, HBTitle *, HBAudio *, + HBAudio *, int firstThread ); +void HBWorkThreadClose( HBWorkThread ** ); + +#endif diff --git a/core/Worker.cpp b/core/Worker.cpp deleted file mode 100644 index 4310e46f..00000000 --- a/core/Worker.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* $Id: Worker.cpp,v 1.11 2003/10/16 13:36:17 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include "Ac3Decoder.h" -#include "Mp3Encoder.h" -#include "Mpeg2Decoder.h" -#include "Mpeg4Encoder.h" -#include "MpegDemux.h" -#include "Resizer.h" -#include "Worker.h" - -HBWorker::HBWorker( HBTitle * title, HBAudio * audio1, - HBAudio * audio2 ) - : HBThread( "worker") -{ - fTitle = title; - fAudio1 = audio1; - fAudio2 = audio2; - - Run(); -} - -void HBWorker::DoWork() -{ - bool didSomething; - uint64_t mpegDemux = 0; - uint64_t mpeg2Decoder = 0; - uint64_t resizer = 0; - uint64_t mpeg4Encoder = 0; - uint64_t ac3Decoder1 = 0; - uint64_t mp3Encoder1 = 0; - uint64_t ac3Decoder2 = 0; - uint64_t mp3Encoder2 = 0; - uint64_t tmpDate; - - for( ;; ) - { - while( fSuspend ) - { - Snooze( 10000 ); - } - - didSomething = false; - - tmpDate = GetDate(); - if( fTitle->fMpegDemux->Work() ) - { - mpegDemux += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - - tmpDate = GetDate(); - if( fTitle->fMpeg2Decoder->Work() ) - { - mpeg2Decoder += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - - tmpDate = GetDate(); - if( fTitle->fResizer->Work() ) - { - resizer += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - - tmpDate = GetDate(); - if( fTitle->fMpeg4Encoder->Work() ) - { - mpeg4Encoder += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - - if( fAudio1 ) - { - tmpDate = GetDate(); - if( fAudio1->fAc3Decoder->Work() ) - { - ac3Decoder1 += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - - tmpDate = GetDate(); - if( fAudio1->fMp3Encoder->Work() ) - { - mp3Encoder1 += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - } - - if( fAudio2 ) - { - tmpDate = GetDate(); - if( fAudio2->fAc3Decoder->Work() ) - { - ac3Decoder2 += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - - tmpDate = GetDate(); - if( fAudio2->fMp3Encoder->Work() ) - { - mp3Encoder2 += ( GetDate() - tmpDate ); - didSomething = true; - } - - if( fDie ) break; - } - - if( !didSomething ) - { - Snooze( 10000 ); - } - } - - tmpDate = mpegDemux + mpeg2Decoder + resizer + mpeg4Encoder + - ac3Decoder1 + mp3Encoder1 + ac3Decoder2 + mp3Encoder2; - Log( "HBWorker stopped. CPU utilization:" ); - Log( "- MPEG demuxer: %.2f %%", 100.0 * mpegDemux / tmpDate ); - Log( "- MPEG-2 decoder: %.2f %%", 100.0 * mpeg2Decoder / tmpDate ); - Log( "- Resizer: %.2f %%", 100.0 * resizer / tmpDate ); - Log( "- MPEG-4 encoder: %.2f %%", 100.0 * mpeg4Encoder / tmpDate ); - if( fAudio1 ) - { - Log( "- AC3 decoder 1: %.2f %%", 100.0 * ac3Decoder1 / tmpDate ); - Log( "- MP3 encoder 1: %.2f %%", 100.0 * mp3Encoder1 / tmpDate ); - } - if( fAudio2 ) - { - Log( "- AC3 decoder 2: %.2f %%", 100.0 * ac3Decoder2 / tmpDate ); - Log( "- MP3 encoder 2: %.2f %%", 100.0 * mp3Encoder2 / tmpDate ); - } -} - diff --git a/core/Worker.h b/core/Worker.h deleted file mode 100644 index 5df8f648..00000000 --- a/core/Worker.h +++ /dev/null @@ -1,28 +0,0 @@ -/* $Id: Worker.h,v 1.3 2003/10/16 13:36:17 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#ifndef HB_WORKER_H -#define HB_WORKER_H - -#include "Common.h" -#include "Thread.h" - -class HBWorker : public HBThread -{ - public: - HBWorker( HBTitle * title, HBAudio * audio1, - HBAudio * audio2 ); - void WaitUntilDone(); - - private: - void DoWork(); - - HBTitle * fTitle; - HBAudio * fAudio1; - HBAudio * fAudio2; -}; - -#endif diff --git a/core/XvidEnc.c b/core/XvidEnc.c new file mode 100644 index 00000000..8f16ad4b --- /dev/null +++ b/core/XvidEnc.c @@ -0,0 +1,170 @@ +/* $Id: XvidEnc.c,v 1.5 2003/11/05 19:14:37 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include "XvidEnc.h" +#include "Fifo.h" +#include "Work.h" + +#include + +/* Local prototypes */ +static int XvidEncWork( HBWork * ); + +struct HBXvidEnc +{ + HB_WORK_COMMON_MEMBERS + + HBHandle * handle; + HBTitle * title; + + void * xvid; + HBBuffer * mpeg4Buffer; + int pass; +}; + +HBXvidEnc * HBXvidEncInit( HBHandle * handle, HBTitle * title ) +{ + HBXvidEnc * x; + if( !( x = malloc( sizeof( HBXvidEnc ) ) ) ) + { + HBLog( "HBXvidEncInit: malloc() failed, gonna crash" ); + return NULL; + } + + x->name = strdup( "XvidEnc" ); + x->work = XvidEncWork; + + x->handle = handle; + x->title = title; + + x->xvid = NULL; + x->mpeg4Buffer = NULL; + x->pass = 42; + + return x; +} + +void HBXvidEncClose( HBXvidEnc ** _x ) +{ + HBXvidEnc * x = *_x; + free( x ); + *_x = NULL; +} + +static int XvidEncWork( HBWork * w ) +{ + HBXvidEnc * x = (HBXvidEnc*) w; + HBTitle * title = x->title; + HBBuffer * scaledBuffer; + HBBuffer * mpeg4Buffer; + XVID_ENC_FRAME xframe; + + int didSomething = 0; + + if( x->mpeg4Buffer ) + { + if( HBFifoPush( title->mpeg4Fifo, &x->mpeg4Buffer ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + } + + if( ( scaledBuffer = HBFifoPop( title->scaledFifo ) ) ) + { + didSomething = 1; + } + else + { + return didSomething; + } + + /* Init or re-init if needed */ + if( scaledBuffer->pass != x->pass ) + { + XVID_INIT_PARAM xinit; + XVID_ENC_PARAM xparam; + + x->pass = scaledBuffer->pass;; + + HBLog( "HBXvidEnc: opening libxvidcore (pass %d)", x->pass ); + + xinit.cpu_flags = 0; + xvid_init( NULL, 0, &xinit, NULL ); + + xparam.width = title->outWidth; + xparam.height = title->outHeight; + + xparam.fincr = title->rateBase; + xparam.fbase = title->rate; + + xparam.rc_bitrate = title->bitrate * 1000; + + /* Default values should be ok */ + xparam.rc_reaction_delay_factor = -1; + xparam.rc_averaging_period = -1; + xparam.rc_buffer = -1; + xparam.max_quantizer = -1; + xparam.min_quantizer = -1; + xparam.max_key_interval = -1; + + if( xvid_encore( NULL, XVID_ENC_CREATE, &xparam, NULL ) ) + { + HBLog( "HBXvidEnc: xvid_encore() failed" ); + } + + x->xvid = xparam.handle; + } + + /* TODO implement 2-pass encoding */ + if( x->pass == 1 ) + { + HBPosition( x->handle, scaledBuffer->position ); + HBBufferClose( &scaledBuffer ); + return didSomething; + } + + mpeg4Buffer = HBBufferInit( title->outWidth * + title->outHeight * 3 / 2 ); + mpeg4Buffer->position = scaledBuffer->position; + + xframe.general = XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V; + xframe.motion = PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | + PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | + PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 | + PMV_USESQUARES16; + xframe.bitstream = mpeg4Buffer->data; + + xframe.image = scaledBuffer->data; + xframe.colorspace = XVID_CSP_I420; + + xframe.quant_intra_matrix = NULL; + xframe.quant_inter_matrix = NULL; + xframe.quant = 0; + xframe.intra = -1; + + xframe.hint.hintstream = NULL; + + if( xvid_encore( x->xvid, XVID_ENC_ENCODE, &xframe, NULL ) ) + { + HBLog( "HBXvidEnc: xvid_encore() failed" ); + } + + mpeg4Buffer->size = xframe.length; + mpeg4Buffer->keyFrame = xframe.intra; + + /* Inform the GUI about the current position */ + HBPosition( x->handle, scaledBuffer->position ); + + HBBufferClose( &scaledBuffer ); + x->mpeg4Buffer = mpeg4Buffer; + + return didSomething; +} + diff --git a/core/XvidEnc.h b/core/XvidEnc.h new file mode 100644 index 00000000..01cb6f4d --- /dev/null +++ b/core/XvidEnc.h @@ -0,0 +1,15 @@ +/* $Id: XvidEnc.h,v 1.1 2003/11/03 12:08:01 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#ifndef HB_XVID_ENC_H +#define HB_XVID_ENC_H + +#include "HandBrakeInternal.h" + +HBXvidEnc * HBXvidEncInit( HBHandle *, HBTitle * ); +void HBXvidEncClose( HBXvidEnc ** ); + +#endif diff --git a/macosx/Controller.h b/macosx/Controller.h index 4759a1d5..469994c6 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -1,12 +1,12 @@ -/* $Id: Controller.h,v 1.6 2003/10/13 23:09:56 titer Exp $ +/* $Id: Controller.h,v 1.4 2003/11/07 21:22:17 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include -#include "Common.h" +#include "HandBrake.h" #include "PictureGLView.h" #include "TargetSizeField.h" @@ -18,7 +18,6 @@ IBOutlet NSWindow * fWindow; /* Scan view */ - uint64_t fLastDVDDetection; IBOutlet NSView * fScanView; IBOutlet NSMatrix * fScanMatrix; IBOutlet NSPopUpButton * fDVDPopUp; @@ -63,7 +62,7 @@ /* "Done" alert panel */ IBOutlet NSPanel * fDonePanel; - /* Crop & resize panel */ + /* Crop & scale panel */ IBOutlet NSPanel * fPicturePanel; IBOutlet HBPictureGLView * fPictureGLView; IBOutlet NSTextField * fWidthField; @@ -78,9 +77,12 @@ IBOutlet NSTextField * fRightField; IBOutlet NSStepper * fRightStepper; IBOutlet NSTextField * fInfoField; + IBOutlet NSButton * fOpenGLCheck; + IBOutlet NSButton * fPreviousButton; + IBOutlet NSButton * fNextButton; int fPicture; - HBManager * fManager; + HBHandle * fHandle; HBList * fTitleList; } @@ -91,6 +93,7 @@ - (IBAction) Scan: (id) sender; - (IBAction) TitlePopUpChanged: (id) sender; +- (IBAction) VideoCodecPopUpChanged: (id) sender; - (IBAction) VideoMatrixChanged: (id) sender; - (IBAction) AudioPopUpChanged: (id) sender; - (IBAction) BrowseFile: (id) sender; @@ -111,6 +114,6 @@ - (IBAction) UpdatePicture: (id) sender; - (void) UpdateIntf: (NSTimer *) timer; -- (void) DetectDrives; +- (void) DetectDrives: (NSNotification *) notification; @end diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 402d721f..a345bdec 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -1,7 +1,7 @@ -/* $Id: Controller.mm,v 1.10 2003/10/13 23:09:56 titer Exp $ +/* $Id: Controller.mm,v 1.7 2003/11/07 21:22:17 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include @@ -11,20 +11,25 @@ #include #include "Controller.h" -#include "Manager.h" @implementation HBController - (void) applicationDidFinishLaunching: (NSNotification *) notification { /* Init libhb */ - fManager = new HBManager( true ); + fHandle = HBInit( 1, 0 ); + [fPictureGLView SetHandle: fHandle]; /* Update the GUI every 1/10 sec */ fDie = false; [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector( UpdateIntf: ) userInfo: nil repeats: YES]; + + /* Detect drives mounted after the app is started */ + [[[NSWorkspace sharedWorkspace] notificationCenter] + addObserver: self selector: @selector( DetectDrives: ) + name: NSWorkspaceDidMountNotification object: nil]; } - (NSApplicationTerminateReply) applicationShouldTerminate: @@ -32,7 +37,7 @@ { /* Clean up */ fDie = true; - delete fManager; + HBClose( &fHandle ); return NSTerminateNow; } @@ -42,6 +47,10 @@ [fDVDPopUp removeAllItems]; [fScanProgress setStyle: NSProgressIndicatorSpinningStyle]; [fScanProgress setDisplayedWhenStopped: NO]; + [fVideoCodecPopUp removeAllItems]; + [fVideoCodecPopUp addItemWithTitle: @"MPEG-4 (Ffmpeg)"]; + [fVideoCodecPopUp addItemWithTitle: @"MPEG-4 (XviD)"]; + [fVideoCodecPopUp selectItemWithTitle: @"MPEG-4 (Ffmpeg)"]; [fAudioBitratePopUp removeAllItems]; [fAudioBitratePopUp addItemWithTitle: @"32"]; [fAudioBitratePopUp addItemWithTitle: @"64"]; @@ -65,8 +74,7 @@ [fWindow center]; /* Detect DVD drives */ - fLastDVDDetection = GetDate(); - [self DetectDrives]; + [self DetectDrives: nil]; [self ScanMatrixChanged: self]; } @@ -139,76 +147,82 @@ - (IBAction) Scan: (id) sender { - /* Ask the manager to start scanning the specified volume */ + /* Ask libhb to start scanning the specified volume */ if( ![fScanMatrix selectedRow] ) { /* DVD drive */ - fManager->ScanVolumes( (char*) [[fDVDPopUp titleOfSelectedItem] - cString] ); + HBScanDevice( fHandle, + (char*) [[fDVDPopUp titleOfSelectedItem] cString], + 0 ); } else { /* DVD folder */ - fManager->ScanVolumes( (char*) [[fDVDFolderField stringValue] - cString] ); + HBScanDevice( fHandle, + (char*) [[fDVDFolderField stringValue] cString], + 0 ); } } - (IBAction) ShowPicturePanel: (id) sender { HBTitle * title = (HBTitle*) - fTitleList->ItemAt( [fTitlePopUp indexOfSelectedItem] ); + HBListItemAt( fTitleList, [fTitlePopUp indexOfSelectedItem] ); - [fPictureGLView SetManager: fManager]; [fPictureGLView SetTitle: title]; fPicture = 0; - [fPictureGLView ShowPicture: fPicture]; + [fPictureGLView ShowPicture: fPicture animate: HB_ANIMATE_NONE]; [fWidthStepper setValueWraps: NO]; [fWidthStepper setIncrement: 16]; [fWidthStepper setMinValue: 16]; - [fWidthStepper setMaxValue: title->fOutWidthMax]; - [fWidthStepper setIntValue: title->fOutWidth]; - [fWidthField setIntValue: title->fOutWidth]; - [fTopStepper setValueWraps: NO]; + [fWidthStepper setMaxValue: title->outWidthMax]; + [fWidthStepper setIntValue: title->outWidth]; + [fWidthField setIntValue: title->outWidth]; + [fDeinterlaceCheck setState: + title->deinterlace ? NSOnState : NSOffState]; + [fTopStepper setValueWraps: NO]; [fTopStepper setIncrement: 2]; [fTopStepper setMinValue: 0]; - [fTopStepper setMaxValue: title->fInHeight / 4]; - [fTopStepper setIntValue: title->fTopCrop]; - [fTopField setIntValue: title->fTopCrop]; + [fTopStepper setMaxValue: title->inHeight / 4]; + [fTopStepper setIntValue: title->topCrop]; + [fTopField setIntValue: title->topCrop]; [fBottomStepper setValueWraps: NO]; [fBottomStepper setIncrement: 2]; [fBottomStepper setMinValue: 0]; - [fBottomStepper setMaxValue: title->fInHeight / 4]; - [fBottomStepper setIntValue: title->fBottomCrop]; - [fBottomField setIntValue: title->fBottomCrop]; + [fBottomStepper setMaxValue: title->inHeight / 4]; + [fBottomStepper setIntValue: title->bottomCrop]; + [fBottomField setIntValue: title->bottomCrop]; [fLeftStepper setValueWraps: NO]; [fLeftStepper setIncrement: 2]; [fLeftStepper setMinValue: 0]; - [fLeftStepper setMaxValue: title->fInWidth / 4]; - [fLeftStepper setIntValue: title->fLeftCrop]; - [fLeftField setIntValue: title->fLeftCrop]; + [fLeftStepper setMaxValue: title->inWidth / 4]; + [fLeftStepper setIntValue: title->leftCrop]; + [fLeftField setIntValue: title->leftCrop]; [fRightStepper setValueWraps: NO]; [fRightStepper setIncrement: 2]; [fRightStepper setMinValue: 0]; - [fRightStepper setMaxValue: title->fInWidth / 4]; - [fRightStepper setIntValue: title->fRightCrop]; - [fRightField setIntValue: title->fRightCrop]; + [fRightStepper setMaxValue: title->inWidth / 4]; + [fRightStepper setIntValue: title->rightCrop]; + [fRightField setIntValue: title->rightCrop]; + + [fPreviousButton setEnabled: NO]; + [fNextButton setEnabled: YES]; char string[1024]; memset( string, 0, 1024 ); sprintf( string, "Final size: %dx%d", - title->fOutWidth, title->fOutHeight ); + title->outWidth, title->outHeight ); [fInfoField setStringValue: [NSString stringWithCString: string]]; /* Resize the panel */ NSSize newSize; /* XXX */ newSize.width = 762 /*fPicturePanelSize.width*/ + - title->fOutWidthMax - 720; + title->outWidthMax - 720; newSize.height = 740 /*fPicturePanelSize.height*/ + - title->fOutHeightMax - 576; + title->outHeightMax - 576; [fPicturePanel setContentSize: newSize]; [NSApp beginSheet: fPicturePanel modalForWindow: fWindow @@ -260,10 +274,10 @@ { fclose( file ); NSBeginCriticalAlertSheet( @"File already exists", - @"Nooo", @"Yes, go ahead!", nil, fWindow, self, + @"Nooo!", @"Yes, go ahead", nil, fWindow, self, @selector( OverwriteAlertDone:returnCode:contextInfo: ), nil, nil, - [NSString stringWithFormat: @"Do you want to overwrite %s ?", + [NSString stringWithFormat: @"Do you want to overwrite %s?", [[fFileField stringValue] cString]] ); return; } @@ -284,32 +298,36 @@ { /* Get the specified title & audio track(s) */ HBTitle * title = (HBTitle*) - fTitleList->ItemAt( [fTitlePopUp indexOfSelectedItem] ); + HBListItemAt( fTitleList, [fTitlePopUp indexOfSelectedItem] ); HBAudio * audio1 = (HBAudio*) - title->fAudioList->ItemAt( [fLanguagePopUp indexOfSelectedItem] ); + HBListItemAt( title->audioList, + [fLanguagePopUp indexOfSelectedItem] ); HBAudio * audio2 = (HBAudio*) - title->fAudioList->ItemAt( [fSecondaryLanguagePopUp - indexOfSelectedItem] ); + HBListItemAt( title->audioList, + [fSecondaryLanguagePopUp indexOfSelectedItem] ); /* Use user settings */ - title->fBitrate = [fCustomBitrateField intValue]; - title->fTwoPass = ( [fTwoPassCheck state] == NSOnState ); - audio1->fOutBitrate = [[fAudioBitratePopUp titleOfSelectedItem] + title->file = strdup( [[fFileField stringValue] cString] ); + title->bitrate = [fCustomBitrateField intValue]; + title->twoPass = ( [fTwoPassCheck state] == NSOnState ); + title->codec = ( [[fVideoCodecPopUp titleOfSelectedItem] compare: + @"MPEG-4 (Ffmpeg)"] == NSOrderedSame ) ? + HB_CODEC_FFMPEG : HB_CODEC_XVID; + audio1->outBitrate = [[fAudioBitratePopUp titleOfSelectedItem] intValue]; if( audio2 ) { - audio2->fOutBitrate = + audio2->outBitrate = [[fAudioBitratePopUp titleOfSelectedItem] intValue]; } /* Let libhb do the job */ - fManager->StartRip( title, audio1, audio2, - (char*) [[fFileField stringValue] cString] ); + HBStartRip( fHandle, title, audio1, audio2 ); } - (IBAction) Cancel: (id) sender { - fManager->StopRip(); + HBStopRip( fHandle ); } - (IBAction) Suspend: (id) sender @@ -320,50 +338,68 @@ return; } - fManager->SuspendRip(); + HBPauseRip( fHandle ); } - (IBAction) Resume: (id) sender { - fManager->ResumeRip(); + HBResumeRip( fHandle ); } - (IBAction) PreviousPicture: (id) sender { - if( fPicture > 0 ) + fPicture--; + if( [fOpenGLCheck state] == NSOnState ) { - fPicture--; - [fPictureGLView ShowPicture: fPicture]; + [fPictureGLView ShowPicture: fPicture + animate: HB_ANIMATE_LEFT]; } + else + { + [fPictureGLView ShowPicture: fPicture + animate: HB_ANIMATE_NONE]; + } + + [fPreviousButton setEnabled: ( fPicture > 0 )]; + [fNextButton setEnabled: YES]; } - (IBAction) NextPicture: (id) sender { - if( fPicture < 9 ) + fPicture++; + if( [fOpenGLCheck state] == NSOnState ) + { + [fPictureGLView ShowPicture: fPicture + animate: HB_ANIMATE_RIGHT]; + } + else { - fPicture++; - [fPictureGLView ShowPicture: fPicture]; + [fPictureGLView ShowPicture: fPicture + animate: HB_ANIMATE_NONE]; } + + [fPreviousButton setEnabled: YES]; + [fNextButton setEnabled: ( fPicture < 9 )]; } - (IBAction) UpdatePicture: (id) sender { HBTitle * title = (HBTitle*) - fTitleList->ItemAt( [fTitlePopUp indexOfSelectedItem] ); - title->fOutWidth = [fWidthStepper intValue]; - title->fDeinterlace = ( [fDeinterlaceCheck state] == NSOnState ); - title->fTopCrop = [fTopStepper intValue]; - title->fBottomCrop = [fBottomStepper intValue]; - title->fLeftCrop = [fLeftStepper intValue]; - title->fRightCrop = [fRightStepper intValue]; - - [fPictureGLView ShowPicture: fPicture]; - - [fWidthStepper setIntValue: title->fOutWidth]; - [fTopStepper setIntValue: title->fTopCrop]; - [fBottomStepper setIntValue: title->fBottomCrop]; - [fLeftStepper setIntValue: title->fLeftCrop]; - [fRightStepper setIntValue: title->fRightCrop]; + HBListItemAt( fTitleList, [fTitlePopUp indexOfSelectedItem] ); + title->outWidth = [fWidthStepper intValue]; + title->deinterlace = ( [fDeinterlaceCheck state] == NSOnState ); + title->topCrop = [fTopStepper intValue]; + title->bottomCrop = [fBottomStepper intValue]; + title->leftCrop = [fLeftStepper intValue]; + title->rightCrop = [fRightStepper intValue]; + + [fPictureGLView ShowPicture: fPicture animate: HB_ANIMATE_NONE]; + + [fWidthStepper setIntValue: title->outWidth]; + [fTopStepper setIntValue: title->topCrop]; + [fBottomStepper setIntValue: title->bottomCrop]; + [fLeftStepper setIntValue: title->leftCrop]; + [fRightStepper setIntValue: title->rightCrop]; [fWidthField setIntValue: [fWidthStepper intValue]]; [fTopField setIntValue: [fTopStepper intValue]]; [fBottomField setIntValue: [fBottomStepper intValue]]; @@ -372,7 +408,7 @@ char string[1024]; memset( string, 0, 1024 ); sprintf( string, "Final size: %dx%d", - title->fOutWidth, title->fOutHeight ); + title->outWidth, title->outHeight ); [fInfoField setStringValue: [NSString stringWithCString: string]]; } @@ -384,25 +420,19 @@ return; } - /* Update DVD popup */ - if( [fWindow contentView] == fScanView && - GetDate() > fLastDVDDetection + 2000000 ) - { - [self DetectDrives]; - fLastDVDDetection = GetDate(); - } - - /* Ask libhb about what's happening now */ - if( fManager->NeedUpdate() ) + int modeChanged; + HBStatus status; + + modeChanged = HBGetStatus( fHandle, &status ); + + switch( status.mode ) { - HBStatus status = fManager->GetStatus(); + case HB_MODE_NEED_DEVICE: + break; - switch( status.fMode ) + case HB_MODE_SCANNING: { - case HB_MODE_NEED_VOLUME: - break; - - case HB_MODE_SCANNING: + if( modeChanged ) { [fScanMatrix setEnabled: NO]; [fDVDPopUp setEnabled: NO]; @@ -410,81 +440,88 @@ [fScanBrowseButton setEnabled: NO]; [fScanProgress startAnimation: self]; [fScanButton setEnabled: NO]; - - char string[1024]; memset( string, 0, 1024 ); - if( status.fScannedTitle ) - { - sprintf( string, "Scanning %s, title %d...", - status.fScannedVolume, - status.fScannedTitle ); - } - else - { - sprintf( string, "Opening %s...", - status.fScannedVolume ); - } - [fScanStatusField setStringValue: - [NSString stringWithCString: string]]; - - break; } - case HB_MODE_INVALID_VOLUME: + char string[1024]; memset( string, 0, 1024 ); + if( status.scannedTitle ) + { + sprintf( string, "Scanning title %d...", + status.scannedTitle ); + } + else { - [fScanMatrix setEnabled: YES]; - [self ScanMatrixChanged: self]; - [fScanProgress stopAnimation: self]; - [fScanButton setEnabled: YES]; + sprintf( string, "Opening device..." ); + } + [fScanStatusField setStringValue: + [NSString stringWithCString: string]]; + + break; + } - [fScanStatusField setStringValue: - @"Invalid volume, try again" ]; + case HB_MODE_INVALID_DEVICE: + { + if( !modeChanged ) break; - } + + [fScanMatrix setEnabled: YES]; + [self ScanMatrixChanged: self]; + [fScanProgress stopAnimation: self]; + [fScanButton setEnabled: YES]; + + [fScanStatusField setStringValue: + @"Invalid volume, try again" ]; + break; + } - case HB_MODE_READY_TO_RIP: - { - fTitleList = status.fTitleList; - - /* Show a temporary empty view while the window - resizing animation */ - [fWindow setContentView: fTempView ]; - - /* Actually resize it */ - NSRect newFrame; - newFrame = [NSWindow contentRectForFrameRect: [fWindow frame] - styleMask: [fWindow styleMask]]; - newFrame.origin.y += newFrame.size.height - - [fRipView frame].size.height; - newFrame.size.height = [fRipView frame].size.height; - newFrame.size.width = [fRipView frame].size.width; - newFrame = [NSWindow frameRectForContentRect: newFrame - styleMask: [fWindow styleMask]]; - [fWindow setFrame: newFrame display: YES animate: YES]; - - /* Show the new GUI */ - [fWindow setContentView: fRipView ]; - [fSuspendButton setEnabled: NO]; - - [fTitlePopUp removeAllItems]; - HBTitle * title; - for( uint32_t i = 0; i < fTitleList->CountItems(); i++ ) - { - title = (HBTitle*) fTitleList->ItemAt( i ); - char string[1024]; memset( string, 0, 1024 ); - sprintf( string, "%d (%02lld:%02lld:%02lld)", - title->fIndex, title->fLength / 3600, - ( title->fLength % 3600 ) / 60, - title->fLength % 60 ); - [[fTitlePopUp menu] addItemWithTitle: - [NSString stringWithCString: string] - action: nil keyEquivalent: @""]; - } - [self TitlePopUpChanged: self]; - + case HB_MODE_READY_TO_RIP: + { + if( !modeChanged ) break; + + fTitleList = status.titleList; + + /* Show a temporary empty view while the window + resizing animation */ + [fWindow setContentView: fTempView ]; + + /* Actually resize it */ + NSRect newFrame; + newFrame = [NSWindow contentRectForFrameRect: [fWindow frame] + styleMask: [fWindow styleMask]]; + newFrame.origin.y += newFrame.size.height - + [fRipView frame].size.height; + newFrame.size.height = [fRipView frame].size.height; + newFrame.size.width = [fRipView frame].size.width; + newFrame = [NSWindow frameRectForContentRect: newFrame + styleMask: [fWindow styleMask]]; + [fWindow setFrame: newFrame display: YES animate: YES]; + + /* Show the new GUI */ + [fWindow setContentView: fRipView ]; + [fSuspendButton setEnabled: NO]; + + [fTitlePopUp removeAllItems]; + HBTitle * title; + for( int i = 0; i < HBListCountItems( fTitleList ); i++ ) + { + title = (HBTitle*) HBListItemAt( fTitleList, i ); + char string[1024]; memset( string, 0, 1024 ); + sprintf( string, "%d - %02dh%02dm%02ds", + title->index, title->length / 3600, + ( title->length % 3600 ) / 60, + title->length % 60 ); + [[fTitlePopUp menu] addItemWithTitle: + [NSString stringWithCString: string] + action: nil keyEquivalent: @""]; } + [self TitlePopUpChanged: self]; + + break; + } - case HB_MODE_ENCODING: + case HB_MODE_ENCODING: + { + if( modeChanged ) { [fTitlePopUp setEnabled: NO]; [fVideoCodecPopUp setEnabled: NO]; @@ -502,150 +539,161 @@ [fSuspendButton setEnabled: YES]; [fSuspendButton setTitle: @"Suspend"]; [fRipButton setTitle: @"Cancel"]; - - if( !status.fPosition ) - { - [fRipStatusField setStringValue: @"Starting..."]; - [fRipProgress setIndeterminate: YES]; - [fRipProgress startAnimation: self];; - } - else - { - char string[1024]; - memset( string, 0, 1024 ); - sprintf( string, "Encoding: %.2f %%", - 100 * status.fPosition ); - [fRipStatusField setStringValue: - [NSString stringWithCString: string]]; - memset( string, 0, 1024 ); - sprintf( string, - "Speed: %.2f fps (%02d:%02d:%02d remaining)", - status.fFrameRate, - status.fRemainingTime / 3600, - ( status.fRemainingTime % 3600 ) / 60, - status.fRemainingTime % 60 ); - [fRipInfoField setStringValue: - [NSString stringWithCString: string]]; - - [fRipProgress setIndeterminate: NO]; - [fRipProgress setDoubleValue: 100 * status.fPosition]; - } - - break; } - - case HB_MODE_SUSPENDED: + + if( !status.position ) { - char string[1024]; memset( string, 0, 1024 ); - sprintf( string, "Encoding: %.2f %% (PAUSED)", - 100 * status.fPosition ) ; + [fRipStatusField setStringValue: @"Starting..."]; + [fRipProgress setIndeterminate: YES]; + [fRipProgress startAnimation: self];; + } + else + { + char string[1024]; + memset( string, 0, 1024 ); + sprintf( string, "Encoding: %.2f %% (pass %d of %d)", + 100 * status.position, status.pass, + status.passCount ); [fRipStatusField setStringValue: [NSString stringWithCString: string]]; - [fRipInfoField setStringValue: @""]; - - [fRipProgress setDoubleValue: 100 * status.fPosition]; + memset( string, 0, 1024 ); + sprintf( string, "Speed: %.2f fps (avg %.2f fps, " + "%02dh%02dm%02ds remaining)", + status.frameRate, status.avFrameRate, + status.remainingTime / 3600, + ( status.remainingTime / 60 ) % 60, + status.remainingTime % 60 ); + [fRipInfoField setStringValue: + [NSString stringWithCString: string]]; - [fSuspendButton setTitle: @"Resume"]; - break; + [fRipProgress setIndeterminate: NO]; + [fRipProgress setDoubleValue: 100 * status.position]; } + + break; + } - case HB_MODE_STOPPING: - [fRipStatusField setStringValue: @"Stopping..."]; - [fRipInfoField setStringValue: @""]; - [fRipProgress setIndeterminate: YES]; - [fRipProgress startAnimation: self];; + case HB_MODE_PAUSED: + { + if( !modeChanged ) break; + + char string[1024]; memset( string, 0, 1024 ); + sprintf( string, "Encoding: %.2f %% (PAUSED)", + 100 * status.position ) ; + [fRipStatusField setStringValue: + [NSString stringWithCString: string]]; + [fRipInfoField setStringValue: @""]; + + [fRipProgress setDoubleValue: 100 * status.position]; - case HB_MODE_DONE: - case HB_MODE_CANCELED: - case HB_MODE_ERROR: - [fRipProgress setIndeterminate: NO]; - - if( status.fMode == HB_MODE_DONE ) - { - [fRipProgress setDoubleValue: 100]; - [fRipStatusField setStringValue: @"Done." ]; - NSBeep(); - [NSApp requestUserAttention: NSInformationalRequest]; - [NSApp beginSheet: fDonePanel - modalForWindow: fWindow modalDelegate: nil - didEndSelector: nil contextInfo: nil]; - [NSApp runModalForWindow: fDonePanel]; - [NSApp endSheet: fDonePanel]; - [fDonePanel orderOut: self]; - } - else if( status.fMode == HB_MODE_CANCELED ) - { - [fRipProgress setDoubleValue: 0]; - [fRipStatusField setStringValue: @"Canceled." ]; - } - else - { - [fRipProgress setDoubleValue: 0]; - switch( status.fError ) - { - case HB_ERROR_A52_SYNC: - [fRipStatusField setStringValue: - @"An error occured (corrupted AC3 data)." ]; - break; - case HB_ERROR_AVI_WRITE: - [fRipStatusField setStringValue: - @"An error occured (could not write to file)." ]; - break; - case HB_ERROR_DVD_OPEN: - [fRipStatusField setStringValue: - @"An error occured (could not open device)." ]; - break; - case HB_ERROR_DVD_READ: - [fRipStatusField setStringValue: - @"An error occured (DVD read failed)." ]; - break; - case HB_ERROR_MP3_INIT: - [fRipStatusField setStringValue: - @"An error occured (could not init MP3 encoder)." ]; - break; - case HB_ERROR_MP3_ENCODE: - [fRipStatusField setStringValue: - @"An error occured (MP3 encoder failed)." ]; - break; - case HB_ERROR_MPEG4_INIT: - [fRipStatusField setStringValue: - @"An error occured (could not init MPEG4 encoder)." ]; - break; - } - } + [fSuspendButton setTitle: @"Resume"]; + break; + } - [fRipInfoField setStringValue: @""]; - - [fTitlePopUp setEnabled: YES]; - [fVideoCodecPopUp setEnabled: YES]; - [fVideoMatrix setEnabled: YES]; - [fTwoPassCheck setEnabled: YES]; - [fCropButton setEnabled: YES]; - [fLanguagePopUp setEnabled: YES]; - [fSecondaryLanguagePopUp setEnabled: YES]; - [fAudioCodecPopUp setEnabled: YES]; - [fAudioBitratePopUp setEnabled: YES]; - [fFileFormatPopUp setEnabled: YES]; - [fFileBrowseButton setEnabled: YES]; - [fSuspendButton setEnabled: NO]; - [fSuspendButton setTitle: @"Suspend"]; - [fRipButton setTitle: @"Rip"]; + case HB_MODE_STOPPING: + if( !modeChanged ) + break; - [self VideoMatrixChanged: self]; + [fRipStatusField setStringValue: @"Stopping..."]; + [fRipInfoField setStringValue: @""]; + [fRipProgress setIndeterminate: YES]; + [fRipProgress startAnimation: self];; + break; - /* Warn the finder to update itself */ - [[NSWorkspace sharedWorkspace] noteFileSystemChanged: - [fFileField stringValue]]; + case HB_MODE_DONE: + case HB_MODE_CANCELED: + case HB_MODE_ERROR: + if( !modeChanged ) break; - default: - break; - } + /* Warn the finder to update itself */ + [[NSWorkspace sharedWorkspace] noteFileSystemChanged: + [fFileField stringValue]]; + + [fRipProgress setIndeterminate: NO]; + [fRipInfoField setStringValue: @""]; + + if( status.mode == HB_MODE_DONE ) + { + [fRipProgress setDoubleValue: 100]; + [fRipStatusField setStringValue: @"Done." ]; + NSBeep(); + [NSApp requestUserAttention: NSInformationalRequest]; + [NSApp beginSheet: fDonePanel + modalForWindow: fWindow modalDelegate: nil + didEndSelector: nil contextInfo: nil]; + [NSApp runModalForWindow: fDonePanel]; + [NSApp endSheet: fDonePanel]; + [fDonePanel orderOut: self]; + } + else if( status.mode == HB_MODE_CANCELED ) + { + [fRipProgress setDoubleValue: 0]; + [fRipStatusField setStringValue: @"Canceled." ]; + } + else + { + [fRipProgress setDoubleValue: 0]; + switch( status.error ) + { + case HB_ERROR_A52_SYNC: + [fRipStatusField setStringValue: + @"An error occured (corrupted AC3 data)." ]; + break; + case HB_ERROR_AVI_WRITE: + [fRipStatusField setStringValue: + @"An error occured (could not write to file)." ]; + break; + case HB_ERROR_DVD_OPEN: + [fRipStatusField setStringValue: + @"An error occured (could not open device)." ]; + break; + case HB_ERROR_DVD_READ: + [fRipStatusField setStringValue: + @"An error occured (DVD read failed)." ]; + break; + case HB_ERROR_MP3_INIT: + [fRipStatusField setStringValue: + @"An error occured (could not init MP3 encoder)." ]; + break; + case HB_ERROR_MP3_ENCODE: + [fRipStatusField setStringValue: + @"An error occured (MP3 encoder failed)." ]; + break; + case HB_ERROR_MPEG4_INIT: + [fRipStatusField setStringValue: + @"An error occured (could not init MPEG4 encoder)." ]; + break; + } + } + + [fTitlePopUp setEnabled: YES]; + [fVideoCodecPopUp setEnabled: YES]; + [fVideoMatrix setEnabled: YES]; + [fTwoPassCheck setEnabled: YES]; + [fCropButton setEnabled: YES]; + [fLanguagePopUp setEnabled: YES]; + [fSecondaryLanguagePopUp setEnabled: YES]; + [fAudioCodecPopUp setEnabled: YES]; + [fAudioBitratePopUp setEnabled: YES]; + [fFileFormatPopUp setEnabled: YES]; + [fFileBrowseButton setEnabled: YES]; + [fSuspendButton setEnabled: NO]; + [fSuspendButton setTitle: @"Suspend"]; + [fRipButton setTitle: @"Rip"]; + + [self VideoMatrixChanged: self]; + [self VideoCodecPopUpChanged: self]; + + break; + + default: + break; } } -- (void) DetectDrives +- (void) DetectDrives: (NSNotification *) notification { /* Scan DVD drives (stolen from VLC) */ io_object_t next_media; @@ -666,7 +714,7 @@ return; } - CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectable ), + CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ), kCFBooleanTrue ); kern_result = @@ -690,7 +738,7 @@ { str_bsd_path = IORegistryEntryCreateCFProperty( next_media, - CFSTR( kIOBSDName ), + CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, 0 ); if( str_bsd_path == NULL ) @@ -720,25 +768,6 @@ IOObjectRelease( media_iterator ); - /* Refresh only if a change occured */ - if( [drivesList count] == (unsigned) [fDVDPopUp numberOfItems] ) - { - bool isSame = true; - for( unsigned i = 0; i < [drivesList count]; i++ ) - { - if( ![[drivesList objectAtIndex: i] isEqualToString: - [fDVDPopUp itemTitleAtIndex: i]] ) - { - isSame = false; - break; - } - } - if( isSame ) - { - return; - } - } - [fDVDPopUp removeAllItems]; for( unsigned i = 0; i < [drivesList count]; i++ ) { @@ -770,29 +799,29 @@ - (IBAction) TitlePopUpChanged: (id) sender { HBTitle * title = (HBTitle*) - fTitleList->ItemAt( [fTitlePopUp indexOfSelectedItem] ); + HBListItemAt( fTitleList, [fTitlePopUp indexOfSelectedItem] ); [fLanguagePopUp removeAllItems]; [fSecondaryLanguagePopUp removeAllItems]; HBAudio * audio; - for( uint32_t i = 0; i < title->fAudioList->CountItems(); i++ ) + for( int i = 0; i < HBListCountItems( title->audioList ); i++ ) { - audio = (HBAudio*) title->fAudioList->ItemAt( i ); + audio = (HBAudio*) HBListItemAt( title->audioList, i ); /* We cannot use NSPopUpButton's addItemWithTitle because it checks for duplicate entries */ [[fLanguagePopUp menu] addItemWithTitle: - [NSString stringWithCString: audio->fDescription] + [NSString stringWithCString: audio->language] action: nil keyEquivalent: @""]; [[fSecondaryLanguagePopUp menu] addItemWithTitle: - [NSString stringWithCString: audio->fDescription] + [NSString stringWithCString: audio->language] action: nil keyEquivalent: @""]; } [fSecondaryLanguagePopUp addItemWithTitle: @"None"]; [fSecondaryLanguagePopUp selectItemWithTitle: @"None"]; [fSecondaryLanguagePopUp setEnabled: - ( title->fAudioList->CountItems() > 1 )]; + ( HBListCountItems( title->audioList ) > 1 )]; [fTargetSizeField SetHBTitle: title]; if( [fVideoMatrix selectedRow] ) @@ -801,6 +830,20 @@ } } +- (IBAction) VideoCodecPopUpChanged: (id) sender +{ + if( [[fVideoCodecPopUp titleOfSelectedItem] + compare: @"MPEG-4 (Ffmpeg)"] == NSOrderedSame ) + { + [fTwoPassCheck setEnabled: YES]; + } + else + { + [fTwoPassCheck setState: NSOffState]; + [fTwoPassCheck setEnabled: NO]; + } +} + - (IBAction) AudioPopUpChanged: (id) sender { if( [fVideoMatrix selectedRow] ) diff --git a/macosx/English.lproj/InfoPlist.strings b/macosx/English.lproj/InfoPlist.strings index 7690c78efb44815c72a5986e36f3f82cc4859b98..9a0f313a756154c1fa217278a835402628e60e5d 100644 GIT binary patch delta 20 ccmeys{DOJHRYuc^ec}^8S}~eVHefse09<+qCIA2c delta 28 gcmaFC{DFDGRaO%QJqE*xec}_}T0z*8H5d;70FBlN-T(jq diff --git a/macosx/English.lproj/MainMenu.nib/classes.nib b/macosx/English.lproj/MainMenu.nib/classes.nib index 38429950..c9539b9d 100644 --- a/macosx/English.lproj/MainMenu.nib/classes.nib +++ b/macosx/English.lproj/MainMenu.nib/classes.nib @@ -18,6 +18,7 @@ Suspend = id; TitlePopUpChanged = id; UpdatePicture = id; + VideoCodecPopUpChanged = id; VideoMatrixChanged = id; }; CLASS = HBController; @@ -40,8 +41,11 @@ fLanguagePopUp = NSPopUpButton; fLeftField = NSTextField; fLeftStepper = NSStepper; + fNextButton = NSButton; + fOpenGLCheck = NSButton; fPictureGLView = HBPictureGLView; fPicturePanel = NSPanel; + fPreviousButton = NSButton; fRightField = NSTextField; fRightStepper = NSStepper; fRipButton = NSButton; diff --git a/macosx/English.lproj/MainMenu.nib/info.nib b/macosx/English.lproj/MainMenu.nib/info.nib index af41a142..96ab6e7c 100644 --- a/macosx/English.lproj/MainMenu.nib/info.nib +++ b/macosx/English.lproj/MainMenu.nib/info.nib @@ -3,31 +3,31 @@ IBDocumentLocation - 29 16 381 380 0 0 1440 878 + 25 188 381 380 0 0 1440 878 IBEditorPositions 29 407 469 205 44 0 0 1440 878 556 - 510 480 420 244 0 0 1440 878 + 510 481 420 244 0 0 1440 878 583 - 648 516 144 171 0 0 1440 878 + 648 517 144 171 0 0 1440 878 589 510 282 420 586 0 0 1440 878 IBFramework Version - 291.0 + 349.0 IBOpenObjects - 583 - 21 - 589 - 365 + 556 434 29 - 556 + 589 + 21 + 583 + 365 IBSystem Version - 6R73 + 7B85 diff --git a/macosx/English.lproj/MainMenu.nib/objects.nib b/macosx/English.lproj/MainMenu.nib/objects.nib index 9fe32351051b07b9098ed0dd4e4dfcb8a4d0f46b..1e6996ef496e2cce6cadd8859f16eca6ebdd0902 100644 GIT binary patch literal 18217 zcmbVU4|G(;xu3a7Amo3DP(@l-L~RhLK|~r6LV}T42$3Zs)=HP%yU9Yb8+SJ(TCH!w z?zUE2>k79JQBa?MDcD+6dS2E3u^z2`r?h=~s`UzoLp{&upHq7DRa>9D-#2sb-g|d9 z0ZNa#_kJ_;&G&!4`DV7ImB||i^iU!h*8}~cpS!zk;xIR&{9`OeACd3fQ()Dp)*pcNuB<-STq@r^);qa6FU7@NAw}Q zq1S3XF%XM}^f=o}v{a#^q(%0)H=Ej>O^>ovRSW)wt$&JSi?pTjc;H5sN=*bU@^$Md z&+f{k(`m+T7EGwW*|hqfk=nk)nm&`-vBN!oCNnxRhcUK0_28&Rq@b~*KhUESCDV3h zca5^$z^Z7p<)SAsby=t1j~7U!qbv)oXOK{IU)QpB-#{Rd)HlQe@sN*{lcDA>bn4fv z@vZ4-Z})AUKlj3-eVSyS%cH@-Kw_{jkkmuIu2>@J55^+{N#EwCx$}w+o6_lTkM!x$ zK);^olGCoSXPssd)zP-5U})wGb6Q#$YiY^uQesM#MuNc>#=%@p3~hR!r966D3L}X` zMi~E$u~aE(2VLuIj!FW(_+-iVfs74BsBwn*T5Dm4)1Do`@kzh2DAw{K1B9RCr z5AzA~Om?(DdH0`;@}zds^`~81&)Bu~HYblLCSb}rb0qQ?OG{fCB)g^W`u&fOl!BL$ za>!v1(b?6f2NJq(C=f}`ojW%J?qE0Vu;D3NM`xzWzIxGu;MXRA=xO-xv*T<98)QKi zVIdY^SFkw#M)9sgI6PdvkL~05uMCVqYR&MvbapgV5`@r!7vgD)^~K--`zEAHNRm5t zOz__b!|5l9RRxvf$Ud3WFZY$Cv~YOKl39=M;Tig#@XW8!t$`tbkMN(ZLR27uqiAb6|`>g8g>9UauC zr8$CrJ9cm%5y>(mtd6mfTaO<<&eN%nNOaK!hTX|sjCX=+AnnlDiG>iR6tZR7OL6U&TI;iN(O?~*zhbnYEdL9 z&!!G#4`!mZTnPrg`%dTGLOGc7? zdUNJ=o3gi`V!wD1`u%Adq2VLE z{|X-~NmgUSJsS!7!e+OyQv041S;f<8zST|76opd`YAw zGIAN5<$VT&^wPTS)M!2S>+vWoV!9umfWp5Kg)d6#K9bbARI|Pjs%acwH51xmAwB3) z%O`HNNK086z!EyVcxO&U)s2GPK8qA|`z*JD(y7VkARI=To11C5QyO`eF^wZqqH}F& z)yT3hBCg0)>QB%ng)K%l4&_Wyi>GfxBpHWW`M$Vm!$6|Zv6oMOE!azEu#x49uCkR2 zyKU(7D@&GP+Al+Q2|~k;9WeXVflwr-n&H4u9p;pw(w?(!O(5Q*Cw+;?O_*?HtD25e zkn>E((^@){`2|I=1Dt1`w-HIg%j7hf=WWAIOC5vIg;yO&F*w{|u# z*4f~eU<#hI^@h)uj@X`4+H~Q(`Hl=Kp5nQv*^orIYz+iA^~7U?(U1z96P>6!iP{zP zC5ofc&t&jv>kA|j{-MCYfF7Sk8PhosSN-x7vBk&NTz zh>+8hQ=gmP< zl?PZi*@C7C9uh1I*OAZc5fwCL<7t8? z1n(8>VQQvl_ONPBO$>)yT7tnKT*nHn%J8m^g!Gup@SbATFJ_LGXbeFi`&NGVo}t1w z^1OSpGwtx**oqj@T9cirrYah~t0*z^g=6vlK++W{&T~hKKj%;)fS=>W)mYz&*#~HnacCGq1{JdLkK#stuA8-K3Gtw2TaU6&dwTL}!TXWG(q9{8p*bDQAzI`X zrwrs>@mNn>Pb4~`A=;P4kO#bZFYu2bjldj;_Q(Lc{AxX_-wKCsniu{WXULQBk8`ea zRXBILp-1qI2m|!jCMH!D42D8*B4oGH`EAMtzp!exkFnK0yQ`!-Cwh#a1*&XyWWaZ} z<8G}U$s?Vt&ZM8W;z|xR`$N_BKz;rAs3-ad69alQ^Pa3}ho$aI!PuoWS#zAQG-*X3+B1k956t(bY~cT4x0#o3P5o2{4)%pV0=tjvZ1c5WmsaSIF{pW3s&P z)L34Bsw{7?!!R~d#rXcZ!*?*B@AIwP)U67S-NNAta?_qMSv~vISlxK4toGZimaOc$ zs3^0W9A=}$>>D0?u3H5)uNq&?wXL4a*Jaglhi~#bnMTCO=Rz?o^Rhmau{;NsUQt{Y zuV#ue{j#-tcm**roq5He?cgEW6ry%TJHOMZjx{_wG8s`&#(8-C_k{Kbp|yen`OFS0 z8mM4WyS%k45=;)p^($7;4qTQ2P_sjHvj8&m0^!*1o3yp`^b!@;k>yF4&Q^mV;TQSeSUgHfvVs;bd{-*>RCKuLbRE$EUq^b)=_v4D8#+ z#-3bg?W^(#PhIs{i`oS`3%Fq0-MOPzz{&1YK{PrxBEc^`B~&}dMRiK--RDMiC}%%* z{YkLhR+Q5;z5*HFiY!1@{G-4q*c%JVx)>|#vJE&t5h+2DD?bep?14%qw@gD+2}8Z# zpVVn@jN+Kvgavz{s{x+g;PrG_V6#S0Igg=u$ErW`p>T(PstPCAL#at2{G;*+>cyAx zkrsG2{mY^cY`%PIsrKpNFwWgP z%hiFx1%$kgbD{l1Xh(@&dMbxRGBG+b0|uzd$D65V)dfO3Qbzrbl-b0bjE8Pk{+V-r zp}mDIAN|b^S?)h%+%#+;K+>N(hg~(_@|A%|l*;XN6o9(SZxAz{mo?u>x$_)%LdVjm z{ibRXgB$uW$SLQeppPQ5V7~$yRKN+%3ldH3(hae}q|b#+oh3*_X<3A)(xVzM@^eV! zpetD}+KVdE<$gWBITF+p1;o9k3j0*j-tOuKx)4l|fvu-AJvCPHO*zY{&R(+|r6m_n zz{`7G2PI>YT`3330~j2>Sfft2j#tJURqpSN4f&S#^%XGtuM4o|s=W3eF9 zR0vL^Zl+OjsLV{kQ1cyn_GIit zA)eey=i4MZUoz%vkK@FxfI?e{GUTmrqzA5Zgs!*MBPtDDhg>y+h9_XFnl7M%~c!eK*gGuQNWU+x0O>puuDQ$=S77*c8sO$oTqDYL8!6!(C zP9&&2Nd`gTaS5_UOrjA!xuYT`dQN6cwH%Y%CegUi$&90g%crD<6LBh2`xF;Ipq~ta z23$>uDfh{tk;>gT)@T$1teC2lR_-4_;zuU}`6_m#EBG0?n82q=xmMc4Y}q!CHKEdm z8dW0?rG55TN$I60GjN)Bpf8Z{t&0u%&ZhmP;B%~$;M_Ta z)8z^JOJJ20jGHp?FL_fY2N~X~*C5YdGd&NLoifQ&c?uhpD!F#pyvehlhy9@YQnRkJ2`Z)s#CCbKe*2H}=!cvZ&}X_O&1@`x5*D z!g1OaDAV3d7bdGjCC&{kfVk4 zOZG8vcWvqE;~WCZn*yPDWV5@dEBIwnu%5GDI##uhVRL85m2}Y{9P7iKEVT`gN4a_9 z1z)O;b0_{w=eU9|$$-0A$^vb^_45V$P@V#P*x==zj_it^0}0;l-c!8k5+WRHVmB@!kGJAx zPQKYD6|%khtq|Tfngj&qhsKbpT>wWu49g@MO|FRZ4n8 zL)mUo65YoS2=*!pr`hyAmf2>sABGV;zYY377w%#l{}i7e(b91kF!nN8$A%!@o}fLO zNh{1E8nJuW2(C9i{K&Y4;2+a~#+i6~1!I6~9auH$j{n$ZK#UBc&Y|J=p?7APYKN6PcM)aG7c!39qqZN7yA|D>@ z63E1`@%}sbtd;9FpCEXtar6iP7l1mWo556>NP?abFDaCG;fDsC(pIvoJOckD(Xsz?NHYJ^q3G zlQG^P37!RqqjPWu+xCcy|Ji3?&$Ywz7RKd6jAIiRg zWxMK|yJwm)w!!@6y^r%z5gLj@d+2s2y5U+?uG_pOf<6bR>uM%}jsXO6?75q$AD^No z$pNY3)A<-L${4QzHc8%CToFkmGsZ@I<36VA4x_?1vjE>}K-^N0)6M~~9Jh#~af2b#ak-9N(DSxy4EReFUIO3E=K9 zAQKUI6*U{Y?NAcpAz&UU1G)$>H)pcrZUCWAl(g{~#D|-l5Ap4q89iVFi~cUOnpN zvj8bHGOELX0Gr9C3rW~Z6wpyS0m(O^6_;p{a{!jJNKo@WeY>0!tDYKVoP#sUVK z36?RAst@It2;%O~ZhRDwEH4EC>R33$F%>;MPPP*Ow_s^v_L#!wj0DMKdM;xFE-bcr zgC(#;0c}p22*|bp=+^%{X@&O#T28sP#TC1w7{bW_=Fg1#Q@sX-PPY^n5IWmoh`v(q z$V)N?1?8OS4yg}#ANX6354edtjAQ8q5Ss!wQ2E7KXmHWAFk_esnd0Pae7L0w{H*}F ziDUZ#@TfDe+DM)XNhm z`2nBfYs3&s1DbOzNa!tmD>s+?M(|l>9lu#iCvp}5T`W^FP@s6EG5~v}exXCwSFeNAtBiWNfUn7+gHZyb z=0C>JkBE)Z;2^H+=2-hD!6wLGb-AF&2wE0L3Ely6XdP@OWF;DtI4$f0*&Wx-UESHo z5*S1c-Ra4v6RkPW%V|K5`~eTNuhl;T zuu2gohOI3i&0sf>rB{bNrtUOTGF@XgI`^EEO{LX*b#`gn!r`#Xgz8a61#?fUH95Nt z`0K;2`#n+$j&5&L2x__qLSV>)LYnpd6SO~cg7(Kw(7xvc?R&>=w^@|Y8iL0OzIB;G zvS&9xCMB%y2Ni3l3%XTdy5Li+l|pKDSl-Yn*8C8fE5o?fRIG8k#H?mkzl(76j-4`E zE9AU|ZIowKDwYZxDSTHdk_sCs1D-?#6*ke1sUqAF4af4@0!qeSvxfF>QSeH6eJ*y%EI_6A!R%$DwO_u`O=ww0>&TYnAf|M&~ zrEF5msayLpWtG*LEKOHJ*v?3*VPcr-1*^%Ak7RV{EH9JFAmxr;PjjK*p? z-oBsi8A~ZzoouFG0}dt}0?6~IDnPQBOgt;b+Inei3AqJBX&TgR=V^{uC_S1SUP_mz zt;?bL0-()to$4Wf$(7$u`DkUBN+t!YQ7Y09R%wQX-60+ttA9gi8!TGtsdII>Xg5mi zJ{Qj2QMPYo=Tkz-V||!@N-~BXXvOBJ;g(d;6$)lyr&T9qxY7h1ogCo;mCuyu*QK+yGQtqbS>y2=^-4%!iZ==YKN zoKZ?t9bPjO!;y2s3Hpi#O04R_@<%{Lbx-MOm1=kS6wDI0_N7reQ+kXNJw8=E8YJ=} zc8e}kRhN3Yy5U|HbAe#JHH$P~$yoj@Z=A5l0@b5ZnG6|E4n3-x#6-Cz^&A}KG=i5x zb#5P{x=T6fQ*Iy};a>?jEe!)jLTZny5mbfMov3{ItL(ToY%lBuidXy6$}p|#u0{y& zm?Cm&p7JaK$=^MXQi`m#M1;0hXljV_T(FrTPHZFUPSY~C-lD@<&A1>1$@sL*c5<8%1k8G!$b3W_;jXx{{A zozRxyfkV}Y@wi85kC>kb?Hatd3H}UFJ|Q@!)6zoQZeA(0hs`sE_I2|n!DDDN8_Y7H zeHA!opwtThvV(1S(0LGm=L&7U`KZu3fM7sqcbL}*O$WSPXqNzVhTtRUJSzAd0HXZA z-JC77o6z!Apx!?x?#PRfA44op_J$SU@C)a5E z76fO)X*ZdTLK`+Q*%ouE(AJ{|YTG}-;~#?U!00;!{}%ekh4wvsp|XCLxmoZmI$*7Q z3N2>}z6C8vxl;K0n$X(uz>-H2-zBui(X&(VC-GP!vP?a;7!SZFH& z!a>Rb6B2_4cwh?t;2`0Lct8Vl%o#!(#OPlxG_Mm{#5_-EL*`MTtpbkCLi;|NwhK-c zg;IJ3gQf{aeB;PxH-G`5k-Ts!^SJpTY}%|B+VyBgYG{~f*nt1OBDBl!_%7}}niY^O zkksNl1ifAp%)kRxc$x?K@;6PG?*KaE*LOe1V_0Z+q5H)`YsS|~p)JPaY{7S%!-7Mm z8l;y-hbEz2imyuqhj92`&&Rta81%2*2|EIA95a#q9r+xZrwjHUCUm+S%{K`xYrYJ% z;C+?QmYA!76MZg&F#>ds;P+z~_7>m4moBu7`4Jom?_U-iBGhVdbr2npiIbJxCpgSY zdr)XUG`De}(KUSDCA9m@<3hX6d{1b8KykdX506Mb>7WbM%f)mSs z!!N4=!m-3optxCRcjIvtj!@0TLKApDSMUeScL2kC4?F>nO9h9E(3uMyQ@cfITTQg| z;j^gkP&40NLP}tyXjHnar@8&B)OW@s)xP+E3 zfopu7FZhGz0-@b%!kglNLsyRg9>JjwkYH1>64gnal`p@AfZeg19u+9tH! zCRBC{-eJ4|;s2$D_nYtIVk_QpdIYcIVEudMTQD*6h|oIGwE-mK0ple%#CaV&PD2E2 z1?J~JkM~Bw5jWV2WGg@duVGILz8#O9f`1o4oSgm0d|PN;co#w=+rvQ+QT+g}VE~92 z`V<~NfS&<~Lq?dB)+aP*ALnV>Ts+Pa>{)XroCEL6g|-m=-Y&yCKo{X1M}P1VZHnM= qbCJ;g&HPko*FwH~N4Zhokj3`6t^=oM!C0U@j{j4Xp&0$YQ2al)pFvvy literal 17820 zcmb_k4Rl<^b)I?pv80t`$ua~JLpBKn8^;FA*eJ4M^kW+vWLbD^3-rIV3hzbN?^oww?`UfUH|+rED54UtfK zWiTBS>@8id=n5zZ%j8s(j=@wq(XW8>M|7=~y3XthtQ$-RxAsK>>0~V4!(~tFeMILA zYPte#0|R}rP%s@!#Iu>K&SQezW1w$!S3u#sG8Wl6U)RgK0@j&O_->EF+djSVkkj6JA7G^P;?K)SX+*b|{K z&eZivjGl<6lZn3h_vdzxu?I7mj3UZrD3S)&vaUb?FJNUYu#S$N))iPC>x;yL{gG7n z)=vqX4FEEWT^kZy=)Ep9hP zhSIBJk-qSpM{Nc(^|P<3XY87Ko6N@)g;1l@nrK@gwbK?Nol&{|smF&)LFjM=n0$hW z=*PwO#FBJ1nXpjEW~0g%!2Gv zmc(xy?-6j$qcwZj9*+M?!3jjt42#R;_Ua`eNECR%dq<)#0YlhRu9uLQMn}s7H>T2& zeiBD@NNG{F$?8AfQ=)6p=_4;!zct2?C(Zk zKVX$%yozg_cUZ4M_1d-6rnNaH+m)^g$I?U~%MP@ULJyue{=BrYORa zjzP&cADSAUq_iV3aHFI&G=1Z;?jWp8w%##)>++S6z6hF6PjFQLEkkL4TVJ0<9-JEa zrR3EHVfYuM0&L~UCa|M2(#J8Wycq9QwE9yaJWcuz6fe?IqpFf?*BauVjFj-$LPA)U8 z2n@jSVM&`pqD;<6NRmrQ`s^;YG@BCrzG#Wl}QZ@~)btagea zXkL)oRwv=vC(vd)6p~c!mac%JE+ri#_yg1jsN*xUlG;jV&76QQKR?a@hn1w6IkL~p zwylZ5wBOa!cButkXwIkLPob;`M3OsVp-5^9Dj@NEGf;#z9o`!(*?lce6`|8hR*hV{ zCKiskcp+ciJC)K@H=pdbKHVEhs(DL&&T!V234)O8RiHPqQ~I{a4DlpMzhW@vRs)f~ zeKOKXSk({~#hejKQio}^MU30g7fhuBJA(rQk>vRlzp>({hz3?_Rb=>Tk5MoZa! zIsJZGjS>2_Cx*_)`}ZjXr9iSGw=Ab$oNH1g1cdkJn(Z2WU#>-kks05n<+Y40ug$fn z2tr0#&sZT8YgHjsWoIznGl+n+IjcW6cFw*}6D|GBXT?ekamO>#v#;3C4!(d8<{+)H zx{i3eJ29|npnWi%PQ(#O$bejx*rN`Gg1vr)V7Hyl5bWG`x`$3(ulL}f_)lnyr3gu) z6tGAb8<$a{!cCA%_CG$Xw^5X+fyGRlO=7!VnM%cEtkNp@J(u(0^5NDKFm%{9{h+0R zX=klbRnpujN{7ikgjoJ^I4wCNx!*l+cn0RD*KZjhc8REbu(B$bL3mRVYmE(m6){97 z%R)9T^{hxiJ*lbH(-4RtWDEzBH~RY=ML8^WyQSXY7HiWaVqINaHi5&ZAd$^eNaQ70 z#YW=)Zzbtpw z^9+Y2!yc7Xog9t5r$S?&O=A%wB?@DC3i}IHQnwx|SwFQ(X12%DNd)KqdE2%Qq~^PH zvpugH+KgzL;Nb-3HGXr=%Kyk+%51^@Rq$THZl_9m=9*NsJ|h}!Z4HG&*p68nJ-Nv% zYa0y564?WpOtz&&W8k3B`R!2757Fel+>q`3=C^~L_S)Q#!d}$*RnsP#V!Hld+QrLF zd0ujQhl3K{>WeNNx)Dz@t!_CL9b)HaYq6y5%C$u;?VEW$3N~zM(qX;!Q?OpynNZ0P z7vF+q-JIuzxxQMk7aPb+zt~VHP<{LHwqd!Nyy8q$!S3A8olS2;8c}+CFtn{FnHY?R zUHe|{-Wyj^GgbL3cuKXDtjtTFpEhIlT*g+<^-!?JP6;%t^{l)-nb?_%`p7Y1g~qxypsm`rgnZ_ze&c{o3T{WuZ_wjERcu31;I;hjzg)tlr>fY=hr!Dk*oA z)TESDwjnm)|2$1;n}r8FIznt!gQXKndYR&pN!4TLY(OWitu8v)c=h$54F+JS$eUk|6A@X9?Q9?R=UC2O$Y3JoNxr?RAJ5;n@s z@!V3vFkA4HbfAwB4mi@sY(ff+uIx%g-O7P3RpzD;VVAKlx77BRLrvhPsW!KC3V&I( z^2(L|bS&M6Xwfyt1!~!i$P}cENt`Ciex)x7+0Uwpf9aTbdrD!){_i z;3U|u-71p7xSIPb9(B}JGheW~&WADK*KGwEebyI|*NrtdH&fzU1SaUjc1lt z53igDM<+AfnCd#EXc-0Hpyf1`T=#GF1P*TNIV2|>8(!0Lh2x&36H_6*%s2;R7P?ZWIb@{XL21(!Co-?7ZgRF@eE|{q$s~A1dl%Nrt_HUtb?9ltSuMdy>Ea6; zFLH}wd_RXk1-si?{u;@r*{T=pof$i@0PdLUL29#JVJ(1l9m&Li|4V+P?!i3efLt^6 zNHOO&VmVKHpqkq4NZf9(D>{rV;hBvK2e6U#N8+JGnDSGuQC^p$XiB56WOVHRNO3sK z3G9reL%lNp<3x#q<;a7D@x;DXCa$xVQ-U1ND=x=p+;S|r_`(bG<2QPRxYTHbvk zd1@o)p^1!+|I|=GD`tH0`1ljAkyF_}9_$|Xn2r^`&+zZr4l~nE7Ry}{yG7P%RJ80$~Y+t`=X6YGIczPKegp;uy-r(RZNs!0AOMg4j zY5OR;h$i}Q+^WJ0%U^pi2wwL8;IDZ}7LqlNj2mx^8}E!8Z~{o8S?RUUkdF}DH#R&= zPBKgw>{{;@+PKi#Aw2n{21*z~(wluuXqh+^)fE^L#?m_ySF-Y@tgOtj%l)PW#vpr*2 z88Q`S7Y_0D{`DAQ{d7ZAIEOE;Va}Llm~$L)u|K500iX5___U(pvX`cYm62FH9ZB{D zLlOUgQj5#G^0{(EXL-WbNV-<610*?Ty!y@Eh={vu3q~spwrVzFxy2#RzyMZ3cUa6n z=Ux~lU~dirdvH4Jb?pgcQ2UDy@P(-c!1Ug1WpupaDrBIxGZIY~AK=_+258<49yU+M z!^{n_p594Dm^al3=_YIOpTK~A#qrh&Ne8~5(5V&*J-zAV5H2i0D0o$l;suYL2)_Iz z>Aau-EpqvJlyZ%QGZK8UwHj&~@5H9OlR%coCTA|#KP@ZkW~{86daDZW@_XNC362ib zn#-5?n4LS5gMESKRerE#&R|0OXG9eA3%qtfMgvwa5Zci)sybTssfKK_hm`kR0_g~y zc_96tXBJq&$KP}}zN`9zgmlP#qqw;fkI2h4xIJdQ!pMN zLzewOl*IS&=b%!g|8to=EDNPxMoPsxj*Y1C9_jl-=+<}*Zyeb_pHayHyOY$vii&|2 z$q*t~sb(zkPMX z<~?tklwi*AO6mn<3#_Spp3gZhJyizKlF-envmyF&iMXSBB%1DL1KrcaKpSwr6x98btkI2kq+Xq| z2p^$#(R48lcL*>@Mx~e0rd{=Ou}pN#R;?6sXtf(<S8WyybqXn9`G{&a)yQdaFksNy%)s-Zg!{^YO);jHXlaO zExHnvUF0q!VG^uBW?0k#1P^(KLY(m)YHCH-DpD}61qhzUF-)nkCIDw3ps@^%y{fR~ z)gtA2iGt?GkShELP&di%q73qEcenUL((`cuUG_z?b+H9cM_$bffp-VYO==@Kht1xG za>jn>g-K$s2CP8vaM%DkCev7~#j^mqxxq38h>J4mIJODiXWUfKUkrwk9k#K+qUh!EZ9pmlp5z>3cv~|Aja%9s}t`YYIvJM zlAjq;?3(~}8T~G-4f1Nxc`5(;opHoRn4wG1Ca)S!s69+b2SroLg$Qv80GJsrqQUH8 z;Lm?g0o?P@%FR9I51O3-)IC4t2oHEh$jRLt+%~pg4~<<#S1<8tP*-fL72Dwv#~pvV z|M6RSby8I+SpCR>x(rBZKvstCK+#?5Aad9^Hf*Lmui*c7U^X?F8N?S&@t(-qxV#MQ zR4yVxRUy;bPgh#7lkO*{rw$%IjL0rzjEvmfQ1wVFRm*Csb zp@KT}$Zu<)U9Ii_z-q~#5w-Scgx{{9HK``*S(Mz>6uH#e)%jBnvKqM=qY>-ujK77& zVOH*7sYNv%J9ujC;pd{ZKI+QlODWj8lv`RtP`ha$43<17Bnj9(Pg#$x?3DG`yi8e- z{mGQ|*o;k9Z?h<40f-*SG%L?3*|V!@8Ly416M$m%}lM|W$UwkuU~+=+D*|M?V46Dujs^C^-hR?>o8Nd!%-B4=9_T^o-k z3hIJN#$Lmg+DFQQr0(XNa-tF}v&a&`2{Dz!km^)Cb4$|y#W%ZI1x6QG<)RjcKBX@OX_sW`4) zB387j2+@Os7ArM&k;?Z_StI+~cL_axDGIEU)%3C6U@A`lNuRx?WHF0)R*ZG@(h3rG z3x+o2P`JG#&x@rO6|PVI0X$=n0LiwF^alssw=8z+7->D+Cnue+YSh=FRwRb-6SE_ zt;z|4r#QYYTKJ)hyFYCy;gslxVIhwy0Ii8`+?l`!k*WM*V9zoNwd$hsuHz&&aR@D{ zRSVZ_lLoujGT8jk9)p!_4yiT`a)=^UEgKzCjq2(1BlptjIEsKZk~DA0WZ_7?)3!kR zLACKIV>Kf~i3!5>B)E@fPY z(lWuHG#iC>z4@A8d(arE-M<9+EJ~pJPL$v#-#2HMneXFP6^dB! zM^JgA&~m{0me4LhX^qfY%-`Xf72XGh28waKqFsd2g@XUs+>I7^KU47Af#H7z`zcEB z9(R~8;{p>J-z&7+Og{u<-XgRiv{^6s&&r*E1Y)303JV{X7g!U~wW(f960Fl(Z8|aaHUxE@6-4Hd7Aovf>CZVk}PYCuLs`m>m zfX8tlL@OL0+-KIDfrc~D(>#2ZiIadIn!W}=e1iQ7E#DE^S5WE_+9l{v0xt3RkMqno zaa;iSl|t(<=Lz;*6DJJ6K-GKaq7yDM--^cvLTdyFan~rCejBG~CXOzi#QTWQet-ws zJ!sw}w4Hcw7M!&7U%2&$(l>zE@~hm~RLM zJnU(qb)$_>@VE&%{K&jqXc08MMrfEA{vEVQf%`Y$uj!dW)}kli!pxL}W)ALDGxJSNyf zfZ~WIgHAZfyAP!eLTkgAM}@W!K%8Je+jPVML2EmO_Fa@BnhDG4!&~q){QQq#Kfwc8 z@@LTTh|sp6=~kfusrD_QL8@9eCITLJ2o3hGT`#oD&32(h%|Ak>=<|TkhVl3{EYe&d zw2%qr`pp(#LF-|m-D^G~w6%D@87jr23p zLjO;McCooYFf^c}9}J-3Ha^imDl}m>Tx){Om}7b~PII;HExGzlVy_JWDPgwSq60~|e3-PwX?O<2SLK$zq(evY}i&pa3Qg~kUl#{fd~ ziUv4-)0)j?n2shSnKI{m1ywK^VAa|MKVagE$TZ&JF;}4VORz?iRttU*k1q=jgJyTa sui){n(3YEL<7+F(`Nw12XuK$gooL-!90G+B!PQCpk3@DR=>Ny?f2NoU0{{R3 diff --git a/macosx/HandBrake.pbproj/project.pbxproj b/macosx/HandBrake.pbproj/project.pbxproj index 2cc6e105..8c918d28 100644 --- a/macosx/HandBrake.pbproj/project.pbxproj +++ b/macosx/HandBrake.pbproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 38; + objectVersion = 39; objects = { 080E96DCFE201CFB7F000001 = { fileRef = 29B97318FDCFA39411CA2CEA; @@ -23,6 +23,7 @@ isa = PBXGroup; name = Classes; refType = 4; + sourceTree = ""; }; 089C165CFE840E0CC02AAC07 = { children = ( @@ -31,13 +32,16 @@ isa = PBXVariantGroup; name = InfoPlist.strings; refType = 4; + sourceTree = ""; }; 089C165DFE840E0CC02AAC07 = { + expectedFileType = text.plist.strings; fileEncoding = 10; isa = PBXFileReference; name = English; path = English.lproj/InfoPlist.strings; refType = 4; + sourceTree = ""; }; 089C165EFE840E0CC02AAC07 = { fileRef = 089C165CFE840E0CC02AAC07; @@ -64,12 +68,16 @@ isa = PBXGroup; name = "Linked Frameworks"; refType = 4; + sourceTree = ""; }; 1058C7A1FEA54F0111CA2CBB = { + expectedFileType = wrapper.framework; + fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; refType = 0; + sourceTree = ""; }; 1058C7A2FEA54F0111CA2CBB = { children = ( @@ -79,6 +87,7 @@ isa = PBXGroup; name = "Other Frameworks"; refType = 4; + sourceTree = ""; }; 1058C7A3FEA54F0111CA2CBB = { fileRef = 1058C7A1FEA54F0111CA2CBB; @@ -97,9 +106,12 @@ //173 //174 17587328FF379C6511CA2CBB = { + expectedFileType = wrapper.application; + fallbackIsa = PBXFileReference; isa = PBXApplicationReference; path = HandBrake.app; refType = 3; + sourceTree = BUILT_PRODUCTS_DIR; }; //170 //171 @@ -118,6 +130,7 @@ isa = PBXGroup; name = Products; refType = 4; + sourceTree = ""; }; //190 //191 @@ -130,6 +143,10 @@ //293 //294 29B97313FDCFA39411CA2CEA = { + buildSettings = { + MACOSX_DEPLOYMENT_TARGET = 10.2; + SDKROOT = /Developer/SDKs/MacOSX10.2.7.sdk; + }; buildStyles = ( 4A9504CCFFE6A4B311CA0CBA, 4A9504CDFFE6A4B311CA0CBA, @@ -154,23 +171,26 @@ name = HandBrake; path = ""; refType = 4; + sourceTree = ""; }; 29B97315FDCFA39411CA2CEA = { children = ( 29B97316FDCFA39411CA2CEA, - 4D358C040534AB8100D654EB, - 4D929FEB0527903D00A80101, + 4DFDC318054AC84C00151618, ); isa = PBXGroup; name = "Other Sources"; path = ""; refType = 4; + sourceTree = ""; }; 29B97316FDCFA39411CA2CEA = { + expectedFileType = sourcecode.cpp.objcpp; fileEncoding = 30; isa = PBXFileReference; path = main.mm; refType = 4; + sourceTree = ""; }; 29B97317FDCFA39411CA2CEA = { children = ( @@ -183,6 +203,7 @@ 4D69F5CC0527944A00A80101, 4D69F5CD0527944A00A80101, 4D69F5CE0527944A00A80101, + 4DDEF3B905474DCC002904DE, 4D118405053054CD00C39CA9, 089C165CFE840E0CC02AAC07, ); @@ -190,6 +211,7 @@ name = Resources; path = ""; refType = 4; + sourceTree = ""; }; 29B97318FDCFA39411CA2CEA = { children = ( @@ -199,12 +221,15 @@ name = MainMenu.nib; path = ""; refType = 4; + sourceTree = ""; }; 29B97319FDCFA39411CA2CEA = { + expectedFileType = wrapper.nib; isa = PBXFileReference; name = English; path = English.lproj/MainMenu.nib; refType = 4; + sourceTree = ""; }; 29B97323FDCFA39411CA2CEA = { children = ( @@ -215,18 +240,25 @@ name = Frameworks; path = ""; refType = 4; + sourceTree = ""; }; 29B97324FDCFA39411CA2CEA = { + expectedFileType = wrapper.framework; + fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; refType = 0; + sourceTree = ""; }; 29B97325FDCFA39411CA2CEA = { + expectedFileType = wrapper.framework; + fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; refType = 0; + sourceTree = ""; }; 29B97326FDCFA39411CA2CEA = { buildPhases = ( @@ -263,7 +295,7 @@ CFBundleExecutable HandBrake CFBundleGetInfoString - HandBrake 0.4.1 - By Eric Petit <titer@m0k.org> + HandBrake 0.5 - By Eric Petit <titer@m0k.org> CFBundleIconFile HandBrake.icns CFBundleIdentifier @@ -275,11 +307,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.4.1 + 0.5 CFBundleSignature HB## CFBundleVersion - 0.4.1 + 0.5 NSMainNibFile MainMenu NSPrincipalClass @@ -291,11 +323,10 @@ 29B97327FDCFA39411CA2CEA = { buildActionMask = 2147483647; files = ( - 4D929FEC0527903D00A80101, 4D6615EA05288C2300A80101, 4D857591052B78E300C39CA9, 4D358C020534A91300D654EB, - 4D358C050534AB8100D654EB, + 4DFDC319054AC84C00151618, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -343,6 +374,7 @@ 4D69F5D50527944A00A80101, 4DEB2025052B055F00C39CA9, 4DDE9725052B7B2B00C39CA9, + 4DDEF3BA05474DCC002904DE, ); isa = PBXFrameworksBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -362,7 +394,12 @@ ); buildSettings = { COPY_PHASE_STRIP = NO; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_OPTIMIZATION_LEVEL = 0; OPTIMIZATION_CFLAGS = "-O0"; + ZERO_LINK = YES; }; isa = PBXBuildStyle; name = Development; @@ -372,6 +409,8 @@ ); buildSettings = { COPY_PHASE_STRIP = YES; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + ZERO_LINK = NO; }; isa = PBXBuildStyle; name = Deployment; @@ -387,9 +426,11 @@ //4D3 //4D4 4D118405053054CD00C39CA9 = { + expectedFileType = image.icns; isa = PBXFileReference; path = HandBrake.icns; refType = 4; + sourceTree = ""; }; 4D118406053054CD00C39CA9 = { fileRef = 4D118405053054CD00C39CA9; @@ -398,16 +439,20 @@ }; }; 4D358C000534A91300D654EB = { + expectedFileType = sourcecode.c.h; fileEncoding = 30; isa = PBXFileReference; path = TargetSizeField.h; refType = 4; + sourceTree = ""; }; 4D358C010534A91300D654EB = { + expectedFileType = sourcecode.cpp.objcpp; fileEncoding = 30; isa = PBXFileReference; path = TargetSizeField.mm; refType = 4; + sourceTree = ""; }; 4D358C020534A91300D654EB = { fileRef = 4D358C000534A91300D654EB; @@ -421,19 +466,6 @@ settings = { }; }; - 4D358C040534AB8100D654EB = { - fileEncoding = 30; - isa = PBXFileReference; - name = Common.h; - path = /Users/titer/HandBrake/core/Common.h; - refType = 0; - }; - 4D358C050534AB8100D654EB = { - fileRef = 4D358C040534AB8100D654EB; - isa = PBXBuildFile; - settings = { - }; - }; 4D6615EA05288C2300A80101 = { fileRef = 4DF3C8CB052889CD00A80101; isa = PBXBuildFile; @@ -441,46 +473,60 @@ }; }; 4D69F5C80527944A00A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = liba52.a; path = /usr/local/lib/liba52.a; refType = 0; + sourceTree = ""; }; 4D69F5C90527944A00A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = libavcodec.a; path = /usr/local/lib/libavcodec.a; refType = 0; + sourceTree = ""; }; 4D69F5CA0527944A00A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = libdvdcss.a; path = /usr/local/lib/libdvdcss.a; refType = 0; + sourceTree = ""; }; 4D69F5CB0527944A00A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = libdvdplay.a; path = /usr/local/lib/libdvdplay.a; refType = 0; + sourceTree = ""; }; 4D69F5CC0527944A00A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = libdvdread.a; path = /usr/local/lib/libdvdread.a; refType = 0; + sourceTree = ""; }; 4D69F5CD0527944A00A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = libmp3lame.a; path = /usr/local/lib/libmp3lame.a; refType = 0; + sourceTree = ""; }; 4D69F5CE0527944A00A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = libmpeg2.a; path = /usr/local/lib/libmpeg2.a; refType = 0; + sourceTree = ""; }; 4D69F5CF0527944A00A80101 = { fileRef = 4D69F5C80527944A00A80101; @@ -525,16 +571,20 @@ }; }; 4D85758E052B78E300C39CA9 = { + expectedFileType = sourcecode.cpp.objcpp; fileEncoding = 30; isa = PBXFileReference; path = PictureGLView.mm; refType = 4; + sourceTree = ""; }; 4D85758F052B78E300C39CA9 = { + expectedFileType = sourcecode.c.h; fileEncoding = 30; isa = PBXFileReference; path = PictureGLView.h; refType = 4; + sourceTree = ""; }; 4D857590052B78E300C39CA9 = { fileRef = 4D85758E052B78E300C39CA9; @@ -548,24 +598,13 @@ settings = { }; }; - 4D929FEB0527903D00A80101 = { - fileEncoding = 30; - isa = PBXFileReference; - name = Manager.h; - path = ../core/Manager.h; - refType = 4; - }; - 4D929FEC0527903D00A80101 = { - fileRef = 4D929FEB0527903D00A80101; - isa = PBXBuildFile; - settings = { - }; - }; 4D929FED0527907200A80101 = { + expectedFileType = archive.ar; isa = PBXFileReference; name = libhb.a; path = ../core/libhb.a; refType = 4; + sourceTree = ""; }; 4D929FEE0527907200A80101 = { fileRef = 4D929FED0527907200A80101; @@ -574,10 +613,13 @@ }; }; 4DDE9724052B7B2B00C39CA9 = { + expectedFileType = wrapper.framework; + fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; refType = 0; + sourceTree = ""; }; 4DDE9725052B7B2B00C39CA9 = { fileRef = 4DDE9724052B7B2B00C39CA9; @@ -585,11 +627,28 @@ settings = { }; }; + 4DDEF3B905474DCC002904DE = { + expectedFileType = archive.ar; + isa = PBXFileReference; + name = libxvidcore.a; + path = /usr/local/lib/libxvidcore.a; + refType = 0; + sourceTree = ""; + }; + 4DDEF3BA05474DCC002904DE = { + fileRef = 4DDEF3B905474DCC002904DE; + isa = PBXBuildFile; + settings = { + }; + }; 4DEB2024052B055F00C39CA9 = { + expectedFileType = wrapper.framework; + fallbackIsa = PBXFileReference; isa = PBXFrameworkReference; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; refType = 0; + sourceTree = ""; }; 4DEB2025052B055F00C39CA9 = { fileRef = 4DEB2024052B055F00C39CA9; @@ -598,16 +657,20 @@ }; }; 4DF3C8CB052889CD00A80101 = { + expectedFileType = sourcecode.c.h; fileEncoding = 30; isa = PBXFileReference; path = Controller.h; refType = 4; + sourceTree = ""; }; 4DF3C8CC052889CD00A80101 = { + expectedFileType = sourcecode.cpp.objcpp; fileEncoding = 30; isa = PBXFileReference; path = Controller.mm; refType = 4; + sourceTree = ""; }; 4DF3C8CE052889CD00A80101 = { fileRef = 4DF3C8CC052889CD00A80101; @@ -615,6 +678,21 @@ settings = { }; }; + 4DFDC318054AC84C00151618 = { + expectedFileType = sourcecode.c.h; + fileEncoding = 30; + isa = PBXFileReference; + name = HandBrake.h; + path = ../core/HandBrake.h; + refType = 4; + sourceTree = ""; + }; + 4DFDC319054AC84C00151618 = { + fileRef = 4DFDC318054AC84C00151618; + isa = PBXBuildFile; + settings = { + }; + }; }; rootObject = 29B97313FDCFA39411CA2CEA; } diff --git a/macosx/PictureGLView.h b/macosx/PictureGLView.h index 06e5a16e..c558c3c0 100644 --- a/macosx/PictureGLView.h +++ b/macosx/PictureGLView.h @@ -1,20 +1,34 @@ -/* PictureGLView */ +/* $Id: PictureGLView.h,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ #include -#include "Manager.h" +#include "HandBrake.h" + +#define HB_ANIMATE_NONE 0 +#define HB_ANIMATE_LEFT 1 +#define HB_ANIMATE_RIGHT 2 @interface HBPictureGLView : NSOpenGLView { - HBManager * fManager; + HBHandle * fHandle; HBTitle * fTitle; uint8_t * fPicture; + uint8_t * fOldPicture; } -- (void) SetManager: (HBManager*) manager; +- (id) initWithFrame: (NSRect) frame; +- (void) reshape; +- (void) drawRect: (NSRect) rect; +- (void) drawAnimation: (int) how; + +- (void) SetHandle: (HBHandle*) handle; - (void) SetTitle: (HBTitle*) title; -- (void) ShowPicture: (int) picture; +- (void) ShowPicture: (int) index animate: (int) how; @end diff --git a/macosx/PictureGLView.mm b/macosx/PictureGLView.mm index 79103f6b..8df19907 100644 --- a/macosx/PictureGLView.mm +++ b/macosx/PictureGLView.mm @@ -1,68 +1,153 @@ +/* $Id: PictureGLView.mm,v 1.3 2003/11/03 22:01:13 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + #include +#include #include "PictureGLView.h" +#define PROUT 2.5 + +/* XXX This file needs some serious cleaning XXX */ + +GLuint texture[2]; +float rotation; +float translation; +uint8_t * truc; + @implementation HBPictureGLView -- (void) SetManager: (HBManager*) manager +- (void) SetHandle: (HBHandle*) handle { - fManager = manager; + fHandle = handle; } - (void) SetTitle: (HBTitle*) title { fTitle = title; - + /* This is needed as the view's size may have changed */ [self clearGLContext]; [self openGLContext]; } -- (void) ShowPicture: (int) index +- (void) ShowPicture: (int) index animate: (int) how { + if( fOldPicture ) free( fOldPicture ); + fOldPicture = fPicture; + /* Get the picture */ - uint8_t * tmp = fManager->GetPreview( fTitle, index ); + uint8_t * tmp = HBGetPreview( fHandle, fTitle, index ); /* Make it be upside-down */ - if( fPicture ) free( fPicture ); - fPicture = (uint8_t*) malloc( 4 * ( fTitle->fOutWidthMax + 2 ) * - ( fTitle->fOutHeightMax + 2 ) ); - for( uint32_t i = 0; i < fTitle->fOutHeightMax + 2; i++ ) + fPicture = (uint8_t*) malloc( 4 * ( fTitle->outWidthMax + 2 ) * + ( fTitle->outHeightMax + 2 ) ); + uint8_t * in = tmp; + uint8_t * out = fPicture + + 4 * ( fTitle->outWidthMax + 2 ) * ( fTitle->outHeightMax + 1 ); + for( int i = 0; i < fTitle->outHeightMax + 2; i++ ) { - memcpy( fPicture + 4 * ( fTitle->fOutWidthMax + 2 ) * i, - tmp + 4 * ( fTitle->fOutWidthMax + 2 ) * - ( fTitle->fOutHeightMax + 1 - i ), - 4 * ( fTitle->fOutWidthMax + 2 ) ); + memcpy( out, in, 4 * ( fTitle->outWidthMax + 2 ) ); + in += 4 * ( fTitle->outWidthMax + 2 ); + out -= 4 * ( fTitle->outWidthMax + 2 ); } free( tmp ); - /* Grrr - should find a way to give ARGB to OpenGL */ - uint8_t r, g, b, a; - for( uint32_t i = 0; i < fTitle->fOutHeightMax + 2; i++ ) + /* ARGB -> RGBA */ + uint32_t * p = (uint32_t*) fPicture; + for( int i = 0; + i < ( fTitle->outHeightMax + 2 ) * ( fTitle->outWidthMax + 2 ); + i++ ) + { + *(p++) = ( ( (*p) & 0xff000000 ) >> 24 ) | + ( ( (*p) & 0x00ff0000 ) << 8 ) | + ( ( (*p) & 0x0000ff00 ) << 8 ) | + ( ( (*p) & 0x000000ff ) << 8 ); + } + + if( how == HB_ANIMATE_NONE ) + { + [self drawRect: [self bounds]]; + return; + } + + in = fOldPicture; + out = truc; + for( int i = 0; i < fTitle->outHeightMax + 2; i++ ) + { + memcpy( out, in, ( fTitle->outWidthMax + 2 ) * 4 ); + in += ( fTitle->outWidthMax + 2 ) * 4; + out += 1024 * 4; + } + glBindTexture( GL_TEXTURE_2D, texture[0] ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 1024, + 1024, 0, GL_RGBA, + GL_UNSIGNED_BYTE, truc ); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + + in = fPicture; + out = truc; + for( int i = 0; i < fTitle->outHeightMax + 2; i++ ) { - for( uint32_t j = 0; j < fTitle->fOutWidthMax + 2; j++ ) + memcpy( out, in, ( fTitle->outWidthMax + 2 ) * 4 ); + in += ( fTitle->outWidthMax + 2 ) * 4; + out += 1024 * 4; + } + glBindTexture( GL_TEXTURE_2D, texture[1] ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 1024, + 1024, 0, GL_RGBA, + GL_UNSIGNED_BYTE, truc ); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + + glEnable( GL_TEXTURE_2D ); + glShadeModel( GL_SMOOTH ); + glClearColor( 0.0f, 0.0f, 0.0f, 0.5f ); + glClearDepth( 1.0f ); + glEnable( GL_DEPTH_TEST ); + glDepthFunc( GL_LEQUAL ); + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + +#define ANIMATION_TIME 500000 + + rotation = 0.0; + float w = ( how == HB_ANIMATE_LEFT ) ? 1.0 : -1.0; + uint64_t date; + int64_t wait; + for( ;; ) + { + date = HBGetDate(); + translation = - PROUT - cos( rotation * M_PI / 180 ) * + ( 1 + w * tan( rotation * M_PI / 180 ) ); + + [self drawAnimation: how]; + + rotation += w; + if( w * rotation >= 90.0 ) + { + break; + } + + wait = ANIMATION_TIME / 90 - ( HBGetDate() - date ); + if( wait > 0 ) { - a = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)]; - r = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+1]; - g = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+2]; - b = fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+3]; - - fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)] = r; - fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+1] = g; - fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+2] = b; - fPicture[4*(i*(fTitle->fOutWidthMax+2)+j)+3] = a; + HBSnooze( wait ); } } - [self setNeedsDisplay: YES]; + [self drawRect: [self bounds]]; } -/* Override NSView's initWithFrame: to specify our pixel format */ - (id) initWithFrame: (NSRect) frame { - fManager = NULL; - fTitle = NULL; - fPicture = NULL; + fHandle = NULL; + fTitle = NULL; + fPicture = NULL; + fOldPicture = NULL; GLuint attribs[] = { @@ -81,34 +166,109 @@ NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*) attribs]; - if( !fmt ) + self = [super initWithFrame:frame pixelFormat: [fmt autorelease]]; + + if( !self ) { - fprintf( stderr, "Sarass\n" ); + return NULL; } - return self = [super initWithFrame:frame pixelFormat: - [fmt autorelease]]; + [[self openGLContext] makeCurrentContext]; + [self reshape]; + + glGenTextures( 2, texture ); + truc = (uint8_t*) malloc( 1024*1024*4 ); + + return self; +} + +/* + * Resize ourself + */ +- (void) reshape +{ + NSRect bounds; + + [[self openGLContext] update]; + bounds = [self bounds]; + glViewport( 0, 0, (GLsizei) bounds.size.width, + (GLsizei) bounds.size.height ); +} + +- (void) drawAnimation: (int) how +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, PROUT, 20.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, translation ); + glRotatef( rotation, 0.0, 1.0, 0.0 ); + + glEnable( GL_POLYGON_SMOOTH ); + glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); + + glBindTexture( GL_TEXTURE_2D, texture[0] ); + + glBegin( GL_QUADS ); + glTexCoord2f( 0.0, 0.0 ); + glVertex3f( -1.0, -1.0, 1.0 ); + glTexCoord2f( ( 2.0 + fTitle->outWidthMax ) / 1024, 0.0 ); + glVertex3f( 1.0, -1.0, 1.0 ); + glTexCoord2f( ( 2.0 + fTitle->outWidthMax ) / 1024, + ( 2.0 + fTitle->outHeightMax ) / 1024 ); + glVertex3f( 1.0, 1.0, 1.0 ); + glTexCoord2f( 0.0, ( 2.0 + fTitle->outHeightMax ) / 1024 ); + glVertex3f( -1.0, 1.0, 1.0 ); + glEnd(); + + glBindTexture( GL_TEXTURE_2D, texture[1] ); + + glBegin( GL_QUADS ); + if( how == HB_ANIMATE_RIGHT ) + { + glTexCoord2f( 0.0, 0.0 ); + glVertex3f( 1.0, -1.0, 1.0 ); + glTexCoord2f( ( 2.0 + fTitle->outWidthMax ) / 1024, 0.0 ); + glVertex3f( 1.0, -1.0, -1.0 ); + glTexCoord2f( ( 2.0 + fTitle->outWidthMax ) / 1024, + ( 2.0 + fTitle->outHeightMax ) / 1024 ); + glVertex3f( 1.0, 1.0, -1.0 ); + glTexCoord2f( 0.0, ( 2.0 + fTitle->outHeightMax ) / 1024 ); + glVertex3f( 1.0, 1.0, 1.0 ); + } + else + { + glTexCoord2f( 0.0, 0.0 ); + glVertex3f( -1.0, -1.0, -1.0 ); + glTexCoord2f( ( 2.0 + fTitle->outWidthMax ) / 1024, 0.0 ); + glVertex3f( -1.0, -1.0, 1.0 ); + glTexCoord2f( ( 2.0 + fTitle->outWidthMax ) / 1024, + ( 2.0 + fTitle->outHeightMax ) / 1024 ); + glVertex3f( -1.0, 1.0, 1.0 ); + glTexCoord2f( 0.0, ( 2.0 + fTitle->outHeightMax ) / 1024 ); + glVertex3f( -1.0, 1.0, -1.0 ); + } + glEnd(); + + [[self openGLContext] flushBuffer]; } -/* Override the view's drawRect: to draw our GL content */ - (void) drawRect: (NSRect) rect { - glViewport( 0, 0, (GLsizei) rect.size.width, - (GLsizei) rect.size.height ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - /* Black background */ - glClearColor( 0, 0, 0, 0 ); - glClear( GL_COLOR_BUFFER_BIT ); + if( !fPicture ) + { + return; + } - /* Show it */ - if( fPicture ) - { - glDrawPixels( fTitle->fOutWidthMax + 2, - fTitle->fOutHeightMax + 2, GL_RGBA, - GL_UNSIGNED_BYTE, fPicture ); - } + glDrawPixels( fTitle->outWidthMax + 2, + fTitle->outHeightMax + 2, GL_RGBA, + GL_UNSIGNED_BYTE, fPicture ); - [[self openGLContext] flushBuffer]; + [[self openGLContext] flushBuffer]; } @end diff --git a/macosx/TargetSizeField.h b/macosx/TargetSizeField.h index 12224cae..6bc4a716 100644 --- a/macosx/TargetSizeField.h +++ b/macosx/TargetSizeField.h @@ -1,12 +1,12 @@ -/* $Id: TargetSizeField.h,v 1.2 2003/10/09 23:33:36 titer Exp $ +/* $Id: TargetSizeField.h,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include -#include "Common.h" +#include "HandBrake.h" @interface HBTargetSizeField : NSTextField diff --git a/macosx/TargetSizeField.mm b/macosx/TargetSizeField.mm index 0c43701f..bde9f0ec 100644 --- a/macosx/TargetSizeField.mm +++ b/macosx/TargetSizeField.mm @@ -1,7 +1,7 @@ -/* $Id: TargetSizeField.mm,v 1.4 2003/10/09 23:33:36 titer Exp $ +/* $Id: TargetSizeField.mm,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #include "TargetSizeField.h" @@ -41,14 +41,14 @@ /* Video chunk headers (8 bytes / frame) and index (16 bytes / frame) */ - available -= 24 * fTitle->fLength * fTitle->fRate / fTitle->fScale; + available -= 24 * fTitle->length * fTitle->rate / fTitle->rateBase; /* Audio tracks */ available -= ( ( [[fSecondaryLanguagePopUp titleOfSelectedItem] compare: @"None"] == NSOrderedSame ) ? 1 : 2 ) * - ( fTitle->fLength * + ( fTitle->length * [[fAudioBitratePopUp titleOfSelectedItem] intValue] * - 128 + 24 * fTitle->fLength * 44100 / 1152 ); + 128 + 24 * fTitle->length * 44100 / 1152 ); if( available < 0 ) { @@ -57,7 +57,7 @@ else { [fBitrateField setIntValue: - available / ( 128 * fTitle->fLength )]; + available / ( 128 * fTitle->length )]; } } diff --git a/macosx/main.mm b/macosx/main.mm index 56aa102f..bd649f8b 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -1,7 +1,7 @@ -/* $Id: main.mm,v 1.5 2003/09/30 14:38:15 titer Exp $ +/* $Id: main.mm,v 1.1.1.1 2003/11/03 12:03:51 titer Exp $ This file is part of the HandBrake source code. - Homepage: . + Homepage: . It may be used under the terms of the GNU General Public License. */ #import diff --git a/test/Test.cpp b/test/Test.cpp deleted file mode 100644 index 4567f74b..00000000 --- a/test/Test.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/* $Id: Test.cpp,v 1.8 2003/10/13 10:58:24 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#include - -#include "Manager.h" - -volatile bool die; - -void SigHandler( int signal ) -{ - die = true; -} - -int main( int argc, char ** argv ) -{ - die = false; - - /* Exit ASAP on Ctrl-C */ - signal( SIGINT, SigHandler ); - - /* Default values */ - bool debug = false; - char * device = NULL; - char * outputFile = NULL; - int titleIdx = 1; - int audio1Idx = 1; - int audio2Idx = 0; - bool twoPass = false; - bool deinterlace = false; - int width = 0; - int topCrop = 0; - int bottomCrop = 0; - int leftCrop = 0; - int rightCrop = 0; - int cpuCount = 0; - int vBitrate = 1024; - int aBitrate = 128; - - /* Parse command line */ - int c; - while( ( c = getopt( argc, argv, "vd:o:t:a:b:piw:j:k:l:m:c:e:f:" ) ) != -1 ) - { - switch( c ) - { - case 'v': - debug = true; - break; - - case 'd': - device = strdup( optarg ); - break; - - case 'o': - outputFile = strdup( optarg ); - break; - - case 't': - titleIdx = atoi( optarg ); - break; - - case 'a': - audio1Idx = atoi( optarg ); - break; - - case 'b': - audio2Idx = atoi( optarg ); - break; - - case 'p': - twoPass = true; - break; - - case 'i': - deinterlace = true; - break; - - case 'w': - width = atoi( optarg ); - break; - - case 'j': - topCrop = atoi( optarg ); - break; - - case 'k': - bottomCrop = atoi( optarg ); - break; - - case 'l': - leftCrop = atoi( optarg ); - break; - - case 'm': - rightCrop = atoi( optarg ); - break; - - case 'c': - cpuCount = atoi( optarg ); - break; - - case 'e': - vBitrate = atoi( optarg ); - break; - - case 'f': - aBitrate = atoi( optarg ); - break; - - default: - break; - } - } - - /* Check parsed options */ - if( !device || !outputFile ) - { - fprintf( stderr, - "Syntax: HBTest [options] -d -o \n" - "Possible options are :\n" - " -v verbose output\n" - " -t select a title (default is 1)\n" - " -a primary audio channel (default is 1)\n" - " -b secondary audio channel (default is none)\n" - " -p 2-pass encoding\n" - " -i deinterlace picture\n" - " -w output width\n" - " -j top cropping\n" - " -k bottom cropping\n" - " -l left cropping\n" - " -m right cropping\n" - " -c CPU count\n" - " -e Video bitrate (default is 1024)\n" - " -f Audio bitrate (default is 128)\n" ); - return 1; - } - - /* Create the manager thread */ - HBManager * manager = new HBManager( debug, cpuCount ); - - /* Tell the manager to scan the specified volume */ - manager->ScanVolumes( device ); - - HBStatus status; - while( !die ) - { - if( !manager->NeedUpdate() ) - { - Snooze( 10000 ); - continue; - } - - status = manager->GetStatus(); - - switch( status.fMode ) - { - case HB_MODE_UNDEF: - break; - - case HB_MODE_SCANNING: - if( !status.fScannedTitle ) - { - fprintf( stderr, "Scanning %s\n", - status.fScannedVolume ); - } - else - { - fprintf( stderr, "Scanning %s, title %d\n", - status.fScannedVolume, - status.fScannedTitle ); - } - break; - - case HB_MODE_READY_TO_RIP: - { - /* Find the title */ - HBTitle * title = NULL; - for( uint32_t i = 0; i < status.fTitleList->CountItems(); i++ ) - { - title = (HBTitle*) status.fTitleList->ItemAt( i ); - if( title->fIndex == titleIdx ) - { - break; - } - else - { - title = NULL; - } - } - - if( !title ) - { - fprintf( stderr, "Error: unvalid title. Possible " - "choices are: " ); - for( uint32_t i = 0; - i < status.fTitleList->CountItems(); i++ ) - { - title = (HBTitle*) status.fTitleList->ItemAt( i ); - fprintf( stderr, "%d%s", title->fIndex, - ( i == status.fTitleList->CountItems() - 1 ) - ? ".\n" : ", " ); - } - die = true; - break; - } - title->fTwoPass = twoPass; - title->fDeinterlace = deinterlace; - if( width ) title->fOutWidth = width; - title->fTopCrop = topCrop; - title->fBottomCrop = bottomCrop; - title->fLeftCrop = leftCrop; - title->fRightCrop = rightCrop; - title->fBitrate = vBitrate; - - HBAudio * audio1 = - (HBAudio*) title->fAudioList->ItemAt( audio1Idx - 1 ); - HBAudio * audio2 = - (HBAudio*) title->fAudioList->ItemAt( audio2Idx - 1 ); - if( audio1 ) audio1->fOutBitrate = aBitrate; - if( audio2 ) audio2->fOutBitrate = aBitrate; - - manager->StartRip( title, audio1, audio2, outputFile ); - break; - } - - case HB_MODE_ENCODING: - fprintf( stderr, "Progress = %.2f %%, %.2f fps " - "(%02d:%02d:%02d remaining)\n", - 100 * status.fPosition, status.fFrameRate, - status.fRemainingTime / 3600, - ( status.fRemainingTime % 3600 ) / 60, - status.fRemainingTime % 60 ); - break; - - case HB_MODE_DONE: - fprintf( stderr, "Done\n" ); - die = true; - break; - - case HB_MODE_CANCELED: - fprintf( stderr, "Canceled\n" ); - die = true; - break; - - case HB_MODE_ERROR: - fprintf( stderr, "Error\n" ); - die = true; - break; - - default: - break; - } - } - - delete manager; - - if( device ) free( device ); - if( outputFile ) free( outputFile ); - - return 0; -} - diff --git a/test/test.c b/test/test.c new file mode 100644 index 00000000..ec576cbb --- /dev/null +++ b/test/test.c @@ -0,0 +1,237 @@ +/* $Id: test.c,v 1.5 2003/11/06 13:28:07 titer Exp $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#include + +#include "HandBrake.h" + +volatile int die; + +void SigHandler( int signal ) +{ + die = 1; +} + +int main( int argc, char ** argv ) +{ + int c; + HBHandle * h; + HBStatus s; + + /* Default values */ + int debug = 1; + char * device = NULL; + char * file = NULL; + int titleIdx = 1; + int audio1Idx = 1; + int audio2Idx = 0; + int twoPass = 0; + int deinterlace = 0; + int width = 0; + int topCrop = 0; + int bottomCrop = 0; + int leftCrop = 0; + int rightCrop = 0; + int cpuCount = 0; + int vBitrate = 1024; + int aBitrate = 128; + int xvid = 0; + + die = 0; + + /* Exit ASAP on Ctrl-C */ + signal( SIGINT, SigHandler ); + + /* Parse command line */ + while( ( c = getopt( argc, argv, "qd:o:t:a:b:piw:j:k:l:m:c:e:f:x" ) ) != -1 ) + { + switch( c ) + { + case 'q': + debug = 0; + break; + + case 'd': + device = strdup( optarg ); + break; + + case 'o': + file = strdup( optarg ); + break; + + case 't': + titleIdx = atoi( optarg ); + break; + + case 'a': + audio1Idx = atoi( optarg ); + break; + + case 'b': + audio2Idx = atoi( optarg ); + break; + + case 'p': + twoPass = 1; + break; + + case 'i': + deinterlace = 1; + break; + + case 'w': + width = atoi( optarg ); + break; + + case 'j': + topCrop = atoi( optarg ); + break; + + case 'k': + bottomCrop = atoi( optarg ); + break; + + case 'l': + leftCrop = atoi( optarg ); + break; + + case 'm': + rightCrop = atoi( optarg ); + break; + + case 'c': + cpuCount = atoi( optarg ); + break; + + case 'e': + vBitrate = atoi( optarg ); + break; + + case 'f': + aBitrate = atoi( optarg ); + break; + + case 'x': + xvid = 1; + break; + + default: + break; + } + } + + /* Check parsed options */ + if( !device || !file ) + { + fprintf( stderr, + "Syntax: HBTest [options] -d -o \n" + "Possible options are :\n" + " -q quiet output\n" + " -t select a title (default is 1)\n" + " -a primary audio channel (default is 1)\n" + " -b secondary audio channel (default is none)\n" + " -p 2-pass encoding\n" + " -i deinterlace picture\n" + " -w output width\n" + " -j top cropping\n" + " -k bottom cropping\n" + " -l left cropping\n" + " -m right cropping\n" + " -c CPU count (default: autodetected)\n" + " -e Video bitrate (default is 1024)\n" + " -f Audio bitrate (default is 128)\n" + " -x Use XviD instead of Ffmpeg\n" ); + return 1; + } + + /* Create the manager thread */ + h = HBInit( debug, cpuCount ); + + while( !die ) + { + HBSnooze( 100000 ); + + if( !HBGetStatus( h, &s ) ) + continue; + + switch( s.mode ) + { + case HB_MODE_UNDEF: + /* Will never happen */ + break; + + case HB_MODE_NEED_DEVICE: + /* Feed libhb with a DVD to scan */ + HBScanDevice( h, device, titleIdx ); + break; + + case HB_MODE_SCANNING: + /* s.scannedTitle: title scanned at the moment */ + break; + + case HB_MODE_INVALID_DEVICE: + die = 1; + break; + + case HB_MODE_READY_TO_RIP: + { + HBAudio * audio1, * audio2; + HBTitle * title = HBListItemAt( s.titleList, 0 ); + + title->file = strdup( file ); + title->twoPass = twoPass; + title->deinterlace = deinterlace; + if( width ) title->outWidth = width; + title->topCrop = topCrop; + title->bottomCrop = bottomCrop; + title->leftCrop = leftCrop; + title->rightCrop = rightCrop; + title->bitrate = vBitrate; + title->codec = xvid ? HB_CODEC_XVID : HB_CODEC_FFMPEG; + + audio1 = HBListItemAt( title->audioList, + audio1Idx - 1 ); + audio2 = HBListItemAt( title->audioList, + audio2Idx - 1 ); + if( audio1 ) audio1->outBitrate = aBitrate; + if( audio2 ) audio2->outBitrate = aBitrate; + + HBStartRip( h, title, audio1, audio2 ); + break; + } + + case HB_MODE_ENCODING: + /* s.position : current progress (0.0->1.0) + s.frameRate : average framerate + s.remainingTime: ... (in seconds) */ + break; + + case HB_MODE_DONE: + die = 1; + break; + + case HB_MODE_CANCELED: + die = 1; + break; + + case HB_MODE_ERROR: + /* s.error: error code */ + die = 1; + break; + + default: + break; + } + } + + HBClose( &h ); + + if( device ) free( device ); + if( file ) free( file ); + + return 0; +} + -- 2.11.0