diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 00:32:19 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 00:32:19 +0000 |
commit | 0d382a262c0638d0f572fc37193ccc5ed3dc895f (patch) | |
tree | 8578dcddfce4191f3f7a142a37769df7add48475 /libk9copy | |
download | k9copy-0d382a262c0638d0f572fc37193ccc5ed3dc895f.tar.gz k9copy-0d382a262c0638d0f572fc37193ccc5ed3dc895f.zip |
Added old abandoned version of k9copy
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/k9copy@1091546 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libk9copy')
67 files changed, 13508 insertions, 0 deletions
diff --git a/libk9copy/Makefile.am b/libk9copy/Makefile.am new file mode 100644 index 0000000..bf76bbc --- /dev/null +++ b/libk9copy/Makefile.am @@ -0,0 +1,29 @@ +AM_CPPFLAGS= -I$(srcdir) $(all_includes) + +KDE_CXXFLAGS = $(ENABLE_PERMISSIVE_FLAG) + +METASOURCES = AUTO + +noinst_LTLIBRARIES = libk9copy.la + + +libk9copy_la_SOURCES = backupdlg.ui dvdprogress.ui k9audiocodecs.cpp \ + k9backupdlg.cpp k9burndvd.cpp k9cell.cpp k9cellcopylist.cpp k9config.cpp \ + k9drawimage.cpp k9dvd.cpp k9dvdauthor.cpp k9dvdbackup.cpp k9dvdchapter.cpp \ + k9dvdprogress.cpp k9dvdread.cpp k9dvdsize.cpp k9dvdtitle.cpp k9dvdtitleset.cpp k9ifo2.cpp \ + k9mp4dlg.cpp k9mp4enc.cpp k9process.cpp k9processlist.cpp k9progress.cpp \ + k9saveimage.cpp k9script.cpp k9titleencopt.cpp k9tools.cpp k9videocodecs.cpp mp4dlg.ui \ + processList.ui progress.ui + +include_HEADERS = + +noinst_HEADERS = bswap.h k9audiocodecs.h k9backupdlg.h k9burndvd.h k9cell.h \ + k9cellcopylist.h k9common.h k9config.h k9drawimage.h k9dvd.h k9dvdauthor.h k9dvdbackup.h \ + k9dvdchapter.h k9dvdprogress.h k9dvdread.h k9dvdsize.h k9dvdtitle.h k9dvdtitleset.h \ + k9ifo2.h k9mp4dlg.h k9mp4enc.h k9process.h k9processlist.h k9progress.h \ + k9saveimage.h k9script.h k9titleencopt.h k9tools.h k9videocodecs.h + + +INCLUDES = -I$(top_srcdir)/dvdread -I$(top_srcdir)/k9decmpeg \ + -I$(top_srcdir)/k9vamps -I$(top_srcdir)/libdvdnav +libk9copy_la_LDFLAGS = $(all_libraries) diff --git a/libk9copy/backupdlg.cpp b/libk9copy/backupdlg.cpp new file mode 100644 index 0000000..a124c9f --- /dev/null +++ b/libk9copy/backupdlg.cpp @@ -0,0 +1,174 @@ +#include <klocale.h> +/**************************************************************************** +** Form implementation generated from reading ui file './backupdlg.ui' +** +** Created: dim. oct. 26 08:55:58 2008 +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "backupdlg.h" + +#include <qvariant.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <qprogressbar.h> +#include <kpushbutton.h> +#include <qframe.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> +#include "kpushbutton.h" + +/* + * Constructs a backupDlg as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +backupDlg::backupDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, fl ) +{ + if ( !name ) + setName( "backupDlg" ); + setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, 0, 0, sizePolicy().hasHeightForWidth() ) ); + setMinimumSize( QSize( 0, 0 ) ); + setMaximumSize( QSize( 9999, 9999 ) ); + setBaseSize( QSize( 500, 230 ) ); + setCursor( QCursor( 3 ) ); + setModal( TRUE ); + backupDlgLayout = new QGridLayout( this, 1, 1, 3, 8, "backupDlgLayout"); + + textLabel1 = new QLabel( this, "textLabel1" ); + textLabel1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, textLabel1->sizePolicy().hasHeightForWidth() ) ); + textLabel1->setCursor( QCursor( 3 ) ); + textLabel1->setFrameShape( QLabel::NoFrame ); + textLabel1->setFrameShadow( QLabel::Raised ); + + backupDlgLayout->addMultiCellWidget( textLabel1, 0, 0, 0, 3 ); + + layout3 = new QVBoxLayout( 0, 0, 6, "layout3"); + + lblStep = new QLabel( this, "lblStep" ); + lblStep->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, lblStep->sizePolicy().hasHeightForWidth() ) ); + QFont lblStep_font( lblStep->font() ); + lblStep_font.setItalic( TRUE ); + lblStep->setFont( lblStep_font ); + lblStep->setCursor( QCursor( 3 ) ); + layout3->addWidget( lblStep ); + + pbStep = new QProgressBar( this, "pbStep" ); + pbStep->setCursor( QCursor( 3 ) ); + layout3->addWidget( pbStep ); + + pbTotal = new QProgressBar( this, "pbTotal" ); + pbTotal->setCursor( QCursor( 3 ) ); + pbTotal->setMargin( 0 ); + pbTotal->setTotalSteps( 4400 ); + pbTotal->setPercentageVisible( TRUE ); + layout3->addWidget( pbTotal ); + + backupDlgLayout->addMultiCellLayout( layout3, 3, 3, 0, 3 ); + + textLabel1_2 = new QLabel( this, "textLabel1_2" ); + textLabel1_2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, textLabel1_2->sizePolicy().hasHeightForWidth() ) ); + textLabel1_2->setCursor( QCursor( 3 ) ); + + backupDlgLayout->addWidget( textLabel1_2, 2, 0 ); + + lblTime = new QLabel( this, "lblTime" ); + lblTime->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, 0, 0, lblTime->sizePolicy().hasHeightForWidth() ) ); + lblTime->setCursor( QCursor( 3 ) ); + + backupDlgLayout->addWidget( lblTime, 2, 1 ); + + layout1 = new QHBoxLayout( 0, 0, 6, "layout1"); + spacer1 = new QSpacerItem( 131, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + layout1->addItem( spacer1 ); + + bAbort = new KPushButton( this, "bAbort" ); + bAbort->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, bAbort->sizePolicy().hasHeightForWidth() ) ); + bAbort->setCursor( QCursor( 0 ) ); + bAbort->setProperty( "stdItem", 26 ); + layout1->addWidget( bAbort ); + + backupDlgLayout->addMultiCellLayout( layout1, 4, 4, 0, 3 ); + + lblFactor = new QLabel( this, "lblFactor" ); + lblFactor->setCursor( QCursor( 3 ) ); + + backupDlgLayout->addWidget( lblFactor, 2, 3 ); + + frame3 = new QFrame( this, "frame3" ); + frame3->setCursor( QCursor( 3 ) ); + frame3->setFrameShape( QFrame::StyledPanel ); + frame3->setFrameShadow( QFrame::Raised ); + frame3->setMargin( 1 ); + frame3Layout = new QGridLayout( frame3, 1, 1, 2, 6, "frame3Layout"); + + bPlay = new KPushButton( frame3, "bPlay" ); + bPlay->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, 0, 0, bPlay->sizePolicy().hasHeightForWidth() ) ); + bPlay->setMinimumSize( QSize( 25, 25 ) ); + bPlay->setMaximumSize( QSize( 25, 25 ) ); + bPlay->setCursor( QCursor( 0 ) ); + bPlay->setToggleButton( TRUE ); + bPlay->setOn( TRUE ); + bPlay->setFlat( FALSE ); + + frame3Layout->addWidget( bPlay, 1, 1 ); + spacer4 = new QSpacerItem( 476, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + frame3Layout->addItem( spacer4, 1, 0 ); + + image = new QLabel( frame3, "image" ); + image->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, 0, 0, image->sizePolicy().hasHeightForWidth() ) ); + image->setPaletteBackgroundColor( QColor( 0, 0, 0 ) ); + image->setCursor( QCursor( 3 ) ); + image->setScaledContents( TRUE ); + + frame3Layout->addMultiCellWidget( image, 0, 0, 0, 1 ); + + backupDlgLayout->addMultiCellWidget( frame3, 1, 1, 0, 3 ); + spacer3 = new QSpacerItem( 380, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + backupDlgLayout->addItem( spacer3, 2, 2 ); + languageChange(); + resize( QSize(385, 425).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); + + // signals and slots connections + connect( bAbort, SIGNAL( clicked() ), this, SLOT( bAbortClick() ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +backupDlg::~backupDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void backupDlg::languageChange() +{ + setCaption( tr2i18n( "k9Copy - Backup progression" ) ); + textLabel1->setText( tr2i18n( "<p align=\"left\"><b>DVD Backup</b></p>" ) ); + lblStep->setText( tr2i18n( "Current step" ) ); + textLabel1_2->setText( tr2i18n( "Elapsed Time" ) ); + lblTime->setText( tr2i18n( "--:--:--" ) ); + bPlay->setText( QString::null ); +} + +void backupDlg::bAbortClick() +{ + qWarning( "backupDlg::bAbortClick(): Not implemented yet" ); +} + +void backupDlg::bPlayToggled(bool) +{ + qWarning( "backupDlg::bPlayToggled(bool): Not implemented yet" ); +} + +#include "backupdlg.moc" diff --git a/libk9copy/backupdlg.ui b/libk9copy/backupdlg.ui new file mode 100644 index 0000000..1aad864 --- /dev/null +++ b/libk9copy/backupdlg.ui @@ -0,0 +1,383 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>backupDlg</class> +<widget class="QDialog"> + <property name="name"> + <cstring>backupDlg</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>385</width> + <height>425</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>9999</width> + <height>9999</height> + </size> + </property> + <property name="baseSize"> + <size> + <width>500</width> + <height>230</height> + </size> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="caption"> + <string>k9Copy - Backup progression</string> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>3</number> + </property> + <property name="spacing"> + <number>8</number> + </property> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="4"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + <property name="text"> + <string><p align="left"><b>DVD Backup</b></p></string> + </property> + </widget> + <widget class="QLayoutWidget" row="3" column="0" rowspan="1" colspan="4"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>lblStep</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <italic>1</italic> + </font> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>Current step</string> + </property> + </widget> + <widget class="QProgressBar"> + <property name="name"> + <cstring>pbStep</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + </widget> + <widget class="QProgressBar"> + <property name="name"> + <cstring>pbTotal</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="totalSteps"> + <number>4400</number> + </property> + <property name="percentageVisible"> + <bool>true</bool> + </property> + </widget> + </vbox> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>Elapsed Time</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>lblTime</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>--:--:--</string> + </property> + </widget> + <widget class="QLayoutWidget" row="4" column="0" rowspan="1" colspan="4"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>131</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KPushButton"> + <property name="name"> + <cstring>bAbort</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>0</cursor> + </property> + <property name="stdItem" stdset="0"> + <number>26</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="2" column="3"> + <property name="name"> + <cstring>lblFactor</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + </widget> + <widget class="QFrame" row="1" column="0" rowspan="1" colspan="4"> + <property name="name"> + <cstring>frame3</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="frameShape"> + <enum>StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + <property name="margin"> + <number>1</number> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>2</number> + </property> + <widget class="KPushButton" row="1" column="1"> + <property name="name"> + <cstring>bPlay</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>25</width> + <height>25</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>25</width> + <height>25</height> + </size> + </property> + <property name="cursor"> + <cursor>0</cursor> + </property> + <property name="text"> + <string></string> + </property> + <property name="toggleButton"> + <bool>true</bool> + </property> + <property name="on"> + <bool>true</bool> + </property> + <property name="flat"> + <bool>false</bool> + </property> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>476</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>image</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="paletteBackgroundColor"> + <color> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + </widget> + </grid> + </widget> + <spacer row="2" column="2"> + <property name="name"> + <cstring>spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>380</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> +</widget> +<connections> + <connection> + <sender>bAbort</sender> + <signal>clicked()</signal> + <receiver>backupDlg</receiver> + <slot>bAbortClick()</slot> + </connection> +</connections> +<slots> + <slot>bAbortClick()</slot> + <slot>bPlayToggled(bool state)</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/libk9copy/bswap.h b/libk9copy/bswap.h new file mode 100755 index 0000000..64751ff --- /dev/null +++ b/libk9copy/bswap.h @@ -0,0 +1,98 @@ +#ifndef BSWAP_H_INCLUDED +#define BSWAP_H_INCLUDED + +/* + * Copyright (C) 2000, 2001 Billy Biggs <[email protected]>, + * H�kan Hjort <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <config.h> + +#if defined(WORDS_BIGENDIAN) +/* All bigendian systems are fine, just ignore the swaps. */ +#define B2N_16(x) (void)(x) +#define B2N_32(x) (void)(x) +#define B2N_64(x) (void)(x) + +#else + +/* For __FreeBSD_version */ +#if defined(HAVE_SYS_PARAM_H) +#include <sys/param.h> +#endif + +#if defined(__linux__) +#include <byteswap.h> +#define B2N_16(x) x = bswap_16(x) +#define B2N_32(x) x = bswap_32(x) +#define B2N_64(x) x = bswap_64(x) + +#elif defined(__NetBSD__) +#include <sys/endian.h> +#define B2N_16(x) BE16TOH(x) +#define B2N_32(x) BE32TOH(x) +#define B2N_64(x) BE64TOH(x) + +#elif defined(__OpenBSD__) +#include <sys/endian.h> +#define B2N_16(x) x = swap16(x) +#define B2N_32(x) x = swap32(x) +#define B2N_64(x) x = swap64(x) + +#elif defined(__FreeBSD__) && __FreeBSD_version >= 470000 +#include <sys/endian.h> +#define B2N_16(x) x = be16toh(x) +#define B2N_32(x) x = be32toh(x) +#define B2N_64(x) x = be64toh(x) + +/* This is a slow but portable implementation, it has multiple evaluation + * problems so beware. + * Old FreeBSD's and Solaris don't have <byteswap.h> or any other such + * functionality! + */ + +#elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) +#define B2N_16(x) \ + x = ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8)) +#define B2N_32(x) \ + x = ((((x) & 0xff000000) >> 24) | \ + (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | \ + (((x) & 0x000000ff) << 24)) +#define B2N_64(x) \ + x = ((((x) & 0xff00000000000000) >> 56) | \ + (((x) & 0x00ff000000000000) >> 40) | \ + (((x) & 0x0000ff0000000000) >> 24) | \ + (((x) & 0x000000ff00000000) >> 8) | \ + (((x) & 0x00000000ff000000) << 8) | \ + (((x) & 0x0000000000ff0000) << 24) | \ + (((x) & 0x000000000000ff00) << 40) | \ + (((x) & 0x00000000000000ff) << 56)) + +#else + +/* If there isn't a header provided with your system with this functionality + * add the relevant || define( ) to the portable implementation above. + */ +#error "You need to add endian swap macros for you're system" + +#endif + +#endif /* WORDS_BIGENDIAN */ + +#endif /* BSWAP_H_INCLUDED */ diff --git a/libk9copy/dvdprogress.cpp b/libk9copy/dvdprogress.cpp new file mode 100644 index 0000000..273e551 --- /dev/null +++ b/libk9copy/dvdprogress.cpp @@ -0,0 +1,97 @@ +#include <klocale.h> +/**************************************************************************** +** Form implementation generated from reading ui file './dvdprogress.ui' +** +** Created: dim. oct. 26 08:55:59 2008 +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "dvdprogress.h" + +#include <qvariant.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <qprogressbar.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> + +/* + * Constructs a DVDProgress as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +DVDProgress::DVDProgress( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, fl ) +{ + if ( !name ) + setName( "DVDProgress" ); + setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, 0, 0, sizePolicy().hasHeightForWidth() ) ); + setMinimumSize( QSize( 0, 150 ) ); + setMaximumSize( QSize( 400, 150 ) ); + setCursor( QCursor( 3 ) ); + DVDProgressLayout = new QGridLayout( this, 1, 1, 11, 6, "DVDProgressLayout"); + + layout2 = new QVBoxLayout( 0, 0, 6, "layout2"); + + lblTotal = new QLabel( this, "lblTotal" ); + lblTotal->setCursor( QCursor( 3 ) ); + layout2->addWidget( lblTotal ); + + pbTotal = new QProgressBar( this, "pbTotal" ); + pbTotal->setCursor( QCursor( 3 ) ); + pbTotal->setProgress( 100 ); + pbTotal->setPercentageVisible( FALSE ); + layout2->addWidget( pbTotal ); + + DVDProgressLayout->addLayout( layout2, 1, 0 ); + + layout1 = new QVBoxLayout( 0, 0, 6, "layout1"); + + lblTitle = new QLabel( this, "lblTitle" ); + lblTitle->setCursor( QCursor( 3 ) ); + layout1->addWidget( lblTitle ); + + pbTitle = new QProgressBar( this, "pbTitle" ); + pbTitle->setCursor( QCursor( 3 ) ); + pbTitle->setTotalSteps( 100 ); + pbTitle->setProgress( 100 ); + pbTitle->setCenterIndicator( TRUE ); + pbTitle->setPercentageVisible( FALSE ); + layout1->addWidget( pbTitle ); + + DVDProgressLayout->addLayout( layout1, 0, 0 ); + + lblStatus = new QLabel( this, "lblStatus" ); + lblStatus->setCursor( QCursor( 3 ) ); + + DVDProgressLayout->addWidget( lblStatus, 2, 0 ); + languageChange(); + resize( QSize(278, 150).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); +} + +/* + * Destroys the object and frees any allocated resources + */ +DVDProgress::~DVDProgress() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void DVDProgress::languageChange() +{ + setCaption( tr2i18n( "k9Copy - DVD Analyze" ) ); + lblTotal->setText( QString::null ); + lblTitle->setText( QString::null ); + lblStatus->setText( QString::null ); +} + +#include "dvdprogress.moc" diff --git a/libk9copy/dvdprogress.ui b/libk9copy/dvdprogress.ui new file mode 100755 index 0000000..dabdac2 --- /dev/null +++ b/libk9copy/dvdprogress.ui @@ -0,0 +1,141 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>DVDProgress</class> +<widget class="QDialog"> + <property name="name"> + <cstring>DVDProgress</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>278</width> + <height>150</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>150</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>400</width> + <height>150</height> + </size> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="caption"> + <string>k9Copy - DVD Analyze</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>lblTotal</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QProgressBar"> + <property name="name"> + <cstring>pbTotal</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="progress"> + <number>100</number> + </property> + <property name="percentageVisible"> + <bool>false</bool> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>lblTitle</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QProgressBar"> + <property name="name"> + <cstring>pbTitle</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="totalSteps"> + <number>100</number> + </property> + <property name="progress"> + <number>100</number> + </property> + <property name="centerIndicator"> + <bool>true</bool> + </property> + <property name="percentageVisible"> + <bool>false</bool> + </property> + </widget> + </vbox> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>lblStatus</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/libk9copy/k9audiocodecs.cpp b/libk9copy/k9audiocodecs.cpp new file mode 100644 index 0000000..361fbf0 --- /dev/null +++ b/libk9copy/k9audiocodecs.cpp @@ -0,0 +1,118 @@ +// +// C++ Implementation: k9audiocodecs +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9audiocodecs.h" + +#include <qstringlist.h> + +class _k9AudioCodec +{ +public: + _k9AudioCodec():name(""),options(""){}; + _k9AudioCodec(QString _name,QString _options) { + name=_name; + options=_options; + } + QString name; + QString options; +}; + + +k9AudioCodecs::k9AudioCodecs(QObject *parent, const char *name) + : QObject(parent, name) +{ + m_config=new k9Config(); + QStringList slLabels=m_config->getCodecLabelsAudio(); + QStringList slCodecs=m_config->getCodecAudio(); + //adds default codecs + if (slLabels.count()==0) { + reset(); + m_config=new k9Config(); + slLabels=m_config->getCodecLabelsAudio(); + slCodecs=m_config->getCodecAudio(); + } + QStringList::iterator c=slCodecs.begin(); + int cpt=0; + for (QStringList::iterator i=slLabels.begin();i!=slLabels.end() ;++i) { + QString o1=(*c); + c++; + m_codecs[cpt++]=_k9AudioCodec((*i),o1); + } + delete m_config; + +} + +void k9AudioCodecs::reset() { + m_codecs[0]=_k9AudioCodec("copy","-oac copy"); + m_codecs[1]=_k9AudioCodec("mp3","-oac lavc -lavcopts acodec=mp3:abitrate=$AUDBR"); + m_codecs[2]=_k9AudioCodec("mp2","-oac lavc -lavcopts acodec=mp2:abitrate=$AUDBR"); + m_codecs[3]=_k9AudioCodec("ac3","-oac lavc -lavcopts acodec=ac3:abitrate=$AUDBR"); + m_codecs[4]=_k9AudioCodec("IMA Adaptive PCM","-oac lavc -lavcopts acodec=adpcm_ima_wav:abitrate=$AUDBR"); + m_codecs[5]=_k9AudioCodec("sonic","-oac lavc -lavcopts acodec=sonic:abitrate=$AUDBR"); + m_codecs[6]=_k9AudioCodec("aac","-oac faac -faacopts br=$AUDBR"); + m_codecs[7]=_k9AudioCodec("mp3 (lame)","-oac mp3lame -lameopts abr:br=$AUDBR"); + save(); +} + +void k9AudioCodecs::save() { + m_config=new k9Config(); + + QStringList labels; + QStringList options; + for (QMap<int,_k9AudioCodec>::iterator i=m_codecs.begin();i!=m_codecs.end();++i) { + labels << i.data().name; + options << i.data().options; + } + m_config->setCodecLabelsAudio(labels); + m_config->setCodecAudio(options); + m_config->save(); + delete m_config; +} + + + + +int k9AudioCodecs::count() { + return m_codecs.count(); +} + +void k9AudioCodecs::setOptions(int _num,QString _value) { + m_codecs[_num].options=_value; +} + +void k9AudioCodecs::setCodecName(int _num,QString _value) { + m_codecs[_num].name=_value; +} + +QString k9AudioCodecs::getOptions(int _num) { + return m_codecs[_num].options; +} + +QString k9AudioCodecs::getCodecName(int _num) { + return m_codecs[_num].name; +} + +void k9AudioCodecs::remove(int _num) { + int nb=count(); + if (nb>0) { + for(int i=_num;i<nb-1;i++) { + m_codecs[i]=m_codecs[i+1]; + } + m_codecs.remove(nb-1); + } +} + +k9AudioCodecs::~k9AudioCodecs() +{ +} + + +#include "k9audiocodecs.moc" diff --git a/libk9copy/k9audiocodecs.h b/libk9copy/k9audiocodecs.h new file mode 100644 index 0000000..bf093a2 --- /dev/null +++ b/libk9copy/k9audiocodecs.h @@ -0,0 +1,45 @@ +// +// C++ Interface: k9audiocodecs +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9AUDIOCODECS_H +#define K9AUDIOCODECS_H + +#include "k9common.h" +#include "k9config.h" +#include <qobject.h> + +/** + @author Jean-Michel PETIT <[email protected]> +*/ + +class _k9AudioCodec; +class k9AudioCodecs : public QObject +{ +Q_OBJECT +public: + k9AudioCodecs(QObject *parent = 0, const char *name = 0); + + ~k9AudioCodecs(); + void save(); + int count(); + void setOptions(int _num,QString _value); + void setCodecName(int _num,QString _value); + QString getOptions(int _num); + QString getCodecName(int _num); + void remove(int _num); + void reset(); +private: + QMap <int,_k9AudioCodec> m_codecs; + k9Config *m_config; + +}; + +#endif diff --git a/libk9copy/k9backupdlg.cpp b/libk9copy/k9backupdlg.cpp new file mode 100644 index 0000000..8c101d8 --- /dev/null +++ b/libk9copy/k9backupdlg.cpp @@ -0,0 +1,182 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jean-Michel Petit * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "k9backupdlg.h" +#include "ac.h" +#include <qtimer.h> +#include <qdatetime.h> +#include <qapplication.h> +#include <qprogressbar.h> +#include <qlabel.h> +#include <kiconloader.h> +#include <kpushbutton.h> +#include <kstdguiitem.h> +#include <kguiitem.h> +#include <qlabel.h> +#include <qpainter.h> +#include <qlayout.h> +#include "k9drawimage.h" + +k9BackupDlg::k9BackupDlg(QWidget* parent, const char* name, bool modal, WFlags fl) + : backupDlg(parent,name, modal,fl) { + Abort=false; + timer = new QTimer( this ); + time = new QTime(0,0); + time->start(); + connect( timer, SIGNAL(timeout()), this, SLOT(timerDone()) ); + timer->start(500, 0 ); + bAbort->setIconSet(KStdGuiItem::cancel().iconSet()); + bPlay->setIconSet(SmallIcon("player_play")); + totalCopied=0; + m_progressTotal=0; + m_progressLabel=""; + m_totalSteps=0; + m_factor=""; + m_progress=0; + connect(&m_decoder, SIGNAL(pixmapReady(QImage *)), this, SLOT(drawPixmap(QImage *))); + m_stop=false; + m_playmovie=true; + m_cpt=0; + m_wimage=new k9DrawImage(image,0); + QGridLayout *l=new QGridLayout(image,1,1); + l->addWidget(m_wimage,0,0); + m_data=NULL; + m_dataSize=0; +} + +void k9BackupDlg::drawPixmap(QImage *_image) { + m_count++; + if (m_count ==4) { + + m_wimage->setImage(*_image); + + m_stop=true; + } +} + +void k9BackupDlg::bPlayToggled( bool state) { + m_playmovie=bPlay->isOn(); +} + + void k9BackupDlg::playMovie(uchar *_data,uint32_t _size) { + if (!m_playmovie || m_dataSize) + return; + m_count=0; + m_dataSize=_size; + m_data=(uchar*)malloc(_size); + tc_memcpy(m_data,_data,_size); +} + + +k9BackupDlg::~k9BackupDlg() { + delete timer; + delete time; + if (m_data) + free(m_data); +} + +void k9BackupDlg::update(){ + lblStep->setText(m_progressLabel); + pbTotal->setProgress(m_progressTotal); + pbStep->setTotalSteps(m_totalSteps); + lblFactor->setText(m_factor); + pbStep->setProgress(m_progress); + + if (m_data) { + if (m_stop) + m_decoder.start(); + m_stop=false; + for (uint32_t i=0;i<m_dataSize-2048;i+=2048) { + if (m_stop) { + m_decoder.stop(); + break; + } + m_decoder.decode(m_data +i ,m_data+i+2048,0); + } + free(m_data); + m_data=NULL; + m_dataSize=0; + + m_playmovie=false; + } + +} + +void k9BackupDlg::timerDone() { + m_cpt++; + if (m_cpt==10) { + m_cpt=0; + m_playmovie=bPlay->isOn(); + } + QTime time2(0,0); + time2=time2.addMSecs(time->elapsed()); + QString remain("--:--:--"); + if (m_progressTotal>0) { + QTime time3(0,0); + time3=time3.addMSecs((time->elapsed()/m_progressTotal)*pbTotal->totalSteps()); + remain=time3.toString("hh:mm:ss"); + } + + lblTime->setText(time2.toString("hh:mm:ss") +" / " +remain); + update(); +} + +void k9BackupDlg::setTotalSteps(uint32_t _totalSteps) { + m_totalSteps=_totalSteps; +} + +void k9BackupDlg::setProgress(uint32_t _position) { + m_progress=_position; +} + +void k9BackupDlg::setTotalMax(uint32_t _max) { + pbTotal->setTotalSteps(_max); +} + +void k9BackupDlg::setProgressTotal(uint32_t _position) { + totalCopied+=_position; + uint64_t total=totalCopied*2048; + total/=(1024*1024); + m_progressTotal=total; + +} + +void k9BackupDlg::setProgressLabel(QString _text) { + m_progressLabel=_text; + update(); +} + +bool k9BackupDlg::getAbort() { + return Abort; +} + +void k9BackupDlg::bAbortClick() { + Abort=true; + reject(); + +} + +void k9BackupDlg::setFactor(QString _factor) { + m_factor=_factor; +} +/*$SPECIALIZATION$*/ + + +#include "k9backupdlg.moc" diff --git a/libk9copy/k9backupdlg.h b/libk9copy/k9backupdlg.h new file mode 100644 index 0000000..dae5b31 --- /dev/null +++ b/libk9copy/k9backupdlg.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jean-Michel Petit * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef K9BACKUPDLG_H +#define K9BACKUPDLG_H + +#include "k9common.h" +#include "backupdlg.h" +#include <qmutex.h> +#include "kdecmpeg2.h" + +class k9DrawImage; + +class k9BackupDlg : public backupDlg +{ + Q_OBJECT + +public: + k9BackupDlg(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~k9BackupDlg(); + /*$PUBLIC_FUNCTIONS$*/ + void setTotalSteps(uint32_t _totalSteps); + void setProgress(uint32_t _position); + void setProgressLabel(QString _text); + void setProgressTotal(uint32_t _position); + void setTotalMax(uint32_t _max); + void setFactor(QString _factor); + bool getAbort(); + void playMovie(uchar *_data,uint32_t _size); +public slots: + /*$PUBLIC_SLOTS$*/ +private : + bool Abort; + QTimer *timer; + QTime *time; + uint64_t totalCopied,m_progressTotal;; + QString m_progressLabel; + uint32_t m_totalSteps,m_progress; + QString m_factor; + bool m_stop; + void update(); + kDecMPEG2 m_decoder; + uint m_count; + QMutex mutex; + bool m_playmovie; + uint m_cpt; + k9DrawImage *m_wimage; + uchar *m_data; + uint32_t m_dataSize; +protected: + /*$PROTECTED_FUNCTIONS$*/ + void bAbortClick(); + void bPlayToggled(bool state); +protected slots: + /*$PROTECTED_SLOTS$*/ + void timerDone(); + void drawPixmap(QImage *image); +}; + +#endif + diff --git a/libk9copy/k9burndvd.cpp b/libk9copy/k9burndvd.cpp new file mode 100644 index 0000000..7d6f603 --- /dev/null +++ b/libk9copy/k9burndvd.cpp @@ -0,0 +1,381 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#include "k9burndvd.h" +#include "k9burndvd.moc" +#include "k9tools.h" +#include <qdir.h> +#include <kmessagebox.h> +#include <kfiledialog.h> +#include <klibloader.h> +#include <kprocess.h> +#include <qapplication.h> +#include <kstandarddirs.h> + +k9BurnDVD::k9BurnDVD() + : QObject(NULL,"") { + cancelled=false; + useK3b=false; + autoBurn=false; + volId="K9Copy"; + iso=false; + m_filename=""; + progress=new k9Progress(NULL,"progress",NULL); + QString s= KGlobal::dirs()->findResource( "data", "k9copy/anim.mng"); + progress->setMovie(s); + m_cdrkit=k9Tools::checkProgram("genisoimage") && k9Tools::checkProgram("wodim"); +} + + + +k9BurnDVD::~k9BurnDVD() { +} + +/** Read property of QString burnDevice. */ +const QString& k9BurnDVD::getburnDevice() { + return burnDevice; +} +/** Write property of QString burnDevice. */ +void k9BurnDVD::setburnDevice( const QString& _newVal) { + burnDevice = _newVal; +} +/** Write property of QString workDir. */ +void k9BurnDVD::setworkDir( const QString& _newVal) { + workDir = _newVal; + if (workDir.right(1)!='/') + workDir +='/'; +} + +void k9BurnDVD::makeIso(QString _filename) { + iso=true; + m_filename=_filename; +} + +void k9BurnDVD::setvolId(QString _newVal) { + volId=_newVal.replace(" ","_"); +} + +void k9BurnDVD::setUseK3b(bool _newVal) { + useK3b=_newVal; +} + +void k9BurnDVD::setAutoBurn(bool _newVal) { + autoBurn=_newVal; +} +void k9BurnDVD::burn() { + if (!useK3b) { + if (! m_cdrkit) + burnWithGrowisofs(); + else + burnWithGenisoimage(); + } else + burnWithK3b(); +} + +void k9BurnDVD::burnWithK3b() { + KProcess *k3b = new KProcess(); + + *k3b << "k3b"; + *k3b << QDir::cleanDirPath(workDir +"/dvd/VIDEO_TS"); + *k3b << "-videodvd"; + k3b->start(); + k3b->detach(); + delete k3b; +} + +void k9BurnDVD::mkisoSizeStderr(KProcess *proc, char *buffer, int buflen) { + QString c=QString::fromLatin1( buffer,buflen);// (proc2->readStderr()); + imageSize=c.replace("\n",""); + ; +} + +void k9BurnDVD::mkisoSizeStdout(KProcess *proc, char *buffer, int buflen) { + QString c=QString::fromLatin1(buffer,buflen);// (proc2->readStdout()); + imageSize=c.replace("\n",""); + ; +} + +const QString &k9BurnDVD::getImageSize() { + QString c; + c="mkisofs"; + proc2=new k9Process; + *proc2 << c; + *proc2 <<"-quiet"; + *proc2 <<"-print-size"; + *proc2 <<"-dvd-video"; + *proc2 <<"-udf"; + *proc2 <<"-r"; + *proc2 <<"-V "+volId; + *proc2 << QDir::cleanDirPath(workDir +"/dvd"); + + connect( proc2, SIGNAL(receivedStderr(KProcess *, char *, int )),this, SLOT(mkisoSizeStderr(KProcess *, char *, int)) ); + connect( proc2, SIGNAL(receivedStdout(KProcess *, char *, int)),this, SLOT(mkisoSizeStdout(KProcess *, char *, int)) ); + if (proc2->start(KProcess::NotifyOnExit,KProcess::All)) { +// while (proc2->isRunning()) { +// qApp->processEvents(); +// } + proc2->sync(); + if (proc2->exitStatus()==0) { + delete proc2; + return imageSize; + } + } + delete proc2; + return ""; +} + +void k9BurnDVD::getGenisoimageCmd(k9Process *proc,QString _fileName,bool _printSize) { + QString progname="genisoimage"; + *proc << progname; + *proc << "-gui"; + *proc << "-graft-points"; + *proc << "-volid" << volId; + *proc <<"-appid" << "k9copy"; + *proc << "-volset-size" << "1"; + *proc << "-volset-seqno" << "1"; + *proc << "-no-cache-inodes" << "-udf"; + *proc << "-iso-level" << "1"; + *proc << "-dvd-video"; + if (!_printSize) { + if (_fileName !="") { + *proc <<"-o"; + *proc <<_fileName; + } + connect( proc, SIGNAL(receivedStderr(KProcess *, char *, int)),this, SLOT(growisoStderr(KProcess *, char *, int)) ); + connect( proc, SIGNAL(receivedStdout(KProcess *, char *, int)),this, SLOT(growisoStdout(KProcess *, char *, int)) ); + } else { + *proc << "-print-size" << "-quiet"; + connect( proc, SIGNAL(receivedStderr(KProcess *, char *, int )),this, SLOT(mkisoSizeStderr(KProcess *, char *, int)) ); + connect( proc, SIGNAL(receivedStdout(KProcess *, char *, int)),this, SLOT(mkisoSizeStdout(KProcess *, char *, int)) ); + } + *proc <<QDir::cleanDirPath(workDir +"/dvd"); + +} + +void k9BurnDVD::getWodimCmd(k9Process *proc) { + *proc <<"|wodim"; + *proc <<"-dao"; + *proc <<"-overburn"; + *proc <<"-data"; + + if (m_speed !=i18n("default")) + *proc << QString("speed=%1").arg(m_speed); + *proc <<QString("dev=%1").arg(burnDevice); + *proc <<QString("tsize=%1s").arg(imageSize); + *proc << "-"; +} + +void k9BurnDVD::burnWithGenisoimage() { + time = new QTime(0,0); + time->start(); + progress->setCaption(i18n("k9Copy - Burning DVD")); + progress->setTitle(i18n("Burning DVD")); + proc=progress->getProcess(); + + bool bok=false; + + while (!cancelled && !bok) { + burnSpeed=0; + QString fileName=""; + if (iso) { + fileName=m_filename; + if (fileName =="") + fileName=KFileDialog::getSaveFileName (QDir::homeDirPath(),"*.iso", 0,i18n("Save image to disk")); + if (fileName =="") { + cancelled=true; + } + } + proc->clearArguments(); + getGenisoimageCmd(proc,fileName,false); + if (!iso) { + k9Process *proc2=new k9Process(NULL,NULL); + getGenisoimageCmd(proc2,"",true); + proc2->start(KProcess::NotifyOnExit,KProcess::All); + proc2->sync(); + getWodimCmd(proc); + proc->setUseShell(true); + if (!autoBurn) { + if ( KMessageBox::warningContinueCancel ( 0,i18n("Insert a recordable DVD"), i18n("DVD burning"))!=KMessageBox::Continue) + cancelled=true; + } + qDebug(proc->debug()); + } + + + if (!cancelled) { + int res=progress->execute(); + if ( res==-1 ) { + KMessageBox::error( 0, i18n("Error burning DVD :\n")+i18n("Unable to run %1").arg("genisoimage"), i18n("DVD burning") ); + cancelled=true; + } else { + if (proc->exitStatus()==0) { + bok=true; + KMessageBox::information( 0, i18n("DVD Burning finished"), i18n("DVD burning") ); + //delete temporary files + // clearOutput(workDir+"dvd"); + } else { + QString c; + + c=i18n("An error occured while Burning DVD: %1").arg(lastMsg) +"\n" +i18n("Insert an other DVD"); + if ( KMessageBox::warningContinueCancel ( 0,c, i18n("authoring"))!=KMessageBox::Continue) { + cancelled=true; + } + } + } + } + } +} + +void k9BurnDVD::burnWithGrowisofs() { + time = new QTime(0,0); + time->start(); + + //KLibFactory *factory; + //factory = KLibLoader::self()->factory("libk9copy"); + +// progress=static_cast<k9Progress *>(factory->create(qApp->mainWidget(),"progress", "k9Progress")); + + progress->setCaption(i18n("k9Copy - Burning DVD")); + progress->setTitle(i18n("Burning DVD")); + bool bok=false; + + + while (!cancelled && !bok) { + burnSpeed=0; + QString c,progname; + if (iso) + progname="mkisofs"; + else + progname="growisofs"; + proc=progress->getProcess(); + *proc << progname; + + if (!iso) { + *proc <<"-overburn"; + *proc <<"-Z"; + *proc <<burnDevice; + *proc <<"-use-the-force-luke=tty"; + *proc <<"-use-the-force-luke=tracksize:"+getImageSize(); + *proc <<"-use-the-force-luke=dao:" + imageSize; + *proc <<"-dvd-compat"; + if (m_speed !=i18n("default")) + *proc <<"-speed=" + m_speed; + + } else { + QString fileName=m_filename; + if (fileName =="") + fileName=KFileDialog::getSaveFileName (QDir::homeDirPath(),"*.iso", 0,i18n("Save image to disk")); + if (fileName !="") { + *proc <<"-o"; + *proc <<fileName; + } else + cancelled=true; + + } + + *proc <<"-dvd-video"; + *proc <<"-udf"; + *proc << "-r"; + *proc <<"-V "+volId; + *proc <<QDir::cleanDirPath(workDir +"/dvd"); + + connect( proc, SIGNAL(receivedStderr(KProcess *, char *, int)),this, SLOT(growisoStderr(KProcess *, char *, int)) ); + connect( proc, SIGNAL(receivedStdout(KProcess *, char *, int)),this, SLOT(growisoStdout(KProcess *, char *, int)) ); + if (!autoBurn && !iso) { + c=i18n("Insert a recordable DVD"); + if ( KMessageBox::warningContinueCancel ( 0,c, i18n("DVD burning"))!=KMessageBox::Continue) + cancelled=true; + } + if (!cancelled) { + int res=progress->execute(); + if ( res==-1 ) { + KMessageBox::error( 0, i18n("Error burning DVD :\n")+i18n("Unable to run %1").arg(progname), i18n("DVD burning") ); + cancelled=true; + } else { + if (proc->exitStatus()==0) { + bok=true; + KMessageBox::information( 0, i18n("DVD Burning finished"), i18n("DVD burning") ); + //delete temporary files + // clearOutput(workDir+"dvd"); + } else { + QString c; + + c=i18n("An error occured while Burning DVD: %1").arg(lastMsg) +"\n" +i18n("Insert an other DVD"); + if ( KMessageBox::warningContinueCancel ( 0,c, i18n("authoring"))!=KMessageBox::Continue) { + cancelled=true; + } + } + } + } + } + delete time; + +} + +/** No descriptions */ +void k9BurnDVD::growisoStderr(KProcess *proc, char *buffer, int buflen) { + QString c=QString::fromLatin1( buffer,buflen);// (proc->readStderr()); + char s[255]; + int a,b; + int pos; + lastMsg=c; + if (c.contains("Current Write Speed")) { + sscanf(c.latin1(),"%s \"Current Write Speed\" is %d.%d",s,&a,&b); + burnSpeed=a+b/10; + } + if (c.contains("Speed set to")) { + sscanf(c.latin1(),"Speed set to %d",&a); + burnSpeed=a/1385; + } + + progress->setTitle(i18n("Burning DVD")); + progress->setLabelText(i18n("Current write speed :%1 x").arg(burnSpeed)); + if (c.contains("% done")) { + pos=c.find("%"); + if (pos!=-1) { + c=c.mid(1,pos-4); + //progress->setLabelText(c); + progress->setProgress(c.toInt(),100); + float m_percent=c.toFloat()/100; + QTime time2(0,0); + time2=time2.addMSecs(time->elapsed()); + if (m_percent>0) { + QTime time3(0,0); + QString m_remain; + time3=time3.addMSecs((uint32_t)(time->elapsed()*(1/m_percent))); + m_remain=time3.toString("hh:mm:ss"); + progress->setElapsed(time2.toString("hh:mm:ss") +" / " +m_remain); + + } + + + + } + } +} +void k9BurnDVD::growisoStdout(KProcess *proc, char *buffer, int buflen) { + QString c=QString::fromLatin1( buffer,buflen);// (proc->readStdout()); + int pos; + pos=c.find("STAT"); + if (pos!=-1) { + c=c.mid(pos); + progress->setLabelText(c); + } +} diff --git a/libk9copy/k9burndvd.h b/libk9copy/k9burndvd.h new file mode 100644 index 0000000..6d9948c --- /dev/null +++ b/libk9copy/k9burndvd.h @@ -0,0 +1,83 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef k9BurnDVD_H +#define k9BurnDVD_H + +#include "k9common.h" +#include "k9progress.h" + +#include <k9process.h> +#include <klocale.h> + +/** +@author Jean-Michel PETIT +*/ +class k9BurnDVD: public QObject +{ +Q_OBJECT +public: + k9BurnDVD(); + + ~k9BurnDVD(); + virtual void setburnDevice( const QString& _newVal); + virtual const QString& getburnDevice(); + virtual QWidget* getDialog() {return progress;}; + void setworkDir( const QString& _newVal); + void setvolId(QString _newVal); + void setUseK3b(bool _newVal); + void setAutoBurn (bool _newVal); + void burn(); + void makeIso(QString _filename); + + void setSpeed(const QString& _value) { m_speed = _value;} + +private: + QTime *time; + k9Progress *progress; + k9Process *proc; + k9Process *proc2; + QString volId; + float burnSpeed; + QString burnDevice; + QString lastMsg; + QString workDir; + QString m_filename; + bool cancelled; + bool useK3b; + bool autoBurn; + bool iso; + bool m_cdrkit; + void burnWithGrowisofs(); + void burnWithGenisoimage(); + void getGenisoimageCmd(k9Process *proc,QString _fileName,bool _printSize); + void getWodimCmd(k9Process *proc); + + void burnWithK3b(); + const QString &getImageSize(); + QString imageSize; + QString m_speed; +private slots: // Private slots + void growisoStderr(KProcess *proc, char *buffer, int buflen); + void growisoStdout(KProcess *proc, char *buffer, int buflen); + void mkisoSizeStderr(KProcess *proc, char *buffer, int buflen); + void mkisoSizeStdout(KProcess *proc, char *buffer, int buflen); +}; + +#endif diff --git a/libk9copy/k9cell.cpp b/libk9copy/k9cell.cpp new file mode 100755 index 0000000..d757e26 --- /dev/null +++ b/libk9copy/k9cell.cpp @@ -0,0 +1,443 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#include "k9cell.h" +#include "k9dvdtitleset.h" + +int k9VobuList::compareItems ( QPtrCollection::Item item1, QPtrCollection::Item item2 ) { + return(((k9Vobu*)item1)->oldSector- ((k9Vobu*)item2)->oldSector); +} + +k9Vobu * k9VobuList::findVobu(uint32_t sector) { + //int c=count(); + //if (c >0) { + k9Vobu *v1,*v2; + v1=first(); + v2=last(); + if (v1==NULL) + return NULL; + + if (sector >= v1->oldSector && sector <= v2->oldSector) + return findVobu(sector,0,count()-1); + else + return NULL; + //} +} + +k9Vobu * k9VobuList::findVobu(uint32_t sector, uint32_t start, uint32_t end) { + + long lstart=start; + long lend=end; + + + while (lstart <=lend) { + long m =(lstart+lend)/2; + k9Vobu *v = (k9Vobu *)at(m); + if ( v->oldSector == sector) { + return v; + } else if ( v->oldSector >sector) { + lend = m-1; + } else { + lstart=m+1; + } + } + return NULL; +} + +uint32_t k9Cell::getnewSize() { + uint32_t size=0; + //for (k9Vobu * vobu=vobus.first();vobu;vobu=vobus.next()) + for (uint i=0; i<vobus.count();i++) { + k9Vobu *vobu=vobus.at(i); + size+=vobu->size; + } + return size; +} + +int k9Cell::getStreamID(int type) { + int abase=0; + if (type >= 0x80 && type <= 0x87) { + // AC3 audio + abase = 0x80; + } else if (type >= 0x88 && type <= 0x8f) { + // DTS audio + abase = 0x88; + } else if (type >= 0xa0 && type <= 0xbf) { + // LPCM audio + abase = 0xa0; + } else if (type >= 0xc0 && type <= 0xdf) { + // MPEG audio + abase = 0xc0; + } else if (type >=0x20 && type <=0x3f) { + //subpicture; + abase =0x20; + } + return (type-abase ); + +} + + +streamType_t k9Cell::identifyStream( uchar *buffer,int *packetType ) { + *packetType = buffer[17]; + + if( (*packetType >= 0xE0) && (*packetType <= 0xEF) ) { // video streams + return stVideo; + } else if( *packetType == 0xBB ) { // system header + return stOther; + } else if( *packetType == 0xBE ) { // padding + return stOther; + } else if( *packetType == 0xBF ) { // nav pack + return stOther; + } else if( (*packetType >= 0xC0) && (*packetType <= 0xDF) ) { // mpeg audio + return stAudio; + } else if( *packetType == 0xBD ) { // private stream, check content + *packetType = buffer[23+buffer[22]]; + if (( (*packetType >=0x80) && (*packetType <=0x8f)) || ((*packetType >=0xa0) && (*packetType <=0xa7)) || ((*packetType >=0xc0) && (*packetType <=0xdf))) + return stAudio; + if ( (*packetType >=0x20) && (*packetType <=0x3f)) + return stSubpicture; + return stOther; + } else + return stOther; + +} + + + +int k9Cell::isNavPack (uchar *_ptr) { + uint32_t start_code; + uchar *ptr=_ptr; + if ((ptr [0]!=0) || (ptr [1] !=0) || (ptr [2] != 0x01) || (ptr [3] != 0xba)) + return 0; + + if ((ptr [4] & 0xc0) != 0x40) + return 0; + + // ptr += 14; + + start_code = (uint32_t) (ptr [14]) << 24; + start_code |= (uint32_t) (ptr [15]) << 16; + start_code |= (uint32_t) (ptr [16]) << 8; + start_code |= (uint32_t) (ptr [17]); + + if (start_code != 0x000001bb) + return 0; + + // ptr += 24; + + start_code = (uint32_t) (ptr [0x26]) << 24; + start_code |= (uint32_t) (ptr [0x27]) << 16; + start_code |= (uint32_t) (ptr [0x28]) << 8; + start_code |= (uint32_t) (ptr [0x29]); + + if (start_code != 0x000001bf) + return 0; + + // ptr += 986; + + start_code = (uint32_t) (ptr [0x400]) << 24; + start_code |= (uint32_t) (ptr [0x401]) << 16; + start_code |= (uint32_t) (ptr [0x402]) << 8; + start_code |= (uint32_t) (ptr [0x403]); + + if (start_code != 0x000001bf) + return 0; + + return 1; +} + + + +k9Cell::k9Cell(QObject *parent, const char *name) + : QObject(parent, name) { + vobus.setAutoDelete(true); + numVobu=0; + + vts=0; + pgc=0; + vob=0; + startSector=0; + lastSector=0; + //TO REMOVE oldStartSector=0; + //TO REMOVE oldLastSector=0; + //TO REMOVE newSize=0; + id=0; + selected=false; + copied=false; + //TO REMOVE nbVideoNew=0; + //TO REMOVE nbVideoOld=0; + angleBlock=angleNone; +} + + +k9Cell::~k9Cell() {} + +//add a title in the title list (titles using this cell) +void k9Cell::addTitle( k9DVDTitle *_title) { + m_titles.append( _title); +} + +bool k9Cell::getforceFactor() { + bool m_forced=false; + for (uint i=0; i< m_titles.count() && !m_forced ;i++) { + k9DVDTitle *title=m_titles.at(i); + if (title->getforceFactor()) + m_forced=true; + } + return m_forced; +} + +// returns the shrink factor. +float k9Cell::getFactor() { + float factor=0; + for (uint i=0; i< m_titles.count() ;i++) { + k9DVDTitle *title=m_titles.at(i); + if ((title->getfactor()< factor || factor==0 ) && title->getforceFactor() ) + factor=title->getfactor(); + } + return factor; +} + + +//looking for the end reference frame adress block +void k9Cell::addRefStream(k9Vobu *_vobu,uchar *_buffer,uint32_t _position) { + if (_vobu->firstRefOk && _vobu->secondRefOk && _vobu->thirdRefOk) + return; + //offset of frame + uint start=0x16+_buffer[0x16]+1; + //PES Length + uint length=_buffer[0x12]; + length=(length <<8 ) + _buffer[0x13]; + + //end of PES + uint end=0x14+length; + + if ( _vobu->frameType!=0x18) { + if (!_vobu->firstRefOk) + _vobu->firstRef=_position; + else if (!_vobu->secondRefOk) + _vobu->secondRef=_position; + else if (!_vobu->thirdRefOk) + _vobu->thirdRef=_position; + } + + for (uint i=start;i <end-7;i++) { + //if last picture is not a B-Frame, keep offset of last video + + //looking for start code picture + if ((_buffer[i-5] ==0) &&( _buffer[i-4] ==0) &&( _buffer[i-3] ==1)&&( _buffer[i-2] ==0)) { + uchar frameType=_buffer[i] &0x38; + // if frameType != B-Frame and a reference picture was found + if ((_vobu->frameType!=0x18) && (_vobu->frameType!=0)) { + if (!_vobu->firstRefOk) { + _vobu->firstRefOk=true; + _vobu->firstRef=_position; + } else if (!_vobu->secondRefOk) { + _vobu->secondRefOk=true; + _vobu->secondRef=_position; + } else if (!_vobu->thirdRefOk) { + _vobu->thirdRefOk=true; + _vobu->thirdRef=_position; + } + } + //keep the current frame type + _vobu->frameType=frameType; + } + } + +} + +k9Vobu * k9Cell::addVobu(uint32_t _sector) { + k9Vobu * vobu = new k9Vobu(this,_sector); + vobus.append(vobu); + return vobu; +} + + +void k9Cell::addNewVobus(char *_buffer,uint32_t _len,uint32_t _position,int _vobNum,long _vobPos) { + uint32_t start= _position ;//lastSector - _len ; + k9Vobu *vobu; + for (uint32_t i= 0 ; i<_len ;i+=DVD_BLOCK_LEN) { + if (isNavPack((uchar*)_buffer+i)) { + vobu=(k9Vobu*)vobus.at(numVobu); + vobu->newSector=i/DVD_BLOCK_LEN +start; + numVobu++; + vobu->vobNum=_vobNum; + vobu->vobPos=_vobPos; + //QString c; + //c.sprintf("vobu : %d old: %d new :%d",numVobu-1,vobu->oldSector,vobu->newSector); + //qDebug (c.latin1()); + + } else { + streamType_t st; + int packetType,id; + st=k9Cell::identifyStream((uchar*)_buffer+i,&packetType); + vobu=(k9Vobu*)vobus.at(numVobu-1); + switch (st) { + case stAudio: + id=k9Cell::getStreamID(packetType); + if (vobu->firstAudio[id]==-1) { + vobu->firstAudio[id]= ((i/ DVD_BLOCK_LEN) + start) - vobu->newSector; + } + break; + case stSubpicture: + id=k9Cell::getStreamID(packetType); + if ((id >=0) && (id<32)) { + if (vobu->firstSubp[id]==-1) { + vobu->firstSubp[id]= ((i / DVD_BLOCK_LEN)+start) - vobu->newSector; + } + } + break; + case stVideo: + addRefStream(vobu,(uchar*)_buffer+i,(i/DVD_BLOCK_LEN +start) - vobu->newSector); + if (vobu->firstVideo==-1) { + vobu->firstVideo = ((i / DVD_BLOCK_LEN)+start) - vobu->newSector; + } + //TO REMOVE nbVideoNew++; + break; + } + + } + vobu->size= _position-vobu->newSector; + // �v�ifier + lastSector=_position; + } + +} + +k9Vobu::k9Vobu(k9Cell *_parent,uint32_t _oldSector) + : QObject(_parent,"") { + parent=_parent; + oldSector = _oldSector; + newSector = 0; + size=0; + for (int i=0;i<8;i++) + firstAudio[i]=-1; + for (int i=0;i<32;i++) + firstSubp[i]=-1; + firstVideo=-1; + empty=false; + vobPos=0; + vobNum=0; + frameType=0; + firstRef=0; + secondRef=0; + thirdRef=0; + firstRefOk=false; + secondRefOk=false; + thirdRefOk=false; +} + + +/*! +\fn k9Cell::findVobu(int _oldSector) +*/ +k9Vobu * k9Cell::findVobu(uint32_t _oldSector) { + return vobus.findVobu(_oldSector) ; +} + + +k9Vobu::~k9Vobu() {} + + +k9Cell* k9CellList::addCell(int _vts,int _pgc, int _vob) { + k9Cell* cell=new k9Cell; + cell->cellList=this; + cell->vts=_vts; + cell->vob=_vob; + cell->pgc=_pgc; + + if (count()!=0) { + k9Cell *prev=(k9Cell*)getLast(); + if (prev->vts==_vts) { + cell->startSector= prev->lastSector +1; + if (_pgc!=prev->pgc) + cell->id=1; + else + cell->id=prev->id+1; + } + } else { + cell->startSector = 0; + cell->id=1; + } + append (cell); + return(cell); + +} + +k9Vobu *k9CellList::findVobu(uint32_t sector) { + k9Vobu *vobu=NULL; + k9Cell *cell=findCell(sector); + if (cell==NULL) + return NULL; + else + return cell->findVobu(sector); + + int nbCells=count(); + for (int i=0;i <nbCells;i++) { + k9Cell * cell = (k9Cell*)at(i); + vobu = cell->findVobu(sector); + if (vobu !=NULL) { + return vobu; + } + cell = (k9Cell*)at(nbCells-1-i); + vobu = cell->findVobu(sector); + if (vobu !=NULL) { + return vobu; + } + + + } + return vobu; +} + +k9Cell * k9CellList::findCell(uint32_t sector) { + return findCell(sector,0,count()-1); +} + +k9Cell * k9CellList::findCell(uint32_t sector, uint32_t start, uint32_t end) { + + long lstart=start; + long lend=end; + + while (lstart <=lend) { + long m =(lstart+lend)/2; + k9Cell *cell = (k9Cell *)at(m); + k9Vobu *fv=cell->vobus.first(); + k9Vobu *lv=cell->vobus.last(); + + + if ( sector >=fv->oldSector && sector<= lv->oldSector) { + return cell; + } else if ( fv->oldSector >sector) { + lend = m-1; + } else { + lstart=m+1; + } + } + return NULL; +} + +k9DVDTitleset * k9Cell::getTitleset() { + k9DVDTitle *title=m_titles.at(0); + return title->gettitleset(); +} + + +#include "k9cell.moc" diff --git a/libk9copy/k9cell.h b/libk9copy/k9cell.h new file mode 100755 index 0000000..c253415 --- /dev/null +++ b/libk9copy/k9cell.h @@ -0,0 +1,129 @@ +/*************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef K9CELL_H +#define K9CELL_H + +#include "k9common.h" +#include "k9dvdtitle.h" + + +enum streamType_t {stAudio,stVideo,stSubpicture,stOther}; +/** +@author Jean-Michel Petit +*/ +class k9CellList; +class k9Cell; +class k9DVDTitleset; +class k9Vobu : public QObject { + Q_OBJECT +public: + k9Vobu(k9Cell * parent,uint32_t _oldSector); + ~k9Vobu(); + uint32_t newSector; + uint32_t oldSector; + uint32_t size; + int firstAudio[8]; + int firstSubp[32]; + int firstVideo; + bool empty; + k9Cell *parent; + long vobPos; + int vobNum; + uchar frameType; + uint32_t firstRef,secondRef,thirdRef; + bool firstRefOk,secondRefOk,thirdRefOk; +}; + +class k9VobuList : public QPtrList <k9Vobu> { +public: + k9Vobu *findVobu(uint32_t sector); +private: + k9Vobu * findVobu(uint32_t sector, uint32_t start, uint32_t end); +protected: + int compareItems ( QPtrCollection::Item item1, QPtrCollection::Item item2 ) ; +}; + +class k9Cell : public QObject { + Q_OBJECT +public: + k9Cell(QObject *parent = 0, const char *name = 0); + ~k9Cell(); + k9Vobu * addVobu(uint32_t _sector); + void addNewVobus(char *_buffer,uint32_t _len,uint32_t _position,int _vobNum,long _vobPos); + static int isNavPack (uchar *ptr); + static streamType_t identifyStream( uchar *buffer,int * packetType ); + static int getStreamID(int type); + k9Vobu * findVobu(uint32_t _oldSector); + uint32_t getnewSize(); + void addTitle(k9DVDTitle *_title); + k9DVDTitleset * getTitleset(); + bool getforceFactor(); + float getFactor(); +public: + k9VobuList vobus; + int vts; + int pgc; + int vob; + uint32_t startSector; + uint32_t lastSector; + //TO REMOVE uint32_t ; + //TO REMOVE uint32_t ; + //TO REMOVE uint32_t newSize; + uchar angleBlock; + //TO REMOVE int nbVideoNew,nbVideoOld; + int id; + bool selected; + bool copied; + QValueList<int> audio; + QValueList<int> subpicture; + k9CellList *cellList; +private: + int numVobu; + void addRefStream(k9Vobu *_vobu,uchar *_buffer,uint32_t _position); + QPtrList <k9DVDTitle> m_titles; +}; + + + +class k9CellList : public QPtrList <k9Cell> { +private: + uint32_t m_position; + k9Cell * findCell(uint32_t sector); + k9Cell * findCell(uint32_t sector, uint32_t start, uint32_t end); + +public: + k9CellList() { + m_position=0; + }; + k9Cell *addCell(int _vts, int _pgc,int _vob); + k9Vobu *findVobu(uint32_t sector); + + void setPosition(const uint32_t& _value) { + m_position = _value; + } + + uint32_t getPosition() const { + return m_position; + } + +}; + + +#endif diff --git a/libk9copy/k9cellcopylist.cpp b/libk9copy/k9cellcopylist.cpp new file mode 100644 index 0000000..656da5f --- /dev/null +++ b/libk9copy/k9cellcopylist.cpp @@ -0,0 +1,373 @@ +/*************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#include "k9cellcopylist.h" +#include "k9dvdtitle.h" +#include "k9ifo2.h" + +#include <kmessagebox.h> + +int k9CellVTSList::compareItems ( QPtrCollection::Item item1, QPtrCollection::Item item2 ) { + k9CellCopyVTS * it1,*it2; + it1=(k9CellCopyVTS *) item1; + it2=(k9CellCopyVTS *)item2; + if (it1->getsize() >it2->getsize()) + return 1; + else if (it1->getsize() <it2->getsize()) + return -1; + else { + if (it1->getnum()>it2->getnum()) + return 1; + else + return -1; + } +} + +uint k9CellCopyVTS::getnum() { + return num; +} +void k9CellCopyVTS::addsize(uint32_t _size) { + size+=_size; +} +uint64_t k9CellCopyVTS::getsize() { + return size; +} + +k9CellCopyList::k9CellCopyList(k9DVDRead * _dvdHandle,k9DVD *_DVD) + : QObjectList() { + setAutoDelete(true); + DVD=_DVD; + dvdHandle=_dvdHandle; + fill(); + + +} + +k9CellCopyList::~k9CellCopyList() {} + +/*! + \fn k9CellCopyList::fill() + */ +void k9CellCopyList::fill() { +// k9Ifo2 kifo(dvdHandle) ,kifoZero(dvdHandle); + ifo_handle_t *hifo,*hifoZero; + k9Ifo2 *kifo,*kifoZero; + kifoZero=dvdHandle->getIfo(0); + hifoZero=kifoZero->getIFO(); + +// kifoZero.openIFO( 0); + + int nrTS= hifoZero->vmgi_mat->vmg_nr_of_title_sets; + + for (int iTS=1 ; iTS<=nrTS;iTS++) { + //kifo.openIFO( iTS); + kifo=dvdHandle->getIfo(iTS); + hifo=kifo->getIFO(); + c_adt_t *c_adt = hifo->vts_c_adt; + uint32_t length = c_adt->last_byte + 1 - C_ADT_SIZE; + cell_adr_t *ptr; + ptr= c_adt->cell_adr_table; + uint32_t imax=length/sizeof(cell_adr_t); + + for(uint32_t i = 0; i <imax; i++) { + uchar angleBlock=angleNone; + k9Cell *cell=NULL; + cell=addCell(iTS,0,i+1,ptr[i].start_sector,ptr[i].last_sector,angleBlock); + } + //kifo.closeIFO(); + } + //kifoZero.closeIFO(); + sortVTSList(); + m_frcinbytes=m_frcoutbytes=m_inbytes=m_outbytes=0; +} + + +k9Cell *k9CellCopyList::addCell(int _VTS,int _pgc,int _id,uint32_t startSector,uint32_t lastSector,uchar _angleBlock) { + bool bInsert=false; + bool bFound=false; + uint position=0; + k9Cell *cell =NULL; + + for (uint i=0;i< count() && !bFound && !bInsert;i++) { + cell=(k9Cell*) at(i); + if (cell->startSector ==startSector && cell->vts==_VTS) { + bFound=true; + if (cell->lastSector!=lastSector ) + qDebug("last sector doesn't match","DVD Backup"); + + } + if (!bFound && (_VTS <cell->vts || (startSector<cell->startSector && cell->vts ==_VTS ) )) { + bInsert=true; + position=i; + } + + } + + if (!bFound) { + cell = new k9Cell(); + cell->vts=_VTS; + cell->startSector=startSector; + cell->lastSector=lastSector; + cell->pgc=_pgc; + cell->id=_id; + cell->angleBlock=_angleBlock; + cell->selected=checkSelected(cell); + + if (bInsert) + insert(position,cell); + else + append(cell); + + uint32_t isize; + isize= cell->selected ? ((lastSector-startSector)*2048):2; + setVTS(_VTS,isize); + } + return(cell); +} +void k9CellCopyList::setVTS(uint _numVTS,uint32_t _size) { + bool bfound=false; + for (uint iVTS=0; iVTS<VTSList.count();iVTS++) { + k9CellCopyVTS *VTS=VTSList.at(iVTS); + if (VTS->getnum()==_numVTS) { + VTS->addsize(_size); + bfound=true; + } + } + if (!bfound) { + k9CellCopyVTS * VTS= new k9CellCopyVTS(_numVTS); + VTS->addsize(_size); + VTSList.append(VTS); + } +} + +void k9CellCopyList::sortVTSList() { + VTSList.sort(); +} + + +void k9CellCopyList::addStreams(k9DVDTitle *_title,k9Cell *_cell) { + k9DVDSubtitle *l_sub; + k9DVDAudioStream *l_auds; + for (int i=0;i<_title->getaudioStreamCount();i++) { + l_auds=_title->getaudioStream(i); + if (l_auds->getselected()) { + QValueList<int>::iterator it; + bool found=false; + for ( it = _cell->audio.begin(); it != _cell->audio.end(); ++it ) { + if (*it == l_auds->getID()) + found=true; + } + if (!found) + _cell->audio.append(l_auds->getID()); + } + } + + for (int i=0;i<_title->getsubPictureCount();i++) { + QString c; + l_sub=_title->getsubtitle(i); + if (l_sub->getselected()) { + QValueList<int>::iterator it; + bool found=false; + for ( it = _cell->subpicture.begin(); it != _cell->subpicture.end(); ++it ) { + if (l_sub->getID().contains(*it)) + found=true; + } + if (!found) + _cell->subpicture+=l_sub->getID(); + } + } +} + +/*! + \fn k9CellCopyList::checkSelected(k9Cell *_cell) + */ +bool k9CellCopyList::checkSelected(k9Cell *_cell) { + bool selected=false; + for (int i=0; i< DVD->gettitleCount();i++) { + k9DVDTitle *title=DVD->gettitle(i); +//FACTOR if ( title->getVTS()==_cell->vts && title ->isSelected()) { + if ( title->getVTS()==_cell->vts) { // { && title ->isSelected()) { + for (int j=0; j <title->getchapterCount();j++) { + k9DVDChapter * chapter= title->getChapter(j); + if (_cell->startSector >= chapter->getstartSector() && _cell->startSector<=chapter->getendSector()) { + //add a reference to the title in the titles list from the cell + _cell->addTitle( title); //FACTOR +// if (title->isSelected()) { + if (chapter->getSelected()) { + addStreams (title,_cell); + selected=true; + } + } + } + } + } + return selected; +} + +double k9CellCopyList::gettotalSize() { + double totalSize=0; + for (uint iCell=0;iCell<count();iCell++) { + k9Cell *cell=(k9Cell*)at(iCell); +// if (!cell->copied) { + if (cell->selected) { + if (cell->angleBlock==angleNone) + totalSize += cell->lastSector-cell->startSector; + else if (cell->angleBlock==angleStart) { + uint32_t start=0,end=0; + start=cell->startSector; + // loop inside the angle block to find the last sector. + while (((k9Cell*)at(iCell))->angleBlock !=angleNone) { + end=((k9Cell*)at(iCell))->lastSector; + iCell++; + } + iCell--; + totalSize += end-start; + } + } else + totalSize += 1; + // } + } + return (totalSize*2048); + ; + +} + +//gives the final size of cells with a forced shrink factor +double k9CellCopyList::getforcedSize(bool _withFactor) { + double totalSize=0; + for (uint iCell=0;iCell<count();iCell++) { + k9Cell *cell=(k9Cell*)at(iCell); + double factor = _withFactor ? cell->getFactor():1; + double size=0; +// if (!cell->copied) { + if (cell->selected && cell->getforceFactor() ) { + if (cell->angleBlock==angleNone) + size = cell->lastSector-cell->startSector; + else if (cell->angleBlock==angleStart) { + uint32_t start=0,end=0; + start=cell->startSector; + // loop inside the angle block to find the last sector. + while (((k9Cell*)at(iCell))->angleBlock !=angleNone) { + end=((k9Cell*)at(iCell))->lastSector; + iCell++; + } + iCell--; + size += end-start; + } + totalSize += (size/factor); + } + // } + } + return (totalSize*2048); + +} + +double k9CellCopyList::getMinFactor(bool _withMenus) { + + double fforced=getforcedSize( false); + double MaxSize=k9DVDSize::getMaxSize(); + MaxSize*=1024*1024; + double menuSize=0; + + if (_withMenus) + menuSize=DVD->getmenuSize(); + + menuSize= menuSize*2048; + //totalSize=part of dvd with auto shrink factor/2.5 + //double totalSize=gettotalSize()+menuSize - (fforced-m_frcinbytes) -m_inbytes; + double totalSize=gettotalSize()+menuSize - (fforced) -m_inbytes; + totalSize/=2.50; + +qDebug(QString("totalSize(%1)=gettotalSize()(%2)+menuSize(%3) -(fforced(%4))-m_inbytes(%6)").arg(totalSize).arg(gettotalSize()).arg(menuSize).arg(fforced).arg(m_frcinbytes).arg(m_inbytes)); + + double minFactor=(fforced-m_frcinbytes) /(MaxSize- (totalSize +m_outbytes) - m_frcoutbytes) ; + qDebug(QString("minfactor(%1)=(fforced(%2) -m_frinbytes(%3))/(MacSize(%4)-totalSize(%5)-m_outbytes(%6) - m_frcoutbytes(%7))").arg(minFactor).arg(fforced).arg(m_frcinbytes).arg(MaxSize).arg(totalSize).arg(m_outbytes).arg(m_frcoutbytes)); + + if (minFactor<1) + minFactor=1; + return minFactor; +} + + +double k9CellCopyList::getfactor(bool _withMenus,bool _streams) { + + double totalSize=gettotalSize(); + + if (_streams) { + double unsel=0; + for (int i=0;i<DVD->gettitleCount();i++) { + k9DVDTitle *track=DVD->gettitle(i); + for (int j=0; j<track->getaudioStreamCount();j++) { + k9DVDAudioStream *audio=track->getaudioStream(j); + if (! audio->getselected()) + unsel+=audio->getsize_mb(); + } + for (int j=0; j<track->getsubPictureCount();j++) { + k9DVDSubtitle *sub=track->getsubtitle(j); + if (! sub->getselected()) + unsel+=sub->getsize_mb(); + } + } + unsel*=1024*1024; + totalSize-=unsel; + } + + double menuSize=0; + + if (_withMenus) + menuSize=DVD->getmenuSize(); + + menuSize= menuSize*2048; + + double dvdSize=k9DVDSize::getMaxSize() ; + dvdSize*=1024*1024; + + double factor; + + double fforced=getforcedSize(false)-m_frcinbytes; + double fforcedsh=getforcedSize(true)-m_frcoutbytes; + double dvdSize2=dvdSize-m_outbytes -fforcedsh; + // dvdSize2 -=menuSize; + + if (dvdSize2 <0) { + factor=2.5; + //qDebug(QString("dvdSize (%1)- _outbytes(%2) - fforcedsh(%3)=%4").arg(dvdSize).arg(m_outbytes).arg(fforcedsh).arg(dvdSize2)); + } + else { + factor=(totalSize +menuSize - fforced -m_inbytes)/ dvdSize2 ; + + factor = (int)(factor*100); + factor /=100; + factor+=0.01; + // } + + uint64_t o=m_outbytes; + uint64_t i=m_inbytes; + //if (o==0) + // o=1; + //qDebug(QString("factor : %1 realise : %2").arg(factor).arg((double)i/(double)o)); + + if (factor<=1) + factor=1; + else if (factor>3) + factor=3; + } + + return (factor); +} diff --git a/libk9copy/k9cellcopylist.h b/libk9copy/k9cellcopylist.h new file mode 100644 index 0000000..c338567 --- /dev/null +++ b/libk9copy/k9cellcopylist.h @@ -0,0 +1,97 @@ +/*************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef K9CELLCOPYLIST_H +#define K9CELLCOPYLIST_H + +#include "k9common.h" +#include "k9dvd.h" +#include "k9cell.h" +#include "k9dvdread.h" + +class k9CellCopyVTS { +private: + uint num; + uint64_t size; +public: + k9CellCopyVTS (int _num) { + num=_num; + size=0; + }; + uint getnum() ; + void addsize(uint32_t _size) ; + uint64_t getsize() ; +}; + + +/** +@author Jean-Michel PETIT +*/ + +class k9CellVTSList : public QPtrList<k9CellCopyVTS> { +protected: + int compareItems ( QPtrCollection::Item item1, QPtrCollection::Item item2 ); +}; + + +class k9CellCopyList : public QObjectList { +public: + k9CellCopyList(k9DVDRead * _dvdHandle,k9DVD *_DVD); + double getfactor(bool _withMenus,bool _streams); + double gettotalSize(); + double getforcedSize(bool _withFactor); + double getMinFactor(bool _withMenus); + k9CellVTSList VTSList; + ~k9CellCopyList(); + + void addInbytes(const uint64_t& _value) { + m_inbytes += _value; + } + + + void addOutbytes(const uint64_t& _value) { + m_outbytes += _value; + } + + void addFrcinbytes(const uint64_t& _value) { + m_frcinbytes += _value; + } + + void addFrcoutbytes(const uint64_t& _value) { + m_frcoutbytes += _value; + } + +private: + k9DVD *DVD; + k9DVDRead *dvdHandle; + uint64_t m_inbytes,m_outbytes; + uint64_t m_frcinbytes,m_frcoutbytes; + + void fill(); + k9Cell *addCell(int _VTS,int _pgc,int _id,uint32_t startSector,uint32_t lastSector,uchar _angleBlock); + bool checkSelected(k9Cell *_cell); + void addStreams(k9DVDTitle *_title,k9Cell *_cell); + void setVTS(uint _numVTS,uint32_t _size); + + //QPtrList <k9CellCopyVTS> VTSList; + void sortVTSList(); + +}; + +#endif diff --git a/libk9copy/k9common.h b/libk9copy/k9common.h new file mode 100644 index 0000000..633e8d6 --- /dev/null +++ b/libk9copy/k9common.h @@ -0,0 +1,48 @@ +// +// C++ Interface: k9common +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "config.h" +#ifndef __STDC_LIMIT_MACROS + #define __STDC_LIMIT_MACROS +#endif +#ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS +#endif + +#if defined(HAVE_INTTYPES_H) + #include <inttypes.h> +#elif defined( HAVE_STDINT_H) + #include <stdint.h> +#endif + + +#ifdef __FreeBSD__ + #include <osreldate.h> +#endif +#include "ifo_types.h" +#include "dvd_reader.h" +#include "ifo_read.h" +#include "nav_read.h" +#include "nav_types.h" + +#include <qobject.h> +#include <qobjectlist.h> +#include <qptrlist.h> + +#ifndef DVD_BLOCK_LEN +#define DVD_BLOCK_LEN 2048 +#endif + +#include "k9dvdsize.h" +#ifndef NDEBUG + #define NDEBUG +#endif diff --git a/libk9copy/k9config.cpp b/libk9copy/k9config.cpp new file mode 100644 index 0000000..2824c37 --- /dev/null +++ b/libk9copy/k9config.cpp @@ -0,0 +1,157 @@ +// +// C++ Implementation: k9config +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9config.h" + +k9Config::k9Config() { + m_config=NULL; + read(); +} + +void k9Config::read() { + // if (! m_config->hasGroup( "options")) + // readOldConfig(); + if (m_config!=NULL) + delete m_config; + m_config=new KSimpleConfig("K9Copy"); + + + m_config->setGroup( "dir"); + m_prefOutput=m_config->readEntry("output",locateLocal("tmp","k9copy/",true)); + + m_config->setGroup("devices"); + m_InputDev=m_config->readNumEntry("input",0); + m_OutputDev=m_config->readNumEntry("output",0); + + m_config->setGroup("options"); + m_prefK3b=m_config->readBoolEntry("usek3b",false); + m_prefAutoBurn=m_config->readBoolEntry("autoburn",false); + m_quickScan=m_config->readBoolEntry("quickscan",true); + m_prefSize=m_config->readNumEntry("dvdsize",4400); + m_useDvdAuthor=m_config->readBoolEntry("useDvdAuthor",true); + m_keepMenus=m_config->readBoolEntry("keepMenus",true); + m_prefDelTmpFiles=m_config->readBoolEntry("deltmpfiles",false); + + m_config->setGroup("mp4"); + m_prefMp4Codec=m_config->readNumEntry("codec",0); + m_prefMp4Size=m_config->readNumEntry("size",700); + m_prefMp4NumberCD=m_config->readNumEntry("numberCD",1); + m_prefMp4Width=m_config->readEntry("width","640"); + m_prefMp4Height=m_config->readEntry("height",""); + m_prefMp4AspectRatio=m_config->readBoolEntry("aspectRatio",true); + m_prefMp42Passes=m_config->readBoolEntry("2passes",false); + m_prefMp4AudioBitrate=m_config->readEntry("audiobitrate","128"); + m_prefMp4VideoBitrate=m_config->readEntry("videobitrate" ""); + m_prefMp4AudioCodec=m_config->readNumEntry("audiocodec",0); + m_prefMp4AudioGain=m_config->readNumEntry("audiogain",7); + m_prefUseCellCache=m_config->readBoolEntry("usecellcache",true); + + m_config->setGroup("mencoder"); + m_prefVersion=m_config->readEntry("version",""); + m_codecAudio=m_config->readListEntry("audio"); + m_codecLabels=m_config->readListEntry("labels"); + m_codecLabelsAudio=m_config->readListEntry("audiolabels"); + + + m_codecVideo=m_config->readListEntry("video"); + + m_config->setGroup("devices"); + m_devices=m_config->readListEntry("dev"); + m_devicesLabels=m_config->readListEntry("labels"); + m_devicesIO=m_config->readListEntry("IO"); + + m_config->setGroup("preview"); + m_useMplayer=m_config->readBoolEntry("useMplayer",false); + m_useGL=m_config->readBoolEntry("useGL",false); + m_MplayerVout=m_config->readNumEntry("MplayerVout",0); + m_MplayerAout=m_config->readNumEntry("MplayerAout",0); + + m_config->setGroup("authoring"); + m_prefAudioFormat=m_config->readEntry("audioFormat","AC3"); + m_prefAudioBitrate=m_config->readNumEntry("audioBitrate",192); + m_prefButtonWidth=m_config->readNumEntry("buttonWidth",50); + m_prefButtonHeight=m_config->readNumEntry("buttonHeight",40); + m_prefButtonHiliteColor=m_config->readColorEntry("buttonHiliteColor",&QColor(Qt::yellow)); + m_prefButtonTextColor=m_config->readColorEntry("buttonTextColor",&QColor(Qt::yellow)); + + m_prefButtonFont=m_config->readFontEntry("buttonFont"); + + +} + +void k9Config::save() { + m_config->setGroup( "dir"); + m_config->writeEntry("output",m_prefOutput); + + m_config->setGroup("devices"); + m_config->writeEntry("input", m_InputDev); + m_config->writeEntry("output",m_OutputDev); + + m_config->setGroup("options"); + m_config->writeEntry("usek3b",m_prefK3b); + m_config->writeEntry("autoburn",m_prefAutoBurn); + m_config->writeEntry("quickscan",m_quickScan); + m_config->writeEntry("dvdsize",m_prefSize); + m_config->writeEntry("useDvdAuthor",m_useDvdAuthor); + m_config->writeEntry("keepMenus",m_keepMenus); + m_config->writeEntry("deltmpfiles",m_prefDelTmpFiles); + + m_config->setGroup("mp4"); + m_config->writeEntry("codec",m_prefMp4Codec); + m_config->writeEntry("size",m_prefMp4Size); + m_config->writeEntry("numberCD",m_prefMp4NumberCD); + m_config->writeEntry("width",m_prefMp4Width); + m_config->writeEntry("height",m_prefMp4Height); + m_config->writeEntry("audiobitrate",m_prefMp4AudioBitrate); + m_config->writeEntry("videobitrate",m_prefMp4VideoBitrate); + m_config->writeEntry("aspectRatio",m_prefMp4AspectRatio); + m_config->writeEntry("2passes",m_prefMp42Passes); + m_config->writeEntry("audiogain",m_prefMp4AudioGain); + m_config->writeEntry("audiocodec", m_prefMp4AudioCodec); + m_config->writeEntry("usecellcache",m_prefUseCellCache); + + + m_config->setGroup("mencoder"); + m_config->writeEntry("version",m_prefVersion); + m_config->writeEntry("audio",m_codecAudio); + m_config->writeEntry("labels",m_codecLabels); + m_config->writeEntry("audiolabels",m_codecLabelsAudio); + m_config->writeEntry("video",m_codecVideo); + + m_config->setGroup("devices"); + m_config->writeEntry("dev",m_devices); + m_config->writeEntry("labels",m_devicesLabels); + m_config->writeEntry("IO",m_devicesIO); + + m_config->setGroup("preview"); + m_config->writeEntry("useMplayer",m_useMplayer); + m_config->writeEntry("useGL",m_useGL); + m_config->writeEntry("MplayerVout",m_MplayerVout); + m_config->writeEntry("MplayerAout",m_MplayerAout); + + m_config->setGroup("authoring"); + m_config->writeEntry("audioFormat",m_prefAudioFormat); + m_config->writeEntry("audioBitrate",m_prefAudioBitrate); + m_config->writeEntry("buttonWidth",m_prefButtonWidth); + m_config->writeEntry("buttonHeight",m_prefButtonHeight); + m_config->writeEntry("buttonHiliteColor",m_prefButtonHiliteColor); + m_config->writeEntry("buttonTextColor",m_prefButtonTextColor); + m_config->writeEntry("buttonFont",m_prefButtonFont); + +} + + +k9Config::~k9Config(){ + delete m_config; + +} + + diff --git a/libk9copy/k9config.h b/libk9copy/k9config.h new file mode 100644 index 0000000..13af407 --- /dev/null +++ b/libk9copy/k9config.h @@ -0,0 +1,453 @@ +// +// C++ Interface: k9config +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9CONFIG_H +#define K9CONFIG_H +#include "k9common.h" + +#include <ksimpleconfig.h> +#include <kstandarddirs.h> + +/** + @author Jean-Michel PETIT <[email protected]> +*/ +class k9Config { +private: + KSimpleConfig *m_config; + int m_InputDev; + int m_OutputDev; + bool m_keepMenus; + QString m_prefOutput; + QString m_prefVersion; + bool m_useDvdAuthor; + bool m_quickScan; + int m_prefSize; + bool m_prefK3b; + bool m_prefMenu; + bool m_prefAutoBurn; + int m_prefMp4Codec; + int m_prefMp4AudioCodec; + int m_prefMp4AudioGain; + int m_prefMp4Size; + int m_prefMp4NumberCD; + int m_prefAudioBitrate; + int m_prefButtonWidth; + int m_prefButtonHeight; + bool m_prefMp4AspectRatio; + bool m_prefMp42Passes; + bool m_prefDelTmpFiles; + bool m_prefUseCellCache; + QString m_prefMp4Width; + QString m_prefMp4Height; + QString m_prefMp4AudioBitrate; + QString m_prefMp4VideoBitrate; + QString m_prefAudioFormat; + QStringList m_codecAudio; + QStringList m_codecLabelsAudio; + QStringList m_codecLabels; + QStringList m_codecVideo; + QString m_prefCodecAudio,m_prefCodecVideo,m_prefCodecLabel; + + QStringList m_devices; + QStringList m_devicesLabels; + QStringList m_devicesIO; + + QColor m_prefButtonHiliteColor; + QColor m_prefButtonTextColor; + QFont m_prefButtonFont; + + bool m_useMplayer; + bool m_useGL; + int m_MplayerVout; + int m_MplayerAout; +public: + k9Config(); + void read(); + void save(); + ~k9Config(); + + void setInputDev(const int& _value) { + m_InputDev = _value; + } + + + int getInputDev() const { + return m_InputDev; + } + + void setOutputDev(const int& _value) { + m_OutputDev = _value; + } + + + int getOutputDev() const { + return m_OutputDev; + } + + void setKeepMenus(bool _value) { + m_keepMenus = _value; + } + + + bool getKeepMenus() const { + return m_keepMenus; + } + + void setPrefOutput(const QString& _value) { + m_prefOutput = _value; + } + + QString getPrefOutput() const { + return m_prefOutput; + } + + void setPrefAudioFormat( const QString &_value) { + m_prefAudioFormat=_value; + } + + QString getPrefAudioFormat() const { + return m_prefAudioFormat; + } + + void setPrefVersion(const QString& _value) { + m_prefVersion = _value; + } + + QString getPrefVersion() const { + return m_prefVersion; + } + + void setUseDvdAuthor(bool _value) { + m_useDvdAuthor = _value; + } + + + bool getUseDvdAuthor() const { + return m_useDvdAuthor; + } + + void setPrefDelTmpFiles( bool _value) { + m_prefDelTmpFiles=_value; + } + + bool getPrefDelTmpFiles() const { + return m_prefDelTmpFiles; + } + + void setPrefUseCellCache( bool _value) { + m_prefUseCellCache=_value; + } + + bool getPrefUseCellCache() const { + return m_prefUseCellCache; + } + void setQuickScan(bool _value) { + m_quickScan = _value; + } + + + bool getQuickScan() const { + return m_quickScan; + } + + void setPrefSize(const int& _value) { + m_prefSize = _value; + } + + + int getPrefSize() const { + return m_prefSize; + } + + void setPrefK3b(bool _value) { + m_prefK3b = _value; + } + + + bool getPrefK3b() const { + return m_prefK3b; + } + + void setPrefMenu(bool _value) { + m_prefMenu = _value; + } + + + bool getPrefMenu() const { + return m_prefMenu; + } + + void setPrefAutoBurn(bool _value) { + m_prefAutoBurn = _value; + } + + + bool getPrefAutoBurn() const { + return m_prefAutoBurn; + } + + void setPrefMp4Codec(const int& _value) { + m_prefMp4Codec = _value; + } + + int getPrefMp4Codec() const { + return m_prefMp4Codec; + } + + void setPrefMp4AudioCodec(const int& _value) { + m_prefMp4AudioCodec = _value; + } + + int getPrefMp4AudioCodec() const { + return m_prefMp4AudioCodec; + } + + + void setPrefMp4Size(const int& _value) { + m_prefMp4Size = _value; + } + + + int getPrefMp4Size() const { + return m_prefMp4Size; + } + + void setPrefMp4AudioGain(const int& _value) { + m_prefMp4AudioGain = _value; + } + + + int getPrefMp4AudioGain() const { + return m_prefMp4AudioGain; + } + + void setPrefMp4NumberCD(const int& _value) { + m_prefMp4NumberCD = _value; + } + + + int getPrefMp4NumberCD() const { + return m_prefMp4NumberCD; + } + + void setPrefMp4Width(const QString& _value) { + m_prefMp4Width = _value; + } + + + QString getPrefMp4Width() const { + return m_prefMp4Width; + } + + void setPrefMp4Height(const QString& _value) { + m_prefMp4Height = _value; + } + + + QString getPrefMp4Height() const { + return m_prefMp4Height; + } + + void setPrefMp4AudioBitrate(const QString& _value) { + m_prefMp4AudioBitrate = _value; + } + + + QString getPrefMp4AudioBitrate() const { + return m_prefMp4AudioBitrate; + } + + void setPrefMp4VideoBitrate(const QString& _value) { + m_prefMp4VideoBitrate = _value; + } + + + QString getPrefMp4VideoBitrate() const { + return m_prefMp4VideoBitrate; + } + + void setCodecAudio(const QStringList& _value) { + m_codecAudio = _value; + } + + + QStringList getCodecAudio() const { + return m_codecAudio; + } + + void setCodecLabels(const QStringList& _value) { + m_codecLabels = _value; + } + + + QStringList getCodecLabels() const { + return m_codecLabels; + } + + void setCodecVideo(const QStringList& _value) { + m_codecVideo = _value; + } + + + QStringList getCodecVideo() const { + return m_codecVideo; + } + + + void setCodecLabelsAudio(const QStringList& _value) { + m_codecLabelsAudio = _value; + } + + + QStringList getCodecLabelsAudio() const { + return m_codecLabelsAudio; + } + + + void setDevices(const QStringList& _value) { + m_devices = _value; + } + + + QStringList getDevices() const { + return m_devices; + } + + void setDevicesLabels(const QStringList& _value) { + m_devicesLabels = _value; + } + + + QStringList getDevicesLabels() const { + return m_devicesLabels; + } + + void setDevicesIO(const QStringList& _value) { + m_devicesIO = _value; + } + + + QStringList getDevicesIO() const { + return m_devicesIO; + } + + void setUseMplayer(bool _value) { + m_useMplayer = _value; + } + + + bool getUseMplayer() const { + return m_useMplayer; + } + + void setUseGL(bool _value) { + m_useGL = _value; + } + + + bool getUseGL() const { + return m_useGL; + } + + void setPrefMp4AspectRatio(bool _value) { + m_prefMp4AspectRatio = _value; + } + + + bool getPrefMp4AspectRatio() const { + return m_prefMp4AspectRatio; + } + + void setPrefMp42Passes(bool _value) { + m_prefMp42Passes = _value; + } + + + bool getPrefMp42Passes() const { + return m_prefMp42Passes; + } + + void setMplayerVout(const int& _value) { + m_MplayerVout = _value; + } + + + int getMplayerVout() const { + return m_MplayerVout; + } + + void setMplayerAout(const int& _value) { + m_MplayerAout = _value; + } + + + int getMplayerAout() const { + return m_MplayerAout; + } + + void setPrefAudioBitrate(int _value) { + m_prefAudioBitrate = _value; + } + + + int getPrefAudioBitrate() const { + return m_prefAudioBitrate; + } + + void setPrefButtonWidth(int _value) { + m_prefButtonWidth = _value; + } + + + int getPrefButtonWidth() const { + return m_prefButtonWidth; + } + + void setPrefButtonHeight(int _value) { + m_prefButtonHeight = _value; + } + + + int getPrefButtonHeight() const { + return m_prefButtonHeight; + } + + void setPrefButtonHiliteColor(const QColor& _value) { + m_prefButtonHiliteColor = _value; + } + + + QColor getPrefButtonHiliteColor() const { + return m_prefButtonHiliteColor; + } + + void setPrefButtonTextColor(const QColor& _value) { + m_prefButtonTextColor = _value; + } + + + QColor getPrefButtonTextColor() const { + return m_prefButtonTextColor; + } + + + void setPrefButtonFont(const QFont& _value) { + m_prefButtonFont = _value; + } + + + QFont getPrefButtonFont() const { + return m_prefButtonFont; + } + +}; + +#endif diff --git a/libk9copy/k9drawimage.cpp b/libk9copy/k9drawimage.cpp new file mode 100644 index 0000000..89aba8f --- /dev/null +++ b/libk9copy/k9drawimage.cpp @@ -0,0 +1,49 @@ +// +// C++ Implementation: k9drawimage +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9drawimage.h" +#include <qpainter.h> + +k9DrawImage::k9DrawImage(QWidget *parent, const char *name) + : QWidget(parent, name) +{ +} + + +k9DrawImage::~k9DrawImage() +{ +} + +void k9DrawImage::setImage(const QImage &_image){ + m_pixmap =_image; + repaint(); +} + +void k9DrawImage::setImage(QString _fileName) { + m_pixmap.load(_fileName); + repaint(); +} + +void k9DrawImage::paintEvent ( QPaintEvent * ) { + int top,left; + QPainter p(this); + + double wratio=(double)width()/(double)m_pixmap.width(); + double hratio=(double)height()/(double)m_pixmap.height(); + double ratio= wratio < hratio ? wratio:hratio; + + top =(int) (height() -m_pixmap.height()*ratio)/2+1; + left =(int) (width() -m_pixmap.width()*ratio)/2 ; + + p.scale(ratio,ratio); + p.drawPixmap((int)(left/ratio),(int)(top/ratio),m_pixmap); + } +#include "k9drawimage.moc" diff --git a/libk9copy/k9drawimage.h b/libk9copy/k9drawimage.h new file mode 100644 index 0000000..87c8f9b --- /dev/null +++ b/libk9copy/k9drawimage.h @@ -0,0 +1,36 @@ +// +// C++ Interface: k9drawimage +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9DRAWIMAGE_H +#define K9DRAWIMAGE_H + +#include <qwidget.h> +#include <qpixmap.h> + +/** + @author Jean-Michel PETIT <[email protected]> +*/ +class k9DrawImage : public QWidget +{ +Q_OBJECT +public: + k9DrawImage(QWidget *parent = 0, const char *name = 0); + void setImage(QString _fileName); + void setImage(const QImage &_image); + ~k9DrawImage(); +private: + QPixmap m_pixmap; + +protected: + void paintEvent ( QPaintEvent *); +}; + +#endif diff --git a/libk9copy/k9dvd.cpp b/libk9copy/k9dvd.cpp new file mode 100755 index 0000000..7ef0098 --- /dev/null +++ b/libk9copy/k9dvd.cpp @@ -0,0 +1,1095 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#include "k9dvd.h" +#include "k9dvdtitle.h" +#include "k9dvdtitleset.h" +#include "k9cellcopylist.h" +#include "k9dvdprogress.h" +#include "k9ifo2.h" +#include <qapplication.h> +#include <klocale.h> +#include <kdebug.h> + +#include <sys/stat.h> + + +k9DVDTitle* k9DVD::gettitle(int num) { + return ((k9DVDTitle*)m_titles.at(num)); +} + +k9DVDTitle* k9DVD::gettitleByNum(int num) { + int j=-1; + for (uint i=0; i < m_titles.count();i++) { + k9DVDTitle *track=(k9DVDTitle*)m_titles.at(i); + if (track->getIndexed()) { + j++; + if (j==num) + return track; + } + } + return (NULL); +} + + +/** Read property of int longestTitle. */ +k9DVDTitle *k9DVD::getlongestTitle() { + return m_longestTitle; +} + +/** Read property of QString title. */ +const QString& k9DVD::getDVDTitle() { + return m_title; +} + +void k9DVD::setDVDTitle(const QString &_newVal) { + m_title=_newVal; +} + +/** Read property of int titleCount. */ +const int& k9DVD::gettitleCount() { + return m_titleCount; +} + +/** Read property of int titlesetCount. */ +const int& k9DVD::gettitlesetCount() { + return m_titlesetCount; +} + +k9DVDTitleset *k9DVD::gettitleset(int num) { + return m_titlesets.at(num); +} + +int k9DVD::getmenuSize() { + return m_menuSize; +} + +k9DVD::k9DVD(QObject *parent, const char *name,const QStringList args) { + m_error=false; + m_opened=false; + m_titles.setAutoDelete(true); + m_titlesets.setAutoDelete(true); + m_lvideoFormat.append("NTSC"); + m_lvideoFormat.append("PAL"); + + m_laspectRatio.append("4:3"); + m_laspectRatio.append("16:9"); + m_laspectRatio.append("?:?"); + m_laspectRatio.append("16:9"); + + m_lquantization.append("16bps"); + m_lquantization.append("20bps"); + m_lquantization.append("24bps"); + m_lquantization.append("drc"); + + m_lmpegVersion.append("mpeg1"); + m_lmpegVersion.append("mpeg2"); + + m_lvideoHeight.append("480"); + m_lvideoHeight.append("576"); + m_lvideoHeight.append("???"); + m_lvideoHeight.append("576"); + + m_lvideoWidth.append("720"); + m_lvideoWidth.append("704"); + m_lvideoWidth.append("352"); + m_lvideoWidth.append("352"); + + m_lpermittedDf.append(""); + m_lpermittedDf.append("noletterbox"); + m_lpermittedDf.append("nopanscan"); + m_lpermittedDf.append("noletterbox & nopanscan"); + + m_laudioFormat.append("ac3"); + m_laudioFormat.append("?"); + m_laudioFormat.append("mp2"); + m_laudioFormat.append("mp2"); + m_laudioFormat.append("pcm"); + m_laudioFormat.append("sdds"); + m_laudioFormat.append("dts"); + + m_lsampleFreq.append("48kHz"); + m_lsampleFreq.append("48kHz"); + + m_laudioType.append(""); + m_laudioType.append("Normal"); + m_laudioType.append(i18n("for visually impaired")); + m_laudioType.append(i18n("director's comments")); + m_laudioType.append(i18n("alternate director's comments")); + + m_lsubpType.append(""); + m_lsubpType.append("Normal"); + m_lsubpType.append(i18n("Large")); + m_lsubpType.append(i18n("Children")); + m_lsubpType.append(i18n("reserved")); + m_lsubpType.append(i18n("Normal captions")); + m_lsubpType.append(i18n("Large captions")); + m_lsubpType.append(i18n("Children captions")); + m_lsubpType.append(""); + m_lsubpType.append(i18n("Forced")); + m_lsubpType.append(i18n("reserved")); + m_lsubpType.append(i18n("reserved")); + m_lsubpType.append(i18n("reserved")); + m_lsubpType.append(i18n("Director's comments")); + m_lsubpType.append(i18n("Large director's comments")); + m_lsubpType.append(i18n("Director's comments for children")); + + + m_frames_per_s[0]=-1.0; + m_frames_per_s[1]=25.00; + m_frames_per_s[2]=-1.0; + m_frames_per_s[3]=29.97; + + m_start=NULL; +} +k9DVD::~k9DVD() { + if (m_dvd.opened()) + m_dvd.close(); +} + +int k9DVD::dvdtime2msec(dvd_time_t *dt) { + double fps = m_frames_per_s[(dt->frame_u & 0xc0) >> 6]; + long ms; + ms = (((dt->hour & 0xf0) >> 3) * 5 + (dt->hour & 0x0f)) * 3600000; + ms += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000; + ms += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000; + + if(fps > 0) + ms +=(long)( ((dt->frame_u & 0x30) >> 3) * 5 + (dt->frame_u & 0x0f) * 1000.0 / fps); + + return ms; +} + +/* +* The following method is based on code from vobcopy, by Robos, with thanks. +*/ + +int k9DVD::get_title_name(const char* dvd_device, char* title) { + FILE *filehandle = 0; + int i; + QString c; + if (! (filehandle = fopen(dvd_device, "r"))) { + c=i18n("Couldn't open %1 for title\n").arg(dvd_device); + // setError(c ); + strcpy(title, i18n("unknown").latin1()); + return -1; + } + + if ( fseek(filehandle, 32808, SEEK_SET )) { + fclose(filehandle); + c=i18n("Couldn't seek in %1 for title\n").arg( dvd_device); + setError(c); + strcpy(title, i18n("unknown").latin1()); + return -1; + } + + if ( 32 != (i = fread(title, 1, 32, filehandle)) ) { + fclose(filehandle); + // c=tr2i18n("Couldn't read enough bytes for title.\n"); + // setError(c); + strcpy(title, i18n("unknown").latin1()); + return 0; + } + + fclose (filehandle); + + title[32] = '\0'; + while(i-- > 2) + if(title[i] == ' ') + title[i] = '\0'; + return 0; +} + +QString k9DVD::lang_name(const QString& code,const QString & name) { + QString c; + int i=0; + lng arrLng[] = { + { " ", i18n("Not Specified") }, { "aa", i18n("Afar") }, { "ab", i18n("Abkhazian") }, { "af", i18n("Afrikaans") }, { "am", i18n("Amharic")}, + { "ar", i18n("Arabic") }, { "as", i18n("Assamese") }, { "ay", i18n("Aymara") }, { "az", i18n("Azerbaijani") }, { "ba", i18n("Bashkir") }, + { "be", i18n("Byelorussian") }, { "bg", i18n("Bulgarian") }, { "bh", i18n("Bihari") }, { "bi", i18n("Bislama") }, { "bn", i18n("Bengali; Bangla") }, + { "bo", i18n("Tibetan") }, { "br", i18n("Breton") }, { "ca", i18n("Catalan") }, { "co", i18n("Corsican") }, { "cs", i18n("Czech") }, + { "cy", i18n("Welsh") }, { "da", i18n("Dansk") }, { "de", i18n("Deutsch") }, { "dz", i18n("Bhutani") }, { "el", i18n("Greek") }, { "en", i18n("English") }, + { "eo", i18n("Esperanto") }, { "es", i18n("Espanol") }, { "et", i18n("Estonian") }, { "eu", i18n("Basque") }, { "fa", i18n("Persian") }, + { "fi", i18n("Suomi") }, { "fj", i18n("Fiji") }, { "fo", i18n("Faroese") }, { "fr", i18n("Francais") }, { "fy", i18n("Frisian") }, { "ga", i18n("Gaelic") }, + { "gd", i18n("Scots Gaelic") }, { "gl", i18n("Galician") }, { "gn", i18n("Guarani") }, { "gu", i18n("Gujarati") }, { "ha", i18n("Hausa") }, + { "he", i18n("Hebrew") }, { "hi", i18n("Hindi") }, { "hr", i18n("Hrvatski") }, { "hu", i18n("Magyar") }, { "hy", i18n("Armenian") }, + { "ia", i18n("Interlingua") }, { "id", i18n("Indonesian") }, { "ie", i18n("Interlingue") }, { "ik", i18n("Inupiak") }, { "in", i18n("Indonesian") }, + { "is", i18n("Islenska") }, { "it", i18n("Italiano") }, { "iu", i18n("Inuktitut") }, { "iw", i18n("Hebrew") }, { "ja", i18n("Japanese") }, + { "ji", i18n("Yiddish") }, { "jw", i18n("Javanese") }, { "ka", i18n("Georgian") }, { "kk", i18n("Kazakh") }, { "kl", i18n("Greenlandic") }, + { "km", i18n("Cambodian") }, { "kn", i18n("Kannada") }, { "ko", i18n("Korean") }, { "ks", i18n("Kashmiri") }, { "ku", i18n("Kurdish") }, + { "ky", i18n("Kirghiz") }, { "la", i18n("Latin") }, { "ln", i18n("Lingala") }, { "lo", i18n("Laothian") }, { "lt", i18n("Lithuanian") }, + { "lv", i18n("Latvian, Lettish") }, { "mg", i18n("Malagasy") }, { "mi", i18n("Maori") }, { "mk", i18n("Macedonian") }, { "ml", i18n("Malayalam") }, + { "mn", i18n("Mongolian") }, { "mo", i18n("Moldavian") }, { "mr", i18n("Marathi") }, { "ms", i18n("Malay") }, { "mt", i18n("Maltese") }, + { "my", i18n("Burmese") }, { "na", i18n("Nauru") }, { "ne", i18n("Nepali") }, { "nl", i18n("Nederlands") }, { "no", i18n("Norsk") }, { "oc", i18n("Occitan") }, + { "om", i18n("Oromo") }, { "or", i18n("Oriya") }, { "pa", i18n("Punjabi") }, { "pl", i18n("Polish") }, { "ps", i18n("Pashto, Pushto") }, + { "pt", i18n("Portugues") }, { "qu", i18n("Quechua") }, { "rm", i18n("Rhaeto-Romance") }, { "rn", i18n("Kirundi") }, { "ro", i18n("Romanian") }, + { "ru", i18n("Russian") }, { "rw", i18n("Kinyarwanda") }, { "sa", i18n("Sanskrit") }, { "sd", i18n("Sindhi") }, { "sg", i18n("Sangho") }, + { "sh", i18n("Serbo-Croatian") }, { "si", i18n("Sinhalese") }, { "sk", i18n("Slovak") }, { "sl", i18n("Slovenian") }, { "sm",i18n( "Samoan") }, + { "sn", i18n("Shona") }, { "so", i18n("Somali") }, { "sq", i18n("Albanian") }, { "sr", i18n("Serbian") }, { "ss", i18n("Siswati") }, + { "st", i18n("Sesotho") }, { "su", i18n("Sundanese") }, { "sv", i18n("Svenska") }, { "sw", i18n("Swahili") }, { "ta", i18n("Tamil") }, + { "te", i18n("Telugu") }, { "tg", i18n("Tajik") }, { "th", i18n("Thai") }, { "ti", i18n("Tigrinya") }, { "tk", i18n("Turkmen") }, { "tl", i18n("Tagalog") }, + { "tn", i18n("Setswana") }, { "to", i18n("Tonga") }, { "tr", i18n("Turkish") }, { "ts", i18n("Tsonga") }, { "tt", i18n("Tatar") }, { "tw", i18n("Twi") }, + { "ug", i18n("Uighur") }, { "uk", i18n("Ukrainian") }, { "ur", i18n("Urdu") }, { "uz", i18n("Uzbek") }, { "vi", i18n("Vietnamese") }, + { "vo", i18n("Volapuk") }, { "wo", i18n("Wolof") }, { "xh", i18n("Xhosa") }, { "yi", i18n("Yiddish") }, { "yo", i18n("Yoruba") }, { "za", i18n("Zhuang") }, + { "zh", i18n("Chinese") }, { "zu", i18n("Zulu") }, { "xx", i18n("Unknown") }, { "\0", i18n("Unknown") } }; + c=i18n("Unknown"); + for (i=0 ; arrLng[i].code[0]!=0;i++) { + lng l =arrLng[i]; + if (name=="") { + if (strcmp(code.latin1(),l.code)==0) { + c = l.name; + } + } else { + if (strcmp(name.latin1(),l.name)==0) { + c = l.code; + } + + } + } + return c; +} + + +int k9DVD::calcNumTitle(ifo_handle_t *ifo,int _vts,int _ttn) { + for (int i=0; i< ifo->tt_srpt->nr_of_srpts;i++) { + if (ifo->tt_srpt->title[i].title_set_nr==_vts && ifo->tt_srpt->title[i].vts_ttn == _ttn) + return (i+1); + } + return 0; + +} + +int k9DVD::scandvd (const QString & device,bool _quickScan) { + char ctitle[255]; + k9DVDChapter::setcptChapter(0); + ifo_handle_t *ifo_zero, *ifo; + pgcit_t *vts_pgcit; + vtsi_mat_t *vtsi_mat; + vmgi_mat_t *vmgi_mat; + audio_attr_t *audio_attr; + video_attr_t *video_attr; + subp_attr_t *subp_attr; + pgc_t *pgc; + int i, j, ltitles, cell, vts_ttn, title_set_nr; + char lang_code[3]; + int has_title = 0; + int max_length = 0; + bool ok; + tt_srpt_t *tt_srpt; + QString txt,c; + + m_start=NULL; + int menuSizes[100]; + for ( j=0; j<100;j++) + menuSizes[j]=0; + + m_titles.clear(); + m_Device=device; + + m_error=false; + m_errMsg=""; + + if (!_quickScan) { + m_progressDlg= new k9DVDProgress(qApp->mainWidget(),"progress",true); + m_progressDlg->setpbTitleStep(0); + m_progressDlg->setpbTotalStep(0); + + connect(this, SIGNAL(sigVobProgress(unsigned int,unsigned int)), this, SLOT(slotVobProgress(unsigned int,unsigned int))); + connect(this, SIGNAL(sigTitleProgress(unsigned int,unsigned int)), this, SLOT(slotTitleProgress(unsigned int,unsigned int))); + connect(this, SIGNAL(sigTitleText(QString&)), this, SLOT(slotTitleText(QString&))); + connect(this, SIGNAL(sigTotalText(QString&)), this, SLOT(slotTotalText(QString&))); + m_progressDlg->show(); + } else + m_progressDlg=NULL; + + qApp->processEvents(); + + k9DVDTitle *l_track; + k9DVDAudioStream *l_auds; + k9DVDChapter *l_chap; + k9DVDSubtitle *l_sub; + QString sh,sm,ss; + /* + ret = stat(device.latin1(), &dvd_stat); + if ( ret < 0 ) { + c=i18n("Can't find device %1\n").arg( device); + setError(c); + return 1; + } + */ + + if (m_dvd.opened()) + m_dvd.close(); + m_dvd.openDevice(device); + if( !m_dvd.opened() ) { + c=i18n("Can't open disc %1!\n").arg(device); + setError(c); + return 2; + } + +// k9Ifo2 kifo_zero(&m_dvd),kifo(&m_dvd); +// kifo_zero.openIFO( 0); + k9Ifo2 *kifo_zero= m_dvd.getIfo(0); + k9Ifo2 *kifo; + + ifo_zero = kifo_zero->getIFO(); + if ( !ifo_zero ) { + c=tr2i18n("Can't open main ifo!\n"); + setError(c); + return 3; + } + + ltitles = ifo_zero->tt_srpt->nr_of_srpts; + m_titleCount = 0; + has_title = get_title_name(device.utf8(), ctitle); + + vmgi_mat = ifo_zero->vmgi_mat; + m_titlesetCount = vmgi_mat->vmg_nr_of_title_sets; + + menuSizes[0]=vmgi_mat->vmg_last_sector; + + m_title=( has_title ? tr2i18n("unknown") : ctitle); + + for (int ts=1;ts <=m_titlesetCount;ts++) { + tt_srpt = ifo_zero->tt_srpt; + kifo=m_dvd.getIfo(ts); + ifo = kifo->getIFO(); + if (ifo==NULL) + continue; + //add the titleset in the titleset list + k9DVDTitleset *titleset = new k9DVDTitleset(ts,ifo->vtsi_mat->vts_last_sector -ifo->vtsi_mat->vtstt_vobs-1); + m_titlesets.append(titleset); + + for (j=0; j < ifo->vts_pgcit->nr_of_pgci_srp; j++) { + // tt_srpt->title[j].title_set_nr); + // GENERAL + vtsi_mat = ifo->vtsi_mat; + vts_pgcit = ifo->vts_pgcit; + pgc = vts_pgcit->pgci_srp[j].pgc; + //retrieve the ttn + int ttn=(vts_pgcit->pgci_srp[j].entry_id) & 0x7F; + bool entryPgc= (vts_pgcit->pgci_srp[j].entry_id & 0x80)==0x80; + int numTitle=calcNumTitle(ifo_zero,ts,ttn); + //JMP : vérifier la numérotation des titres ...... + if (vtsi_mat && (pgc->nr_of_cells >0)) { + m_titleCount++; + vts_ttn = ttn;//ifo->vts_ptt_srpt->title[j].ptt[0].pgcn; //ifo_zero->tt_srpt->title[j].vts_ttn; + + //JMPtxt=i18n("Title %1").arg(indexedCount); + txt=i18n("Title %1").arg(numTitle); + emit sigTotalText (txt); + emit sigTitleProgress(numTitle,ltitles); + video_attr = &vtsi_mat->vts_video_attr; + + vmgi_mat = ifo_zero->vmgi_mat; + title_set_nr = ts; //ifo_zero->tt_srpt->title[j].title_set_nr; + menuSizes[title_set_nr]=vtsi_mat->vtstt_vobs + vtsi_mat->vtsi_last_sector +1; + + //vts_pgcit->pgci_srp[ifo->vts_ptt_srpt->title[vts_ttn - 1].ptt[0].pgcn - 1].pgc; + + int titleStartSector=pgc->cell_playback[0].first_sector; + //l_track=addTitle(j+1,title_set_nr,ifo->vts_ptt_srpt->title[vts_ttn - 1].ptt[0].pgcn - 1,titleStartSector,isTitleIndex(ifo_zero,ts,vts_ttn)); + l_track=addTitle(titleset,m_titleCount, numTitle,title_set_nr,j,titleStartSector, entryPgc); + titleset->add + (l_track); + + sh.sprintf("%02x",pgc->playback_time.hour); + sm.sprintf("%02x",pgc->playback_time.minute); + ss.sprintf("%02x",pgc->playback_time.second); + l_track->length.setHMS(sh.toInt(&ok,10),sm.toInt(&ok,10),ss.toInt(&ok,10)); + + //printf(tr2i18n("Title: %02d, Length: %02x:%02x:%02x "), j+1, pgc->playback_time.hour, pgc->playback_time.minute, pgc->playback_time.second); + + if (dvdtime2msec(&pgc->playback_time) > max_length && entryPgc) { + max_length = dvdtime2msec(&pgc->playback_time); + m_longestTitle = l_track; + } + + l_track->chapterCount = pgc->nr_of_programs;// ifo_zero->tt_srpt->title[j].nr_of_ptts; + l_track->audioStreamCount = vtsi_mat->nr_of_vts_audio_streams; + l_track->subPictureCount = vtsi_mat->nr_of_vts_subp_streams; + l_track->VTS = ts;// ifo_zero->tt_srpt->title[j].title_set_nr; + l_track->TTN = ttn; // ifo_zero->tt_srpt->title[j].vts_ttn; + l_track->FPS = m_frames_per_s[(pgc->playback_time.frame_u & 0xc0) >> 6]; + l_track->format= (*m_lvideoFormat.at(video_attr->video_format)); + m_format = l_track->format; + /* QStringList::Iterator it; + it= videoFormat.at(video_attr->video_format); + c= (*it).latin1(); + */ + + l_track->aspectRatio = (*m_laspectRatio.at(video_attr->display_aspect_ratio)); + l_track->width = (*m_lvideoWidth.at(video_attr->picture_size)); + ; + l_track->height = (*m_lvideoHeight.at(video_attr->video_format)); + l_track->DF = (*m_lpermittedDf.at(video_attr->permitted_df)); + + for (i=0; i<16; i++) { + QString pal; + pal.sprintf("%08x",pgc->palette[i]); + l_track->palette.append(pal); + } + + // ANGLES + l_track->angleCount = ifo_zero->tt_srpt->title[j].nr_of_angles; + + // AUDIO + // for (i=0; i<vtsi_mat->nr_of_vts_audio_streams; i++) { + l_track->audioStreamCount=0; + for (i=0; i<vtsi_mat->nr_of_vts_audio_streams; i++) { + if (pgc->audio_control[i]>>8 !=0) { + l_track->audioStreamCount++; + l_auds=l_track->addAudioStream(); + l_auds->id = 1+ ((pgc->audio_control[i]>>8) & 0x7) ; + //this only true for AC3 streams + l_auds->m_streamId = (pgc->audio_control[i]>>8); + audio_attr = &vtsi_mat->vts_audio_attr[i]; + //dts stream starts at 0x88 + if (audio_attr->audio_format==6) + l_auds->m_streamId +=8; + //JMPaudio_attr = &vtsi_mat->vts_audio_attr[l_auds->id-1]; + snprintf(lang_code,3, "%c%c", audio_attr->lang_code>>8, audio_attr->lang_code & 0xff); + if (!lang_code[0]) { + lang_code[0] = 'x'; + lang_code[1] = 'x'; + } + l_auds->langCod=lang_code; + l_auds->language=lang_name(l_auds->langCod,""); + if (l_auds->language==i18n("Unknown")) + l_auds->langCod="xx"; + + l_auds->format= (*m_laudioFormat.at(audio_attr->audio_format)); + l_auds->frequency = (*m_lsampleFreq.at(audio_attr->sample_frequency)); + l_auds->quantization = (*m_lquantization.at(audio_attr->quantization)); + l_auds->channels = audio_attr->channels+1; + l_auds->appMode = audio_attr->application_mode; + l_auds->content = (*m_laudioType.at(audio_attr->code_extension)); + //if (((pgc->audio_control[i]>>8) & 0x80) ==0x80) { + //} else { + // l_auds->id=1; + //} + } + } + l_track->m_defAudio=NULL; + l_track->m_defSubtitle=NULL; + // CHAPTERS + cell = 0; + unsigned long total_sectors = 0; + + l_track->chapterCount= pgc->nr_of_programs; + for (i=0;i < l_track->chapterCount;i++) + l_track->addChapter(i+1); + + k9DVDChapter *l_pchap=NULL; + for (i=0; i<pgc->nr_of_programs; i++) { + int second=0, minute=0, hour=0, tmp; + char hex[3]; + int next = pgc->program_map[i+1]; + unsigned long sectors = 0; + l_chap = l_track->getChapter(i); + //first sector + l_chap->startSector=pgc->cell_playback[cell].first_sector; + ; + l_chap->endSector=0; + if (i == pgc->nr_of_programs - 1) + next = pgc->nr_of_cells + 1; + + int iangleStart=-1,iangleEnd=-1; + while (cell < next - 1) { + //using c2 otherwise the value of cell were lost + //int c2=cell; + //l_chap->cells.append(c2); + int startSect=pgc->cell_playback[cell].first_sector; + l_chap->startSectors.append(startSect); + + snprintf(hex,3, "%02x", pgc->cell_playback[cell].playback_time.second); + tmp = second + atoi(hex); + minute = minute + (tmp / 60); + second = tmp % 60; + snprintf(hex,3, "%02x", pgc->cell_playback[cell].playback_time.minute); + tmp = minute + atoi(hex); + hour = hour + (tmp / 60); + minute = tmp % 60; + + l_chap->endSector= pgc->cell_playback[cell].last_sector; + //last sector + + /* Check if we're entering an angle block. (vamp_play-title) */ + int cell2=cell; + if ( pgc->cell_playback[ cell ].block_type + == BLOCK_TYPE_ANGLE_BLOCK && cell>iangleEnd ) { + iangleStart=cell; + for( int idc = 0;; ++idc ) { + k9ChapterCell * chapterCell=new k9ChapterCell(cell2+idc,idc+1); + l_chap->cells.append(chapterCell); + chapterCell->setstartSector(pgc->cell_playback[cell2+idc].first_sector); + chapterCell->setlastSector(pgc->cell_playback[cell2+idc].last_sector); + if (idc==0) + chapterCell->setangleBlock(angleStart); + else + chapterCell->setangleBlock(angleInside); + if( pgc->cell_playback[ cell2 + idc ].block_mode + == BLOCK_MODE_LAST_CELL ) { + iangleEnd=cell2+idc; + chapterCell->setangleBlock(angleEnd); + sectors += pgc->cell_playback[iangleEnd].last_sector - pgc->cell_playback[iangleStart].first_sector + 1; + + break; + } + } + } else { + if (!(cell>=iangleStart && cell <=iangleEnd)) { + k9ChapterCell * chapterCell=new k9ChapterCell(cell,1); + l_chap->cells.append(chapterCell); + chapterCell->setstartSector(pgc->cell_playback[cell].first_sector); + chapterCell->setlastSector(pgc->cell_playback[cell].last_sector); + + sectors += pgc->cell_playback[cell].last_sector - pgc->cell_playback[cell].first_sector + 1; + + } + } + cell++; + + } + + l_track->vobusize_mb += calcVobuSize(ifo,l_chap); + total_sectors += sectors; + l_chap->length.setHMS(hour,minute,second); + l_chap->sectors=sectors; + if (l_pchap!=NULL) { + QTime t; + int position; + t.setHMS(0,0,0); + position=t.secsTo(l_chap->length); + t=l_pchap->time.addSecs(position); + l_chap->time=t; + } + l_pchap=l_chap; + } + l_track->size_mb =((float)total_sectors *2048)/(1024*1024); + l_track->m_sectors= total_sectors; + // SUBTITLES + l_track->subPictureCount=0; + for (i=0; i<vtsi_mat->nr_of_vts_subp_streams; i++) { + if (pgc->subp_control[i]>>24 !=0) { + l_sub=l_track->addSubtitle(i+1); + unsigned char subpc; + subpc=pgc->subp_control[i]>>24; + if ((subpc & 0x80)==0x80) { + if (l_track->aspectRatio=="4:3") { + l_sub->id.append(1+ (subpc & 0x1F)); + } else { + subpc=(pgc->subp_control[i]>>16) & 0x1F; + l_sub->id.append(1+ subpc); + subpc=(pgc->subp_control[i]>>8) & 0x1F; + if (! l_sub->id.contains(1+ subpc) && ! l_track->DF.contains("noletterbox")) + l_sub->id.append(1+ subpc); + subpc=pgc->subp_control[i] & 0x1F; + if (! l_sub->id.contains(1+ subpc) && ! l_track->DF.contains("nopanscan")) + l_sub->id.append(1+ subpc); + } + kdDebug() << "VTS: " << l_track->VTS << " TTN: " << l_track->TTN << \ + " Subtitle " << i+1 << ": " << l_sub->id << " " << l_sub->language << \ + " " << l_sub->content << endl; + } + l_track->subPictureCount++; + subp_attr = &vtsi_mat->vts_subp_attr[i]; + snprintf(lang_code,3, "%c%c", subp_attr->lang_code>>8, subp_attr->lang_code & 0xff); + if (!lang_code[0]) { + lang_code[0] = 'x'; + lang_code[1] = 'x'; + } + //JMP : l_sub->setselected(!titleIndexed); + l_sub->langCod=lang_code; + l_sub->language=lang_name(lang_code,""); + l_sub->content= (*m_lsubpType.at(subp_attr->code_extension)); + } + } + if (entryPgc && !_quickScan) + calcStreamSize(*l_track); + } + + } + //kifo.closeIFO(); + } + m_menuSize=0; + for (j=0;j<100;j++) + m_menuSize+=menuSizes[j]; + //kifo_zero.closeIFO(); + + if (!_quickScan) + delete m_progressDlg; + + m_progressDlg=0; + m_opened=true; + //m_dvd.close(); + return 0; +} + +float k9DVD::calcVobuSize(ifo_handle_t *_ifo,k9DVDChapter *_chapter) { + vobu_admap_t * vobu_admap = _ifo->vts_vobu_admap; + int length = vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE; + float total=0; + for(uint32_t i = 0; i < length/sizeof(uint32_t); i++) { + if(vobu_admap->vobu_start_sectors[i] >= _chapter->startSector + &&vobu_admap->vobu_start_sectors[i] <= _chapter->endSector) + total++; + } + + total=total*2048; + total=total/(1024*1024); + return total; + +} + +/** Adds a new track in the titles list the list is sorted by VTS and pgc*/ +k9DVDTitle* k9DVD::addTitle(k9DVDTitleset *_titleset,int id,int num,int _VTS,int _pgc,uint32_t _startSector,bool _indexed) { + k9DVDTitle *track,*tmp; + track = new k9DVDTitle; + track->numTitle=num; + track->indexed=_indexed; + track->id=id; + track->m_titleset=_titleset; + //JMP : modification + track->forceSelection = false; // !_indexed; + + track->ts_nr=_VTS; + track->pgc=_pgc; + bool bappend=true; + for (uint i=0;i<m_titles.count();i++) { + tmp=(k9DVDTitle*)m_titles.at(i); + k9DVDChapter *chap =tmp->getChapter(0); + + if (tmp->ts_nr >_VTS) { + bappend=false; + } else if ( (tmp->ts_nr==_VTS) && ((tmp->pgc >_pgc) || (chap->getstartSector() > _startSector)) ) { + bappend=false; + } + if (!bappend) { + m_titles.insert(i,track); + break; + } + + } + if (bappend) + m_titles.append(track); + track->name=i18n("Title %1").arg(num); + + if (!_indexed) { + for (uint i=0;i<m_titles.count();i++) { + tmp=(k9DVDTitle*)m_titles.at(i); + if (tmp->numTitle==num && tmp->indexed) + tmp->m_titles.append(track); + } + } + + return(track); + +} + +void k9DVD::calcStreamSize(k9DVDTitle & track) { + struct stream_counter streams[64]; + int stream_count; + int start = 0; + int stop = 0; + k9DVDChapter *c_start,*c_stop; + struct streamSize streamList[64]; + int c, x; + QString pg; + + for( x=0 ; x<64 ; x++ ) { // init stream usage list + streams[x].id = 0; + streams[x].count = 0; + streams[x].size_mb = 0; + streams[x].percent = 0; + streamList[x].id=0; + streamList[x].percent=0; + streamList[x].size_mb=0; + } + + x = 0; + c = 0; + + if( track.chapterCount == 2 ) { // select which chapters to probe for stream sizes + start=0; + stop=1; + } + if (track.chapterCount == 1) { + start=0; + stop=0; + } + if (track.chapterCount >2) { + start=0; + stop=(int)(track.chapterCount-1); + } + c_start=(k9DVDChapter*)track.chapters.at(start); + c_stop=(k9DVDChapter*)track.chapters.at(stop); + pg=tr2i18n("reading title"); + emit sigTitleText(pg); + + //probe stream usage + c = stream_vob( track.ts_nr,c_start->startSector, c_stop->endSector, streams); + + for( x=0 ; x<64 ; x++ ) { + if( streams[x].id == 0 ) + break; + streams[x].percent = (float)streams[x].count / (float)(c / 100.); // calc usage in percent + } + // create streamlist with all streams + stream_count=0; + for( c=0 ; c<64 ; c++ ) { + if( streams[c].id == 0 ) + break; + streamList[stream_count].id = streams[c].id; + if( stream_count >= 64 ) + break; + stream_count++; + x++; + } + + // other_streams_mb = 0; // calc size of all selected streams + for( x=0 ; x<stream_count ; x++ ) { + for( c=0 ; c<64 ; c++ ) { + if( streamList[x].id == streams[c].id ) { + streamList[x].percent=streams[c].percent; + streamList[x].size_mb= (float) ((track.size_mb / 100.) * streams[c].percent); + } + } + } + + k9DVDAudioStream *l_auds; + k9DVDSubtitle *l_sub; + k9DVDTitle *l_track; + int i; + l_track=&track; + + for (x=0;x<64;x++) { + if (streamList[x].id==0) + break; + if (streamList[x].id== 0xe0) + l_track->videosize_mb = streamList[x].size_mb; + } + + for (i=0;i<l_track->audioStreamCount;i++) { + l_auds=(k9DVDAudioStream*)l_track->audioStreams.at(i); + for (x=0;x<64;x++) { + if (streamList[x].id==0) + break; + int id=streamList[x].id; + if (( (id >=0x80) && (id <=0x8f)) || ((id >=0xa0) && (id <=0xa7)) || ((id >=0xc0) && (id <=0xdf))) { + if ( getVampsID(id) == l_auds->id) { + l_auds->size_mb = streamList[x].size_mb; + //stop the loop, go to next audio stream + break; + } + } + + } + } + for (i=0;i<l_track->subPictureCount;i++) { + l_sub=(k9DVDSubtitle*)l_track->subtitles.at(i); + for (x=0;x<64;x++) { + if (streamList[x].id==0) + break; + int id=streamList[x].id; + if ( (id >=0x20) && (id <=0x3f)) { + if ( l_sub->id.contains(id - 0x20 +1) ) { + l_sub->size_mb = streamList[x].size_mb; + break; + } + } + } + } + + +} + +int k9DVD::identify_stream( unsigned char *buffer ) { + uint8_t packet_type = buffer[17]; + + if( (packet_type >= 0xE0) && (packet_type <= 0xEF) ) { // video streams + ; + } else if( packet_type == 0xBB ) { // system header + ; + } else if( packet_type == 0xBE ) { // padding + ; + } else if( packet_type == 0xBF ) { // nav pack + ; + } else if( (packet_type >= 0xC0) && (packet_type <= 0xDF) ) { // mpeg audio + ; + } else if( packet_type == 0xBD ) { // private stream, check content + packet_type = buffer[23+buffer[22]]; + } + + return packet_type; +} + +long k9DVD::stream_vob( int title, unsigned long startblock, unsigned long lastblock, struct stream_counter *sc) { + + k9DVDFile *dvdfile; + //JMP unsigned char buffer[DVD_VIDEO_LB_LEN]; + unsigned char buffer[DVD_VIDEO_LB_LEN*800]; + unsigned char *ptrbuff; + int blocksize=800,y; + int step=(int)((lastblock-startblock)/800) / 10;// * 0.05; + if (step==0) + step=1; + unsigned char stream_id; + long total=0; + unsigned long i, x ,nbread=0; + ssize_t size; + QString c; + dvdfile =m_dvd.openTitle( title); + if( !dvdfile ) { + c=i18n("Error opening vobs for title %1\n").arg( title); + setError(c); + return 0; + } + + i = startblock; + while( (i >= startblock) && (i <= lastblock) && (blocksize>0)) { // read blocks + size= dvdfile->readBlocks( i,blocksize , buffer); + emit sigVobProgress(i-startblock,lastblock-startblock); + total+=size; + if( !size ) { + c=i18n("ERROR reading block %1\n").arg(i); + setError(c); + break; + } + ptrbuff=buffer; + for (y=0;y<blocksize;y++) { + stream_id = identify_stream(ptrbuff); // get stream id + nbread++; + for( x=0 ; x<64 ; x++ ) { // scan for already present counter + if( sc[x].id != 0 ) { + if( stream_id != sc[x].id ) { + continue; + } + } + + sc[x].id = stream_id; // increase stream packet counter + sc[x].count++; + break; + } + ptrbuff+=DVD_VIDEO_LB_LEN; + } + i+=blocksize*step;// 6; + if (i+blocksize> lastblock) + blocksize=lastblock-i; + + } + + dvdfile->close(); + return total; +} + + + +uint64_t k9DVD::getsizeSelected(bool _streams) { + uint64_t selstreams=0,vidstreams=0; + int i,x; + k9DVDTitle *l_track; + k9DVDAudioStream *l_auds; + k9DVDSubtitle *l_sub; + bool withvideo; + + for (i=0;i<m_titleCount;i++) { + l_track=gettitle(i); + + withvideo=l_track->isSelected() && l_track->getIndexed(); + + if ( withvideo) { + vidstreams +=l_track->getsectors(); + if (_streams) { + for (x=0;x<l_track->audioStreamCount;x++) { + l_auds=l_track->getaudioStream(x); + if (!l_auds->selected) + selstreams += l_auds->size_mb*512; + } + for (x=0;x<l_track->subPictureCount;x++) { + l_sub=l_track->getsubtitle(x); + if (!l_sub->selected) + selstreams += l_sub->size_mb*512; + } + } + } + } + vidstreams -=selstreams; + + return (vidstreams ); +} + + +float k9DVD::getfactor(bool _withMenus,bool _streams,bool _useDvdAuthor) { + if (!_useDvdAuthor || _withMenus) { + //m_dvd.openDevice(Device); + k9CellCopyList *cellCopyList =new k9CellCopyList(&m_dvd,this); + double factor=cellCopyList->getfactor(_withMenus,_streams); + //m_dvd.close(); + return (factor); + } else { + float selstreams=0,vidstreams=0,l_factor; + int i,x; + k9DVDTitle *l_track; + k9DVDAudioStream *l_auds; + k9DVDSubtitle *l_sub; + bool withvideo; + double forced=0,forcedsh=0; + for (i=0;i<m_titleCount;i++) { + l_track=gettitle(i); + + withvideo=l_track->isSelected() && l_track->getIndexed(); + + if ( withvideo) { + //size_mb = size of titles - size of unselected chapters + float size_mb=l_track->gettotalsize_mb()-l_track->getChaptersSize_mb( false) ; //gettotalsize_mb does include parts of titles + vidstreams +=size_mb ; + if (l_track->getforceFactor()) { + forced+=size_mb; + forcedsh+=(size_mb/l_track->getfactor()); + } + if (_streams) { + for (x=0;x<l_track->audioStreamCount;x++) { + l_auds=l_track->getaudioStream(x); + if (!l_auds->selected) + selstreams += l_auds->size_mb; + } + for (x=0;x<l_track->subPictureCount;x++) { + l_sub=l_track->getsubtitle(x); + if (!l_sub->selected) + selstreams += l_sub->size_mb; + } + } + } + } + vidstreams -=selstreams; + + l_factor = ((float) vidstreams - forced) / (k9DVDSize::getMaxSize() - forcedsh); + l_factor = (int)((l_factor+0.01)*100); + l_factor /=100; + if (l_factor <1) + l_factor=1; + + return(l_factor); + } +} +void k9DVD::slotVobProgress(unsigned int position,unsigned int total) { + m_progressDlg->setpbTitleStep(position); + m_progressDlg->setpbTitleTotalSteps(total); + qApp->processEvents(); +} + +void k9DVD::slotTitleProgress(unsigned int position,unsigned int total) { + m_progressDlg->setpbTotalStep(position); + m_progressDlg->setpbTotalTotalSteps(total); + qApp->processEvents(); +} + +void k9DVD::slotTitleText(QString& text) { + m_progressDlg->setlblTitle(text); + qApp->processEvents(); +} + +void k9DVD::slotTotalText(QString& text) { + m_progressDlg->setlblTotal(text); + qApp->processEvents(); +} + +const QString& k9DVD::getDevice() { + return m_Device; +} + +const bool& k9DVD::geterror() { + return m_error; +} + +const QString& k9DVD::geterrMsg() { + return m_errMsg; +} + +void k9DVD::setError(const QString & err) { + m_error=true; + m_errMsg=err; + if (m_progressDlg !=NULL) + m_progressDlg->hide(); +} + +const bool& k9DVD::getopened() { + return m_opened; +} + + +QString &k9DVD::getFormat() { + return (m_format); +} + +int k9DVD::getVampsID(int type) { + int abase; + if (type >= 0x80 && type <= 0x87) { + // AC3 audio + abase = 0x80; + } else if (type >= 0x88 && type <= 0x8f) { + // DTS audio + abase = 0x88; + } else if (type >= 0xa0 && type <= 0xbf) { + // LPCM audio + abase = 0xa0; + } else if (type >= 0xc0 && type <= 0xdf) { + // MPEG audio + abase = 0xc0; + } + + return (type-abase +1); + +} + + +k9DVDTitle* k9DVD::getstart() { + return m_start; +} + +void k9DVD::setstart(k9DVDTitle* title) { + m_start=title; +} + +// returns the title number in the reauthored DVD +int k9DVD::getnewTitleNum(k9DVDTitle *title) { + int num=0; + k9DVDTitle *tr; + for (int i=0 ;i < m_titleCount;i++) { + tr=gettitle(i); + if (tr->isSelected() && tr->getIndexed()) { + ++num; + if (tr->getnumTitle() == title->getnumTitle()) + return(num); + } + } + + return(-1); +} + + +void k9DVD::close() { + m_opened=false; + if (m_dvd.opened()) + m_dvd.close(); + m_titles.clear(); + m_titlesets.clear(); +} diff --git a/libk9copy/k9dvd.h b/libk9copy/k9dvd.h new file mode 100755 index 0000000..55182df --- /dev/null +++ b/libk9copy/k9dvd.h @@ -0,0 +1,174 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef K9DVD_H +#define K9DVD_H +#include "k9common.h" +#include "k9dvdread.h" +#include <qstringlist.h> +#include <qdatetime.h> +#include <qvaluelist.h> + + +struct streamSize { + unsigned char id; + float size_mb; + float percent; +}; + +struct stream_counter { + unsigned char id; + int count; + float size_mb; + float percent; +}; + +class k9DVDProgress; +class k9DVDChapter; +class k9DVDTitle; +class k9DVDTitleset; + +/** get the DVD structure with titles lengths and streams lengths. + *@author + */ + +class k9DVD : public QObject { +Q_OBJECT +private: + QObjectList m_titles; + QPtrList<k9DVDTitleset> m_titlesets; + QString m_title; + int m_titleCount; + k9DVDTitle *m_longestTitle; + QStringList m_lvideoFormat; + QStringList m_laspectRatio; + QStringList m_lquantization; + QStringList m_lmpegVersion; + QStringList m_lvideoHeight; + QStringList m_lvideoWidth; + QStringList m_lpermittedDf; + QStringList m_laudioFormat; + QStringList m_lsampleFreq; + QStringList m_laudioType; + QStringList m_lsubpType; + QStringList m_langCode; + QStringList m_langName; + double m_frames_per_s[4]; + uint m_menuSize; + k9DVDProgress *m_progressDlg; + QString m_Device; + bool m_error; + QString m_errMsg; + bool m_opened; + QString m_format; + k9DVDTitle* m_start; + int m_titlesetCount; +public: + k9DVD(QObject *parent=0,const char *name=0,const QStringList args=0) ; + ~k9DVD(); + + /** + * Opens and estimates the size of each stream + * @param device input device + * @return return code (0=ok) + */ + virtual int scandvd (const QString & device,bool _quickScan); + + /** + * gets the title of the DVD + * @return DVD title + */ + virtual const QString& getDVDTitle(); + + /** + * set the title of the DVD + * @param _newVal the new DVD title + */ + virtual void setDVDTitle(const QString &_newVal); + + /** + * + * @return returns the number of titles + */ + virtual const int& gettitleCount(); + + /** + * + * @return returns the number of titlesets + */ + virtual const int& gettitlesetCount(); + + + /** + * returns a title of the DVD + * @param num the title number + * @return the title + */ + virtual k9DVDTitle* gettitle(int num); + + /** + * returns a title (which is in tt_srpt) + * @param num the title number + * @return the title + */ + virtual k9DVDTitle* gettitleByNum(int num); + virtual k9DVDTitle *getlongestTitle(); + virtual float getfactor(bool withMenus,bool _streams,bool _useDvdAuthor); + virtual const QString& getDevice(); + virtual const bool& geterror(); + virtual const QString& geterrMsg(); + virtual const bool& getopened(); + virtual uint64_t getsizeSelected(bool _streams); + virtual QString &getFormat(); + virtual k9DVDTitle* getstart(); + virtual void setstart(k9DVDTitle* title); + virtual int getnewTitleNum(k9DVDTitle *title); + virtual int getmenuSize(); + virtual void close(); + virtual k9DVDTitleset *gettitleset(int num); + virtual k9DVDRead * getdvd() {return &m_dvd;} + static QString lang_name(const QString & code,const QString & name); +private: // Private methods + k9DVDRead m_dvd; + k9DVDTitle* addTitle(k9DVDTitleset *titleset,int id,int num,int _VTS,int _pgc,uint32_t _startSector, bool _indexed); + float calcVobuSize(ifo_handle_t *_ifo,k9DVDChapter *_chapter); + long stream_vob( int title, unsigned long startblock, unsigned long lastblock, struct stream_counter *sc); + int identify_stream( unsigned char *buffer ) ; + int dvdtime2msec(dvd_time_t *dt); + int get_title_name(const char* dvd_device, char* title); + void calcStreamSize(k9DVDTitle & title); + void setError(const QString &err); + int getVampsID(int type); + int calcNumTitle(ifo_handle_t *ifo,int _vts,int _ttn); +public slots: // Public slots + void slotVobProgress(unsigned int position,unsigned int total); + void slotTitleProgress(unsigned int position,unsigned int total); + void slotTitleText(QString &text); + void slotTotalText(QString &text); +signals: // Signals + void sigVobProgress(unsigned int position,unsigned int total); + void sigTitleProgress(unsigned int position,unsigned int total); + void sigTitleText(QString &text); + void sigTotalText(QString &text); +}; + +typedef struct lng { char code[3]; QString name;}; + +#endif + diff --git a/libk9copy/k9dvdauthor.cpp b/libk9copy/k9dvdauthor.cpp new file mode 100755 index 0000000..8ee4959 --- /dev/null +++ b/libk9copy/k9dvdauthor.cpp @@ -0,0 +1,591 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#include "k9dvdauthor.h" +#include "k9dvdtitle.h" +#include "k9dvdbackup.h" +#include "kmessagebox.h" +#include "k9tools.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <qdom.h> +#include <qfile.h> +#include <qnamespace.h> +#include <qprocess.h> +#include <qdir.h> +#include <qdatetime.h> +#include <qdatastream.h> +#include <qfile.h> +#include <qlabel.h> +#include <qprogressdialog.h> +#include <signal.h> +#include <klocale.h> +#include <qvaluelist.h> +#include <kstandarddirs.h> +#include <qapplication.h> + + +class k9Progress; + +k9DVDAuthor::k9DVDAuthor(QObject *DVDStruct,const char* name,const QStringList& args) { + DVD=(k9DVD*)DVDStruct; + xml=NULL; + cancelled=false; + error=false; + progress = new k9Progress(qApp->mainWidget(),"progress",NULL); + files.setAutoDelete(true); + +} +k9DVDAuthor::~k9DVDAuthor() { + QPtrListIterator <KTempFile> it (files); + KTempFile *file; + while ( (file = it.current()) != 0 ) { + ++it; + file->file()->remove(); + } + if (xml!=NULL) + delete xml; + +} +/** No descriptions */ +void k9DVDAuthor::createXML() { + int i; + if (xml!=NULL) + delete xml; + xml=new QDomDocument(); + + QDomElement root = xml->createElement( "dvdauthor" ); + root.setAttribute ("dest",workDir+"dvd"); + xml->appendChild( root ); + + // Create vmgm menu + QDomElement vmgm = xml->createElement("vmgm"); + root.appendChild(vmgm); + addMenus(vmgm); + + m_totalPartSize=0; + + m_forced=0; + m_forcedsh=0; + uint64_t chapterssize=0; + //computes the size of related titles + for (int iTitle=0; iTitle < DVD->gettitleCount();iTitle++) { + k9DVDTitle *title=DVD->gettitle(iTitle); + if (title->isSelected() && title->getIndexed()) { + chapterssize+= title->getChaptersSize(false); + for (int iTitle2=0;iTitle2<title->getTitles().count() ;iTitle2++) { + k9DVDTitle *title2=title->getTitles().at(iTitle2); + m_totalPartSize+= title2->getsize_mb() *1024*1024; + if (title->getforceFactor()) { + m_forced+=title2->getsectors()*2048; + m_forcedsh+=(title2->getsectors()/title->getfactor())*2048; + } + chapterssize+= title2->getChaptersSize(false); + } + } + //total size of forced titles + if (title->isSelected() && title->getforceFactor()) { + m_forced+=title->getsectors()*2048; + m_forcedsh+=(title->getsectors()/title->getfactor())*2048; + } + + } + + //total size of titles to copy + m_totalSize=((uint64_t)DVD->getsizeSelected(false))*DVD_VIDEO_LB_LEN + m_totalPartSize -chapterssize*DVD_VIDEO_LB_LEN; + + m_firsttitle=true; + + for (i=0;i< DVD->gettitleCount();i++) { + k9DVDTitle *tmp = DVD->gettitle(i); + addTitle(root,tmp); + } + + QString x = xml->toString(); + + //QFile file( locateLocal("tmp", "k9copy/k9author.xml" )); + + // if ( file.open( IO_WriteOnly ) ) { + QTextStream stream( m_xml->file() ); + xml->save(stream,1); + m_xml->file()->close(); + // } +} + +void k9DVDAuthor::addMenus(QDomElement &titleSet) { + int i; + QDomElement menu,video,pgc,pre,vob,button; + QDomText precmd; + QDomText buttonText; + QTime max(0,0); + QString c,start; + + k9DVDTitle * l_track= DVD->getstart(); + if (l_track==NULL) { + start="call vmgm menu;"; + } else { + if( DVD->getnewTitleNum(l_track)==-1) { + error=true; + QString sMsg; + //sMsg.QString::sprintf(tr2i18n("'%s' not selected"),l_track->getname().latin1()); + sMsg=i18n("'%1' not selected").arg(l_track->getname()); + KMessageBox::error( 0,sMsg, tr2i18n("authoring")); + } + start.sprintf("jump titleset %d menu;",DVD->getnewTitleNum(l_track)); + } + factor=DVD->getfactor(false,false,true); + menu=xml->createElement("menus"); + titleSet.appendChild(menu); + pgc=xml->createElement("pgc"); + pgc.setAttribute("entry","title"); + menu.appendChild(pgc); + pre=xml->createElement("pre"); + pgc.appendChild(pre); + precmd=xml->createTextNode(""); + QString cmd="if (g0==0) \n { \n subtitle=0; \n g0=1;\n "+start+"\n}\n"; + pre.appendChild(precmd); + int numt=0; + + for (i=0;i < DVD->gettitleCount();i++) { + if (DVD->gettitle(i)->isSelected() && DVD->gettitle(i)->getIndexed()) { + ++numt; + cmd+=c.sprintf("if (g1==%d) {jump titleset %d menu;}\n", numt,numt); + } + } + + precmd.setNodeValue(cmd); +} + +/** No descriptions */ +void k9DVDAuthor::addTitle(QDomElement &root, k9DVDTitle *title) { + int i,j; + + k9DVDSubtitle *l_sub; + k9DVDAudioStream *l_auds; + k9DVDTitle *l_track= title; + QDomElement e,t,pgc; + QString caud="",csub="",c,palette; + + if (l_track->isSelected() && l_track->getIndexed()) { + double titleFactor; + if (l_track->getforceFactor()) + titleFactor=l_track->getfactor(); + else + titleFactor=factor; + QDomElement titleSet = xml->createElement("titleset"); + root.appendChild(titleSet); + QDomElement titleMenu = xml->createElement("menus"); + titleSet.appendChild(titleMenu); + QDomElement pgc = xml->createElement("pgc"); + titleMenu.appendChild(pgc); + QDomElement pre = xml->createElement("pre"); + pgc.appendChild(pre); + QDomText precmd=xml->createTextNode(""); + + int subtitle=0,audio=-1; + if (l_track->getDefSubtitle() != NULL) { + for (int isub=0;isub<l_track->getsubPictureCount();isub++) { + if (l_track->getsubtitle(isub)->getselected()) { + subtitle++; + } + if (l_track->getsubtitle(isub)==l_track->getDefSubtitle()) + break; + } + } + if (l_track->getDefAudio() != NULL) { + for (int iaud=0;iaud < l_track->getaudioStreamCount();iaud++) { + if (l_track->getaudioStream(iaud)->getselected()) { + audio++; + } + if(l_track->getaudioStream(iaud)==l_track->getDefAudio()) + break; + } + } + + QString txtcmd; + if (audio !=-1) { + txtcmd="subtitle=%1;\n audio=%2;\n g1=0;jump title 1;"; + txtcmd=txtcmd.arg(subtitle+63).arg(audio); + } else { + txtcmd="subtitle=%1;\n g1=0;jump title 1;"; + txtcmd=txtcmd.arg(subtitle+63); + } + + precmd.setNodeValue(txtcmd); + pre.appendChild(precmd); + + //create palette for subpictures + KTempFile *paletteFile=new KTempFile(locateLocal("tmp", "k9copy/k9p"), ".yuv"); + files.append(paletteFile); + paletteFile->setAutoDelete(false); + palette=paletteFile->name(); + + //palette.sprintf("palette%d.yuv",l_track->getnumTitle()); + //palette= locateLocal("tmp", "k9copy/k9" +palette); + QTextStream stream( paletteFile->file() ); + for (j=0;j<16;j++) { + l_track->getpalette(j,c); + stream << c+"\n"; + } + paletteFile->file()->close(); + + t=xml->createElement("titles"); + titleSet.appendChild(t); + e=xml->createElement("video"); + e.setAttribute("aspect",l_track->getaspectRatio()); + e.setAttribute("format",l_track->getformat().lower()); + if (l_track->getaspectRatio()!="4:3") { + e.setAttribute("widescreen","nopanscan"); + } + t.appendChild(e); + + for (i=0;i<l_track->getaudioStreamCount();i++) { + l_auds=l_track->getaudioStream(i); + if (l_auds->getselected()) { + e=xml->createElement("audio"); + e.setAttribute("format",l_auds->getformat()); + e.setAttribute("channels",l_auds->getchannels()); + e.setAttribute("quant",l_auds->getquantization()); + e.setAttribute("lang",l_auds->getlangCod()); + t.appendChild(e); + if (caud != "") + caud+=','; + caud+=c.sprintf("%d",l_auds->getID()); + } + } + + for (i=0;i<l_track->getsubPictureCount();i++) { + l_sub=l_track->getsubtitle(i); + if (l_sub->getselected()) { + e=xml->createElement("subpicture"); + e.setAttribute("lang",l_sub->getlangCod()); + t.appendChild(e); + if (csub !="") + csub+=','; + csub+=c.sprintf("%d",(l_sub->getID()).first()); + } + } + + pgc=xml->createElement("pgc"); + pgc.setAttribute("palette",palette); + t.appendChild(pgc); +/* + for (i=0;i<l_track->getaudioStreamCount();i++) { + l_auds=l_track->getaudioStream(i); + if (l_auds->getselected()) { + e=xml->createElement("audio"); + e.setAttribute("id",l_auds->getID()-1); + t.appendChild(e); + if (caud != "") + caud+=','; + caud+=c.sprintf("%d",l_auds->getID()); + } + } + + for (i=0;i<l_track->getsubPictureCount();i++) { + l_sub=l_track->getsubtitle(i); + if (l_sub->getselected()) { + e=xml->createElement("subpicture"); + e.setAttribute("id",(l_sub->getID()).first()-1); + t.appendChild(e); + if (csub !="") + csub+=','; + csub+=c.sprintf("%d",(l_sub->getID()).first()); + } + } +*/ + if (caud !="") + caud="--audiofilter "+caud; + if (csub !="") + csub="--subpicturefilter "+csub; + + int numPart=0; + + for (int iTitle=0;iTitle<=l_track->getTitles().count();iTitle++) { + k9DVDTitle *title; + if (iTitle==0) + title=l_track; + else + title=l_track->getTitles().at(iTitle-1); + + for (i=0;i<title->getchapterCount();i++) { + numPart++; + uint icell=0; + k9DVDChapter *l_chap=title->getChapter(i); + if (!l_chap->getSelected()) + continue; + + bool first=true; + uint32_t chapterSize= (l_chap->getendSector()-l_chap->getstartSector())*DVD_VIDEO_LB_LEN; + QString sChapter,sCell; + + for (k9ChapterCell *cell =l_chap->cells.first();cell ;cell =l_chap->cells.next() ) { + icell++; + + sCell = QString("--cell %1").arg(icell); + sChapter=QString("--chapter %1").arg(numPart); + + //test + uint32_t itotSize = (cell->getlastSector()-cell->getstartSector())* DVD_VIDEO_LB_LEN; + QString file; + e=xml->createElement("vob"); + file=QString("k9copy --play --input %1 --dvdtitle %2 %3 %4 %5 %6 --vampsfactor %7 --inputsize %8 --chaptersize %9 ") + .arg(DVD->getDevice()) + .arg(title->getnumTitle()) + .arg(sChapter) + .arg(sCell) + .arg(caud) + .arg(csub) + .arg(titleFactor,0,'f',2) + .arg(itotSize,0,'f',0) + .arg(chapterSize,0,'f',0); + if (m_firsttitle) { + file +=" --initstatus "; + m_firsttitle=false; + } + if (l_track->getforceFactor()) { + file +=" --ffactor "; + } + file +=QString(" --inject %1 --totalsize %2 --dvdsize %3 |") + .arg(inject) + .arg(m_totalSize -m_forced ,0,'f',0) + .arg(((uint64_t)k9DVDSize::getMaxSize() *1024 *1024) - m_forcedsh,0,'f',0); + + e.setAttribute("file",file); + if (first) + e.setAttribute("chapters",l_chap->gettime().toString("0")); + pgc.appendChild(e); + first=false; + } + // } + } + + } + QDomElement post = xml->createElement("post"); + pgc.appendChild(post); + QDomText postcmd=xml->createTextNode(""); + + k9DVDTitle * l_next=l_track->getnextTitle(); + if (l_next!=NULL) { + c.sprintf("g1=%d;\ncall vmgm menu;",DVD->getnewTitleNum(l_next)); + if( DVD->getnewTitleNum(l_next)==-1) { + error=true; + c=i18n("'%1' not selected").arg(l_next->getname()); + KMessageBox::error( 0, c, tr2i18n("authoring")); + } + + postcmd.setNodeValue(c); + } + post.appendChild(postcmd); + } + +} + + +const QString& k9DVDAuthor::getworkDir() { + return workDir; +} +void k9DVDAuthor::setworkDir( const QString& _newVal) { + workDir = _newVal; + if (workDir.right(1)!='/') + workDir +='/'; +} + +void k9DVDAuthor::author() { + + if ( ! k9Tools::checkProgram("dvdauthor")) { + KMessageBox::error (qApp->mainWidget(),i18n("Unable to run %1").arg("dvdauthor") , i18n("authoring")); + error = TRUE; + return; + } + + + bool burnOk=false; + //nettoyage du répertoire de sortie + k9Tools::clearOutput(workDir+"dvd"); + + time = new QTime(0,0); + time->start(); + + progress->setTitle(i18n("Authoring")); + progress->setCaption(i18n("k9Copy - Backup progression")); + progress->setProgress(0,100); + //progress->show(); + + m_xml=new KTempFile(locateLocal("tmp", "k9copy/k9a"),".xml"); + + m_inject=new KTempFile(locateLocal("tmp", "k9copy/k9v"),".inj"); + inject=m_inject->name(); + + if (!cancelled && !error) + createXML(); +// if (error || cancelled) +// delete progress; + + //run dvdauthor + if (!cancelled && !error) { + QString c("dvdauthor"); + proc=progress->getProcess();// new QProcess(c,0); + *proc << c << "-x" << m_xml->name(); //locateLocal("tmp", "k9copy/k9author.xml"); + connect( proc, SIGNAL(receivedStderr(KProcess *, char *, int)), + this, SLOT(DVDAuthorStderr(KProcess *, char *, int )) ); + connect( proc, SIGNAL(receivedStdout(KProcess *, char *, int )), + this, SLOT(DVDAuthorStdout(KProcess *, char *, int)) ); + // connect(progress, SIGNAL(cancelled()), this, SLOT(stopProcess())); + + m_copied=0; + m_lastPos=0; + //if (m_totalSize >k9DVDSize::getMaxSize()) + // m_totalSize=k9DVDSize::getMaxSize(); + proc-> setWorkingDirectory(workDir); + int result=progress->execute(); + if ( result==-1 ) { + KMessageBox::error( 0, tr2i18n("Dvdauthor error :\n") + lastMsg,tr2i18n("authoring")); + + } else { + cancelled=(result==0); + if ((proc->exitStatus()==0) && (proc->normalExit()) && !cancelled && !error) { + burnOk=true; + } else { + if (cancelled) { + //QMessageBox::critical( 0, tr2i18n("authoring"), tr2i18n("Authoring canceled")); + KMessageBox::error( 0, tr2i18n("Authoring cancelled"),tr2i18n("authoring")); + + } else + KMessageBox::error( 0, tr2i18n("An error occured while running DVDAuthor:\n")+lastMsg ,tr2i18n("authoring")); + + } + } + // delete proc; + // delete progress; + if (!burnOk) + error=true; + } + + delete time; + m_xml->file()->remove(); + m_inject->file()->remove(); + delete m_inject; + delete m_xml; +} + + +/** No descriptions */ +void k9DVDAuthor::DVDAuthorStderr(KProcess *proc, char *buffer, int buflen ) { + + //QString m_stderr(proc->readStderr()); + QString m_stderr=QString::fromLatin1(buffer, buflen); + float m_percent; + QString m_remain; + + int pos=m_stderr.find("INFOPOS:"); + if (pos!=-1) { + progress->setTitle(i18n("Authoring")); + QString tmp=m_stderr.mid(pos); + uint32_t totalBytes,totalSize; + sscanf(tmp.latin1(),"INFOPOS: %d %d",&totalBytes,&totalSize); + //if (totalBytes>m_lastPos) + // m_copied+=totalBytes - m_lastPos; + m_copied=totalBytes; + m_lastPos=totalBytes; + //qDebug(QString("copied : %1 totalSize : %2").arg(m_copied).arg(m_totalSize*512)); + m_percent=(float)m_copied / (float)(m_totalSize/DVD_VIDEO_LB_LEN ); + + + QTime time2(0,0); + time2=time2.addMSecs(time->elapsed()); + if (m_percent>0) { + QTime time3(0,0); + time3=time3.addMSecs((uint32_t)(time->elapsed()*(1/m_percent))); + m_remain=time3.toString("hh:mm:ss"); + } + + m_percent*=100; + progress->setLabelText(""); + + progress->setProgress(m_percent,100); + progress->setElapsed(time2.toString("hh:mm:ss") +" / " +m_remain); + + } + /* else { + if (!m_stderr.startsWith("libdvdread") && m_stderr.startsWith("libdvdnav")) + qDebug(m_stderr); + } + */ + int end; + lastMsg=m_stderr; + + if (m_stderr.contains("STAT:")) { + pos=m_stderr.find("fixing VOBU"); + if (pos!=-1) { + progress->setTitle(i18n("Authoring")); + progress->setLabelText(i18n("Fixing VOBUS")); + end=m_stderr.find("%"); + if (end!=-1) { + pos =end -2; + m_stderr=m_stderr.mid(pos,end-pos); + m_stderr=m_stderr.stripWhiteSpace(); + //progress->setLabelText(c); + progress->setProgress(m_stderr.toInt(),100); + } + } + } + + pos=m_stderr.find("INFOIMAGE:"); + if (pos!=-1) { + progress->setImage(m_stderr.mid(pos+10)); + } + + + +} + +void k9DVDAuthor::DVDAuthorStdout(KProcess *proc, char *buffer, int buflen) { + QString c=QString::fromLatin1( buffer,buflen); + //(proc->readStdout()); + int pos; + pos=c.find("STAT"); + if (pos!=-1) { + c=c.mid(pos); + progress->setLabelText(c); + qApp->processEvents(); + } +} + +/** No descriptions */ +void k9DVDAuthor::stopProcess() { + proc->kill(); + cancelled=true; +} + +/** Read property of bool burnDVD. */ +const bool& k9DVDAuthor::getburnDVD() { + return burnDVD; +} +/** Write property of bool burnDVD. */ +void k9DVDAuthor::setburnDVD( const bool& _newVal) { + burnDVD = _newVal; +} + + + +bool k9DVDAuthor::getError() { + return error; +} diff --git a/libk9copy/k9dvdauthor.h b/libk9copy/k9dvdauthor.h new file mode 100755 index 0000000..83a5265 --- /dev/null +++ b/libk9copy/k9dvdauthor.h @@ -0,0 +1,85 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef K9DVDAUTHOR_H +#define K9DVDAUTHOR_H + +#include "k9common.h" +#include "k9dvd.h" +#include "k9progress.h" + +#include <qdom.h> +#include "k9process.h" +#include <qdatastream.h> +#include <qprogressdialog.h> +#include <klocale.h> +#include <ktempfile.h> +/** + *@author + */ + +class k9DVDAuthor : public QObject { +Q_OBJECT +public: + k9DVDAuthor(QObject *DVDStruct,const char* name=0,const QStringList& args=0) ; + ~k9DVDAuthor(); + virtual void setworkDir( const QString& _newVal); + virtual const QString& getworkDir(); + virtual bool getError(); + virtual void author(); + virtual void setburnDVD( const bool& _newVal); + virtual const bool& getburnDVD(); + virtual QWidget *getDialog(){return progress;}; +private: // Private attributes + /** */ + QTime *time; + k9DVD* DVD; + double factor; + QDomDocument *xml; + QString lastMsg,totSize,inject; + k9Process *proc; + QString workDir; + k9Progress *progress; + bool cancelled; + bool error; + bool burnDVD; + bool m_firsttitle; + uint64_t m_totalSize; + uint64_t m_forced,m_forcedsh; + uint32_t m_copied,m_lastPos; + uint64_t m_totalPartSize; + KTempFile *m_xml,*m_inject; + QPtrList <KTempFile> files; + void createXML(); + void addTitle(QDomElement &root, k9DVDTitle *title); + void createMenus(bool preview); + void addMenus(QDomElement &titleSet); + void processMenu(); + void spumux(); +private slots: // Private slots + /** No descriptions */ + void DVDAuthorStderr(KProcess *proc, char *buffer, int buflen); + void DVDAuthorStdout(KProcess *proc, char *buffer, int buflen); + + /** No descriptions */ + void stopProcess(); +}; + +#endif + diff --git a/libk9copy/k9dvdbackup.cpp b/libk9copy/k9dvdbackup.cpp new file mode 100755 index 0000000..a651475 --- /dev/null +++ b/libk9copy/k9dvdbackup.cpp @@ -0,0 +1,1776 @@ +/*************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#include "k9dvdbackup.h" +#include "k9dvd.h" +#include "bswap.h" +#include "k9ifo2.h" +#include "k9vamps.h" +#include "ac.h" +#include "k9dvdtitleset.h" +#include <kmessagebox.h> +#include <kapplication.h> +#include <qapplication.h> +#include <qfileinfo.h> + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <errno.h> +#include <string.h> +#include <klocale.h> +#include <qdir.h> +#include <kstandarddirs.h> +#include "k9backupdlg.h" +#include "dvdread.h" +#include "k9script.h" +#include "k9tools.h" + +#define BUF_SECS 1024 + + +#include "k9dvdbackup.moc" + +int k9CadtList::compareItems(QPtrCollection::Item item1,QPtrCollection::Item item2) { + cell_adr_t * it1=(cell_adr_t*)item1; + cell_adr_t * it2=(cell_adr_t*)item2; + return it1->start_sector - it2->start_sector; +}; + +int k9TitleSetList::compareItems ( QPtrCollection::Item item1, QPtrCollection::Item item2 ) { + k9TitleSet * it1,*it2; + it1=(k9TitleSet *) item1; + it2=(k9TitleSet *)item2; + return it1->VTS - it2->VTS; +} + +/*void k9TitleSet::clearCells() { + while (!cells.isEmpty()) delete cells.take(); + //qDeleteAll(cells); + cells.clear(); +} + */ + +k9TitleSet::k9TitleSet(int _VTS):QObject(NULL,"") { + startSector=0; + lastSector=0; + VTS=_VTS; + cells.setAutoDelete(true); + ifoTitle=NULL; +} + +k9TitleSet::~k9TitleSet() { + //ifoTitle->closeIFO(); + //delete ifoTitle; +} + +k9Cell* k9TitleSet::addCell(int _vts,int _pgc, int _vob) { + return cells.addCell(_vts,_pgc,_vob); + +} + +uint32_t k9TitleSet::getSize() { + return (lastSector +1) ; +} + + +k9DVDBackup::k9DVDBackup(QObject* _dvd,const char* name,const QStringList& ) + : QObject(NULL, name) { + DVD = (k9DVD*)_dvd; + m_dvdread=DVD->getdvd(); + currVTS=0; + outputFile=NULL; + currTS=NULL; + errMsg=""; + error=false; + backupDlg = new k9BackupDlg(qApp->mainWidget(),"",true); + // cells.setAutoDelete(true); + vamps=new k9vamps(this); + m_withMenu=false; + m_forcedFactor=false; + m_preserve=true; +} + + +k9DVDBackup::~k9DVDBackup() { + if (outputFile !=NULL) { + outputFile->close(); + delete outputFile; + } + delete backupDlg; + delete vamps; +} + +void k9DVDBackup::setWithMenus(bool _value) { + m_withMenu=_value; +} + +bool k9DVDBackup::geterror() { + return error; +} + +void k9DVDBackup::seterror(const QString &_msg) { + error=true; + errMsg=_msg; +} + + +QString k9DVDBackup::getErrMsg() { + return(errMsg); +} + +void k9DVDBackup::prepareVTS(int _VTS) { + if (error) + return; + ifo_handle_t *hifo; + + cellSize=0; + if (currTS==NULL) { + currVTS=0; + m_vmgSize=copyMenu2(0); + calcFactor(); + if (outputFile != NULL) { + outputFile->close(); + delete outputFile; + outputFile=NULL; + } + } + if (backupDlg->getAbort()) { + seterror(tr2i18n("DVD backup cancelled")); + return; + } + //creation of output file + if (currVTS != _VTS) { + if (outputFile != NULL) { + outputFile->close(); + delete outputFile; + outputFile=NULL; + updateIfo(); + updateVob(&currTS->cells); + } + + if (backupDlg->getAbort()) { + seterror(tr2i18n("DVD backup cancelled")); + return; + } + + uint32_t startSector=0; + + if (currTS != NULL) { + startSector = currTS->startSector + currTS->getSize(); + } else { + k9Ifo2 *kifo; + kifo=m_dvdread->getIfo(0); + hifo = kifo->getIFO(); + if (!hifo) { + seterror( tr2i18n("unable to open VIDEO_TS.IFO")); + return; + } + startSector= hifo->vmgi_mat->vmg_last_sector+1 ; + } + + currTS = new k9TitleSet(_VTS); + currVOB=0; + currVTS=_VTS; + + calcFactor(); //menus are always shrinked + currTS->menuSize=copyMenu2(_VTS); + if (outputFile != NULL) { + outputFile->close(); + delete outputFile; + } + + QString filename; + filename.sprintf("/VTS_%02d_1.VOB",_VTS); + filename=output+filename; + outputFile=new QFile(filename); + if (! outputFile->open(IO_WriteOnly)) { + seterror(tr2i18n("Unable to open file ") + filename); + return; + } + + currVOB=1; + + currTS->startSector=startSector; + currTS->lastSector += currTS->menuSize ; + titleSets.append(currTS); + + k9Ifo2 *kifo; + kifo=m_dvdread->getIfo(_VTS); + currTS->ifoTitle=kifo; + + m_position=0; + m_copyMenu=false; + calcFactor(); + } + + currVTS=_VTS; + +} + + +void k9DVDBackup::copyCell(int _VTS,k9Cell * _cell,bool _empty) { + if (error) + return; + + prepareVTS(_VTS); + if (error) + return; + + if (_cell->getforceFactor()) + forceFactor( _cell->getFactor()); + + + mutex.lock(); + k9Cell *cell= currTS->addCell(_VTS,0,0); + //JMP cell->startSector=m_position; + cell->startSector=cell->cellList->getPosition(); + currCell=cell; + //start cell copy + mutex.unlock(); + if (!_empty) { + if (!vamps->running()) { + vamps->reset(); + vamps->setPreserve(true); + vamps->setInputSize(argSize); + QValueList<int>::iterator it; + for ( it = _cell->audio.begin(); it != _cell->audio.end(); ++it ) { + if (m_preserve) + vamps->addAudio(*it); + else + vamps->addAudio(*it,_cell->getTitleset()->getNewAudioStreamId(*it)); + } + + for ( it = _cell->subpicture.begin(); it != _cell->subpicture.end(); ++it ) { + vamps->addSubpicture(*it); + } + + vamps->setVapFactor(argFactor); + vamps->start(QThread::NormalPriority); + } + playCell(_VTS,_cell,_empty); + } else + copyEmptyPgc(_VTS,_cell); + qApp->processEvents(); +} + +void k9DVDBackup::copyEmptyPgc(int _vts,k9Cell *_cell) { + if (error) + return; + + ifo_handle_t *vts_handle=currTS->ifoTitle->getIFO(); + ; + + k9DVDFile *dvdfile; + if ((dvdfile = m_dvdread->openTitle( _vts))== 0) { + QString stmp; + stmp=i18n("Unable to open titleset %1").arg(_vts); + seterror(stmp); + return ; + } + backupDlg->setTotalSteps(vts_handle->vtsi_mat->vts_last_sector-vts_handle->vtsi_mat->vtstt_vobs -1); + QString c; + c=i18n("Extracting titleset %1").arg(_vts); + backupDlg->setProgressLabel(c); + backupDlg->show(); + + + uint32_t sector; + int32_t len=0; + uchar buffer[DVD_VIDEO_LB_LEN]; + sector = _cell->startSector; + backupDlg->setProgress(sector); + dsi_t dsi_pack; + uint32_t nsectors; + + len=dvdfile->readBlocks (sector, 1, buffer); + //JMP : D V C + if (!k9Cell::isNavPack( buffer) || len==-1) + setDummyNavPack( buffer,sector); + + k9Vobu * vobu=currCell->addVobu(sector); + vobu->empty=true; + currCell->addNewVobus((char*)buffer,DVD_VIDEO_LB_LEN,currCell->cellList->getPosition(),currVOB,outputFile->at()); + outputFile->writeBlock((char*)buffer,DVD_VIDEO_LB_LEN); + + /* parse contained DSI pack */ + navRead_DSI (&dsi_pack, buffer + DSI_START_BYTE); + currCell->vob = dsi_pack.dsi_gi.vobu_vob_idn; + + //dummy video pack + setDummyPack( buffer); + currCell->addNewVobus((char*)buffer,DVD_VIDEO_LB_LEN,currCell->cellList->getPosition()+1,currVOB,outputFile->at()); + outputFile->writeBlock((char*)buffer,DVD_VIDEO_LB_LEN); + + nsectors=1; + len=1; + + //vobu->size +=nsectors; + currCell->lastSector=currCell->startSector+ len; + currCell->cellList->setPosition(currCell->cellList->getPosition()+1+len); + currTS->lastSector+=len+1; + dvdfile->close(); + backupDlg->setProgressTotal(len+1); + if (!m_forcedFactor) { + m_cellCopyList->addInbytes( DVD_VIDEO_LB_LEN *2); + m_cellCopyList->addOutbytes( DVD_VIDEO_LB_LEN *2); + } else { + m_cellCopyList->addFrcinbytes(DVD_VIDEO_LB_LEN *2); + m_cellCopyList->addFrcoutbytes( DVD_VIDEO_LB_LEN *2); + + } +} + + +void k9DVDBackup::getOutput(uchar * buffer, uint32_t buflen) { + if (error) + return; + mutex.lock(); + backupDlg->playMovie(buffer,buflen); + mutex.unlock(); + + if (!m_forcedFactor) + m_cellCopyList->addOutbytes( buflen); + else + m_cellCopyList->addFrcoutbytes( buflen); + + uchar *temp =buffer; + QString sName; + if ((buflen %2048) !=0) + qDebug("getOutput, buffer : %u",buflen); + uint end=0; + + for (uint itemp=0;itemp<buflen;itemp+=DVD_VIDEO_LB_LEN) { + if (buflen-itemp <DVD_VIDEO_LB_LEN) + break; + + + mutex.lock(); + long fileSize=outputFile->size(); + end=itemp+DVD_VIDEO_LB_LEN; + if (k9Cell::isNavPack(temp+itemp)) { + + k9Vobu * vobu = vobuQueue.dequeue(); + + cellOut=vobu->parent; + dsi_t dsiPack; + navRead_DSI (&dsiPack, (uchar*)(temp+itemp) + DSI_START_BYTE); + + cellOut->vob = dsiPack.dsi_gi.vobu_vob_idn; + if ((dsiPack.dsi_gi.vobu_ea * DVD_VIDEO_LB_LEN) + fileSize >= (1024*1024*1024)) { + outputFile->close(); + delete outputFile; + currVOB++; + if (currVTS==0) + sName = "/VIDEO_TS.VOB"; + else + sName.sprintf("/VTS_%02d_%d.VOB",(int)currVTS,(int)currVOB); + sName=output+sName; + outputFile=new QFile(sName); + if ( !outputFile->open(IO_WriteOnly)) { + seterror(tr2i18n("Unable to open file ") + sName); + mutex.unlock(); + return; + } + } + } + cellOut->addNewVobus((char*)(temp+itemp),DVD_VIDEO_LB_LEN,cellOut->cellList->getPosition() ,currVOB,outputFile->at()); + outputFile->writeBlock((char*)(temp+itemp),DVD_VIDEO_LB_LEN); + + backupDlg->setProgressTotal(1); + cellOut->cellList->setPosition( cellOut->cellList->getPosition()+1); + if (!m_copyMenu) + currTS->lastSector++; + mutex.unlock(); + } +} + + +/*! +\fn k9DVDBackup::setDevice(QString _device) +*/ +void k9DVDBackup::setDevice(QString _device) { + device=_device; +} + + +/*! +\fn k9DVDBackup::setOutput(QString _output) +*/ +void k9DVDBackup::setOutput(QString _output) { + output=QDir::cleanDirPath(_output); +} + + +uint32_t k9DVDBackup::copyMenu2(int _vts) { + if (error || !m_withMenu ) + return 0; + k9Ifo2 *kifo; + kifo=m_dvdread->getIfo( _vts); + ifo_handle_t *hifo =kifo->getIFO(); + m_ifo=hifo; + uint32_t msize=0; + uint32_t menuLastSector; + if (_vts==0) + msize=hifo->vmgi_mat->vmg_last_sector -1 - 2* hifo->vmgi_mat->vmgi_last_sector; + else + msize=hifo->vtsi_mat->vtstt_vobs - hifo->vtsi_mat->vtsi_last_sector -1; + + if (msize==0) { + //kifo.closeIFO(); + return 0; + } + menuLastSector=msize-1; + + + m_position=0; + m_copyMenu=true; + QString targetName; + if (_vts == 0) { + targetName="VIDEO_TS.VOB"; + } else { + targetName.sprintf("VTS_%02i_0.VOB",_vts); + } + targetName=output+"/"+targetName; + + outputFile=new QFile(targetName); + if (! outputFile->open(IO_WriteOnly)) { + seterror(tr2i18n("Unable to open file ") + targetName); + return 0; + } + + k9DVDFile *dvdfile; + if ((dvdfile = m_dvdread->openMenu( _vts))== 0) { + QString stmp; + stmp=i18n("Unable to open menu for titleset %1").arg(_vts); + seterror (stmp); + return 0; + } + + k9CellList *lstCell; + if (_vts==0) + lstCell = &vmgCells; + else + lstCell = &currTS->menuCells; + + lstCell->setAutoDelete(true); + + + c_adt_t *c_adt = hifo->menu_c_adt; + // c_adt shouldn't be null. It would say that the menu doesn't contain video !? + if (c_adt==NULL) + return 0; + + uint32_t length = c_adt->last_byte + 1 - C_ADT_SIZE; + cell_adr_t *ptr; + ptr= c_adt->cell_adr_table; + + uint32_t sector, dsi_next_vobu = 0; + uint32_t imax=length/sizeof(cell_adr_t); + QString c; + c=i18n("Extracting menu for titleset %1").arg(_vts); + backupDlg->setProgressLabel(c); + + backupDlg->show(); + backupDlg->setTotalSteps(ptr[imax-1].last_sector); + + k9CadtList cadr; + + uint32_t nbCells=0; + for (uint32_t i=0;i<imax;i++) { + if ((ptr+i)->last_sector > menuLastSector) + (ptr+i)->last_sector=menuLastSector; + + if ((ptr+i)->start_sector <= menuLastSector) { + cadr.append(ptr+i); + nbCells++; + } + //else + //qDebug() << QString("cell start sector (%1) exceed menu size (%2)").arg((ptr+i)->start_sector).arg(menuLastSector); + } + cadr.sort(); + vamps->reset(); + vamps->setPreserve(true); + for (uint i=1;i<=8;i++) + vamps->addAudio(i); + + for (uint i=1;i<=32;i++) + vamps->addSubpicture(i); + + vamps->setVapFactor(argFactor); + vamps->setInputSize(msize*2048); + + vamps->start(QThread::NormalPriority); + // while(!vamps->running() && !vamps->finished()); + + for(uint32_t i = 0; i < nbCells; i++) { + currCell=lstCell->addCell(_vts,1,1); + dsi_next_vobu=0; + cell_adr_t * cellAdr=cadr.at(i); + for (sector = cellAdr->start_sector; + sector <= cellAdr->last_sector; sector += dsi_next_vobu & 0x7fffffff) { + backupDlg->setProgress(sector); + if (backupDlg->getAbort()) { + seterror(tr2i18n("DVD backup cancelled")); + } + + if (error) { + vamps->abort(); + break; + } else if (vamps->geterror()) { + seterror( vamps->geterrMsg()); + break; + } + dsi_next_vobu= copyVobu(dvdfile,sector,NULL); + } + } + vamps->setNoData(); + vamps->wait(); + uint32_t size=0; + + //JMP size=m_position; + size =lstCell->getPosition(); + + dvdfile->close(); + outputFile->close(); + delete outputFile; + outputFile=NULL; + //kifo.closeIFO(); + + updateVob(lstCell); + + m_copyMenu=false; + return size; +} + + + + +void k9DVDBackup::playCell (int vts_num, k9Cell *_cell,bool _empty) { + + if (error) + return; + + ifo_handle_t *vts_handle; + k9DVDFile *dvdfile; + uint32_t sector, dsi_next_vobu = 0; + /* open disc */ + if (m_dvdread->opened()) { + /* load information for the given VTS */ + // vts_handle = ifoOpen (dvd_handle, vts_num); + vts_handle=currTS->ifoTitle->getIFO(); + if (!vts_handle) { + QString stmp; + stmp=i18n("Unable to open ifo file for titleset %1").arg(vts_num); + seterror (stmp); + //JMP vamps->setNoData(); + return; + } + + backupDlg->setTotalSteps( vts_handle->vtsi_mat->vts_last_sector-vts_handle->vtsi_mat->vtstt_vobs -1); + QString c; + c=i18n("Extracting titleset %1").arg(vts_num); + backupDlg->setProgressLabel(c); + backupDlg->show(); + } else { + seterror(tr2i18n("Unable to open DVD")); + //JMP vamps->setNoData(); + return; + } + + + /* open VTS data */ + dvdfile = m_dvdread->openTitle (vts_num); + if (! dvdfile) { + QString stmp; + stmp=i18n("Unable to open vobs for titleset %1").arg(vts_num); + seterror( stmp); + //JMP vamps->setNoData(); + return; + } + + + /* loop until out of the cell */ +//TO REMOVE currCell->oldStartSector=_cell->startSector; + for (sector = _cell->startSector; + sector <= _cell->lastSector; sector += dsi_next_vobu & 0x7fffffff) { + + backupDlg->setProgress(sector); + if (backupDlg->getAbort()) { + seterror(tr2i18n("DVD backup cancelled")); + } + + if (error) { + vamps->abort(); + break; + } else if (vamps->geterror()) { + seterror( vamps->geterrMsg()); + break; + } + dsi_next_vobu= copyVobu(dvdfile,sector,NULL,_empty); + } + dvdfile->close(); +} + +void k9DVDBackup::setDummyNavPack(uchar *buf,uint32_t _sector) +{ + int8_t *ptr = (int8_t*)buf; + static uint8_t nav_pack1 [] = + { + /* pack header: SCR=0, mux rate=10080000bps, stuffing length=0 */ + 0, 0, 1, 0xba, 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, 0x01, 0x89, 0xc3, 0xf8, + /* system header */ + 0, 0, 1, 0xbb, 0x00, 0x12, + /* contents of system header filled in at run time (18 bytes) */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* PES header for first private stream 2 packet */ + 0, 0, 1, 0xbf, 0x03, 0xd4 + }; + static uint8_t nav_pack2 [] = + { + /* PES header for second private stream 2 packet */ + 0, 0, 1, 0xbf, 0x03, 0xfa + }; + + tc_memcpy (ptr, nav_pack1, sizeof (nav_pack1)); + ptr += sizeof (nav_pack1); + memset (ptr, 0, DVD_VIDEO_LB_LEN/2 - sizeof (nav_pack1)); + ptr = (int8_t*)buf + DVD_VIDEO_LB_LEN/2; + tc_memcpy (ptr, nav_pack2, sizeof (nav_pack2)); + ptr += sizeof (nav_pack2); + memset (ptr, 0, DVD_VIDEO_LB_LEN/2 - sizeof (nav_pack2)); + + dsi_t dsiPack; + pci_t pciPack; + navRead_DSI (&dsiPack, buf + DSI_START_BYTE); + k9Ifo2::navRead_PCI (&pciPack, buf+0x2d); + dsiPack.dsi_gi.nv_pck_lbn=_sector; + dsiPack.dsi_gi.vobu_ea = 1; + + navRead_DSI((dsi_t*)(buf + DSI_START_BYTE),(uchar*)&dsiPack); + pciPack.pci_gi.nv_pck_lbn =dsiPack.dsi_gi.nv_pck_lbn; + k9Ifo2::navRead_PCI((pci_t*)(buf+0x2d),(uchar*)&pciPack); +} + + +void k9DVDBackup::setDummyPack(uchar *_buffer) { + int8_t *ptr = (int8_t*)_buffer; + uint8_t dummy_pack [] = + { + /* pack header: SCR=0, mux rate=10080000bps, stuffing length=0 */ + 0, 0, 1, 0xba, 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, 0x01, 0x89, 0xc3, 0xf8, + /* PES header for dummy video packet */ + 0, 0, 1, 0xe0, 0x07, 0xec, 0x81, 0x00, 0x00 + }; + + tc_memcpy (ptr, dummy_pack, sizeof (dummy_pack)); + ptr += sizeof (dummy_pack); + memset (ptr, 0xff, DVD_VIDEO_LB_LEN - sizeof (dummy_pack)); + +} + + +uint32_t k9DVDBackup::findNextVobu(uint32_t _sector) { + k9Ifo2 *ifo; + ifo = m_dvdread->getIfo(currVTS); + m_ifo=ifo->getIFO(); + vobu_admap_t * vobu_admap; + if (m_copyMenu) + vobu_admap = m_ifo->menu_vobu_admap; + else + vobu_admap = m_ifo->vts_vobu_admap; + uint32_t length = vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE; + for(uint32_t i = 0; i < length/sizeof(uint32_t); i++) { + if (vobu_admap->vobu_start_sectors[i] >= _sector) { + uint32_t nextVobu=vobu_admap->vobu_start_sectors[i+1]; + //ifo.closeIFO(); + return nextVobu; + } + } + //ifo.closeIFO(); + return 0; + +} + + + +uint32_t k9DVDBackup::copyVobu(k9DVDFile *_fileHandle,uint32_t _startSector,k9Vobu * _vobu,bool _empty) { + dsi_t dsi_pack; + k9Vobu * currVobu; + bool badNavPack=false; + + uint32_t nsectors, nextVobu=0; + int32_t len=0; + uchar *buf; + uint32_t sector=_startSector; + /* read nav pack */ + buf=(uchar*) malloc(DVD_VIDEO_LB_LEN); + len = _fileHandle->readBlocks ( sector, 1, buf); + /* parse contained DSI pack */ + + //test if nav pack is ok + if (len !=-1) { + navRead_DSI (&dsi_pack, buf + DSI_START_BYTE); + if (dsi_pack.dsi_gi.nv_pck_lbn != sector) { + len=-1; + } + } + + if (len==-1) { + setDummyNavPack(buf,sector); + nextVobu=findNextVobu(sector); + qDebug ("VOBU : %u Read Error !!!! ==> %u",sector,nextVobu); + badNavPack=true; + } + currVobu=_vobu; + + mutex.lock(); + if (k9Cell::isNavPack(buf)) { +//TO REMOVE currCell->oldLastSector=sector; + if (currVobu==NULL) { + currVobu =currCell->addVobu(sector); + vobuQueue.enqueue(currVobu); + } + } + mutex.unlock(); + /* generate an MPEG2 program stream (including nav packs) */ + wrote=false; + + vamps->addData(buf,DVD_VIDEO_LB_LEN); + + + + if (!m_forcedFactor) + m_cellCopyList->addInbytes( DVD_VIDEO_LB_LEN); + else + m_cellCopyList->addFrcinbytes(DVD_VIDEO_LB_LEN); + uint32_t end; + + if (badNavPack) { + setDummyPack(buf); + nsectors=1; + if (nextVobu !=0) end=nextVobu-_startSector-1; + + } else { + if (!_empty) + nsectors = dsi_pack.dsi_gi.vobu_ea; + else + nsectors = 1; + + //uint32_t dsi_next_vobu = dsi_pack.vobu_sri.next_vobu; + + buf=(uchar*) realloc(buf,nsectors*DVD_VIDEO_LB_LEN); + + end=dsi_pack.dsi_gi.vobu_ea; + + if (_empty) + setDummyPack(buf); + /* read VOBU */ + else + for (uint32_t i=0;i< nsectors;i++) { + len = _fileHandle->readBlocks ( (sector + 1)+i, 1, buf +(i*DVD_VIDEO_LB_LEN)); + if (len==-1) { + qDebug ("VOBU : %u Read Error !!!!",sector); + //setDummyPack(buf + (i*DVD_VIDEO_LB_LEN)); + setDummyPack(buf); + nsectors=1; + break; + } + } + } + + /* write VOBU */ + for (uint32_t i=0;i<nsectors ;i++) { + vamps->addData(buf + (i*DVD_VIDEO_LB_LEN), DVD_VIDEO_LB_LEN); + } + free(buf); + + if (! m_forcedFactor) + m_cellCopyList->addInbytes( nsectors*DVD_VIDEO_LB_LEN); + else + m_cellCopyList->addFrcinbytes( nsectors*DVD_VIDEO_LB_LEN); + + mutex.lock(); + qApp->processEvents(); + mutex.unlock(); + + return (end+1); +} + + + +k9Vobu * k9DVDBackup::remapVobu(uint32_t *value) { + k9Vobu *vobu=NULL; + uint32_t sector,mask; + if ( (*value & 0x80000000) == 0x80000000) { + sector = *value & 0x7FFFFFFF; + mask=0x80000000; + } else { + sector =*value; + mask=0; + } + *value=0; + k9CellList *lstCell; + if(! m_copyMenu) { + lstCell=&(currTS->cells); + } else { + if (currVTS==0) + lstCell=&vmgCells; + else + lstCell=&(currTS->menuCells); + } + vobu=lstCell->findVobu(sector); + if (vobu !=NULL) { + *value = vobu->newSector | mask; + return vobu; + } + + *value=0; + return vobu; + +} + + +k9Vobu * k9DVDBackup::remapOffset(uint32_t _sector,uint32_t *_offset,int _dir) { + k9Vobu *vobu1=NULL, *vobu2=NULL; + uint32_t offset,sector; + uint32_t maskOffset1=0,maskOffset2=0,maskSector=0; + + if ((*_offset!= 0xbfffffff) && (*_offset!=0x3fffffff) && (*_offset!=0x7fffffff)) { + + if ( (*_offset & 0x80000000) == 0x80000000) + maskOffset1= 0x80000000; + if ( (*_offset & 0x40000000) == 0x40000000) + maskOffset2= 0x40000000; + offset = *_offset & 0x3FFFFFFF; + + if ( (_sector & 0x80000000) == 0x80000000) { + sector = _sector & 0x7FFFFFFF; + maskSector=0x80000000; + } else { + sector =_sector; + maskSector=0; + } + + k9CellList *lstCell; + if(! m_copyMenu) { + lstCell=&(currTS->cells); + } else { + if (currVTS==0) + lstCell=&vmgCells; + else + lstCell=&(currTS->menuCells); + } + vobu1 = lstCell->findVobu(sector); + vobu2 = lstCell->findVobu(sector+_dir*offset); + + + + if ((vobu1 !=NULL) && (vobu2!=NULL)) { + *_offset = abs(vobu1->newSector - vobu2->newSector) | maskOffset1 ; + *_offset |= maskOffset2; + return vobu2; + } + + if (vobu1==NULL && vobu2==NULL) + qDebug ("remapOffset : sector not found"); + } + return vobu2; +} + + +void k9DVDBackup::updateMainIfo() { + + if (error) + return; + + k9Ifo2 ifo(m_dvdread); + ifo.setOutput(output); + ifo.setDevice(device); + + ifo.openIFO(0); + ifo_handle_t *hifo =ifo.getIFO(); + + hifo->vmgi_mat->vmg_last_sector= 1+ m_vmgSize+hifo->vmgi_mat->vmgi_last_sector*2; + if (m_vmgSize >0) { + if (hifo->vmgi_mat->vmgm_vobs != hifo->vmgi_mat->vmgi_last_sector +1) + qDebug ("error in ifo file : vmgm_vobs %u -> %u)",hifo->vmgi_mat->vmgm_vobs,hifo->vmgi_mat->vmgi_last_sector +1); + hifo->vmgi_mat->vmgm_vobs=hifo->vmgi_mat->vmgi_last_sector +1; + } + + currVTS=0; + + k9Vobu* vobu2=NULL; + uint32_t newPos=0; + //update first play PGC + if (hifo->first_play_pgc !=NULL ) { + m_copyMenu=true; + pgc_t *pgc=hifo->first_play_pgc; + if (! m_withMenu && pgc->command_tbl!=0 ) { + pgc->command_tbl->nr_of_pre=0; + pgc->command_tbl->nr_of_post=0; + pgc->command_tbl->nr_of_cell=0; + } + + + cell_playback_t *cell_playback =pgc->cell_playback; + uint32_t nr= pgc->nr_of_cells; + + vobu2=NULL; + cell_playback_t cell; + newPos=0; + for( uint32_t j = 0; j < nr; j++) { + k9Vobu *vobu=remapVobu(&cell_playback[j].first_sector); + vobu2=vobu; + + remapVobu(&cell_playback[j].first_ilvu_end_sector); + if (vobu !=NULL) { + vobu=remapVobu(&cell_playback[j].last_vobu_start_sector); + if (vobu==NULL) { + cell_playback[j].last_vobu_start_sector=cell_playback[j].first_sector; + vobu=vobu2; + pgc->playback_time.hour=0; + pgc->playback_time.minute=0; + pgc->playback_time.second=0; + + cell_playback[j].playback_time.hour=0; + cell_playback[j].playback_time.minute=0; + cell_playback[j].playback_time.second=0; + } + cell_playback[j].last_sector = vobu->newSector+vobu->size;// -1 ; + cell_playback[newPos]=cell_playback[j]; + cell=cell_playback[newPos]; + newPos++; + } else { + cell_playback[newPos]=cell; + newPos++; + } + } + for (uint32_t j=newPos;j<nr;j++) + cell_playback[j].last_sector=0; + pgc->nr_of_cells=newPos; + m_copyMenu=false; + } + + + + updatePgci_ut(hifo); + update4Menu(hifo); + + //mise �jour des startSectors + k9TitleSet *TSp=NULL; + titleSets.sort(); + for (uint iTS=0;iTS < titleSets.count();iTS++) { + k9TitleSet *TS=titleSets.at(iTS); + uint32_t startSector; + if (TSp!=NULL) + startSector = TSp->startSector + TSp->getSize(); + else + startSector=hifo->vmgi_mat->vmg_last_sector+1 ; + TS->startSector=startSector; + TSp=TS; + } + + hifo->vmgi_mat->vmg_category=0; + bool found=false; + for (uint32_t i=0 ; i< hifo->tt_srpt->nr_of_srpts;i++) { + for (uint iTS=0;iTS<titleSets.count() &&(!found);iTS++) { + k9TitleSet *TS=titleSets.at(iTS); + if (TS->VTS == hifo->tt_srpt->title[i].title_set_nr ) { + hifo->tt_srpt->title[i].title_set_sector = TS->startSector; + found=true; + } + } + found=false; + } + + ifo.saveIFO(); + ifo.closeIFO(); + +} + +void k9DVDBackup::updatePgci_ut(ifo_handle_t *_hifo) { + pgci_ut_t *pgci_ut=_hifo->pgci_ut; + k9Vobu* vobu2=NULL; + uint newPos=0; + //update pgci_ut + + if (pgci_ut !=0 && m_withMenu) { + m_copyMenu=true; + for (uint i=0; i <pgci_ut->nr_of_lus;i++) { + pgci_lu_t *pgci_lu= &pgci_ut->lu[i]; + pgcit_t * pgcit= pgci_lu->pgcit; + for (uint i2=0 ; i2 <pgcit->nr_of_pgci_srp;i2++) { + pgci_srp_t * pgci_srp=&pgcit->pgci_srp[i2]; + pgc_t *pgc=pgci_srp->pgc; + + + if (! m_withMenu && pgc->command_tbl!=0) { + pgc->command_tbl->nr_of_pre=0; + pgc->command_tbl->nr_of_post=0; + pgc->command_tbl->nr_of_cell=0; + } + + cell_playback_t *cell_playback =pgc->cell_playback; + uint32_t nr= pgc->nr_of_cells; + + vobu2=NULL; + cell_playback_t cell; + newPos=0; + for( uint32_t j = 0; j < nr; j++) { + k9Vobu *vobu=remapVobu(&cell_playback[j].first_sector); + vobu2=vobu; + + if (cell_playback[j].first_ilvu_end_sector !=0) { + uint32_t tmp=cell_playback[j].first_ilvu_end_sector+1; + remapVobu(&tmp); + if (tmp!=0) + cell_playback[j].first_ilvu_end_sector=tmp-1; + } + if (vobu !=NULL) { + vobu=remapVobu(&cell_playback[j].last_vobu_start_sector); + if (vobu !=NULL) + cell_playback[j].last_sector = vobu->newSector+vobu->size;// -1 ; + cell_playback[newPos]=cell_playback[j]; + cell=cell_playback[newPos]; + newPos++; + } else { + cell_playback[newPos]=cell; + newPos++; + } + } + for (uint32_t j=newPos;j<nr;j++) + cell_playback[j].last_sector=0; + pgc->nr_of_cells=newPos; + } + } + m_copyMenu=false; + } + + if (!m_withMenu ) { + k9Script *script=new k9Script(_hifo,DVD); + script->updatePGCIUT(); + script->updateFPPGC(); + delete script; + if (_hifo->vmgi_mat) { + _hifo->vmgi_mat->vmgm_c_adt=0; + _hifo->vmgi_mat->vmgm_vobu_admap=0; + } else { + _hifo->vtsi_mat->vtsm_c_adt=0; + _hifo->vtsi_mat->vtsm_vobu_admap=0; + } + } + + +} + +void k9DVDBackup::update4Menu(ifo_handle_t *_hifo) { + if (!m_withMenu) + return; + // Mise �jour vtsm_c_adt pour le menu + m_copyMenu=true; //indispensable pour remapvobu + c_adt_t *c_adt = _hifo->menu_c_adt; + uint32_t length; + if (c_adt!=NULL) { + length = c_adt->last_byte + 1 - C_ADT_SIZE; + cell_adr_t *ptr= c_adt->cell_adr_table; + for(uint32_t i = 0; i < length/sizeof(cell_adr_t); i++) { + uint32_t startSect=ptr[i].start_sector; + // last sector of a vobu = start sector of next vobu -1 + uint32_t lastSect= ptr[i].last_sector +1; + k9Vobu *vobu=remapVobu(&startSect); + if (vobu == NULL) + qDebug ("Error : could not find startSector"); + else { + if (remapVobu(&lastSect)==NULL) + lastSect=vobu->parent->lastSector; + else + lastSect--; + ptr[i].start_sector = startSect; + ptr[i].last_sector = lastSect; + } + + } + } + + vobu_admap_t * vobu_admap = _hifo->menu_vobu_admap; + if (vobu_admap != NULL) { + length = vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE; + uint newPos=0; + for(uint32_t i = 0; i < length/sizeof(uint32_t); i++) { + if (remapVobu(&vobu_admap->vobu_start_sectors[i])!= NULL) { + vobu_admap->vobu_start_sectors[newPos]=vobu_admap->vobu_start_sectors[i]; + newPos++; + } + } + for (uint32_t i=newPos ; i < length/sizeof(uint32_t);i++) + vobu_admap->vobu_start_sectors[i]=0; + + vobu_admap->last_byte = newPos * sizeof(uint32_t) -1 +VOBU_ADMAP_SIZE; + } + m_copyMenu=false; + +} + +void k9DVDBackup::updateIfo() { + + if (error) + return; + + k9Ifo2 ifo(m_dvdread); + ifo.setOutput(output); + ifo.setDevice(device); + + ifo.openIFO(currVTS); + + ifo_handle_t *hifo =ifo.getIFO(); + + pgcit_t * pgcit = hifo->vts_pgcit; + + //update total VTS size with IFO size + currTS->lastSector += 2 *(hifo->vtsi_mat->vtsi_last_sector ) +1; + + hifo->vtsi_mat->vts_last_sector = currTS->lastSector ; + + hifo->vtsi_mat->vtstt_vobs = hifo->vtsi_mat->vtsi_last_sector + 1 + currTS->menuSize; + //JMP + if (currTS->menuSize >0) { + if (hifo->vtsi_mat->vtsm_vobs != hifo->vtsi_mat->vtsi_last_sector +1) + qDebug ("error in ifo file %u : vtsm_vobs %u -> %u",currTS->VTS,hifo->vtsi_mat->vtsm_vobs,hifo->vtsi_mat->vtsi_last_sector +1); + hifo->vtsi_mat->vtsm_vobs= hifo->vtsi_mat->vtsi_last_sector +1 ; + + }else + hifo->vtsi_mat->vtsm_vobs=0; + + updatePgci_ut(hifo); + + k9Vobu* vobu2=NULL; + uint32_t newPos=0; + //update first play PGC + if (hifo->first_play_pgc !=NULL ) { + pgc_t *pgc=hifo->first_play_pgc; + if (! m_withMenu && pgc->command_tbl!=0) { + pgc->command_tbl->nr_of_pre=0; + pgc->command_tbl->nr_of_post=0; + pgc->command_tbl->nr_of_cell=0; + } + cell_playback_t *cell_playback =pgc->cell_playback; + uint32_t nr= pgc->nr_of_cells; + + vobu2=NULL; + cell_playback_t cell; + newPos=0; + for( uint j = 0; j < nr; j++) { + k9Vobu *vobu=remapVobu(&cell_playback[j].first_sector); + vobu2=vobu; + + remapVobu(&cell_playback[j].first_ilvu_end_sector); + if (vobu !=NULL) { + vobu=remapVobu(&cell_playback[j].last_vobu_start_sector); + if (vobu==NULL) { + cell_playback[j].last_vobu_start_sector=cell_playback[j].first_sector; + vobu=vobu2; + pgc->playback_time.hour=0; + pgc->playback_time.minute=0; + pgc->playback_time.second=0; + + cell_playback[j].playback_time.hour=0; + cell_playback[j].playback_time.minute=0; + cell_playback[j].playback_time.second=0; + } + cell_playback[j].last_sector = vobu->newSector+vobu->size;// -1 ; + cell_playback[newPos]=cell_playback[j]; + cell=cell_playback[newPos]; + newPos++; + } else { + cell_playback[newPos]=cell; + newPos++; + } + } + for (uint32_t j=newPos;j<nr;j++) + cell_playback[j].last_sector=0; + pgc->nr_of_cells=newPos; + } + + newPos=0; + + + audio_attr_t vts_audio_attr[8]; + + //update each PGC + bool bUpdateAudioAttr=true; + + if (!m_preserve) { + memcpy (vts_audio_attr, hifo->vtsi_mat->vts_audio_attr,sizeof(audio_attr_t)*8); + memset(hifo->vtsi_mat->vts_audio_attr,0,sizeof(audio_attr_t)*8); + } + + for(uint32_t i = 0; i < pgcit->nr_of_pgci_srp; i++) { + pgc_t *pgc=pgcit->pgci_srp[i].pgc; + int numTitle=pgcit->pgci_srp[i].entry_id & 0x7F; + + if (! m_withMenu) { + k9Script *script=new k9Script(hifo,DVD); + script->updatePGC(pgc,currTS->VTS,numTitle); + delete script; + } + + //shift audio streams; + if (!m_preserve) { + int idx=0; + uint16_t audio_control [8]; + memcpy(audio_control,pgc->audio_control,sizeof(uint16_t) *8); + memset(pgc->audio_control,0,sizeof(uint16_t) *8); + for (int istr=0; istr< 8; istr++) { + uint16_t ctrl=audio_control[istr] & 0xF8FF; + int streamId = 1+ ((audio_control[istr]>>8) & 0x7) ; + int newStreamId = DVD->gettitleset(currTS->VTS-1)->getNewAudioStreamId(streamId); + if (newStreamId !=0) { + pgc->audio_control[idx]=ctrl | ((newStreamId-1)<<8); + if (bUpdateAudioAttr) { + hifo->vtsi_mat->vts_audio_attr[idx]=vts_audio_attr[istr]; + } + idx++; + } + } + if (bUpdateAudioAttr) + hifo->vtsi_mat->nr_of_vts_audio_streams=idx; + bUpdateAudioAttr=false; + } + + cell_playback_t *cell_playback =pgc->cell_playback; + uint32_t nr= pgc->nr_of_cells; + + vobu2=NULL; + cell_playback_t cell; + newPos=0; + for( uint32_t j = 0; j < nr; j++) { + k9Vobu *vobu=remapVobu(&cell_playback[j].first_sector); + vobu2=vobu; + + if (cell_playback[j].first_ilvu_end_sector !=0) { + uint32_t tmp=cell_playback[j].first_ilvu_end_sector+1; + remapVobu(&tmp); + if (tmp!=0) + cell_playback[j].first_ilvu_end_sector=tmp-1; + } + if (vobu !=NULL) { + vobu=remapVobu(&cell_playback[j].last_vobu_start_sector); + if (vobu==NULL) { + cell_playback[j].last_vobu_start_sector=cell_playback[j].first_sector; + vobu=vobu2; + pgc->playback_time.hour=0; + pgc->playback_time.minute=0; + pgc->playback_time.second=0; + + cell_playback[j].playback_time.hour=0; + cell_playback[j].playback_time.minute=0; + cell_playback[j].playback_time.second=0; + + } + cell_playback[j].last_sector = vobu->newSector+vobu->size;// -1 ; + cell_playback[newPos]=cell_playback[j]; + cell=cell_playback[newPos]; + newPos++; + } else { + cell_playback[newPos]=cell; + newPos++; + } + } + for (uint32_t j=newPos;j<nr;j++) + cell_playback[j].last_sector=0; + pgc->nr_of_cells=newPos; + } + + + c_adt_t *c_adt = hifo->vts_c_adt; + uint32_t length = c_adt->last_byte + 1 - C_ADT_SIZE; + cell_adr_t *ptr= c_adt->cell_adr_table; + newPos=0; + for(uint32_t i = 0; i < length/sizeof(cell_adr_t); i++) { + uint32_t startSect=ptr[i].start_sector; + // last sector of a vobu = start sector of next vobu -1 + uint32_t lastSect= ptr[i].last_sector +1; + k9Vobu *vobu=remapVobu(&startSect); + if (vobu == NULL) + qDebug ("Error : could not find startSector"); + else { + if (remapVobu(&lastSect)==NULL) + lastSect= vobu->parent->lastSector; + else + lastSect--; + ptr[i].start_sector = startSect; + ptr[i].last_sector = lastSect; + } + } + + + vobu_admap_t * vobu_admap = hifo->vts_vobu_admap; + length = vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE; + newPos=0; + for(uint32_t i = 0; i < length/sizeof(uint32_t); i++) { + if (remapVobu(&vobu_admap->vobu_start_sectors[i])!= NULL) { + vobu_admap->vobu_start_sectors[newPos]=vobu_admap->vobu_start_sectors[i]; + newPos++; + } + } + for (uint32_t i=newPos ; i < length/sizeof(uint32_t);i++) + vobu_admap->vobu_start_sectors[i]=0; + + vobu_admap->last_byte = newPos * sizeof(uint32_t) -1 +VOBU_ADMAP_SIZE; + + + //update VTS_TMAP + vts_tmapt_t *vts_tmapt=hifo->vts_tmapt; + if (vts_tmapt) { + for(uint32_t i = 0; i < vts_tmapt->nr_of_tmaps; i++) { + if(vts_tmapt->tmap[i].nr_of_entries == 0) { // Early out if zero entries + continue; + } + map_ent_t * map_ent=vts_tmapt->tmap[i].map_ent; + newPos=0; + for(uint32_t j = 0; j < vts_tmapt->tmap[i].nr_of_entries; j++) { + //bit 31 indicates whether VOBU time codes are discontinous with previous + uint32_t mask=map_ent[j] & 0x80000000 ; + uint32_t value=map_ent[j] & 0x7FFFFFFF; + if (remapVobu(&value) !=NULL) { + map_ent[j]=value | mask; + map_ent[newPos]=map_ent[j]; + newPos++; + } else + map_ent[j]=0; + } + for (int j = newPos; j < vts_tmapt->tmap[i].nr_of_entries;j++) + map_ent[j]=0; + vts_tmapt->tmap[i].nr_of_entries=newPos; + } + } + + update4Menu(hifo); + + ifo.saveIFO(); +} + +void k9DVDBackup::updateVob(k9CellList *cellLst) { + int nbVobuUpdated=0; + + uchar buffer[DVD_VIDEO_LB_LEN]; + QFile *file=NULL; + QString dbg; + int pVobNum=-1; + //for (uint iCell=0;iCell<currTS->cells.count();iCell++) { + // k9Cell *cell=currTS->cells.at(iCell); + for (uint iCell=0;iCell< cellLst->count();iCell++) { + k9Cell *cell=cellLst->at(iCell); + for (uint ivobu=0; ivobu<cell->vobus.count();ivobu++) { + qApp->processEvents(); + k9Vobu * vobu = cell->vobus.at(ivobu); + int VobNum=vobu->vobNum; + if (error) + return; + if (pVobNum !=VobNum) { + if (file !=NULL){ + file->close(); + delete file; + } + //fclose(file); + QString sName; + if (currVTS==0) + sName="VIDEO_TS.VOB"; + else + sName.sprintf("VTS_%02d_%d.VOB",(int)currVTS,(int)VobNum); + dbg=i18n("Updating vob %1").arg(sName); + sName=output+"/"+sName; + QFileInfo finfo(sName); + long fileSize=finfo.size(); + + backupDlg->setTotalSteps(fileSize); + backupDlg->setProgressLabel(dbg); + file =new QFile(sName); + file->open( IO_ReadWrite); + //file=fopen(sName,"r+b"); + pVobNum=VobNum; + } + if( file !=NULL) { + uint32_t sector=0; + long pos=vobu->vobPos; + backupDlg->setProgress(pos); + if (backupDlg->getAbort()) { + seterror(tr2i18n("DVD backup canceled")); + break; + } + + bool emptyPgc=false; + /* long currpos=ftell(file); + long offset=pos-currpos; + fseek(file,offset,SEEK_CUR); + */ + //fseek(file,pos,SEEK_SET); + file->at(pos); + //fread(buffer,DVD_VIDEO_LB_LEN,1,file); + file->readBlock((char*)buffer,DVD_VIDEO_LB_LEN); + if (k9Cell::isNavPack((uchar*)buffer)) { + dsi_t dsiPack; + pci_t pciPack; + nbVobuUpdated++; + navRead_DSI (&dsiPack, buffer + DSI_START_BYTE); + k9Ifo2::navRead_PCI (&pciPack, buffer+0x2d); + sector=dsiPack.dsi_gi.nv_pck_lbn; //JMP : pour debug + //vobu=remapVobu(&dsiPack.dsi_gi.nv_pck_lbn ); + sector=vobu->oldSector; + dsiPack.dsi_gi.nv_pck_lbn=vobu->newSector; + if (vobu != NULL) { + dsiPack.dsi_gi.vobu_ea = vobu->size; + emptyPgc=vobu->empty; + } else { + dbg.sprintf("remapVobu failed for %d",dsiPack.dsi_gi.nv_pck_lbn); + } + + if (!emptyPgc) { + remapOffset(sector, &dsiPack.vobu_sri.next_video,1 ); + for (int i =0;i<19;i++) { + remapOffset(sector,&dsiPack.vobu_sri.fwda[i],1); + } + remapOffset(sector,&dsiPack.vobu_sri.next_vobu,1); + remapOffset(sector,&dsiPack.vobu_sri.prev_vobu,-1); + for (int i =0;i<19;i++) { + remapOffset(sector,&dsiPack.vobu_sri.bwda[i],-1); + } + + remapOffset(sector,&dsiPack.vobu_sri.prev_video,-1); + + //1st audio packet + for (int i =0 ;i <8 ;i++) { + //if (((dsiPack.synci.a_synca[i] & 0x8000) != 0x8000 ) && (dsiPack.synci.a_synca[i] !=0x3FFF) && (dsiPack.synci.a_synca[i] !=0x0)) { + if ( (dsiPack.synci.a_synca[i] !=0x3FFF) && (dsiPack.synci.a_synca[i] !=0x0)) { + if (vobu->firstAudio[i] !=-1) { + dsiPack.synci.a_synca[i]=vobu->firstAudio [i]; + } else { + //JMP dsiPack.synci.a_synca[i] =0; + dsiPack.synci.a_synca[i] =0x3FFF; + } + } + } + //1st subpicture packet + for (int i =0 ;i <32 ;i++) { + // if (((dsiPack.synci.sp_synca[i] & 0x80000000) != 0x80000000) && + // (dsiPack.synci.sp_synca[i] != 0x3FFFFFFF) && (dsiPack.synci.sp_synca[i] != 0x7FFFFFFF) && (dsiPack.synci.sp_synca[i] != 0x0)) { + if ((dsiPack.synci.sp_synca[i] != 0x3FFFFFFF) && (dsiPack.synci.sp_synca[i] != 0x0)) { + if (vobu->firstSubp[i] !=-1) { + dsiPack.synci.sp_synca[i]=vobu->firstSubp [i]; + } else { + //JMP dsiPack.synci.sp_synca[i] =0; + dsiPack.synci.sp_synca[i] =0x3FFFFFFF; + } + } + } + //ILVU + + for (int i=0;i<9;i++) { + if (dsiPack.sml_agli.data[i].address !=0 && dsiPack.sml_agli.data[i].address !=0x7FFFFFFF) { + uint32_t tmpAdr=dsiPack.sml_agli.data[i].address; + uint32_t tmpSize=(dsiPack.sml_agli.data[i].address & 0x7FFFFFFF) + dsiPack.sml_agli.data[i].size; + int dir; + if ((tmpAdr & 0x80000000) ==0x80000000) + dir=-1; + else + dir=1; + remapOffset(sector,&tmpAdr,dir); + remapOffset(sector,&tmpSize,1); + dsiPack.sml_agli.data[i].address=tmpAdr; + dsiPack.sml_agli.data[i].size=tmpSize-(tmpAdr &0x7FFFFFFF); + } + } + + + if (dsiPack.sml_pbi.ilvu_ea !=0) { + uint32_t tmp=dsiPack.sml_pbi.ilvu_ea+1; + remapOffset(sector,&tmp,1); + if (tmp!=0) + tmp--; + dsiPack.sml_pbi.ilvu_ea=tmp; + } + if (dsiPack.sml_pbi.ilvu_sa !=0) { + k9Vobu *vobu2=remapOffset(sector,&dsiPack.sml_pbi.ilvu_sa,1); + if (vobu2!= NULL) { + QFile *file2; + if ( vobu2->vobNum != VobNum) { + QString sName; + sName.sprintf("/VTS_%02d_%d.VOB",(int)currVTS,(int)vobu2->vobNum); + sName=output+sName; + file2=new QFile(sName); + file2->open(IO_ReadWrite); + //file2=fopen(sName,"rb"); + } else + file2=file; + //fseek(file2,vobu2->vobPos,SEEK_SET); + file2->at(vobu2->vobPos); + uchar *tmpbuff=(uchar*)malloc(2048); + //fread(tmpbuff,DVD_VIDEO_LB_LEN,1,file2); + file2->readBlock( (char*)tmpbuff,DVD_VIDEO_LB_LEN); + dsi_t dsiNext; + navRead_DSI (&dsiNext, tmpbuff + DSI_START_BYTE); + uint32_t sectmp= dsiNext.sml_pbi.ilvu_ea+1; + remapOffset(dsiNext.dsi_gi.nv_pck_lbn,§mp,1); + dsiPack.sml_pbi.size=sectmp; + free (tmpbuff); + if (vobu2->vobNum!=VobNum) { + file2->close(); + delete file2; + } + + } + } + // end block reference frames + dsiPack.dsi_gi.vobu_1stref_ea = vobu->firstRef; + dsiPack.dsi_gi.vobu_2ndref_ea=vobu->secondRef; + dsiPack.dsi_gi.vobu_3rdref_ea=vobu->thirdRef; + + + // update pci pack + for (int i=0; i<9;i++) { + if ((pciPack.nsml_agli.nsml_agl_dsta[i] & 0x80000000) != 0x80000000) + remapOffset(sector,&pciPack.nsml_agli.nsml_agl_dsta[i],1); + } + + } else { + dsiPack.vobu_sri.next_video= 0xbfffffff; + for (int i =0;i<19;i++) + dsiPack.vobu_sri.fwda[i] = 0x3fffffff; + dsiPack.vobu_sri.next_vobu=0x3fffffff; + dsiPack.vobu_sri.prev_vobu=0x3fffffff; + for (int i =0;i<19;i++) + dsiPack.vobu_sri.bwda[i] = 0x3fffffff; + dsiPack.vobu_sri.prev_video=0xbfffffff; + for (int i =0 ;i <8 ;i++) + dsiPack.synci.a_synca[i]=0x3fff; + for (int i =0 ;i <32 ;i++) + dsiPack.synci.sp_synca[i] =0x3FFFFFFF; + // end block reference frames + dsiPack.dsi_gi.vobu_1stref_ea = 0; + dsiPack.dsi_gi.vobu_2ndref_ea=0; + dsiPack.dsi_gi.vobu_3rdref_ea=0; + //JMP for tests + pciPack.pci_gi.vobu_s_ptm=0; + pciPack.pci_gi.vobu_e_ptm=0; + pciPack.pci_gi.vobu_se_e_ptm=0; + pciPack.pci_gi.e_eltm.hour = pciPack.pci_gi.e_eltm.minute =pciPack.pci_gi.e_eltm.second=0; + dsiPack.dsi_gi.c_eltm.hour=dsiPack.dsi_gi.c_eltm.minute=dsiPack.dsi_gi.c_eltm.second=0; + + for (int i=0;i<9;i++) { + dsiPack.sml_agli.data[i].address=0x7FFFFFFF; + dsiPack.sml_agli.data[i].size=0; + } + dsiPack.sml_pbi.ilvu_ea=0; + dsiPack.sml_pbi.ilvu_sa=0; + dsiPack.sml_pbi.size=0; + + dsiPack.dsi_gi.vobu_1stref_ea = 0; + dsiPack.dsi_gi.vobu_2ndref_ea=0; + dsiPack.dsi_gi.vobu_3rdref_ea=0; + + } + // mise en place des donnees modifi�s dans le buffer de sortie + navRead_DSI((dsi_t*)(buffer + DSI_START_BYTE),(uchar*)&dsiPack); + pciPack.pci_gi.nv_pck_lbn =dsiPack.dsi_gi.nv_pck_lbn; + k9Ifo2::navRead_PCI((pci_t*)(buffer+0x2d),(uchar*)&pciPack); + //mise �jour du fichier + //fseek(file,pos,SEEK_SET); + file->at(pos); + //fwrite(buffer,DVD_VIDEO_LB_LEN,1,file); + file->writeBlock((const char*)buffer,DVD_VIDEO_LB_LEN); + } + + } else { + qDebug ("erreur positionning"); + } + } + } + if (file!=NULL) { + file->close(); + delete file; + } +} + + +uint k9DVDBackup::getLastCell(k9CellCopyList *_cellCopyList, uint _index) { + + k9Cell *orig=(k9Cell*)_cellCopyList->at(_index); + uint result=_index; + + uint64_t dsize=1+orig->lastSector-orig->startSector; + + uchar audioOrig[8]; + uchar subpOrig[32]; + memset(audioOrig,0,sizeof(uchar)*8); + memset(subpOrig,0,sizeof(uchar)*32); + + ; + QValueList<int>::iterator it; + for ( it = orig->audio.begin(); it != orig->audio.end(); ++it ) + audioOrig[*it -1]=1; + + for ( it = orig->subpicture.begin(); it != orig->subpicture.end(); ++it ) + subpOrig[*it -1]=1; + + float factor=-1; + + for (uint iCell=_index+1;(iCell<_cellCopyList->count()) ;iCell++) { + k9Cell *cell=(k9Cell*)_cellCopyList->at(iCell); + if ((cell->vts== orig->vts) && ( cell->selected)) { + //if the cell factor changed, it's a new group of cells + if (factor==-1) + factor=cell->getFactor(); + else { + if (cell->getFactor()!=factor) + break; + } + + uchar audio[8]; + uchar subp[32]; + memset(audio,0,sizeof(uchar)*8); + memset(subp,0,sizeof(uchar)*32); + ; + QValueList<int>::iterator it; + for ( it = cell->audio.begin(); it != cell->audio.end(); ++it ) + audio[*it -1]=1; + + for ( it = cell->subpicture.begin(); it != cell->subpicture.end(); ++it ) + subp[*it -1]=1; + + if ( (memcmp(audioOrig,audio,sizeof(uchar)*8) ==0) && (memcmp(subpOrig,subp,sizeof(uchar)*32) ==0)) { + result=iCell; + dsize+=1+cell->lastSector-cell->startSector; + } else + break; + } else + break; + } + + dsize*=DVD_BLOCK_LEN; + argSize=dsize; + return result; +} + +void k9DVDBackup::calcFactor() { + double factor=m_cellCopyList->getfactor(m_withMenu,false); + QString sFactor; + sFactor.sprintf("%.2f",factor); + backupDlg->setFactor(sFactor); + argFactor = factor; + m_forcedFactor=false; +} + +void k9DVDBackup::forceFactor(double _factor) { + double factor=_factor; + double minFactor=m_cellCopyList->getMinFactor( m_withMenu); + if (factor<minFactor) + factor=minFactor; + QString sFactor; + sFactor.sprintf("%.2f",factor); + backupDlg->setFactor(sFactor); + argFactor = factor; + m_forcedFactor=true; + qDebug("force factor : %f min:%f",factor,minFactor); +} + + +void k9DVDBackup::execute() { + QString sOutput=output; + + output=QDir::cleanDirPath(output +"/dvd"); + + QDir root("/"); + root.mkdir(output); + k9Tools::clearOutput(output); + + QDir dir(output); + dir.mkdir("VIDEO_TS"); + dir.mkdir("AUDIO_TS"); + + output=QDir::cleanDirPath(output +"/VIDEO_TS"); + + m_dvdread->openDevice(device); + if (!m_dvdread->opened()) { + seterror(tr2i18n("Unable to open DVD")); + return; + } + + k9CellCopyList *cellCopyList =new k9CellCopyList(m_dvdread,DVD); + m_cellCopyList=cellCopyList; + + double totalSize=cellCopyList->gettotalSize(); + if (m_withMenu) + totalSize+=DVD->getmenuSize() *2048 ; + + totalSize/=(1024*1024); + totalSize = (totalSize >k9DVDSize::getMaxSize()) ? k9DVDSize::getMaxSize():totalSize; + + backupDlg->setTotalMax((uint32_t)totalSize); + + int lastCell; + calcFactor(); + + //VTSList is sorted by size, so it is easier to ajust the compression factor + for(uint iTS=0;iTS<cellCopyList->VTSList.count() &&(!error);iTS++) { + k9CellCopyVTS *VTS=cellCopyList->VTSList.at(iTS); + //loop on each cell from the titleset + lastCell=-1; + for (uint iCell=0;(iCell<cellCopyList->count()) ;iCell++) { + k9Cell *cell=(k9Cell*)cellCopyList->at(iCell); + if (cell->vts==(int) VTS->getnum() && (!cell->copied)) { + // currCopyCell=cell; + if (lastCell < (int)iCell) { + lastCell=getLastCell( cellCopyList,iCell); + //adjusting factor of compression + if ( cell->getforceFactor()) + forceFactor( cell->getFactor()); + else + calcFactor(); + } + copyCell(cell->vts,cell,! cell->selected); + if (!error) { + cell->copied=true; + } + // } + if (lastCell==(int)iCell) { + vamps->setNoData(); + vamps->wait(); + } + if (error) + break; + } + } + vamps->setNoData(); + vamps->wait(); + } + delete cellCopyList; + + if (!error) { + updateIfo(); + updateVob(&currTS->cells); + updateMainIfo(); + } + output=sOutput; + backupDlg->hide(); + + if (error) + KMessageBox::error(0,errMsg,"DVD Backup"); + //m_dvdread->close(); +} diff --git a/libk9copy/k9dvdbackup.h b/libk9copy/k9dvdbackup.h new file mode 100755 index 0000000..36349ef --- /dev/null +++ b/libk9copy/k9dvdbackup.h @@ -0,0 +1,140 @@ +/*************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef K9DVDBACKUP_H +#define K9DVDBACKUP_H + +#include "k9common.h" +#include "k9cell.h" +#include "k9cellcopylist.h" +#include "k9dvdread.h" +#include <qptrqueue.h> +#include <qmutex.h> +#include <qfile.h> +/** +@author Jean-Michel Petit +*/ + +class k9BackupDlg; +class k9Ifo2; + +class k9TitleSet : public QObject { + Q_OBJECT +public: + k9TitleSet(int _VTS); + ~k9TitleSet(); + uint32_t startSector; + uint32_t lastSector; + int VTS; + uint32_t menuSize; + k9CellList cells,menuCells; + k9Cell*addCell(int _vts,int _pgc, int _vob); + uint32_t getSize(); + k9Ifo2 *ifoTitle; +private: +}; + +class k9TitleSetList:public QPtrList <k9TitleSet> { +protected: + int compareItems ( QPtrCollection::Item item1, QPtrCollection::Item item2 ); +}; + +class k9CadtList:public QPtrList<cell_adr_t> { +protected: + int compareItems(QPtrCollection::Item item1,QPtrCollection::Item item2); +}; + +class k9vamps; + +class k9DVDBackup : public QObject { + Q_OBJECT +public: + k9DVDBackup(QObject *_dvd,const char* name=0,const QStringList& args=0) ; + + ~k9DVDBackup(); + virtual void setDevice(QString _device); + virtual void setOutput(QString _output); + virtual QString getErrMsg(); + virtual void execute(); + virtual bool geterror(); + virtual void setWithMenus(bool _value); + virtual QWidget *getDialog() {return (QWidget*)backupDlg;}; +public slots: + void getOutput(uchar *buffer,uint32_t size); + +protected: + QString device; + QString output; + bool wrote; +private: + k9DVDRead *m_dvdread; + bool m_copyMenu; + bool m_withMenu; + bool m_forcedFactor; + k9DVD *DVD; + QString errMsg; + QString vampsMsg; + QFile* outputFile; + long cellSize; + long currVTS; + k9TitleSet *currTS; + int currVOB; + ifo_handle_t *m_ifo; + k9Cell *currCell,*cellOut;//,*currCopyCell; + k9CellCopyList *m_cellCopyList; + uint32_t m_position,m_vmgSize; + bool m_preserve; + //uint64_t m_inbytes,m_outbytes; + k9TitleSetList titleSets; + float argFactor; + uint64_t argSize; + void prepareVTS(int VTS); + void playCell (int vts_num, k9Cell *_cell,bool _empty=false); + uint32_t findNextVobu(uint32_t _sector); + uint32_t copyVobu(k9DVDFile *_fileHandle,uint32_t _startSector,k9Vobu *_vobu,bool _empty=false); + void copyCell(int VTS, k9Cell *_cell,bool _empty); +// void copyAngleBlock(k9CellCopyList *_list,uint _num); + void copyEmptyPgc(int _vts,k9Cell *_cell); + void updateVob(k9CellList *_cells); + + void updateIfo(); + void updateMainIfo(); + void updatePgci_ut(ifo_handle_t *_hifo); + void update4Menu(ifo_handle_t *_hifo); + void setDummyPack(uchar *_buffer); + void setDummyNavPack(uchar *_buffer,uint32_t _sector); + uint32_t copyMenu2(int _vts); + k9CellList vmgCells; + + k9Vobu * remapVobu(uint32_t *value); + k9Vobu * remapOffset(uint32_t _sector,uint32_t *offset,int dir); + k9BackupDlg *backupDlg; + uint getLastCell(k9CellCopyList *_cellCopyList,uint _index); + void calcFactor(); + void forceFactor(double _factor); + bool error; + void seterror(const QString &_msg); + k9vamps *vamps; + QPtrQueue <k9Vobu> vobuQueue; + QMutex mutex; +}; + + + +#endif diff --git a/libk9copy/k9dvdchapter.cpp b/libk9copy/k9dvdchapter.cpp new file mode 100644 index 0000000..e96385e --- /dev/null +++ b/libk9copy/k9dvdchapter.cpp @@ -0,0 +1,69 @@ +// +// C++ Implementation: k9dvdchapter +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9dvdchapter.h" +#include "k9dvdtitle.h" + +//************************* k9DVDChapter************************ +/** Read property of int num. */ +const int& k9DVDChapter::getnum() +{ + return num; +} +/** Read property of QTime length. */ +const QTime& k9DVDChapter::getlength() +{ + return length; +} + +/** Read property of int sectors. */ +const int& k9DVDChapter::getsectors() +{ + return sectors; +} + +const QTime& k9DVDChapter::gettime() +{ + return time; +} +k9DVDTitle *k9DVDChapter::getTitle() +{ + return m_title; +} + +k9DVDChapter::k9DVDChapter() +{ + length.setHMS(0,0,0); + num=0; + sectors=0; + startSector=0; + endSector=0; + m_selected=false; + time.setHMS(0,0,0); + cells.setAutoDelete(true); +} + + +bool k9DVDChapter::getSelected() const +{ + return m_selected; +} + + +void k9DVDChapter::setSelected(bool _value) +{ + if (_value && !m_title->isSelected() ) { + m_title->setforceSelection( true); + m_title->selectChapters( false); + } + m_selected = _value; + +} diff --git a/libk9copy/k9dvdchapter.h b/libk9copy/k9dvdchapter.h new file mode 100644 index 0000000..b7e2826 --- /dev/null +++ b/libk9copy/k9dvdchapter.h @@ -0,0 +1,88 @@ +// +// C++ Interface: k9dvdchapter +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9DVDCHAPTER_H +#define K9DVDCHAPTER_H + +#include "k9common.h" +#include "k9dvd.h" +#include <qptrlist.h> + +static int cptChapter=0; + + +enum angleBlock_t {angleNone=0,angleInside=1,angleStart=3,angleEnd=5}; + +class k9DVDTitle; +class k9ChapterCell :public QObject +{ + Q_OBJECT +public: + k9ChapterCell(uint _id,uint _angle){ m_id=_id;m_angle=_angle;m_angleBlock=angleNone;}; + virtual uint getid() {return m_id;}; + virtual uint getangle(){return m_angle;}; + virtual uchar getangleBlock() {return m_angleBlock;}; + virtual void setangleBlock(uchar _angleBlock) {m_angleBlock=_angleBlock;}; + virtual void setstartSector(uint32_t _value) { m_startSector=_value;}; + virtual uint32_t getstartSector() { return m_startSector;}; + virtual void setlastSector(uint32_t _value) { m_lastSector=_value;}; + virtual uint32_t getlastSector() { return m_lastSector;}; + +private: + uint m_id; + uint m_angle; + uchar m_angleBlock; + uint32_t m_startSector,m_lastSector; +}; + +class k9DVDChapter : public QObject +{ + Q_OBJECT + friend class k9DVDTitle; + friend class k9DVD; +private: // Private attributes + /** */ + int num; + int id; + /** */ + QTime length; + QTime time; + /** */ + int sectors; + unsigned long startSector; + unsigned long endSector; + k9DVDTitle *m_title; + bool m_selected; + static int getcptChapter() { cptChapter ++; return cptChapter;}; + static void setcptChapter(int _newValue) { cptChapter=_newValue;}; +public: // Public methods + k9DVDChapter(); + /** Read property of int num. */ + virtual const int& getnum(); + /** Read property of QTime length. */ + virtual const QTime& getlength(); + /** Read property of int sectors. */ + virtual const int& getsectors(); + QPtrList<k9ChapterCell> cells; + QValueList<uint32_t> startSectors; + virtual const QTime & gettime(); + virtual k9DVDTitle * getTitle(); + unsigned long getstartSector() { return startSector;}; + unsigned long getendSector() {return endSector;}; + + void setSelected(bool _value); + + + bool getSelected() const; + +}; + +#endif diff --git a/libk9copy/k9dvdprogress.cpp b/libk9copy/k9dvdprogress.cpp new file mode 100755 index 0000000..43c3ad8 --- /dev/null +++ b/libk9copy/k9dvdprogress.cpp @@ -0,0 +1,62 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#include "k9dvdprogress.h" +#include <qprogressbar.h> +#include <qlabel.h> + +k9DVDProgress::k9DVDProgress(QWidget* parent, const char* name, bool modal, WFlags fl) + : DVDProgress( parent, name, modal, fl ) +{ +} + +k9DVDProgress::~k9DVDProgress(){ +} +/** No descriptions */ +void k9DVDProgress::setpbTitleTotalSteps(unsigned int total){ +pbTitle->setTotalSteps(total); + +} +/** No descriptions */ +void k9DVDProgress::setpbTitleStep(unsigned int position){ +pbTitle->setProgress(position); +} +/** No descriptions */ +void k9DVDProgress::setpbTotalTotalSteps(int total){ + pbTotal->setTotalSteps(total); +} +/** No descriptions */ +void k9DVDProgress::setpbTotalStep(int position){ + pbTotal->setProgress(position); +} +/** No descriptions */ +void k9DVDProgress::setlblTitle(QString & text){ +lblTitle->setText(text); +} +/** No descriptions */ +void k9DVDProgress::setlblTotal(QString& text){ +lblTotal->setText(text); +} + +void k9DVDProgress::closeEvent( QCloseEvent* ce ) +{ + ce->ignore(); + return; +} diff --git a/libk9copy/k9dvdprogress.h b/libk9copy/k9dvdprogress.h new file mode 100755 index 0000000..3458278 --- /dev/null +++ b/libk9copy/k9dvdprogress.h @@ -0,0 +1,51 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#ifndef K9DVDPROGRESS_H +#define K9DVDPROGRESS_H + +#include "dvdprogress.h" + +/** + *@author + */ + +class k9DVDProgress : public DVDProgress { +Q_OBJECT +public: + k9DVDProgress(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~k9DVDProgress(); + /** No descriptions */ + void setpbTitleTotalSteps(unsigned int total); + /** No descriptions */ + void setpbTitleStep(unsigned int position); + /** No descriptions */ + void setpbTotalTotalSteps(int total); + /** No descriptions */ + void setpbTotalStep(int position); + /** No descriptions */ + void setlblTitle(QString & text); + /** No descriptions */ + void setlblTotal(QString& text); +protected: + void closeEvent( QCloseEvent* ce ); +}; + +#endif diff --git a/libk9copy/k9dvdread.cpp b/libk9copy/k9dvdread.cpp new file mode 100644 index 0000000..1ec173d --- /dev/null +++ b/libk9copy/k9dvdread.cpp @@ -0,0 +1,171 @@ +// +// C++ Implementation: k9dvdread +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9dvdread.h" +#include "dvdread.h" +#include "k9ifo2.h" + +k9DVDRead::k9DVDRead(){ + m_dvd=NULL; + ifos.setAutoDelete(true); + files.setAutoDelete(true); +} + + +k9DVDRead::~k9DVDRead() { + if (m_dvd !=NULL) + close(); +} + +k9DVDFile::k9DVDFile(k9DVDRead *_dvd) { + m_file=NULL; + m_dvd=_dvd; +} + +k9DVDFile::~k9DVDFile() { + if (m_file != NULL) + close(); +} + +/*! + \fn k9DVDRead::openDevice(const QString & _device) + */ +void k9DVDRead::openDevice(const QString & _device) { + m_dvd=DVDOpen(_device.utf8()); + //turn UDF cache off + //DVDUDFCacheLevel(m_dvd, 0 ); + if (m_dvd) { + k9Ifo2 *ifoz=new k9Ifo2(this); + ifoz->openIFO(0); + ifos.append(ifoz); + ifo_handle_t *hifoz=ifoz->getIFO(); + int nrTS= hifoz->vmgi_mat->vmg_nr_of_title_sets; + + for (int iTS=1 ; iTS<=nrTS;iTS++) { + k9Ifo2 *ifo=new k9Ifo2(this); + ifo->openIFO(iTS); + ifos.append(ifo); + } + } +} + +k9Ifo2 *k9DVDRead::getIfo(int _num) { + k9Ifo2 *ifo=ifos.at(_num); + + return ifo; +} + +QString k9DVDRead::getDiscId() { +uchar ID[17]; +QString id=""; +if (DVDDiscID(m_dvd,ID) !=-1) { + ID[16]=0; + id=QString::fromLatin1((const char*)ID); +} +return id; +} +/*! + \fn k9DVDRead::close() + */ +void k9DVDRead::close() +{ + DVDClose(m_dvd); + ifos.clear(); + files.clear(); + m_dvd=NULL; +} + +bool k9DVDRead::opened() { + return (m_dvd !=NULL); +} + + +k9DVDFile * k9DVDRead::openIfo(uint _vts) { + k9DVDFile *file =new k9DVDFile(this); + file->openIfo(_vts); + files.append(file); + return file; +} + +k9DVDFile *k9DVDRead::openMenu(uint _vts) { + k9DVDFile *file =new k9DVDFile(this); + file->openMenu(_vts); + files.append(file); + return file; +} + +k9DVDFile *k9DVDRead::openTitle(uint _vts) { + k9DVDFile *file =new k9DVDFile(this); + file->openTitle(_vts); + files.append(file); + return file; +} + +/*! + \fn k9DVDFile::openIfo(uint _vts) + */ +void k9DVDFile::openIfo(uint _vts) { + m_file=DVDOpenFile(m_dvd->getDvd(),_vts,DVD_READ_INFO_FILE); +} + + +/*! + \fn k9DVDFile::openMenu(uint _vts) + */ +void k9DVDFile::openMenu(uint _vts) +{ + m_file=DVDOpenFile(m_dvd->getDvd() ,_vts,DVD_READ_MENU_VOBS); +} + + +/*! + \fn k9DVDFile::openTitle(uint _vts) + */ +void k9DVDFile::openTitle(uint _vts) +{ + m_file=DVDOpenFile(m_dvd->getDvd(),_vts,DVD_READ_TITLE_VOBS); +} + + +/*! + \fn k9DVDFile::close() + */ +void k9DVDFile::close() +{ + if (m_file !=NULL) { + DVDCloseFile(m_file); + m_file=NULL; + } +} + + +/*! + \fn k9DVDFile::read(uchar *_buffer,uint32_t _size) + */ +int k9DVDFile::readBytes(uchar *_buffer,uint32_t _size) +{ + if (m_file !=NULL) + return DVDReadBytes(m_file,_buffer,_size); + else + return -1; +} + +int k9DVDFile::readBlocks(uint32_t _sector,uint32_t _size,uchar*_buffer) { + if (m_file !=NULL) { + return DVDReadBlocks(m_file,_sector,_size,_buffer); + } + else + return -1; +} + + + + diff --git a/libk9copy/k9dvdread.h b/libk9copy/k9dvdread.h new file mode 100644 index 0000000..b962c12 --- /dev/null +++ b/libk9copy/k9dvdread.h @@ -0,0 +1,70 @@ +// +// C++ Interface: k9dvdread +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9DVDREAD_H +#define K9DVDREAD_H + +#include "k9common.h" +#include <qlibrary.h> + +/** + @author Jean-Michel PETIT <[email protected]> +*/ + +class k9DVDRead; +class k9Ifo2; + +class k9DVDFile { +friend class k9DVDRead; +private: + dvd_file_t *m_file; + k9DVDRead *m_dvd; + QLibrary *m_library; + void openIfo(uint _vts); + void openMenu(uint _vts); + void openTitle(uint _vts); + +public: + k9DVDFile(k9DVDRead *_dvd); + ~k9DVDFile(); + void close(); + int readBytes(uchar *_buffer,uint32_t _size); + int readBlocks(uint32_t _sector,uint32_t _size,uchar*_buffer); +}; + + +class k9DVDRead{ +friend class k9DVDTitle; +private: + dvd_reader_t *m_dvd; + QPtrList <k9DVDFile> files; + QPtrList <k9Ifo2> ifos; +public: + k9DVDRead(); + ~k9DVDRead(); + void openDevice(const QString & _device); + k9DVDFile *openIfo(uint _vts); + k9DVDFile *openMenu(uint _vts); + k9DVDFile *openTitle(uint _vts); + k9Ifo2 *getIfo(int _num); + QString getDiscId(); + void close(); + bool opened(); + + dvd_reader_t* getDvd() const { + return m_dvd; + } + + +}; + + +#endif diff --git a/libk9copy/k9dvdsize.cpp b/libk9copy/k9dvdsize.cpp new file mode 100644 index 0000000..41360cc --- /dev/null +++ b/libk9copy/k9dvdsize.cpp @@ -0,0 +1,43 @@ +// +// C++ Implementation: k9dvdsize +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9dvdsize.h" + +int DVD_MAX_SIZE=4400; + +k9DVDSize::k9DVDSize(QObject *parent,const char *name,const QStringList args) +{ +} + +int k9DVDSize::getMaxSize(){ + return DVD_MAX_SIZE; +} + +void k9DVDSize::setMaxSize(int _size){ + DVD_MAX_SIZE=_size; + +} + +int k9DVDSize::getMaxSizeDyn(){ + return DVD_MAX_SIZE; +} + +void k9DVDSize::setMaxSizeDyn(int _size){ + DVD_MAX_SIZE=_size; + +} + + +k9DVDSize::~k9DVDSize() +{ +} + + diff --git a/libk9copy/k9dvdsize.h b/libk9copy/k9dvdsize.h new file mode 100644 index 0000000..fee2278 --- /dev/null +++ b/libk9copy/k9dvdsize.h @@ -0,0 +1,34 @@ +// +// C++ Interface: k9dvdsize +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9DVDSIZE_H +#define K9DVDSIZE_H + +#include <qobject.h> +#include <qstringlist.h> +/** +@author Jean-Michel PETIT +*/ +class k9DVDSize:public QObject { +Q_OBJECT +private: + static int m_size; +public: + k9DVDSize(QObject *parent=0,const char *name=0,const QStringList args=0) ; + static int getMaxSize(); + static void setMaxSize(int _size); + virtual int getMaxSizeDyn(); + virtual void setMaxSizeDyn(int _size); + ~k9DVDSize(); + +}; + +#endif diff --git a/libk9copy/k9dvdtitle.cpp b/libk9copy/k9dvdtitle.cpp new file mode 100644 index 0000000..acd2bdb --- /dev/null +++ b/libk9copy/k9dvdtitle.cpp @@ -0,0 +1,503 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ + +#include "k9dvdtitle.h" + +#include <qapplication.h> + +#include <string.h> +#include <sys/stat.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <qvaluelist.h> +#include "k9dvdtitleset.h" +#include "k9titleencopt.h" + +//*******************k9DVDAudioStream************** +k9DVDAudioStream::k9DVDAudioStream() { + size_mb=0; + selected=false; +} + +/** Read property of QString format. */ +const QString& k9DVDAudioStream::getformat() { + return format; +} + +/** Read property of QString frequency. */ +const QString& k9DVDAudioStream::getfrequency() { + return frequency; +} +/** Read property of QString quantization. */ +const QString& k9DVDAudioStream::getquantization() { + return quantization; +} +/** Read property of int channels. */ +const int& k9DVDAudioStream::getchannels() { + return channels; +} +/** Read property of int appMode. */ +const int& k9DVDAudioStream::getappMode() { + return appMode; +} +/** Read property of QString content. */ +const QString& k9DVDAudioStream::getcontent() { + return content; +} + +/** Read property of float size_mb. */ +const float& k9DVDAudioStream::getsize_mb() { + return size_mb; +} + + +/** Read property of bool selected. */ +const bool& k9DVDAudioStream::getselected() { + return selected; +} +/** Write property of bool selected. */ +void k9DVDAudioStream::setselected( const bool& _newVal) { + bool before=title->isSelected(); + selected = _newVal; + title->gettitleset()->setAudio(getID(),_newVal); + title->gettitleset()->updateSelection(); + bool after=title->isSelected(); + if (after!=before) + title->selectChapters( after); +} + +/** Read property of QString langCod. */ +const QString& k9DVDAudioStream::getlangCod() { + return langCod; +} +/** Read property of QString language. */ +const QString& k9DVDAudioStream::getlanguage() { + return language; +} + +k9DVDTitle * k9DVDAudioStream::gettitle() { + return title; +} + +int k9DVDAudioStream::getID() { + return(id); +} + +//*******************k9DVDSubtitle ******************* + +k9DVDSubtitle::k9DVDSubtitle() { + size_mb=0; + selected=false; +} + + +/** Read property of QString langCod. */ +const QString& k9DVDSubtitle::getlangCod() { + return langCod; +} +/** Read property of QString language. */ +const QString& k9DVDSubtitle::getlanguage() { + return language; +} +/** Read property of int num. */ +const int& k9DVDSubtitle::getnum() { + return num; +} +/** Read property of QString content. */ +const QString& k9DVDSubtitle::getcontent() { + return content; +} + +/** Read property of bool selected. */ +const bool& k9DVDSubtitle::getselected() { + return selected; +} +/** Write property of bool selected. */ +void k9DVDSubtitle::setselected( const bool& _newVal) { + bool before=title->isSelected(); + selected = _newVal; + title->gettitleset()->updateSelection(); + bool after=title->isSelected(); + if (after!=before) + title->selectChapters(after); +} + +/** Read property of float size_mb. */ +const float& k9DVDSubtitle::getsize_mb() { + return size_mb; +} + +k9DVDTitle * k9DVDSubtitle::gettitle() { + return title; +} + + +/*! +\fn k9DVDSubtitle::getID() +*/ +QValueList<int>& k9DVDSubtitle::getID() { + return id; +} + + +//************************* k9DVDTitle *************************** + +/** No descriptions */ +k9DVDAudioStream* k9DVDTitle::addAudioStream() { + k9DVDAudioStream *auds; + auds = new k9DVDAudioStream; + auds->title=this; + audioStreams.append(auds); + return(auds); +} + +/** No descriptions */ +k9DVDSubtitle* k9DVDTitle::addSubtitle(int num) { + k9DVDSubtitle *subt; + subt = new k9DVDSubtitle; + subt->title=this; + subt->num=num; + subtitles.append(subt); + return(subt); +} + +/** No descriptions */ +k9DVDChapter* k9DVDTitle::addChapter(int num) { + k9DVDChapter *chap; + chap = new k9DVDChapter; + chap->m_title=this; + chap->num = num; + chap->id=k9DVDChapter::getcptChapter(); + chapters.append(chap); + return(chap); +} + +k9DVDChapter* k9DVDTitle::getChapter(int num) { + return (k9DVDChapter*)chapters.at(num); +} + +/** No descriptions */ +k9DVDAudioStream *k9DVDTitle::getaudioStream(int num) { + return (k9DVDAudioStream*)audioStreams.at(num); +} + + +/** Read property of int chapterCount. */ +const int& k9DVDTitle::getchapterCount() { + return chapterCount; +} +/** Read property of int streamCount. */ +const int& k9DVDTitle::getstreamCount() { + return streamCount; +} + +/** Read property of int audioStreamCount. */ +const int& k9DVDTitle::getaudioStreamCount() { + return audioStreamCount; +} + +/** Read property of int audioStreamCount. */ +const int& k9DVDTitle::getsubPictureCount() { + return subPictureCount; +} +/** Read property of int streamCount. */ +const QTime& k9DVDTitle::getlength() { + return length; +} + +/** Read property of int streamCount. */ +const int& k9DVDTitle::getnumTitle() { + return numTitle; +} + +/** No descriptions */ +k9DVDSubtitle *k9DVDTitle::getsubtitle(int num) { + return (k9DVDSubtitle*)subtitles.at(num); +} + +/** Read property of float size_mb. */ +const float& k9DVDTitle::getsize_mb() { + return size_mb; +} + +const float k9DVDTitle::gettotalsize_mb() { + float size =size_mb; + for (uint i=0;i<m_titles.count();i++) { + k9DVDTitle *tmp=m_titles.at(i); + size +=tmp->getsize_mb(); + } + return size; + +} + +//If _selected=true, returns the size of selected chapters, otherwise returns size of +//unselected ones +const float k9DVDTitle::getChaptersSize_mb(bool _selected){ + return (getChaptersSize(_selected)/512); +} + +//If _selected=true, returns the size of selected chapters, otherwise returns size of +//unselected ones +const uint64_t k9DVDTitle::getChaptersSize(bool _selected){ + uint64_t total=0; + for (int i=0;i<chapterCount ;i++) { + k9DVDChapter *chap = getChapter( i); + if (chap->getSelected()==_selected) { + total+= chap->getsectors(); + } + } + for (uint i=0;i<m_titles.count();i++) { + k9DVDTitle * title=m_titles.at(i); + total+=title->getChaptersSize(_selected); + } + return total; + +} + +const float k9DVDTitle::gettotalvideosize_mb() { + float size =videosize_mb; + for (uint i=0;i<m_titles.count();i++) { + k9DVDTitle *tmp=m_titles.at(i); + size+=tmp->getvideosize_mb(); + } + return size; + +} + + +QTime k9DVDTitle::gettotallength() { + QTime totalTime=getlength(); + for (uint i=0;i<m_titles.count();i++) { + k9DVDTitle *tmp=m_titles.at(i); + QTime t; + int msecs= t.msecsTo(tmp->getlength()); + totalTime=totalTime.addMSecs(msecs); + } + return totalTime; + +} + +QTime k9DVDTitle::getSelectedLength() { + QTime totalTime(0,0); + for (k9DVDChapter *chapter=chapters.first();chapter;chapter=chapters.next()) { + if (chapter->getSelected()) { + QTime t; + int msecs= t.msecsTo(chapter->getlength()); + totalTime=totalTime.addMSecs(msecs); + } + } + + + for (uint i=0;i<m_titles.count();i++) { + k9DVDTitle *tmp=m_titles.at(i); + QPtrList <k9DVDChapter> tchapters=tmp->getChapters(); + for (k9DVDChapter *chapter=tchapters.first();chapter;chapter=tchapters.next()) { + if (chapter->getSelected()) { + QTime t; + int msecs= t.msecsTo(chapter->getlength()); + totalTime=totalTime.addMSecs(msecs); + } + } + } + return totalTime; + +} + + +/** Read property of float videosize_mb. */ +const float& k9DVDTitle::getvideosize_mb() { + return videosize_mb; +} + + +/** Read property of int VTS. */ +const int& k9DVDTitle::getVTS() { + return VTS; +} +/** Read property of int TTN. */ +const int& k9DVDTitle::getTTN() { + return TTN; +} +/** Read property of float FPS. */ +const float& k9DVDTitle::getFPS() { + return FPS; +} +/** Read property of QString format. */ +const QString& k9DVDTitle::getformat() { + return format; +} +/** Read property of QString aspectRatio. */ +const QString& k9DVDTitle::getaspectRatio() { + return aspectRatio; +} +/** Read property of QString width. */ +const QString& k9DVDTitle::getwidth() { + return width; +} +/** Read property of QString height. */ +const QString& k9DVDTitle::getheight() { + return height; +} +/** Read property of QString palette. */ +void k9DVDTitle::getpalette(int i,QString & c) { + c=*palette.at(i); +} +/** Read property of QString DF. */ +const QString& k9DVDTitle::getDF() { + return DF; +} +/** Read property of int angleCount. */ +const int& k9DVDTitle::getangleCount() { + return angleCount; +} + + +bool k9DVDTitle::isSelected() { + k9DVDAudioStream *l_auds; + k9DVDSubtitle *l_sub; + uint i; + + if (forceSelection) + return true; + + for (i=0;i<audioStreams.count();i++) { + l_auds=getaudioStream(i); + if (l_auds->getselected()) { + return(true); + } + } + + for (i=0;i<subtitles.count();i++) { + l_sub=getsubtitle(i); + if (l_sub->getselected()) { + return(true); + } + } + return(false); +} + + void k9DVDTitle::setforceSelection(bool _state) { + bool before=isSelected(); + forceSelection = _state; + gettitleset()->updateSelection(); + bool after=isSelected(); + if (after!=before) { + selectChapters(after); + emit selectionChanged(); + } +} + + +/** Read property of QString name. */ +const QString& k9DVDTitle::getname() { + return name; +} +/** Write property of QString name. */ +void k9DVDTitle::setname( const QString& _newVal) { + name = _newVal; +} + +/*! +\fn k9DVDTitle::getpgc() +*/ +int k9DVDTitle::getpgc() { + return(pgc); +} + + +/*! +\fn k9DVDTitle::setNextTitle(k9DVDTitle * nextTitle) +*/ +void k9DVDTitle::setnextTitle(k9DVDTitle * nTitle) { + nextTitle=nTitle; +} + + +/*! +\fn k9DVDTitle::getnextTitle() +*/ +k9DVDTitle* k9DVDTitle::getnextTitle() { + return nextTitle; +} + + +k9DVDAudioStream* k9DVDTitle::getDefAudio() const { + return m_defAudio; +} + + +void k9DVDTitle::setDefAudio(k9DVDAudioStream* _value) { + m_defAudio = _value; + m_defAudioSet = true; +} + + +k9DVDSubtitle* k9DVDTitle::getDefSubtitle() const { + return m_defSubtitle; +} + + +void k9DVDTitle::setDefSubtitle(k9DVDSubtitle* _value) { + m_defSubtitle = _value; + m_defSubtitleSet=true; +} + + +k9DVDTitle::k9DVDTitle() { + audioStreams.setAutoDelete(true); + chapters.setAutoDelete(true); + subtitles.setAutoDelete(true); + size_mb=0; + videosize_mb=0; + vobusize_mb=0; + nextTitle=NULL; + m_defAudio=NULL; + m_defSubtitle=NULL; + m_defAudioSet=false; + m_defSubtitleSet=false; + forceSelection=false; + m_forceFactor=false; + m_factor=0; + m_encOpt=NULL; +} + +k9TitleEncOpt* k9DVDTitle::getEncOpt() { + if (!m_encOpt) + m_encOpt=new k9TitleEncOpt(this); + return m_encOpt; + +} + + +void k9DVDTitle::selectChapters(bool _state) { + for (int i=0;i < chapterCount;i++) { + getChapter(i)->setSelected( _state); + } + + for (uint iTitle=0;iTitle<m_titles.count();iTitle++) { + k9DVDTitle * title=m_titles.at(iTitle); + title->selectChapters(_state); + } +} + + + + diff --git a/libk9copy/k9dvdtitle.h b/libk9copy/k9dvdtitle.h new file mode 100644 index 0000000..9b29f53 --- /dev/null +++ b/libk9copy/k9dvdtitle.h @@ -0,0 +1,259 @@ +/************************************************************************** +* Copyright (C) 2005 by Jean-Michel Petit * +* [email protected] * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +***************************************************************************/ +#ifndef K9DVDTITLE_H +#define K9DVDTITLE_H + +#include "k9common.h" +#include "k9dvd.h" +#include "k9dvdchapter.h" +#include <qdatetime.h> +#include <qstringlist.h> +#include <qptrlist.h> + +class k9DVDTitleSet; + +class k9DVDVideoStream : public QObject{ +Q_OBJECT +friend class k9DVDTitle; +private: // Private attributes +public: // Public methods + +}; + +class k9DVDAudioStream : public QObject{ +Q_OBJECT +friend class k9DVDTitle; +friend class k9DVD; +private: // Private attributes + /** */ + QString langCod; + /** */ + QString language; + /** */ + QString format; + /** */ + QString frequency; + /** */ + QString quantization; + /** */ + int channels; + /** */ + int appMode; + /** */ + QString content; + /** */ + float size_mb; + /** */ + bool selected; + int id; + k9DVDTitle *title; + int m_streamId; +public: // Public methods + k9DVDAudioStream(); + /** Read property of QString langCod. */ + virtual const QString& getlangCod(); + /** Read property of QString language. */ + virtual const QString& getlanguage(); + /** Read property of QString format. */ + virtual const QString& getformat(); + /** Read property of QString frequency. */ + virtual const QString& getfrequency(); + /** Read property of QString quantization. */ + virtual const QString& getquantization(); + /** Read property of int channels. */ + virtual const int& getchannels(); + /** Read property of int appMode. */ + virtual const int& getappMode(); + /** Read property of QString content. */ + virtual const QString& getcontent(); + /** Read property of float size_mb. */ + virtual const float& getsize_mb(); + /** Write property of bool selected. */ + virtual void setselected( const bool& _newVal); + /** Read property of bool selected. */ + virtual const bool& getselected(); + + virtual k9DVDTitle* gettitle(); + virtual int getID(); + + virtual int getStreamId() const {return m_streamId;}; + +}; + +class k9DVDSubtitle : public QObject{ +Q_OBJECT +friend class k9DVDTitle; +friend class k9DVD; +private: // Private attributes + /** */ + QString langCod; + /** */ + QString language; + /** */ + int num; + /** */ + QString content; + /** */ + float size_mb; + /** */ + bool selected; + QValueList<int> id; + k9DVDTitle *title; +public: // Public methods + k9DVDSubtitle(); + /** Read property of QString langCod. */ + virtual const QString& getlangCod(); + /** Read property of QString language. */ + virtual const QString& getlanguage(); + /** Read property of int num. */ + virtual const int& getnum(); + /** Read property of QString content. */ + virtual const QString& getcontent(); + /** Read property of float size_mb. */ + virtual const float& getsize_mb(); + /** Write property of bool selected. */ + virtual void setselected( const bool& _newVal); + /** Read property of bool selected. */ + virtual const bool& getselected(); + virtual k9DVDTitle* gettitle(); + virtual QValueList<int>& getID(); +}; + + +class k9TitleEncOpt; + + +class k9DVDTitle : public QObject{ +Q_OBJECT +friend class k9DVD; +private: // Public attributes + unsigned int ts_nr; + int chapterCount; + int streamCount; + int audioStreamCount; + int subPictureCount; + QTime length; + k9DVDVideoStream videoStream; + QObjectList audioStreams; + QObjectList subtitles; + int VTS; + int TTN; + float FPS; + QString format; + QString aspectRatio; + int numTitle; + QString width; + QString height; + QStringList palette; + QString DF; + float size_mb; + int angleCount; + float videosize_mb; + float vobusize_mb; + QString name; + k9DVDTitle* nextTitle; + int id; + k9DVDTitleset *m_titleset; + k9DVDAudioStream *m_defAudio; + k9DVDSubtitle *m_defSubtitle; + bool m_defAudioSet; + bool m_defSubtitleSet; + QPtrList <k9DVDTitle> m_titles; + uint32_t m_sectors; + bool m_forceFactor; + float m_factor; + k9TitleEncOpt *m_encOpt; +public: // Public methods + k9DVDTitle(); + virtual k9DVDTitleset *gettitleset() {return m_titleset;}; + virtual const int& getchapterCount(); + virtual const int& getstreamCount(); + virtual const int& getaudioStreamCount(); + virtual const int& getsubPictureCount(); + virtual const QTime& getlength(); + virtual QTime gettotallength(); + virtual QTime getSelectedLength(); + + virtual const int& getVTS(); + virtual const int& getTTN(); + virtual const float& getFPS(); + virtual const QString& getformat(); + virtual const QString& getaspectRatio(); + virtual const QString& getwidth(); + virtual const QString& getheight(); + virtual void getpalette(int i,QString & c); + virtual const QString& getDF(); + virtual const int& getangleCount(); + virtual const int& getnumTitle(); + virtual k9DVDAudioStream *getaudioStream(int num); + virtual k9DVDSubtitle *getsubtitle(int num); + virtual const float& getsize_mb(); + virtual const float gettotalsize_mb(); + virtual const float gettotalvideosize_mb(); + virtual const float getChaptersSize_mb(bool _selected); + virtual const uint64_t getChaptersSize(bool _selected); + virtual const float& getvideosize_mb(); + virtual bool isSelected(); + virtual void setname( const QString& _newVal); + virtual const QString& getname(); + virtual int getpgc(); + virtual void setnextTitle(k9DVDTitle * nTitle); + virtual k9DVDTitle* getnextTitle(); + virtual k9DVDChapter *getChapter(int num); + virtual bool getIndexed() {return indexed;}; + virtual void setforceSelection(bool _state); + virtual int getId() {return id;}; + virtual void setDefAudio(k9DVDAudioStream* _value); + virtual k9DVDAudioStream* getDefAudio() const; + virtual void setDefSubtitle(k9DVDSubtitle* _value); + virtual k9DVDSubtitle* getDefSubtitle() const; + virtual bool getDefAudioSet() const {return m_defAudioSet;}; + virtual bool getDefSubtitleSet() const {return m_defSubtitleSet;}; + virtual QPtrList< k9DVDTitle > getTitles() const {return m_titles;}; + virtual uint32_t getsectors() { return m_sectors;}; + virtual float getfactor() { return m_factor;}; + virtual bool getforceFactor() { return m_forceFactor;}; + virtual void selectChapters(bool _state); + virtual QPtrList< k9DVDChapter > getChapters() const {return chapters;}; + virtual k9TitleEncOpt* getEncOpt() ; + +public slots: + virtual void setfactor(float _value) {m_factor=_value;}; + virtual void setforceFactor(bool _value) {m_forceFactor=_value;}; + +signals: + void selectionChanged(); +private: // Private methods + k9DVDAudioStream* addAudioStream(); + k9DVDChapter* addChapter(int num); + k9DVDSubtitle* addSubtitle(int num); + QPtrList <k9DVDChapter> chapters; + bool indexed; + bool forceSelection; + int pgc; + +public: // Public attributes +}; + + + + +#endif + diff --git a/libk9copy/k9dvdtitleset.cpp b/libk9copy/k9dvdtitleset.cpp new file mode 100644 index 0000000..cfa445a --- /dev/null +++ b/libk9copy/k9dvdtitleset.cpp @@ -0,0 +1,138 @@ +// +// C++ Implementation: k9dvdtitleset +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "k9dvdtitleset.h" +#include <string.h> +#include <sys/stat.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <qvaluelist.h> + +k9DVDTitleset::k9DVDTitleset( uint _num,uint32_t _size) { + m_num=_num; + m_size=_size; + m_selected=false; + m_updating=false; + for (uint i=0;i<8;i++) + m_audioStreams[i]=false; +}; + + +const QString k9DVDTitleset::getsize_mb() +{ + double size_mb=(double)m_size /512; + QString c; + c.sprintf("%.2f",size_mb); + return c; +} + +int k9DVDTitleset::getnum() +{ + return m_num; +} + +void k9DVDTitleset::add(k9DVDTitle * _title) +{ + titles.append(_title); +} + +int k9DVDTitleset::count() +{ + return titles.count(); +} + +k9DVDTitle * k9DVDTitleset::gettitle(uint _pos) +{ + return titles.at(_pos); +} + +uint32_t k9DVDTitleset::getsize() +{ + return m_size; +} + +bool k9DVDTitleset::getselected() +{ + return m_selected; +} + +void k9DVDTitleset::setselected(bool _state) +{ + // selectionner / d�electionner tous les titres + for (int i=0; i<count();i++) + { + k9DVDTitle *title=titles.at(i); + for (int j=0; j <title->getaudioStreamCount();j++) + title->getaudioStream(j)->setselected(_state); + for (int j=0;j<title->getsubPictureCount();j++) + title->getsubtitle(j)->setselected(_state); + title->setforceSelection(_state); + } + m_selected=_state;; +} + +void k9DVDTitleset::updateSelection() +{ + if (m_updating) + return; + m_updating=true; + + + bool selected=m_selected; + m_selected=false; + //check if at least on title is selected + for (int i=0; i<count() && (!m_selected);i++) + { + k9DVDTitle *title=titles.at(i); + if (title->isSelected() && title->getIndexed()) + m_selected=true; + } + + //if titleset selected, we select all features. otherwise they are unselected + if (selected !=m_selected) + for (int i=0; i<count();i++) + { + k9DVDTitle *title=titles.at(i); + //FIXED : parts of title selection + if (title->getIndexed() && title->isSelected()) + for (uint iTitle=0;iTitle <title->getTitles().count();iTitle++) + { + k9DVDTitle *title2=title->getTitles().at(iTitle); + for (int j=0; j <title2->getaudioStreamCount();j++) + title2->getaudioStream(j)->setselected(title->getaudioStream(j)->getselected()); + for (int j=0;j<title2->getsubPictureCount();j++) + title2->getsubtitle(j)->setselected(title2->getsubtitle(j)->getselected()); + title2->setforceSelection(true); + } + } + m_updating=false; +} + +void k9DVDTitleset::setAudio(int _id,bool _selected) { + m_audioStreams[_id -1]=_selected; +} + +int k9DVDTitleset::getNewAudioStreamId(int _oldId) { + int newId=0; + //Returns the new stream Id, only if the stream is selected. Otherwise, returns 0 + if (m_audioStreams[_oldId-1]) { +/* for (int i=0; i<_oldId;i++) { + if (m_audioStreams[i]) + newId++; + } +*/ + return _oldId; + } + return newId; +} + diff --git a/libk9copy/k9dvdtitleset.h b/libk9copy/k9dvdtitleset.h new file mode 100644 index 0000000..7e42522 --- /dev/null +++ b/libk9copy/k9dvdtitleset.h @@ -0,0 +1,48 @@ +// +// C++ Interface: k9dvdtitleset +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9DVDTITLESET_H +#define K9DVDTITLESET_H + +#include "k9common.h" +#include "k9dvd.h" +#include <qdatetime.h> +#include <qstringlist.h> +#include <qptrlist.h> +#include "k9dvdtitle.h" + +class k9DVDTitleset :public QObject +{ + Q_OBJECT +private: + int m_num; + uint32_t m_size; + QPtrList <k9DVDTitle> titles; + bool m_selected; + bool m_updating; + bool m_audioStreams[8]; +public: + k9DVDTitleset( uint _num,uint32_t _size); + virtual void add(k9DVDTitle *_title); + virtual int count(); + virtual k9DVDTitle *gettitle(uint _pos); + virtual uint32_t getsize(); + virtual const QString getsize_mb(); + virtual bool getselected(); + virtual void setselected(bool state); + virtual void updateSelection(); + virtual int getnum(); + virtual void setAudio(int _id,bool _selected); + virtual int getNewAudioStreamId(int _oldId); +} +; + +#endif diff --git a/libk9copy/k9ifo2.cpp b/libk9copy/k9ifo2.cpp new file mode 100644 index 0000000..56ba072 --- /dev/null +++ b/libk9copy/k9ifo2.cpp @@ -0,0 +1,933 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jean-Michel Petit * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "k9ifo2.h" +#include "bswap.h" +#include "dvdread.h" + + +k9Ifo2::k9Ifo2(k9DVDRead *_dvdread) + : QObject(NULL,"") { + _ifo=NULL; + m_dvd=_dvdread; +} + + +k9Ifo2::~k9Ifo2() { + closeIFO(); + + +} + +/*! + \fn k9Ifo2::setDevice(QString &_device) + */ +void k9Ifo2::setDevice(QString &_device) { + device=_device; +} + + +/*! + \fn k9Ifo2::setOutput(QString &_output) + */ +void k9Ifo2::setOutput(QString &_output) { + output=_output; +} + + +/*! + \fn k9Ifo2::openIFO(int _num) + */ +ifo_handle_t * k9Ifo2::openIFO(int _num) { + _ifo = ifoOpen(m_dvd->getDvd(), _num); + numIfo=_num; + return _ifo; + +} + + +/*! + \fn k9Ifo2::IFOClose( ifo_handle_t* _ifo) + */ +void k9Ifo2::closeIFO() { + if(_ifo!=NULL) { + ifoClose(_ifo); + _ifo=NULL; + } +} + +ifo_handle_t * k9Ifo2::getIFO() { + return _ifo; +} + +/*! + \fn k9Ifo2::saveIFO(ifo_handle_t* _ifo) + */ +void k9Ifo2::saveIFO() { + uint32_t size; + /* DVD handler */ + k9DVDFile *dvdfile; + bool mainIfo = (numIfo==0); + + QString filename,filename2; + if (mainIfo) { + filename="/VIDEO_TS/VIDEO_TS.IFO"; + } else { + filename.sprintf("/VIDEO_TS/VTS_%02d_0.IFO",numIfo); + } + if (numIfo==0) + size=_ifo->vmgi_mat->vmgi_last_sector +1; + else + size=_ifo->vtsi_mat->vtsi_last_sector +1; + + size*=DVD_BLOCK_LEN; + // if (k9UDFFindFile(dvd,(char*) filename.latin1(), &size)) { + if (size > 0) { + uchar *buffer ; + buffer=new uchar[size]; + bufCopy=new uchar[size]; + m_buffer=new uchar[size*2]; + memset(buffer,0,size); + memset(bufCopy,0,size); + memset(m_buffer,0,size*2); + //Lecture du fichier IFO original et sauvegarde dans buffer + if ((dvdfile = m_dvd->openIfo(numIfo))== 0) { + fprintf(stderr, "Failed opening IFO for titleset %d\n", 0); + free(buffer); + return; + } + + /* if(DVDFileSeek(dvd_file, 0)!=0) { + return; + } + */ + + if (dvdfile->readBytes(buffer,size) != size) { + fprintf(stderr, "Error reading IFO for titleset %d\n", 0); + free(buffer); + dvdfile->close(); + return; + } + + memcpy(bufCopy,buffer,size); + bufCopySize=size; + dvdfile->close(); + if (mainIfo) { + m_position=0; + updateVMG(buffer); + m_position=1024; //sizeof(vmgi_mat_t); + updateFP_PGC(buffer); + _ifo->vmgi_mat->vmgi_last_byte=m_position -1; + + updateTT_SRPT(buffer); + updatePGCI_UT(buffer); + + updateVTS_ATRT(buffer); + updateTXTDT_MGI(buffer); + updateC_ADT(buffer,true); + updateVOBU_ADMAP(buffer,true); + + updateVMG(buffer); + + } else { + m_position=0; + updateVTS(buffer); + m_position=sizeof(vtsi_mat_t); + //_ifo->vtsi_mat->vtsi_last_byte=m_position -1; + updateVTS_PTT_SRPT(buffer); + updatePGCIT(buffer); + updatePGCI_UT(buffer); + updateVTS_TMAPT(buffer); + updateC_ADT(buffer,true); + updateVOBU_ADMAP(buffer,true); + updateC_ADT(buffer, false); + updateVOBU_ADMAP(buffer,false); + updateVTS(buffer); + } + m_position=round(m_position); + + //sauvegarder buffer dans fichier + if (mainIfo) { + filename=output + "/VIDEO_TS.IFO"; + filename2=output + "/VIDEO_TS.BUP"; + } else { + filename.sprintf("/VTS_%02d_0.IFO",numIfo); + filename=output + filename; + + filename2.sprintf("/VTS_%02d_0.BUP",numIfo); + filename2=output + filename2; + } + + QFile ifofile (filename); + ifofile.open(IO_WriteOnly); + if (ifofile.writeBlock((char*)m_buffer,m_position) == -1) { + QString sError("erreur"); + } + ifofile.close(); + + QFile ifofile2 (filename2); + ifofile2.open(IO_WriteOnly); + if (ifofile2.writeBlock((char*)m_buffer,m_position) == -1) { + QString sError("erreur"); + } + ifofile2.close(); + + + delete buffer; + delete bufCopy; + delete m_buffer; + } +} + + +/*! + \fn k9Ifo2::updateVMG(uchar * _buffer) + */ +void k9Ifo2::updateVMG(uchar * _buffer) { + vmgi_mat_t vmgi_mat; + memcpy(&vmgi_mat,_ifo->vmgi_mat,sizeof(vmgi_mat_t)); + uint32_t lastSector=vmgi_mat.vmgi_last_sector; + uint32_t lastByte=vmgi_mat.vmgi_last_byte; + //JMP : à vérifier + if (m_position !=0) { + lastSector=(round(m_position) - DVD_BLOCK_LEN) / DVD_BLOCK_LEN; + //lastByte=vmgi_mat.vmgi_last_sector * DVD_BLOCK_LEN +DVD_BLOCK_LEN -1; + vmgi_mat.vmg_last_sector+=2*(lastSector-vmgi_mat.vmgi_last_sector); + } + + vmgi_mat.vmgi_last_sector=lastSector; + if (vmgi_mat.vmgm_vobs !=0) + vmgi_mat.vmgm_vobs=vmgi_mat.vmgi_last_sector +1; + + B2N_32(vmgi_mat.vmg_last_sector); + B2N_32(vmgi_mat.vmgi_last_sector); + B2N_32(vmgi_mat.vmg_category); + B2N_16(vmgi_mat.vmg_nr_of_volumes); + B2N_16(vmgi_mat.vmg_this_volume_nr); + B2N_16(vmgi_mat.vmg_nr_of_title_sets); + B2N_64(vmgi_mat.vmg_pos_code); + B2N_32(vmgi_mat.vmgi_last_byte); + B2N_32(vmgi_mat.first_play_pgc); + B2N_32(vmgi_mat.vmgm_vobs); + B2N_32(vmgi_mat.tt_srpt); + B2N_32(vmgi_mat.vmgm_pgci_ut); + B2N_32(vmgi_mat.ptl_mait); + B2N_32(vmgi_mat.vts_atrt); + B2N_32(vmgi_mat.txtdt_mgi); + B2N_32(vmgi_mat.vmgm_c_adt); + B2N_32(vmgi_mat.vmgm_vobu_admap); + B2N_16(vmgi_mat.vmgm_audio_attr.lang_code); + B2N_16(vmgi_mat.vmgm_subp_attr.lang_code); + + memcpy(m_buffer,&vmgi_mat,sizeof(vmgi_mat_t)); +} + + +/*! + \fn k9Ifo2::updateFP_PGC(uchar * _buffer) + */ +void k9Ifo2::updateFP_PGC(uchar * _buffer) { + //int offset=_ifo->vmgi_mat->first_play_pgc; + _ifo->vmgi_mat->first_play_pgc=m_position; + return updatePGC(_buffer,_ifo->first_play_pgc,m_position); + + +} + +/*! + \fn k9Ifo2::updatePGC(uchar *_buffer,pgc_t *_pgc,int _offset) + */ +void k9Ifo2::updatePGC(uchar *_buffer,pgc_t *_pgc,int _offset) { + pgc_t pgc; + memcpy(&pgc,_pgc,sizeof(pgc_t)); + uint start=m_position; + m_position+=PGC_SIZE; + + if(pgc.command_tbl_offset != 0) { + pgc.command_tbl_offset=PGC_SIZE; + updatePGC_COMMAND_TBL(_buffer ,pgc.command_tbl ,m_position); + } + if(pgc.program_map_offset != 0) { + pgc.program_map_offset=m_position-start; + updatePGC_PROGRAM_MAP(_buffer, pgc.program_map,pgc.nr_of_programs ,m_position); + } + if(pgc.cell_playback_offset != 0) { + pgc.cell_playback_offset=m_position-start; + updatePGC_CELL_PLAYBACK_TBL(_buffer ,pgc.cell_playback,pgc.nr_of_cells,m_position); + } + + if(pgc.cell_position_offset != 0) { + pgc.cell_position_offset=m_position-start; + updatePGC_CELL_POSITION_TBL(_buffer,pgc.cell_position,pgc.nr_of_cells,m_position); + } + + B2N_16(pgc.command_tbl_offset); + B2N_16(pgc.next_pgc_nr); + B2N_16(pgc.prev_pgc_nr); + B2N_16(pgc.goup_pgc_nr); + B2N_16(pgc.program_map_offset); + B2N_16(pgc.cell_playback_offset); + B2N_16(pgc.cell_position_offset); + + int i; + for(i = 0; i < 8; i++) + B2N_16(pgc.audio_control[i]); + for(i = 0; i < 32; i++) + B2N_32(pgc.subp_control[i]); + for(i = 0; i < 16; i++) + B2N_32(pgc.palette[i]); + + memcpy(m_buffer+_offset,&pgc,PGC_SIZE); +} + + + +/*! + \fn k9Ifo2::updatePGC_COMMAND_TBL(uchar *_buffer,pgc_command_tbl_t *_cmd_tbl,int offset) + */ +void k9Ifo2::updatePGC_COMMAND_TBL(uchar *_buffer,pgc_command_tbl_t *_cmd_tbl,int _offset) { + struct { + uint16_t nr_of_pre; + uint16_t nr_of_post; + uint16_t nr_of_cell; + uint16_t last_byte; + } + ATTRIBUTE_PACKED cmd_tbl; + + memcpy(&cmd_tbl,_cmd_tbl,sizeof(cmd_tbl)); + + //moves the offset to save vm_cmd + m_position+=sizeof(cmd_tbl); + + if(_cmd_tbl->nr_of_pre != 0) { + unsigned int pre_cmds_size = _cmd_tbl->nr_of_pre * COMMAND_DATA_SIZE; + memcpy(m_buffer + m_position,_cmd_tbl->pre_cmds,pre_cmds_size); + m_position+=pre_cmds_size; + } + if(_cmd_tbl->nr_of_post != 0) { + unsigned int post_cmds_size = _cmd_tbl->nr_of_post * COMMAND_DATA_SIZE; + memcpy(m_buffer + m_position,_cmd_tbl->post_cmds,post_cmds_size); + m_position+=post_cmds_size; + } + if(_cmd_tbl->nr_of_cell != 0) { + unsigned int cell_cmds_size = _cmd_tbl->nr_of_cell * COMMAND_DATA_SIZE; + memcpy(m_buffer +m_position,_cmd_tbl->cell_cmds,cell_cmds_size); + m_position+=cell_cmds_size; + } + B2N_16(cmd_tbl.nr_of_pre); + B2N_16(cmd_tbl.nr_of_post); + B2N_16(cmd_tbl.nr_of_cell); + cmd_tbl.last_byte=m_position-_offset-1; + B2N_16(cmd_tbl.last_byte); + memcpy(m_buffer+_offset,&cmd_tbl,sizeof(cmd_tbl)); + + +} + + +/*! + \fn k9Ifo2::updatePGC_PROGRAM_MAP(uchar *_buffer, pgc_program_map_t *_program_map, int _nr, int_offset + */ +void k9Ifo2::updatePGC_PROGRAM_MAP(uchar *_buffer, pgc_program_map_t *_program_map, int _nr, int _offset) { + int size = _nr * sizeof(pgc_program_map_t); + memcpy(m_buffer+_offset, _program_map, size); + // pad to word boundary + size += size % 2; + m_position += size; +} + + +/*! + \fn k9Ifo2::updatePGC_CELL_PLAYBACK_TBL(uchar *_buffer, cell_playback_t *_cell_playback,int _nr, int _offset) + */ +void k9Ifo2::updatePGC_CELL_PLAYBACK_TBL(uchar *_buffer, cell_playback_t *_cell_playback,int _nr, int _offset) { + cell_playback_t *cell_playback; + int size = _nr * sizeof(cell_playback_t); + cell_playback=(cell_playback_t*) malloc(size); + memcpy(cell_playback,_cell_playback,size); + + for( int i = 0; i < _nr; i++) { + B2N_32(cell_playback[i].first_sector); + B2N_32(cell_playback[i].first_ilvu_end_sector); + B2N_32(cell_playback[i].last_vobu_start_sector); + B2N_32(cell_playback[i].last_sector); + } + + memcpy(m_buffer + _offset,cell_playback,size); + m_position+=size; + + free(cell_playback); +} + + +/*! + \fn k9Ifo2::updatePGC_CELL_POSITION_TBL(uchar *_buffer,cell_position_t *_cell_position,int _nr, int _offset) + */ +void k9Ifo2::updatePGC_CELL_POSITION_TBL(uchar *_buffer,cell_position_t *_cell_position,int _nr, int _offset) { + cell_position_t * cell_position; + int size = _nr * sizeof(cell_position_t); + cell_position=(cell_position_t*)malloc(size); + memcpy(cell_position,_cell_position,size); + for( int i = 0; i < _nr; i++) { + B2N_16(cell_position[i].vob_id_nr); + } + memcpy(m_buffer + _offset,cell_position,size); + m_position+=size; + free(cell_position); +} + +int k9Ifo2::round(int _value) { + return ((_value-1)|(DVD_BLOCK_LEN-1))+1; // DVD_BLOCK_LEN-1 = 0x7FF +} + +/*! + \fn k9Ifo2::updateTT_SRPT(uchar *_buffer) + */ +void k9Ifo2::updateTT_SRPT(uchar *_buffer) { + if(_ifo->vmgi_mat->tt_srpt != 0) { + tt_srpt_t * tt_srpt; + tt_srpt=(tt_srpt_t*) malloc(sizeof(tt_srpt_t)); + // int offset= _ifo->vmgi_mat->tt_srpt * DVD_BLOCK_LEN; + + m_position=round(m_position); + int offset=m_position; + _ifo->vmgi_mat->tt_srpt=m_position/DVD_BLOCK_LEN; + + memcpy (tt_srpt,_ifo->tt_srpt,sizeof(tt_srpt_t)); + + + int info_length = tt_srpt->last_byte + 1 - TT_SRPT_SIZE; + title_info_t * title_info; + title_info =(title_info_t*) malloc(info_length); + memcpy(title_info, tt_srpt->title,info_length); + + for(int i = 0; i < tt_srpt->nr_of_srpts; i++) { + B2N_16(title_info[i].nr_of_ptts); + B2N_16(title_info[i].parental_id); + B2N_32(title_info[i].title_set_sector); + } + memcpy(m_buffer+offset+TT_SRPT_SIZE,title_info,info_length); + + free(title_info); + m_position +=info_length; + + B2N_16(tt_srpt->nr_of_srpts); + B2N_32(tt_srpt->last_byte); + memcpy(m_buffer+offset,tt_srpt,TT_SRPT_SIZE); + free (tt_srpt); + } + +} + + +void k9Ifo2::updatePGCI_UT(uchar *_buffer) { + int sector,sector2; + if(_ifo->vmgi_mat) { + if(_ifo->vmgi_mat->vmgm_pgci_ut == 0) + return; + m_position=round(m_position); + _ifo->vmgi_mat->vmgm_pgci_ut=m_position/DVD_BLOCK_LEN; + } else if(_ifo->vtsi_mat) { + if(_ifo->vtsi_mat->vtsm_pgci_ut == 0) + return; + m_position=round(m_position); + _ifo->vtsi_mat->vtsm_pgci_ut=m_position/DVD_BLOCK_LEN; + } else { + return; + } + + + sector2=sector=m_position; + if (_ifo->pgci_ut !=NULL) { + pgci_ut_t * pgci_ut; + pgci_ut = (pgci_ut_t*) malloc( sizeof(pgci_ut_t)); + memcpy (pgci_ut,_ifo->pgci_ut,sizeof(pgci_ut_t)); + m_position+=PGCI_UT_SIZE; + sector2=m_position; + + pgci_lu_t pgci_lu[_ifo->pgci_ut->nr_of_lus]; + m_position+=_ifo->pgci_ut->nr_of_lus*PGCI_LU_SIZE; + memcpy(pgci_lu,_ifo->pgci_ut->lu,_ifo->pgci_ut->nr_of_lus*sizeof(pgci_lu_t)); + + for(int i = 0; i < _ifo->pgci_ut->nr_of_lus; i++) { + B2N_16(pgci_lu[i].lang_code); + pgci_lu[i].lang_start_byte=m_position - sector; + B2N_32(pgci_lu[i].lang_start_byte); + updatePGCIT_internal(_buffer,_ifo->pgci_ut->lu[i].pgcit,m_position); + } + for (int i=0;i <_ifo->pgci_ut->nr_of_lus;i++) + memcpy(m_buffer+sector2+i*PGCI_LU_SIZE ,&(pgci_lu[i]),PGCI_LU_SIZE); + + B2N_16(pgci_ut->nr_of_lus); + pgci_ut->last_byte=m_position-sector-1; + B2N_32(pgci_ut->last_byte); + memcpy(m_buffer+sector,pgci_ut,PGCI_UT_SIZE); + free(pgci_ut); + + + } + +} + +void k9Ifo2::updatePGCIT(uchar *_buffer) { + if(!_ifo->vtsi_mat) + return ; + + if(_ifo->vtsi_mat->vts_pgcit == 0) /* mandatory */ + return ; + m_position=round(m_position); + _ifo->vtsi_mat->vts_pgcit=m_position / DVD_BLOCK_LEN; + updatePGCIT_internal(_buffer,_ifo->vts_pgcit,_ifo->vtsi_mat->vts_pgcit * DVD_BLOCK_LEN); +} + + +void k9Ifo2::updatePGCIT_internal(uchar *_buffer, pgcit_t *_pgcit, int _offset) { + pgcit_t * pgcit; + pgcit=(pgcit_t*)malloc(sizeof(pgcit_t)); + memcpy(pgcit,_pgcit,sizeof(pgcit_t)); + + int offset=m_position+PGCIT_SIZE; + m_position+=PGCIT_SIZE; + + pgci_srp_t pgci_srp[_pgcit->nr_of_pgci_srp]; + memcpy(pgci_srp,_pgcit->pgci_srp,sizeof(pgci_srp_t)*_pgcit->nr_of_pgci_srp); + + m_position+=_pgcit->nr_of_pgci_srp*PGCI_SRP_SIZE; + + for(int i = 0; i < _pgcit->nr_of_pgci_srp; i++) { + B2N_16(pgci_srp[i].ptl_id_mask); + pgci_srp[i].pgc_start_byte=m_position-_offset; + B2N_32(pgci_srp[i].pgc_start_byte); //JMP:faux + updatePGC(_buffer,_pgcit->pgci_srp[i].pgc,m_position); + } + + for(int i = 0; i < _pgcit->nr_of_pgci_srp; i++) + memcpy(m_buffer+offset+i*PGCI_SRP_SIZE,&(pgci_srp[i]),PGCI_SRP_SIZE); + + B2N_16(pgcit->nr_of_pgci_srp); + pgcit->last_byte=m_position-_offset-1; + B2N_32(pgcit->last_byte); + memcpy(m_buffer+_offset ,pgcit,PGCIT_SIZE); + free(pgcit); + +} + + +void k9Ifo2::updatePTL_MAIT(uchar *_buffer) { + if(!_ifo->vmgi_mat) + return; + + _ifo->vmgi_mat->ptl_mait = 0; + return; +} + +void k9Ifo2::updateVTS_ATRT(uchar *_buffer) { + if(_ifo->vmgi_mat->vts_atrt == 0) + return; + uint32_t orig=_ifo->vmgi_mat->vts_atrt * DVD_BLOCK_LEN; + m_position=round(m_position); + _ifo->vmgi_mat->vts_atrt=m_position/DVD_BLOCK_LEN; + + memcpy(m_buffer+m_position,_buffer+orig,_ifo->vts_atrt->last_byte+1); + + m_position+=_ifo->vts_atrt->last_byte+1; + /* + int sector = _ifo->vmgi_mat->vts_atrt * DVD_BLOCK_LEN; + vts_atrt_t *vts_atrt; + vts_atrt = (vts_atrt_t*)malloc(sizeof(vts_atrt_t)); + memcpy(vts_atrt,_ifo->vts_atrt,VTS_ATRT_SIZE); + B2N_16(vts_atrt->nr_of_vtss); + B2N_32(vts_atrt->last_byte); + memcpy(m_buffer+sector,vts_atrt,VTS_ATRT_SIZE); + free(vts_atrt); + m_position+=VTS_ATRT_SIZE; + + sector += VTS_ATRT_SIZE; + + memcpy(m_buffer+sector,_buffer +orig+VTS_ATRT_SIZE ,VTS_ATTRIBUTES_SIZE*_ifo->vts_atrt->nr_of_vtss); + + m_position+=VTS_ATTRIBUTES_SIZE*_ifo->vts_atrt->nr_of_vtss; + */ +} + +void k9Ifo2::updateTXTDT_MGI(uchar * _buffer) { + if(_ifo->vmgi_mat->txtdt_mgi == 0) + return; + + struct { + char disc_name[15]; + char nr_of_language_units; + uint32_t last_byte; + txtdt_lu_t *lu; + } ATTRIBUTE_PACKED txtdtmgi; + + + m_position=round(m_position); + int orig=_ifo->vmgi_mat->txtdt_mgi*DVD_BLOCK_LEN; + int offset=m_position; + _ifo->vmgi_mat->txtdt_mgi =m_position/ DVD_BLOCK_LEN; + memcpy(&txtdtmgi,_buffer+orig,sizeof(txtdtmgi)); + + B2N_32(txtdtmgi.last_byte); + memcpy(m_buffer+offset,_buffer+orig ,txtdtmgi.last_byte+1); + m_position+=txtdtmgi.last_byte+1; +} + +void k9Ifo2::updateC_ADT(uchar * _buffer, bool _isMenu) { + if(_ifo->vmgi_mat) { + if(_ifo->vmgi_mat->vmgm_c_adt != 0) { + m_position =round(m_position); // + _ifo->vmgi_mat->vmgm_c_adt=m_position/ DVD_BLOCK_LEN; + updateC_ADT_Internal(_buffer,_ifo->menu_c_adt,m_position); + } + } else if(_ifo->vtsi_mat) { + if(_ifo->vtsi_mat->vtsm_c_adt != 0 && _isMenu) { + m_position=round(m_position); //sector = + _ifo->vtsi_mat->vtsm_c_adt=m_position / DVD_BLOCK_LEN; + updateC_ADT_Internal(_buffer,_ifo->menu_c_adt,m_position); + } + if (_ifo->vtsi_mat->vts_c_adt !=0 && !_isMenu) { + m_position=round(m_position); //sector = + _ifo->vtsi_mat->vts_c_adt=m_position / DVD_BLOCK_LEN; + updateC_ADT_Internal(_buffer,_ifo->vts_c_adt,m_position); + } + } else { + return ; + } + +} + +void k9Ifo2::updateC_ADT_Internal(uchar *_buffer,c_adt_t *_c_adt,int _sector) { + c_adt_t * c_adt; + c_adt =(c_adt_t*) malloc (sizeof(c_adt_t)); + memcpy(c_adt,_c_adt,sizeof(c_adt_t)); + + + int offset =_sector + C_ADT_SIZE; + m_position+=C_ADT_SIZE; + + int info_length = _c_adt->last_byte + 1 - C_ADT_SIZE; + + cell_adr_t *cell_adr,*ptr; + cell_adr=(cell_adr_t*) malloc(sizeof(cell_adr_t)); + + ptr= _c_adt->cell_adr_table; + for(int i = 0; i < info_length/sizeof(cell_adr_t); i++) { + memcpy(cell_adr,&(ptr[i]),sizeof(cell_adr_t)); + B2N_16(cell_adr->vob_id); + B2N_32(cell_adr->start_sector); + B2N_32(cell_adr->last_sector); + memcpy(m_buffer+offset,cell_adr,sizeof(cell_adr_t)); + offset+=sizeof(cell_adr_t); + //ptr+=sizeof(cell_adr_t); + } + + m_position+=info_length; + free(cell_adr); + + B2N_16(c_adt->nr_of_vobs); + c_adt->last_byte=m_position-_sector-1; + B2N_32(c_adt->last_byte); + memcpy(m_buffer+_sector,c_adt,C_ADT_SIZE); + free(c_adt); +} + +void k9Ifo2::updateVOBU_ADMAP(uchar * _buffer, bool _isMenu) { + int sector; + if(_ifo->vmgi_mat) { + + if(_ifo->vmgi_mat->vmgm_vobu_admap == 0) + return ; + sector = m_position=round(m_position);//_ifo->vmgi_mat->vmgm_vobu_admap * DVD_BLOCK_LEN; + _ifo->vmgi_mat->vmgm_vobu_admap=m_position/DVD_BLOCK_LEN; + updateVOBU_ADMAP_Internal(_buffer,_ifo->menu_vobu_admap,sector); + + } else if(_ifo->vtsi_mat) { + + if(_ifo->vtsi_mat->vtsm_vobu_admap != 0 && _isMenu) { + sector = m_position=round(m_position);//sector = _ifo->vtsi_mat->vtsm_vobu_admap * DVD_BLOCK_LEN; + _ifo->vtsi_mat->vtsm_vobu_admap=m_position/DVD_BLOCK_LEN; + updateVOBU_ADMAP_Internal(_buffer,_ifo->menu_vobu_admap,sector); + } + if (_ifo->vtsi_mat->vts_vobu_admap !=0 && !_isMenu) { + sector = m_position=round(m_position);//sector = _ifo->vtsi_mat->vts_vobu_admap * DVD_BLOCK_LEN; + _ifo->vtsi_mat->vts_vobu_admap=m_position/DVD_BLOCK_LEN; + updateVOBU_ADMAP_Internal(_buffer,_ifo->vts_vobu_admap,sector); + } + } else { + return ; + } +} + +void k9Ifo2::updateVOBU_ADMAP_Internal(uchar *_buffer,vobu_admap_t *_vobu_admap,int _sector) { + vobu_admap_t *vobu_admap; + vobu_admap=(vobu_admap_t*)malloc(sizeof(vobu_admap_t)); + memcpy(vobu_admap,_vobu_admap,sizeof(vobu_admap_t)); + + int offset = _sector + VOBU_ADMAP_SIZE; + m_position+=VOBU_ADMAP_SIZE; + + int info_length = _vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE; + uint32_t *vobu_start_sectors; + vobu_start_sectors=(uint32_t*)malloc(info_length); + memcpy(vobu_start_sectors,_vobu_admap->vobu_start_sectors,info_length); + + for(int i = 0; i < info_length/sizeof(uint32_t); i++) + B2N_32(vobu_start_sectors[i]); + + memcpy(m_buffer+offset,vobu_start_sectors,info_length); + + m_position+=info_length; + free(vobu_start_sectors); + vobu_admap->last_byte=m_position-_sector-1; + B2N_32(vobu_admap->last_byte); + memcpy(m_buffer+_sector,vobu_admap,VOBU_ADMAP_SIZE); + free(vobu_admap); + +} + +void k9Ifo2::updateVTS(uchar *_buffer) { + vtsi_mat_t *vtsi_mat; + vtsi_mat = (vtsi_mat_t *)malloc(sizeof(vtsi_mat_t)); + memcpy(vtsi_mat,_ifo->vtsi_mat,sizeof(vtsi_mat_t)); + + uint32_t lastSector=vtsi_mat->vtsi_last_sector; + //uint32_t lastByte=vtsi_mat->vtsi_last_byte; + //JMP : à vérifier + if (m_position >0) { + lastSector=(round(m_position)-DVD_BLOCK_LEN) /DVD_BLOCK_LEN; + //lastByte=vtsi_mat->vtsi_last_sector*DVD_BLOCK_LEN +DVD_BLOCK_LEN-1; + vtsi_mat->vts_last_sector+=2*(lastSector-vtsi_mat->vtsi_last_sector); + vtsi_mat->vtstt_vobs+=lastSector-vtsi_mat->vtsi_last_sector; + } + + vtsi_mat->vtsi_last_sector=lastSector; + //vtsi_mat->vtsi_last_byte=lastByte; + if (vtsi_mat->vtsm_vobs !=0) + vtsi_mat->vtsm_vobs= vtsi_mat->vtsi_last_sector +1 ; + + B2N_32(vtsi_mat->vts_last_sector); + B2N_32(vtsi_mat->vtsi_last_sector); + B2N_32(vtsi_mat->vts_category); + + B2N_32(vtsi_mat->vtsi_last_byte); + B2N_32(vtsi_mat->vtsm_vobs); + B2N_32(vtsi_mat->vtstt_vobs); + B2N_32(vtsi_mat->vts_ptt_srpt); + B2N_32(vtsi_mat->vts_pgcit); + B2N_32(vtsi_mat->vtsm_pgci_ut); + B2N_32(vtsi_mat->vts_tmapt); + B2N_32(vtsi_mat->vtsm_c_adt); + B2N_32(vtsi_mat->vtsm_vobu_admap); + B2N_32(vtsi_mat->vts_c_adt); + B2N_32(vtsi_mat->vts_vobu_admap); + B2N_16(vtsi_mat->vtsm_audio_attr.lang_code); + B2N_16(vtsi_mat->vtsm_subp_attr.lang_code); + for(int i = 0; i < 8; i++) + B2N_16(vtsi_mat->vts_audio_attr[i].lang_code); + for(int i = 0; i < 32; i++) + B2N_16(vtsi_mat->vts_subp_attr[i].lang_code); + + memcpy(m_buffer,vtsi_mat,sizeof(vtsi_mat_t)); + + free(vtsi_mat); +} + +void k9Ifo2::updateVTS_PTT_SRPT(uchar *_buffer) { + if(!_ifo->vtsi_mat) + return ; + + if(_ifo->vtsi_mat->vts_ptt_srpt == 0) /* mandatory */ + return ; + + vts_ptt_srpt_t * vts_ptt_srpt; + vts_ptt_srpt = (vts_ptt_srpt_t *)malloc(sizeof(vts_ptt_srpt_t)); + memcpy(vts_ptt_srpt,_ifo->vts_ptt_srpt,sizeof(vts_ptt_srpt_t)); + int orig=_ifo->vtsi_mat->vts_ptt_srpt * DVD_BLOCK_LEN; + int offset = m_position=round(m_position);//_ifo->vtsi_mat->vts_ptt_srpt * DVD_BLOCK_LEN; + _ifo->vtsi_mat->vts_ptt_srpt=m_position/DVD_BLOCK_LEN; + + B2N_16(vts_ptt_srpt->nr_of_srpts); + B2N_32(vts_ptt_srpt->last_byte); + + memcpy(m_buffer+offset,vts_ptt_srpt,VTS_PTT_SRPT_SIZE); + free(vts_ptt_srpt); + m_position+=VTS_PTT_SRPT_SIZE; + + int info_length = _ifo->vts_ptt_srpt->last_byte + 1 - VTS_PTT_SRPT_SIZE; + + memcpy(m_buffer+m_position,_buffer+orig+VTS_PTT_SRPT_SIZE, info_length); + m_position+=info_length; +} + + +/*! + \fn k9Ifo2::checkBuffer() + */ + + +void k9Ifo2::updateVTS_TMAPT(uchar *_buffer) { + if(!_ifo->vtsi_mat) + return ; + + if(_ifo->vtsi_mat->vts_tmapt == 0) { /* optional(?) */ + return ; + } + + vts_tmapt_t *vts_tmapt1,*vts_tmapt; + vts_tmapt=_ifo->vts_tmapt; + int info_length = vts_tmapt->nr_of_tmaps * 4; + + uint32_t offsets[vts_tmapt->nr_of_tmaps]; + + vts_tmapt1 = (vts_tmapt_t *)malloc(VTS_TMAPT_SIZE); + memcpy(vts_tmapt1,_ifo->vts_tmapt,VTS_TMAPT_SIZE); + uint32_t offset = m_position=round(m_position); + + _ifo->vtsi_mat->vts_tmapt =m_position / DVD_BLOCK_LEN; + + int offset0=offset; + offset+=VTS_TMAPT_SIZE; + m_position +=VTS_TMAPT_SIZE; + + + offset += info_length; + m_position+=info_length; + + info_length=0; + vts_tmap_t *tmap=vts_tmapt->tmap; + //loop on tmaps to compute total size + for (int i=0;i <vts_tmapt->nr_of_tmaps;i++) { + int tmapSize=VTS_TMAP_SIZE+tmap[i].nr_of_entries*sizeof(map_ent_t); + info_length+=tmapSize+4; + } + + tmap = (vts_tmap_t *)malloc(sizeof(vts_tmap_t)* vts_tmapt->nr_of_tmaps); + memcpy(tmap,vts_tmapt->tmap,sizeof(vts_tmap_t)* vts_tmapt->nr_of_tmaps); + + vts_tmapt1->last_byte=VTS_TMAPT_SIZE+info_length-1; + for(int i = 0; i < vts_tmapt->nr_of_tmaps; i++) { + int tmapSize=VTS_TMAP_SIZE+tmap[i].nr_of_entries*sizeof(map_ent_t); + int nr_map_ent=tmap[i].nr_of_entries; + B2N_16(tmap[i].nr_of_entries); + offsets[i]=m_position-offset0; + B2N_32(offsets[i]); + memcpy(m_buffer+m_position,&(tmap[i]),VTS_TMAP_SIZE); + m_position+=VTS_TMAP_SIZE; + offset+=VTS_TMAP_SIZE; + + if(nr_map_ent == 0) { // Early out if zero entries + continue; + } + int info_length2 = tmapSize-VTS_TMAP_SIZE; + map_ent_t *map_ent = (map_ent_t *)malloc(info_length2); + memcpy(map_ent,tmap[i].map_ent,info_length2); + for(int j = 0; j < nr_map_ent; j++) { + B2N_32(map_ent[j]); + memcpy(m_buffer+m_position,&(map_ent[j]),sizeof(map_ent_t)); + offset+=sizeof(map_ent_t); + m_position+=sizeof(map_ent_t); + } + free(map_ent); + } + + free(tmap); + B2N_16(vts_tmapt1->nr_of_tmaps); + B2N_32(vts_tmapt1->last_byte); + memcpy(m_buffer+offset0,vts_tmapt1,VTS_TMAPT_SIZE); + memcpy(m_buffer+offset0+VTS_TMAPT_SIZE,offsets,vts_tmapt->nr_of_tmaps*4); + free(vts_tmapt1); + + +} +void k9Ifo2::checkBuffer(QString lib,uchar* _buffer) { + /* for (int j=0;j<bufCopySize;j++) { + uchar *c,*c2; + c=(uchar*) (_buffer+j); + c2=(uchar*)(bufCopy+j); + if (*c!=*c2) { + return; + } + } + */ + return; + if (memcmp(bufCopy,_buffer,bufCopySize)!=0) { + QString c; + c="Buffer de sortie altéré: " +lib; + qDebug(c.latin1()); + } +} + +void k9Ifo2::navRead_PCI(pci_t *pci, uchar *buffer) { + int i, j; + + memcpy(pci, buffer, sizeof(pci_t)); + + /* Endian conversions */ + + /* pci pci_gi */ + B2N_32(pci->pci_gi.nv_pck_lbn); + B2N_16(pci->pci_gi.vobu_cat); + B2N_32(pci->pci_gi.vobu_s_ptm); + B2N_32(pci->pci_gi.vobu_e_ptm); + B2N_32(pci->pci_gi.vobu_se_e_ptm); + + /* pci nsml_agli */ + for(i = 0; i < 9; i++) + B2N_32(pci->nsml_agli.nsml_agl_dsta[i]); + + /* pci hli hli_gi */ + B2N_16(pci->hli.hl_gi.hli_ss); + B2N_32(pci->hli.hl_gi.hli_s_ptm); + B2N_32(pci->hli.hl_gi.hli_e_ptm); + B2N_32(pci->hli.hl_gi.btn_se_e_ptm); + + /* pci hli btn_colit */ + for(i = 0; i < 3; i++) + for(j = 0; j < 2; j++) + B2N_32(pci->hli.btn_colit.btn_coli[i][j]); + + /* NOTE: I've had to change the structure from the disk layout to get + * the packing to work with Sun's Forte C compiler. */ + + /* pci hli btni */ + for(i = 0; i < 36; i++) { + char tmp[sizeof(pci->hli.btnit[i])], swap; + memcpy(tmp, &(pci->hli.btnit[i]), sizeof(pci->hli.btnit[i])); + /* Byte 4 to 7 are 'rotated' was: ABCD EFGH IJ is: ABCG DEFH IJ */ + swap = tmp[6]; + tmp[6] = tmp[5]; + tmp[5] = tmp[4]; + tmp[4] = tmp[3]; + tmp[3] = swap; + + /* Then there are the two B2N_24(..) calls */ +#ifndef WORDS_BIGENDIAN + swap = tmp[0]; + tmp[0] = tmp[2]; + tmp[2] = swap; + + swap = tmp[4]; + tmp[4] = tmp[6]; + tmp[6] = swap; +#endif + memcpy(&(pci->hli.btnit[i]), tmp, sizeof(pci->hli.btnit[i])); + } + +} diff --git a/libk9copy/k9ifo2.h b/libk9copy/k9ifo2.h new file mode 100644 index 0000000..da04944 --- /dev/null +++ b/libk9copy/k9ifo2.h @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jean-Michel Petit * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef K9IFO2_H +#define K9IFO2_H +#include "k9common.h" +#include "k9dvdread.h" +#include <qfile.h> +#include <stdlib.h> +/** +@author Jean-Michel Petit +*/ +class k9Ifo2 : public QObject { + Q_OBJECT +public: + k9Ifo2(k9DVDRead *_dvdread); + + ~k9Ifo2(); + + void setDevice(QString &_device); + void setOutput(QString &_output); + ifo_handle_t * openIFO(int _num); + void closeIFO(); + void saveIFO(); + ifo_handle_t * getIFO(); + static void navRead_PCI(pci_t *pci, uchar *buffer); + int test; + + +protected: + QString device; + QString output; + ifo_handle_t *_ifo; + int numIfo; +private: + QFile* outputFile; + long cellSize; + uchar * bufCopy,*m_buffer; + int bufCopySize; + k9DVDRead *m_dvd; + uint m_position; +private: + int round(int); + void updateVMG(uchar * _buffer); + void updateFP_PGC(uchar * _buffer); + void updatePGC_COMMAND_TBL(uchar *_buffer,pgc_command_tbl_t *_cmd_tbl,int offset); + void updatePGC_PROGRAM_MAP(uchar *_buffer,pgc_program_map_t *_program_map, int _nr,int _offset); + void updatePGC_CELL_PLAYBACK_TBL(uchar *_buffer, cell_playback_t *_cell_playback,int _nr, int _offset); + void updatePGC_CELL_POSITION_TBL(uchar *_buffer,cell_position_t *_cell_position,int _nr, int _offset); + void updatePGC(uchar *_buffer,pgc_t *_pgc,int _offset); + void updateTT_SRPT(uchar *_buffer); + void updatePGCI_UT(uchar *_buffer); + void updatePTL_MAIT(uchar *_buffer); + void updateVTS_ATRT(uchar *_buffer); + void updateTXTDT_MGI(uchar * _buffer); + void updateC_ADT(uchar * _buffer, bool _isMenu); + void updateVOBU_ADMAP(uchar * _buffer, bool _isMenu); + void updatePGCIT(uchar *_buffer); + void updatePGCIT_internal(uchar *_buffer, pgcit_t *_pgcit, int offset); + void updateVTS(uchar *_buffer); + void updateVTS_PTT_SRPT(uchar *_buffer); + void updateVTS_TMAPT(uchar *_buffer) ; + void updateC_ADT_Internal(uchar *_buffer,c_adt_t *_c_adt,int _sector); + void updateVOBU_ADMAP_Internal(uchar *_buffer,vobu_admap_t *_vobu_admap,int _sector); + void checkBuffer(QString lib,uchar *_buffer); +}; + + +#endif diff --git a/libk9copy/k9mp4dlg.cpp b/libk9copy/k9mp4dlg.cpp new file mode 100644 index 0000000..d8b5bda --- /dev/null +++ b/libk9copy/k9mp4dlg.cpp @@ -0,0 +1,80 @@ +// +// C++ Implementation: +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + + +#include "k9mp4dlg.h" +#include <qlabel.h> +#include <kprogress.h> +#include <qpainter.h> +#include <kstandarddirs.h> +#include <qlayout.h> +#include "k9drawimage.h" + + +k9MP4Dlg::k9MP4Dlg(QWidget* parent, const char* name) +: MP4Dlg(parent,name, true) +{ + m_wimage=new k9DrawImage(image,0); + QGridLayout *l=new QGridLayout(image,1,1); + l->addWidget(m_wimage,0,0); + m_timer.start(); +} + +k9MP4Dlg::~k9MP4Dlg() +{ +} + +/*$SPECIALIZATION$*/ + +void k9MP4Dlg::Cancel() { + //QDialog::accept(); + emit sigCancel(); +} + +void k9MP4Dlg::setTitleLabel(QString _titleLabel) { + lblTitle->setText(_titleLabel); +} + + +void k9MP4Dlg::setfps(QString _fps) { + lblfps->setText(_fps); +} + +void k9MP4Dlg::setremain(QString _remain) { + if (m_timer.elapsed() >=1000) { + lblRemain->setText(_remain); + m_timer.restart(); + } +} + +void k9MP4Dlg::setProgress(int _progress) { + pbProgress->setProgress(_progress); + +} + +void k9MP4Dlg::setbitrate(QString _bitrate) { + lblbitrate->setText(_bitrate); +} + +void k9MP4Dlg::setsize( QString _size) { + lblsize->setText(_size); +} + + +void k9MP4Dlg::setImage(QString _fileName) { + m_wimage->setImage(_fileName); +} + + + +#include "k9mp4dlg.moc" + diff --git a/libk9copy/k9mp4dlg.h b/libk9copy/k9mp4dlg.h new file mode 100644 index 0000000..266ed47 --- /dev/null +++ b/libk9copy/k9mp4dlg.h @@ -0,0 +1,49 @@ +// +// C++ Interface: +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef K9MP4DLG_H +#define K9MP4DLG_H +#include "mp4dlg.h" +#include <qimage.h> +#include <qdatetime.h> + +class k9DrawImage; + +class k9MP4Dlg : public MP4Dlg +{ + Q_OBJECT + +public: + k9MP4Dlg(QWidget* parent = 0, const char* name = 0); + ~k9MP4Dlg(); + /*$PUBLIC_FUNCTIONS$*/ + void setfps(QString _fps); + void setsize(QString _size); + void setbitrate(QString _bitrate); + void setremain(QString _remain); + void setProgress(int _progress); + void setTitleLabel(QString _titleLabel); + void Cancel(); + void setImage(QString _fileName) ; + +signals: + /*$PUBLIC_SLOTS$*/ + void sigCancel(); +private: + k9DrawImage *m_wimage; + QTime m_timer; +protected: + /*$PROTECTED_FUNCTIONS$*/ +}; + +#endif + diff --git a/libk9copy/k9mp4enc.cpp b/libk9copy/k9mp4enc.cpp new file mode 100644 index 0000000..7d82c4f --- /dev/null +++ b/libk9copy/k9mp4enc.cpp @@ -0,0 +1,571 @@ +// +// C++ Implementation: k9mp4enc +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9mp4enc.h" +#include "k9mp4dlg.h" +#include "k9config.h" +#include <qcstring.h> +#include <qapplication.h> +#include <klocale.h> +#include <qstringlist.h> +#include <qdir.h> +#include <kfiledialog.h> +#include <kmessagebox.h> +#include <qstringlist.h> +#include <ktempfile.h> +#include <kstandarddirs.h> +#include "k9tools.h" +#include "k9audiocodecs.h" +#include "k9videocodecs.h" +#include <qcstring.h> + +k9MP4Enc::k9MP4Enc ( QObject *parent, const char *name,const QStringList& ) + : QObject ( parent, name ) +{ + m_fourcc=m_height=m_width=m_audioBitrate=m_videoBitrate=m_filename=""; + m_codec=0; //lavc_mp4; + m_audioCodec=0; + m_cpt=-1; + m_parts=1; + + QStringList laudio; + QStringList llabels; + QStringList lvideo; + + k9Config config; + m_lstAudio=config.getCodecAudio(); + m_lstCodecs=config.getCodecLabels(); + m_lstVideo=config.getCodecVideo(); + + timer = new QTimer ( this ); + connect ( timer, SIGNAL ( timeout() ), this, SLOT ( timerDone() ) ); + m_progress=new k9MP4Dlg ( qApp->mainWidget(),0 ); + +} + +QString k9MP4Enc::round16 ( QString _wh ) +{ + if ( _wh !="" ) + { + int value=_wh.toInt() /16; + return QString::number ( value*16 ); + + } + else + return _wh; + + +} + +QString k9MP4Enc::getChapterList ( k9DVDTitle *_title ) +{ + QString res=""; + QPtrList <k9DVDChapter> chapters=_title->getChapters(); + for ( k9DVDChapter *chapter=chapters.first();chapter;chapter=chapters.next() ) + { + if ( chapter->getSelected() ) + { + res+=res=="" ? QString::number ( chapter->getnum() ) : ","+QString::number ( chapter->getnum() ); + } + } + QPtrList <k9DVDTitle> titles=_title->getTitles(); + + for ( k9DVDTitle *title=titles.first();title;title=titles.next() ) + { + chapters=title->getChapters(); + for ( k9DVDChapter *chapter=chapters.first();chapter;chapter=chapters.next() ) + { + if ( chapter->getSelected() ) + { + res+=res=="" ? QString::number ( chapter->getnum() ) : ","+QString::number ( chapter->getnum() ); + } + } + } + return res; + +} + + +int k9MP4Enc::getselectedSubp ( k9DVDTitle *_title ) +{ + for ( int i=0;i< _title->getsubPictureCount();i++ ) + { + if ( _title->getsubtitle ( i )->getselected() ) + { + return _title->getsubtitle ( i )->getID().first()-1; + } + } + //nos subtitle selected + return -1; +} + + + +void k9MP4Enc::execute ( k9DVDTitle *_title ) +{ + bool error=false; + + if ( m_mpeg2 ) + { + m_parts=1; + m_2pass=false; + } + + if ( ! k9Tools::checkProgram ( "mencoder" ) && ! m_mpeg2 ) + { + KMessageBox::error ( qApp->mainWidget(),i18n ( "Unable to run %1" ).arg ( "mencoder" ) , i18n ( "Encoding error" ) ); + error = TRUE; + return; + } + + time = new QTime ( 0,0 ); + m_percent=0; + m_remain="--:--:--"; + + m_totalSize=_title->getChaptersSize ( true ); + + QString injectName; + KTempFile injectFile ( locateLocal ( "tmp", "k9copy/k9v" ), "" ); + injectFile.setAutoDelete ( true ); + injectFile.close(); + injectName=injectFile.name(); + + + int maxPass=0; + int pass=0; + + //build the cell list for mpeg2 extraction + QMap<QString,int> chapterCells; + QMap<QString, int>::iterator ichapterCells; + QStringList chapters; + if ( m_mpeg2 && m_mpegChapters ) + { + m_parts=0; + chapters=QStringList::split ( ",", getChapterList ( _title ) ); + for ( unsigned int idxChap = 0; idxChap < chapters.size(); idxChap++ ) + { + QString chapter = chapters[idxChap]; + //foreach (QString chapter,chapters) { + int iCell=0; + k9DVDChapter *chap=_title->getChapter ( chapter.toInt()-1 ); + //foreach(k9ChapterCell *cell ,chap->cells) { + iCell++; + chapterCells.insert ( chapter,iCell ); + m_parts++; + //} + } + ichapterCells = chapterCells.begin(); + } + + for ( int m_part =1 ; ( m_part <=m_parts ) && !error ;m_part++ ) + { + if ( m_2pass ) + { + maxPass=2; + pass=1; + } + KTempFile passLogFile ( locateLocal ( "tmp", "k9copy/k9v" ), "" ); + passLogFile.setAutoDelete ( true ); + passLogFile.close(); + + do + { + uint32_t nbSectors= m_totalSize / m_parts ; + + uint32_t startSector= nbSectors* ( m_part-1 ); + uint32_t endSector= startSector+nbSectors; + + //calculer le bitrate en faisant la somme des cells compris entre startSector et endSector + //FIXME Mettre en place la sélection par chapitres + m_stderr=""; + m_title=_title; + if ( m_height=="" || m_height=="0" ) + m_height="-2"; + if ( m_width=="" ) + m_width="640"; + if ( m_audioBitrate=="" ) + m_audioBitrate="128"; + if ( m_size=="" ) + m_size="700"; + if ( m_filename=="" ) + m_filename=KFileDialog::getSaveFileName ( QDir::homeDirPath(),"*.avi", 0,i18n ( "Save file to disk" ) ); + if ( m_filename =="" ) + return; + + QDir d=QDir::root(); + if ( d.exists ( m_filename ) ) + d.remove ( m_filename ); + + m_progress->setbitrate ( QString::number ( getBitRate ( _title ) ) ); + if ( !m_mpeg2 ) + m_progress->setsize ( m_size +i18n ( "MB" ) +" X " +QString::number ( m_parts ) ); + else + m_progress->setsize ( m_size +i18n ( "MB" ) +" X " ); + + m_process=new k9Process ( this,0 ); + m_process->setUseShell ( true ); + *m_process << "k9copy" << "--play" << "--endsector" << QString::number ( endSector ) ; + *m_process << "--inject" << injectName; //"/tmp/kde-jmp/inject"; + *m_process << "--input" << "'"+m_device+"'"; + *m_process << "--dvdtitle" << QString::number ( _title->getnumTitle() ); + + if ( m_mpegChapters && m_mpeg2 ) + { + *m_process << "--chapter" << ichapterCells.key();//chapters.at(m_part-1); + //*m_process << "--cell" << QString::number(ichapterCells.value()); + } + else + *m_process << "--chapterlist" << getChapterList ( _title ); + + if ( m_part==1 || m_mpeg2 ) + *m_process << "--initstatus"; + else + *m_process << "--continue"; + + if ( pass==1 ) + *m_process << "--firstpass"; + + for ( int i=0;i<_title->getaudioStreamCount();i++ ) + { + if ( _title->getaudioStream ( i )->getselected() ) + { + *m_process << "--audiofilter" << QString::number ( _title->getaudioStream ( i )->getID() ); + break; + } + } + + if ( getselectedSubp ( _title ) !=-1 ) + { + *m_process << "--subpicturefilter" ; + QString s=""; + for ( int i=1; i<=_title->getsubPictureCount();i++ ) + s+= ( i>1?",":"" ) + QString::number ( i ); + *m_process << s; + } + + if ( m_usecache ) + *m_process << "--usecache"; + + if ( m_mpeg2 ) + { + m_progress->setbitrate ( "--" ); + double size; + + if ( _title->getforceFactor() ) + { + size = _title->getChaptersSize_mb ( true ) /_title->getfactor(); + *m_process << "--vampsfactor" << QString::number ( _title->getfactor() ) << "--ffactor"; + } + else + size = _title->getChaptersSize_mb ( true ); + m_progress->setsize ( QString::number ( size ) +i18n ( "MB" ) ); + QString path=m_filename; + if ( m_parts>1 ) + { + QString ext=m_filename.section ( ".",-1 ); + if ( ext!="" ) + ext="."+ext; + path=m_filename.left ( m_filename.length()-ext.length() ); + //path=QString("%1-chapter%2-cell%3%4").arg(path).arg(ichapterCells.key()).arg(ichapterCells.value()).arg(ext); + path=QString ( "%1-chapter%2%3" ).arg ( path ).arg ( ichapterCells.key() ).arg ( ext ); + ++ichapterCells; + } + *m_process << "> "+path; + } + else + { + *m_process << "| mencoder" << "/dev/stdin"; + *m_process << "-passlogfile" << passLogFile.name(); + + bool audio=false; + QString sPass=""; + QString sCodec=""; + + k9AudioCodecs *audioCodecs=new k9AudioCodecs ( 0,0 ); + k9VideoCodecs *videoCodecs=new k9VideoCodecs ( 0,0 ); + + QString sVOption; + m_pass=pass; + switch ( pass ) + { + case 1: + sVOption=replaceParams ( videoCodecs->getOptions1 ( m_codec ) ); + break; + case 2: + sVOption=replaceParams ( videoCodecs->getOptions2 ( m_codec ) ); + break; + default: + sVOption=replaceParams ( videoCodecs->getOptions0 ( m_codec ) ); + break; + } + sCodec=videoCodecs->getCodecName ( m_codec ); + sVOption=sVOption.simplifyWhiteSpace(); + int pos; + //*m_process << "-ovc" << sVOption; + /* int pos=sVOption.find("-vf"); + if (pos==-1) + *m_process <<"-vf" << QString("scale=%1:%2").arg(m_width).arg(m_height); + else + sVOption=sVOption.insert(pos+4,QString("scale=%1:%2,").arg(m_width).arg(m_height)); + */ + *m_process << sVOption; + + QString sAOption=replaceParams ( audioCodecs->getOptions ( m_audioCodec ) ).simplifyWhiteSpace(); + + + + if ( pass >0 ) + m_progress->setTitleLabel ( i18n ( "Encoding %1" ).arg ( sCodec ) +" - "+i18n ( "pass %1" ).arg ( pass ) ); + else + m_progress->setTitleLabel ( i18n ( "Encoding %1" ).arg ( sCodec ) ); + + if ( m_fourcc !="" ) + *m_process << "-ffourcc" << m_fourcc; + else if ( videoCodecs->getFourcc ( m_codec ) !="" ) + *m_process << "-ffourcc" << videoCodecs->getFourcc ( m_codec ); + + delete audioCodecs; + delete videoCodecs; + + //looking for first audio selected + for ( int i=0;i<_title->getaudioStreamCount();i++ ) + { + if ( _title->getaudioStream ( i )->getselected() ) + { + //*m_process << "-oac" << sAOption; + pos=sAOption.find ( "-af" ); + if ( pos==-1 ) + *m_process << QString ( "-af volume=%1" ).arg ( m_audioGain ); + else + sAOption=sAOption.insert ( pos+4,QString ( "volume=%1," ).arg ( m_audioGain ) ); + *m_process << sAOption; + + audio=true; + break; + } + } + + if ( getselectedSubp ( _title ) !=-1 ) + { + *m_process << "-sid" << QString::number ( getselectedSubp ( _title ) ); + } + if ( !audio ) + *m_process << "-nosound"; + + QString path=m_filename; + + if ( m_parts>1 ) + { + QString ext=m_filename.section ( ".",-1 ); + if ( ext!="" ) + ext="."+ext; + path=m_filename.left ( m_filename.length()-ext.length() ); + path=path+QString::number ( m_part ) +ext; + } + if ( pass==1 ) + *m_process << "-o" << "/dev/null"; + else + *m_process <<"-o" << "'"+path+"'"; + if ( path.upper().endsWith ( "MPEG" ) || path.upper().endsWith ( "MPG" ) ) + *m_process << "-of" << "mpeg"; + else if ( path.upper().endsWith ( "AVI" ) ) + *m_process << "-of" << "avi"; + else + { + *m_process << "-of" << "lavf"; + *m_process << "-lavfopts" << "i_certify_that_my_video_stream_does_not_use_b_frames"; + } + //*m_process << "-of" << "avi"; + + } + QString s=""; + for ( uint i=0; i< m_process->args().count();i++ ) + { + QCString str=* ( m_process->args().at ( i ) ); + s +=QString ( str ) +" "; + } + qDebug ( s ); + time->start(); + m_timer3.start(); + connect ( m_process, SIGNAL ( receivedStdout ( KProcess *, char *, int ) ),this, SLOT ( getStdout ( KProcess *, char *, int ) ) ); + connect ( m_process, SIGNAL ( receivedStderr ( KProcess *, char *, int ) ),this, SLOT ( getStderr ( KProcess *, char *, int ) ) ); + //connect(m_process, SIGNAL(processExited(KProcess*)),this,SLOT(exited(KProcess*))); + connect ( m_progress,SIGNAL ( sigCancel() ),this,SLOT ( slotCancel() ) ); + m_canceled=false; + m_progress->show(); + m_process->start ( KProcess::OwnGroup, KProcess::All ); + timer->start ( 500, 0 ); + m_process->sync(); + //if application is exiting, kill the encoding process + if ( m_process->isRunning() ) + { + m_process->kill(); + return; + } + if ( m_canceled ) + { + KMessageBox::information ( qApp->mainWidget(),i18n ( "MPEG-4 Encoding cancelled" ), i18n ( "MPEG-4 Encoding" ) ); + error=true; + } + else if ( !m_process->normalExit() ) + { + KMessageBox::error ( qApp->mainWidget(),"<b>"+i18n ( "Error while running mencoder :" ) +"</b><br>"+m_stderr, i18n ( "Encoding error" ) ); + error=true; + } + if ( maxPass >0 ) + pass++; + } + while ( pass<=maxPass && !error && m_2pass ); + + } +} + + +void k9MP4Enc::slotCancel() +{ + m_canceled=true; + m_process->kill(); +} + + +QString k9MP4Enc::replaceParams ( QString _value ) +{ + QString str=_value; + str.replace ( "$PASS",QString::number ( m_pass ) ); + str.replace ( "$WIDTH",m_width ); + str.replace ( "$HEIGHT",m_height ); + str.replace ( "$VIDBR",QString::number ( getBitRate ( m_title ) ) ); + str.replace ( "$AUDBR",m_audioBitrate ); + return str; +} + + +int k9MP4Enc::getBitRate ( k9DVDTitle *_title ) +{ + // bitrate video = (MB *8388.608) /SEC - bitrate audio + + if ( m_videoBitrate!="" ) + { + return m_videoBitrate.toInt(); + } + else + { + int size=m_size.toInt(); + float titleSize=_title->getChaptersSize_mb ( true ); + if ( titleSize< ( float ) size ) + size= ( int ) ( titleSize/m_parts ) ; + m_progress->setsize ( QString::number ( size ) +i18n ( "MB" ) +" X " +QString::number ( m_parts ) ); + QTime t1 ( 0,0 ); + int sec=t1.secsTo ( _title->getSelectedLength() ); + //int bitrate=(int)( ((size*m_parts) * 8388.608)/sec - m_audioBitrate.toInt()); + int bitrate=8* ( ( ( size*m_parts*1024 )- ( m_audioBitrate.toInt() *sec/8 ) ) /sec ); + + return bitrate; + } +} + + +void k9MP4Enc::getStdout ( KProcess *, char *buffer, int buflen ) +{ + QCString tmp ( buffer,buflen ); + m_cpt++; + if ( m_cpt==100 ) + m_cpt=0; + + if ( m_cpt!=0 ) + return; + + int pos=tmp.find ( "Pos:" ); + if ( pos!=-1 ) + { + QString tmp2=tmp.mid ( pos ); + float t; + int frame; + int fps; + sscanf ( tmp2.latin1(),"Pos: %f%*s%d",&t,&frame ); + tmp2=tmp2.mid ( tmp2.find ( "(" ) +1 ); + tmp2=tmp2.mid ( tmp2.find ( ")" ) +1 ); + sscanf ( tmp2.latin1(),"%d",&fps ); + + m_progress->setfps ( QString::number ( fps ) ); + } + + +} + +void k9MP4Enc::getStderr ( KProcess *proc, char *buffer, int buflen ) +{ + //m_stderr=QString::fromLatin1(buffer,buflen); + QCString cstderr ( buffer,buflen+1 ); + + if ( cstderr.find ( "FATAL:" ) !=-1 ) + { + proc->kill(); + } + + int pos=cstderr.find ( "INFOPOS:" ); + if ( pos!=-1 ) + { + if ( m_timer3.elapsed() >500 ) + { + m_timer3.restart(); + QString tmp=cstderr.mid ( pos ); + uint32_t totalBytes,totalSize; + sscanf ( tmp.latin1(),"INFOPOS: %d %d",&totalBytes,&totalSize ); + if ( totalSize !=0 ) + m_percent= ( float ) totalBytes / ( float ) m_totalSize; + + + QTime time2 ( 0,0 ); + time2=time2.addMSecs ( time->elapsed() ); + if ( m_percent>0 ) + { + QTime time3 ( 0,0 ); + time3=time3.addMSecs ( ( uint32_t ) ( time->elapsed() * ( 1/m_percent ) ) ); + m_remain=time3.toString ( "hh:mm:ss" ); + } + + m_percent*=100; + m_progress->setProgress ( ( int ) m_percent ); + m_progress->setremain ( time2.toString ( "hh:mm:ss" ) +" / " +m_remain ); + } + } + else + { + pos=cstderr.find ( "INFOIMAGE:" ); + if ( pos!=-1 ) + { + m_progress->setImage ( cstderr.mid ( pos+10 ) ); + } + else + qDebug ( "[%s]",buffer ); + } + m_stderr=cstderr; +} + +void k9MP4Enc::timerDone() +{ + QTime time2 ( 0,0 ); + time2=time2.addMSecs ( time->elapsed() ); + m_progress->setremain ( time2.toString ( "hh:mm:ss" ) +" / " +m_remain ); + +} + +bool k9MP4Enc::isCanceled() +{ + return m_canceled; +} + + +k9MP4Enc::~k9MP4Enc() {} + + +#include "k9mp4enc.moc" diff --git a/libk9copy/k9mp4enc.h b/libk9copy/k9mp4enc.h new file mode 100644 index 0000000..91a80a2 --- /dev/null +++ b/libk9copy/k9mp4enc.h @@ -0,0 +1,131 @@ +// +// C++ Interface: k9mp4enc +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9MP4ENC_H +#define K9MP4ENC_H +#include "k9common.h" +#include "k9dvdtitle.h" + +#include <qobject.h> +#include <k9process.h> +#include <qtimer.h> +#include <qstringlist.h> +class k9MP4Dlg; +/** + @author Jean-Michel PETIT <[email protected]> +*/ +class k9MP4Enc : public QObject { + Q_OBJECT +private: + k9Process *m_process; + k9MP4Dlg *m_progress; + k9DVDTitle *m_title; + int getBitRate(k9DVDTitle *_title); + QString m_txt; + QString m_device; + QString m_filename; + QString m_height; + QString m_width; + QString m_size; + QString m_audioBitrate; + QString m_videoBitrate; + QString m_audioGain; + QString m_fourcc; + QString m_stderr; + int m_parts; + float m_percent; + QTimer *timer; + QString m_remain; + uint32_t m_totalSize; + bool m_2pass; + int m_pass; + bool m_canceled; + int m_codec; + int m_audioCodec; + bool m_usecache; + bool m_mpeg2; + bool m_mpegChapters; + + QStringList m_lstVideo,m_lstAudio,m_lstCodecs; + int m_cpt; + QTime *time,m_timer3; + QString replaceParams(QString _input); + QString round16(QString _wh); + QString getChapterList(k9DVDTitle *_title); + int getselectedSubp(k9DVDTitle *_title); + +private slots: + void getStdout(KProcess *proc, char *buffer, int buflen); + void getStderr(KProcess *proc, char *buffer, int buflen); + void timerDone(); + void slotCancel(); + +public: + k9MP4Enc(QObject *parent = 0, const char *name = 0,const QStringList& args=0); + ~k9MP4Enc(); + + virtual void execute(k9DVDTitle *_title ); + + virtual void setNumberCD(const QString & _value) { + m_parts = _value.toInt(); + if (m_parts==0) m_parts=1; + } + + virtual void setDevice(const QString& _value) { + m_device = _value.stripWhiteSpace(); + }; + virtual void setFilename(const QString& _value) { + m_filename = _value.stripWhiteSpace(); + }; + virtual void setHeight(const QString& _value) { + m_height = _value.stripWhiteSpace(); + }; + virtual void setWidth(const QString& _value) { + m_width = _value.stripWhiteSpace(); + }; + virtual void setSize(const QString& _value) { + m_size = _value.stripWhiteSpace(); + }; + virtual void setAudioBitrate(const QString& _value) { + m_audioBitrate = _value.stripWhiteSpace(); + }; + virtual void setVideoBitrate(const QString& _value) { + m_videoBitrate = _value.stripWhiteSpace(); + }; + virtual void setAudioGain(const QString& _value) { + m_audioGain = _value.stripWhiteSpace(); + }; + virtual void setfourcc(const QString& _value) { + m_fourcc = _value.stripWhiteSpace(); + }; + + virtual void set2Passes(bool _value) { + m_2pass=_value; + } + + virtual void setUseCache(bool _value) { + m_usecache=_value; + } + + virtual void setMpeg2(bool _value) { + m_mpeg2=_value; + } + + virtual void setCodec(const int& _value) {m_codec = _value;}; + + virtual void setAudioCodec(const int& _value) {m_audioCodec = _value;}; + + virtual QWidget *getDialog() {return (QWidget*)m_progress;}; + + virtual bool isCanceled(); +}; + +#endif diff --git a/libk9copy/k9process.cpp b/libk9copy/k9process.cpp new file mode 100644 index 0000000..5b17545 --- /dev/null +++ b/libk9copy/k9process.cpp @@ -0,0 +1,59 @@ +// +// C++ Implementation: k9process +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9process.h" +#include <qobject.h> +#include <qapplication.h> +#include <qeventloop.h> + +k9Process::k9Process(QObject *parent, const char *name) + : KProcess(parent, name),m_waitSync(false) +{ + connect(this,SIGNAL(processExited( KProcess* )),this,SLOT(slotProcessExited( KProcess* ))); + +} + + +k9Process::~k9Process() +{ +} + +void k9Process::sync() { + m_waitSync=true; + QApplication::eventLoop()->enterLoop(); +} + + +void k9Process::slotProcessExited( KProcess * proc) { + if (m_waitSync) { + QApplication::eventLoop()->exitLoop(); + m_waitSync=false; + } +} + +const QString & k9Process::debug() { + m_debug=""; + for (int i=0;i<arguments.count();i++ ){ + m_debug +=" "+ *(arguments.at(i)); + } + return m_debug; +} + +bool k9Process::start (RunMode runmode, Communication comm) { + m_elapsed.start(); + return KProcess::start(runmode,comm); +} +#include "k9process.moc" + + +int k9Process::getElapsed() const { + return m_elapsed.elapsed(); +} diff --git a/libk9copy/k9process.h b/libk9copy/k9process.h new file mode 100644 index 0000000..540aafd --- /dev/null +++ b/libk9copy/k9process.h @@ -0,0 +1,38 @@ +// +// C++ Interface: k9process +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9PROCESS_H +#define K9PROCESS_H + +#include <kprocess.h> +#include <qdatetime.h> +/** + @author Jean-Michel PETIT <[email protected]> +*/ +class k9Process : public KProcess +{ +Q_OBJECT +public: + k9Process(QObject *parent = 0, const char *name = 0); + void sync(); + const QString & debug(); + ~k9Process(); + int getElapsed() const; + virtual bool start (RunMode runmode=NotifyOnExit, Communication comm=NoCommunication); +private: + bool m_waitSync; + QString m_debug; + QTime m_elapsed; +private slots: + void slotProcessExited(KProcess *proc); +}; + +#endif diff --git a/libk9copy/k9processlist.cpp b/libk9copy/k9processlist.cpp new file mode 100644 index 0000000..8947cc5 --- /dev/null +++ b/libk9copy/k9processlist.cpp @@ -0,0 +1,192 @@ +// +// C++ Implementation: +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + + +#include "k9processlist.h" +#include <qstyle.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qlistview.h> +#include <qrect.h> +#include <qprogressbar.h> +#include <qpixmap.h> +#include <qapplication.h> +#include <qeventloop.h> +#include <kpushbutton.h> + +class _k9ProcessListItem : public QListViewItem { +public: + _k9ProcessListItem(QListView *_listview,const QString & _text):QListViewItem(_listview,_text) { + m_fileName=""; + m_pos=0; + m_num=_listview->childCount(); + } + void setFileName(const QString &_fileName) { m_fileName=_fileName;} + void setPos(double _pos) { m_pos=_pos;} + + QString getFileName() const { return m_fileName;} + + double getPos() const { return m_pos;} + int compare ( QListViewItem * i, int col, bool ascending ) const { + return m_num-((_k9ProcessListItem*)i)->m_num; + } +private: + QString m_fileName; + double m_pos; + int m_num; +}; + + +k9ProcessList::k9ProcessList(QWidget* parent, const char* name, WFlags fl) : processList(parent,name,fl) +{ + m_processes.setAutoDelete(true); + m_maxProcess=4; + connect(&m_timer,SIGNAL(timeout()),this,SLOT(timeout())); + bCancel->setEnabled(false); +} + +k9ProcessList::~k9ProcessList() +{ +} +/*$SPECIALIZATION$*/ +void k9ProcessList::timeout() { + if (m_waitSync) { + QApplication::eventLoop()->exitLoop(); + m_waitSync=false; + } +} + +void k9ProcessList::bCancelClick() { + m_cancel=true; + for (k9Process *p=m_processes.first();p;p=m_processes.next()) { + if (p->isRunning()) + p->kill(); + } + +} + +void k9ProcessList::wait(int _msec) { + m_waitSync=true; + m_timer.start(_msec,true); + QApplication::eventLoop()->enterLoop(); +} + +int k9ProcessList::getNbRunning() { + int res=0; + for (int i=0;i<m_processes.count();i++) { + k9Process *p=m_processes.at(i); + if (p->isRunning()) + res++; + } + return res; +} + + +void k9ProcessList::execute() { + bCancel->setEnabled(true); + m_cancel=false; + m_error=false; + k9Process *p=NULL; + for (QPtrListStdIterator <k9Process> it=m_processes.begin() ;it!=m_processes.end() ;++it ) { + p=(*it); + while (getNbRunning() >=m_maxProcess && ! m_cancel) { + wait(1000); + } + if (m_cancel) + break; + if (!p->start(KProcess::OwnGroup,KProcess::All)) + m_error=true; + } + //waiting for processes + for (p=m_processes.first();p;p=m_processes.next()) { + if (p->isRunning()) + p->sync(); + } + bCancel->setEnabled(false); +} + +void k9ProcessList::addProgress(const QString &_text) { + QListViewItem *item = new _k9ProcessListItem(lProcess,_text); + QProgressBar b(this); + b.setProgress(100,100); + b.resize(100,40); + item->setPixmap(0,QPixmap::grabWidget(&b,0,0,b.width(),b.height())); +} + +void k9ProcessList::setProgress (k9Process * _process,int _position, int _total) { + QProgressBar b(this); + b.setProgress(_position,_total); + b.resize(100,40); + QListViewItem *it =m_items[_process]; + it->setPixmap(0,QPixmap::grabWidget(&b,0,0,b.width(),b.height())); +} + +void k9ProcessList::setText(k9Process *_process, const QString &_text,int _col) { + QListViewItem *it =m_items[_process]; + it->setText(_col,_text); +} + +void k9ProcessList::setFileName(k9Process *_process,const QString &_fileName) { + _k9ProcessListItem *it = (_k9ProcessListItem*)m_items[_process]; + it->setFileName(_fileName); + +} + +void k9ProcessList::setPos(k9Process *_process,double _pos) { + _k9ProcessListItem *it = (_k9ProcessListItem*)m_items[_process]; + it->setPos(_pos); +} + +k9Process *k9ProcessList::addProcess(const QString &label) { + QString name=QString("process%1").arg(m_items.count()) ; + k9Process *process=new k9Process(this,name.latin1()); + m_processes.append(process); + QListViewItem *item = new _k9ProcessListItem(lProcess,label); + m_items[process]=item; + setProgress(process,0,100); + connect(process,SIGNAL(processExited( KProcess* )),this,SLOT(processExited(KProcess*))); + return process; +} + +void k9ProcessList::processExited(KProcess *_process){ + if (!_process->normalExit()) + m_cancel=true; + else if (_process->exitStatus() !=0 ) + m_error=true; + +} + +#include "k9processlist.moc" + +void k9ProcessList::clear() { + m_processes.clear(); + m_items.clear(); +} + +int k9ProcessList::getMaxProcess() const { + return m_maxProcess; +} + + +void k9ProcessList::setMaxProcess(int _value) { + m_maxProcess = _value; +} + + +bool k9ProcessList::getCancel() const { + return m_cancel; +} + + +bool k9ProcessList::getError() const { + return m_error; +} diff --git a/libk9copy/k9processlist.h b/libk9copy/k9processlist.h new file mode 100644 index 0000000..cbcc754 --- /dev/null +++ b/libk9copy/k9processlist.h @@ -0,0 +1,65 @@ +// +// C++ Interface: +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef K9PROCESSLIST_H +#define K9PROCESSLIST_H +#include "k9common.h" +#include "../libk9copy/processList.h" +#include "k9process.h" +#include <qmap.h> +#include <qtimer.h> +class k9ProcessList : public processList { + Q_OBJECT + +public: + k9ProcessList(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~k9ProcessList(); + /*$PUBLIC_FUNCTIONS$*/ + void execute(); + void addProgress(const QString &_text); + void setProgress (k9Process * _process,int _position, int _total); + void setText(k9Process *_process, const QString &_text,int _col); + void setFileName(k9Process *_process,const QString &_fileName); + void setPos(k9Process *_process,double _pos); + k9Process *addProcess(const QString &label); + + void setMaxProcess(int _value); + int getMaxProcess() const; + bool getCancel() const; + void clear(); + + bool getError() const; + +public slots: + /*$PUBLIC_SLOTS$*/ + +protected: + /*$PROTECTED_FUNCTIONS$*/ + int m_maxProcess; + QMap <k9Process*,QListViewItem*> m_items; + QPtrList <k9Process> m_processes; + QTimer m_timer; + bool m_cancel; + bool m_error; + bool m_waitSync; + int getNbRunning(); + void wait(int _msec); + +protected slots: + /*$PROTECTED_SLOTS$*/ + void timeout(); + virtual void bCancelClick(); + virtual void processExited(KProcess *); +}; + +#endif + diff --git a/libk9copy/k9progress.cpp b/libk9copy/k9progress.cpp new file mode 100644 index 0000000..d2c46ac --- /dev/null +++ b/libk9copy/k9progress.cpp @@ -0,0 +1,116 @@ +// +// C++ Implementation: +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + + +#include "k9progress.h" +#include <kprogress.h> +#include <qlabel.h> +#include <qapplication.h> +#include <qeventloop.h> +#include <qimage.h> +#include <qpainter.h> +#include <kstandarddirs.h> +#include <qmovie.h> +#include <qlayout.h> + + + +k9Progress::k9Progress(QWidget* parent, const char* name,const QStringList &args) + : Progress(parent,name,0) { + m_process=new k9Process(this,0); + m_wimage=new k9DrawImage(image,0); + QGridLayout *l=new QGridLayout(image,1,1); + l->addWidget(m_wimage,0,0); + + +} + + +k9Progress::~k9Progress() { + delete m_process; +} + + +void k9Progress::setElapsed(const QString _text) { + lblElapsed->setText(_text); +} + +void k9Progress::setTitle(const QString _text) { + lblTitle->setText(_text); +} + + +void k9Progress::setLabelText(const QString _text) { + LabelText->setText(_text); +} + +void k9Progress::setProgress(long _position,long _total) { + ProgressBar->setRange(0,_total); + ProgressBar->setProgress(_position); +} + +int k9Progress::execute() { + if (! m_process->isRunning()) { + if (!m_process->start(KProcess::NotifyOnExit,KProcess::All )) + return -1; + } + +// m_timer.start(200,FALSE); + show(); + m_canceled=false; + //the sync method allows to wait for the process end while receiving stdout. + m_process->sync(); + +// m_timer.stop(); + if (!m_canceled && m_process->normalExit()) + return 1; + else + return 0; +} + + +void k9Progress::bCancelClick() { + m_process->kill(); + m_canceled=true; +} + +k9Process* k9Progress::getProcess() const { + return m_process; +} + +/*$SPECIALIZATION$*/ + + +void k9Progress::setImage(QString _fileName) { + m_wimage->setImage(_fileName); +} + +void k9Progress::setImage(const QImage &_image) { + m_wimage->setImage(_image); +} + + +void k9Progress::setMovie(QString _fileName) { + image->setPaletteBackgroundColor(this->paletteBackgroundColor()); + QMovie mv(_fileName,2048); + mv.setBackgroundColor(this->paletteBackgroundColor()); + image->setMovie(mv); + m_wimage->hide(); +} + + +#include "k9progress.moc" + + +bool k9Progress::getCanceled() const { + return m_canceled; +} diff --git a/libk9copy/k9progress.h b/libk9copy/k9progress.h new file mode 100644 index 0000000..9c88490 --- /dev/null +++ b/libk9copy/k9progress.h @@ -0,0 +1,58 @@ +// +// C++ Interface: +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef K9PROGRESS_H +#define K9PROGRESS_H + +#include "k9common.h" +#include "../libk9copy/progress.h" +#include <k9process.h> +#include <qimage.h> +#include <qtimer.h> +#include "k9drawimage.h" + +class k9Progress : public Progress { + Q_OBJECT + +public: + k9Progress(QWidget* parent = 0, const char* name = 0, const QStringList &args=0); + ~k9Progress(); + virtual k9Process * getProcess() const; + virtual void setProgress(long _position,long _total); + virtual void setLabelText(const QString _text); + virtual void setElapsed(const QString _text); + virtual void setTitle(const QString _text); + virtual void setImage(QString _fileName) ; + virtual void setImage(const QImage &_image); + virtual void setMovie(QString _fileName); + + virtual int execute(); + + bool getCanceled() const; + + /*$PUBLIC_FUNCTIONS$*/ + +public slots: + /*$PUBLIC_SLOTS$*/ + +protected: + /*$PROTECTED_FUNCTIONS$*/ + k9Process *m_process; + k9DrawImage *m_wimage; + void bCancelClick(); + bool m_canceled; +protected slots: + /*$PROTECTED_SLOTS$*/ +}; + +#endif + diff --git a/libk9copy/k9saveimage.cpp b/libk9copy/k9saveimage.cpp new file mode 100644 index 0000000..b919510 --- /dev/null +++ b/libk9copy/k9saveimage.cpp @@ -0,0 +1,84 @@ +// +// C++ Implementation: k9saveimage +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9saveimage.h" +#include "kdecmpeg2.h" +#include <stdio.h> + +#include <qimage.h> +#include <kstandarddirs.h> + +void k9SaveImage::drawImage(QImage *_image) { + m_cpt++; + if (m_cpt ==20) { + m_image=*_image; + m_decoder->pause(); + } +} + + +k9SaveImage::k9SaveImage() + : QObject(),QThread() +{ + m_tempFile= new KTempFile(locateLocal("tmp", "k9copy/k9p"), ""); + m_tempFile->setAutoDelete(true); + m_decoder=new kDecMPEG2(); + connect(m_decoder, SIGNAL(pixmapReady(QImage *)), this, SLOT(drawImage(QImage *))); +} + + +k9SaveImage::~k9SaveImage() +{ + delete m_decoder; + delete m_tempFile; +} + +void k9SaveImage::play() { + m_cpt=0; + m_stop=false; + m_timer.start(); + m_decoder->start(); +} +void k9SaveImage::stop() { + m_stop=true; + wait(); + m_decoder->stop(); +} + +void k9SaveImage::addData(uchar *_buffer, uint32_t _size) { + if (m_timer.elapsed() >=7000 ) { + if (m_mutex.tryLock()) { + m_size=_size; + + m_buffer=new uchar[m_size]; + tc_memcpy(m_buffer,_buffer,m_size); + m_mutex.unlock(); + start(LowestPriority); + } + m_timer.restart(); + } +} + + +void k9SaveImage::run() { + m_mutex.lock(); + m_cpt=0; + m_decoder->decode(m_buffer ,m_buffer+m_size,0); + delete m_buffer; + QString sFileName=m_tempFile->name(); + m_image.save(sFileName,"PNG"); + sFileName="\rINFOIMAGE:"+sFileName; + fprintf(stderr,sFileName.utf8()); + + m_mutex.unlock(); +} + +#include "k9saveimage.moc" diff --git a/libk9copy/k9saveimage.h b/libk9copy/k9saveimage.h new file mode 100644 index 0000000..9733577 --- /dev/null +++ b/libk9copy/k9saveimage.h @@ -0,0 +1,60 @@ +// +// C++ Interface: k9saveimage +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9SAVEIMAGE_H +#define K9SAVEIMAGE_H + +#include "k9common.h" +#include <qthread.h> +#include <qobject.h> +#include <qdatetime.h> + +#include "k9fifo.h" +#include <ktempfile.h> +#include <qimage.h> + + +/** + @author Jean-Michel PETIT <[email protected]> +*/ +typedef enum { FrameType_B=0x18,FrameType_I=0x08,FrameType_P=0x10,FrameType_D=0x20} eFrameType; + +class kDecMPEG2; + +class k9SaveImage : public QObject,QThread +{ +Q_OBJECT +public: + k9SaveImage(); + ~k9SaveImage(); + + void play(); + void stop(); + void addData(uchar *_buffer, uint32_t _size); +protected: + void run(); +public slots: + void drawImage(QImage*); + +private: + kDecMPEG2 *m_decoder; + k9fifo m_fifo; + bool m_stop; + QTime m_timer; + uint m_cpt; + KTempFile *m_tempFile; + uchar *m_buffer; + uint32_t m_size; + QMutex m_mutex; + QImage m_image; +}; + +#endif diff --git a/libk9copy/k9script.cpp b/libk9copy/k9script.cpp new file mode 100644 index 0000000..f42e8db --- /dev/null +++ b/libk9copy/k9script.cpp @@ -0,0 +1,391 @@ +// +// C++ Implementation: k9script +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9script.h" +#include "k9dvd.h" +#include "k9dvdtitle.h" +#include "bswap.h" +#include "dvdread.h" +#include <stdlib.h> + +k9Script::k9Script(ifo_handle_t *_ifo, k9DVD *_dvd ) +{ + m_ifo=_ifo; + m_dvd=_dvd; + +} + + +k9Script::~k9Script() +{} + + +vm_cmd_t *k9Script::GOTO(char line,char register1,char value) +{ + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0;cmd[1]=0xA1;cmd[2]=0;cmd[3]=register1;cmd[4]=0; + cmd[5]=value; + cmd[6]=0; + cmd[7]=line; + return &m_cmd; +} + +vm_cmd_t *k9Script::GOTO(char line) +{ + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0;cmd[1]=0x01;cmd[2]=0;cmd[3]=0;cmd[4]=0; + cmd[5]=0; + cmd[6]=0; + cmd[7]=line; + return &m_cmd; +} + +vm_cmd_t *k9Script::JUMPTT(char title,char register1,char register2) +{ + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x30;cmd[1]=0x22;cmd[2]=0;cmd[3]=0;cmd[4]=0; + cmd[5]=title; + cmd[6]=register1; + cmd[7]=register2; + return &m_cmd; +} + +vm_cmd_t *k9Script::JUMPVMGM_MENU() +{ + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x30;cmd[1]=0x06;cmd[2]=0;cmd[3]=0;cmd[4]=0; + cmd[5]=0x42; + cmd[6]=0; + cmd[7]=0; + return &m_cmd; +} + +vm_cmd_t *k9Script::CALLVMGM_MENU() +{ + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x30;cmd[1]=0x08;cmd[2]=0;cmd[3]=0;cmd[4]=0x01; + cmd[5]=0x42; + cmd[6]=0; + cmd[7]=0; + return &m_cmd; +} + + +vm_cmd_t *k9Script::EXIT(char register1,char register2) +{ + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x30;cmd[1]=0x21;cmd[2]=0;cmd[3]=0;cmd[4]=0; + cmd[5]=0;cmd[6]=register1;cmd[7]=register2; + return &m_cmd; +} + + +vm_cmd_t *k9Script::setGPRM(char numReg,uint16_t value) { + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x71;cmd[1]=0;cmd[2]=0; + cmd[3]=numReg; + B2N_16(value); + memcpy(cmd+4,&value,sizeof(uint16_t)); + cmd[6]=0; + cmd[7]=0; + return &m_cmd; + +} +vm_cmd_t *k9Script::setGPRMREG(char numReg,uint16_t value) { + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x61;cmd[1]=0;cmd[2]=0; + cmd[3]=numReg; + B2N_16(value); + memcpy(cmd+4,&value,sizeof(uint16_t)); + cmd[6]=0; + cmd[7]=0; + return &m_cmd; + +} + + +vm_cmd_t *k9Script::setSTN(char numAudio,char numSubpicture) { + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x51;cmd[1]=0;cmd[2]=0; + cmd[3]=numAudio==0 ? 0 : 0x80+numAudio-1; + cmd[4]=numSubpicture==0 ? 0 : 0xC0+numSubpicture-1; + cmd[5]=0; + cmd[6]=0; + cmd[7]=0; + return &m_cmd; + +} + +vm_cmd_t *k9Script::setSTN(char numAngle) { + uchar* cmd=(uchar*) &m_cmd; + cmd[0]=0x51;cmd[1]=0;cmd[2]=0; + cmd[3]=0; + cmd[4]=0; + cmd[5]=numAngle==0 ? 0 : 0x80+numAngle-1; + cmd[6]=0; + cmd[7]=0; + return &m_cmd; +} + +void k9Script::updatePGCIUT() { + //first, free the old PGCIUT + ifoFree_PGCI_UT(m_ifo); + + m_ifo->pgci_ut = (pgci_ut_t*) malloc(sizeof(pgci_ut_t)); + pgci_ut_t* pgci_ut = m_ifo->pgci_ut; + pgci_ut->zero_1=0; + pgci_ut->nr_of_lus=1; + + pgci_ut->lu = (pgci_lu_t*) malloc(sizeof(pgci_lu_t)); + pgci_lu_t *lu =pgci_ut->lu; + uchar * lng=(uchar*) &(lu->lang_code); + lng[0]='n'; lng[1]='e'; + lu->lang_extension=0; + lu->exists=0x80; + + pgcit_t *pgcit=(pgcit_t*) malloc(sizeof(pgcit_t)); + lu->pgcit=pgcit; + memset(pgcit,0,sizeof(pgcit_t)); + pgcit->nr_of_pgci_srp=1; + pgci_srp_t * srp=(pgci_srp_t*)malloc(sizeof(pgci_srp_t)); + memset(srp,0,sizeof(pgci_srp_t)); + pgcit->pgci_srp=srp; + srp->entry_id=0x82; + + pgc_t *pgc=(pgc_t*)malloc(sizeof(pgc_t)); + srp->pgc=pgc; + memset(pgc,0,sizeof(pgc_t)); + + pgc_command_tbl_t * command_tbl=(pgc_command_tbl_t*) malloc(sizeof(pgc_command_tbl_t)); + pgc->command_tbl=command_tbl; + pgc->command_tbl_offset=1; + memset(command_tbl,0,sizeof(pgc_command_tbl_t)); + + if (m_ifo->vmgi_mat != NULL) + updatePGCIUT_VMG(command_tbl); + else + updatePGCIUT_VTS(command_tbl); +} + +void k9Script::updateFPPGC() { + ifoFree_FP_PGC(m_ifo); + pgc_t*pgc=(pgc_t*)malloc(sizeof(pgc_t)); + m_ifo->first_play_pgc=pgc; + memset(pgc,0,sizeof(pgc_t)); + + pgc_command_tbl_t * command_tbl=(pgc_command_tbl_t*) malloc(sizeof(pgc_command_tbl_t)); + pgc->command_tbl=command_tbl; + pgc->command_tbl_offset=1; + memset(command_tbl,0,sizeof(pgc_command_tbl_t)); + // set GRPM(0)= First Title + addPreCmd(command_tbl,JUMPTT(m_dvd->getstart()->getnumTitle(),0,0)); + // jump VMGM Menu + //addPreCmd(command_tbl,JUMPVMGM_MENU()); + +} + +void k9Script::updatePGC(pgc_t *_pgc ,int numVTS,int numPGC) { + k9DVDTitle *title=NULL; + for (int i=0; i <m_dvd->gettitleCount();i++) { + title=m_dvd->gettitle(i); + if (title->getVTS()== numVTS && title->getTTN()==numPGC && title->getIndexed()) + break; + } + + pgc_command_tbl_t *command_tbl=_pgc->command_tbl; + if (command_tbl ==NULL) { + command_tbl=(pgc_command_tbl_t*) malloc(sizeof(pgc_command_tbl_t)); + _pgc->command_tbl=command_tbl; + _pgc->command_tbl_offset=1; + memset(command_tbl,0,sizeof(pgc_command_tbl_t)); + } + + if (numPGC==0) + return; + + for (int i=0; i < command_tbl->nr_of_pre;i++) { + //replace all JUMPs by a goto to the last line of cell commands ( link to next title) + char *cmd=(char*)&(command_tbl->pre_cmds[i]); + if (cmd[0]==0x30) { + char NOP[8]={0,0,0,0,0,0,0,0}; + memcpy(cmd,NOP,8); + } + + } + if (title->isSelected()) { + char numSubP=0,numAudio=0; + if (title->getDefSubtitle() !=NULL) + numSubP=title->getDefSubtitle()->getnum(); + if (title->getDefAudio() !=NULL) + numAudio=title->getDefAudio()->getID(); + if (numSubP+numAudio >0) { + char *c=(char*)command_tbl->pre_cmds; + bool binsert=false; + if (c==NULL) + binsert=true; + else if ( *c==0x51) + binsert=true; + if (binsert) + memcpy(command_tbl->pre_cmds,setSTN( numAudio,numSubP),8); + else + insertPreCmd(command_tbl,setSTN( numAudio,numSubP)); + } + } + + for (int i=0; i < command_tbl->nr_of_cell;i++) { + //replace all JUMPs by a goto to the last line of cell commands ( link to next title) + JumpVmg(&(command_tbl->cell_cmds[i])); + + } + for (int i=0; i < command_tbl->nr_of_post;i++) { + //replace all JUMPs by a goto to the last line of cell commands ( link to next title) + JumpVmg(&(command_tbl->post_cmds[i])); + } + + + bool insertCall=true; + if (command_tbl->nr_of_post !=0) { + vm_cmd_t *cmd=&command_tbl->post_cmds[command_tbl->nr_of_post -1]; + if (memcmp(cmd,CALLVMGM_MENU(),8)==0) + insertCall=false; + } + + if (insertCall) + for (int i=0; i <m_dvd->gettitleCount();i++) { + k9DVDTitle *title=m_dvd->gettitle(i); + if (title->getVTS()== numVTS && title->getTTN()==numPGC && title->isSelected() && title->getIndexed()) { + addPostCmd(command_tbl,CALLVMGM_MENU()); + break; + } + } +} + +// replace the actual jump by a jump to he vmgm menu +void k9Script::JumpVmg(vm_cmd_t * command) { + char *cmd=(char*) command; + if (cmd[0]==0x30) { + cmd[1]=cmd[1] & 0xF0 + 0x08; //0x20 =conditionnal jump + cmd[2]=cmd[3]=0; + cmd[4]=0x01; + cmd[5]=0x42; + } + +} + + +void k9Script::updatePGCIUT_VTS(pgc_command_tbl_t *command_tbl) { + addPreCmd( command_tbl, JUMPVMGM_MENU()); +} + + +void k9Script::updatePGCIUT_VMG(pgc_command_tbl_t *command_tbl) +{ + command_tbl->nr_of_pre=0; + command_tbl->pre_cmds=NULL; + + //initialisation of the registers + for (int i=0;i<=15;i++) + if (i!=1) + addPreCmd( command_tbl,setGPRM( i,0)); + + addTitles(command_tbl); +} + +void k9Script::addTitles(pgc_command_tbl_t *command_tbl) { + char NOP[8]={0,0,0,0,0,0,0,0}; + + //Set GPRM(1) = current title (SPRM(4)) + addPreCmd(command_tbl,setGPRMREG(1,0x84)); + + int nbSelected=0; + for (int i=0;i<m_dvd->gettitleCount();i++) { + k9DVDTitle *title=m_dvd->gettitle(i); + if (title->isSelected() && title->getIndexed()) + nbSelected++; + } + int a=0; + for (int i=0;i<m_dvd->gettitleCount();i++) { + k9DVDTitle *title=m_dvd->gettitle(i); + if (title->isSelected() && title->getIndexed()) { + //SI GPRM1=numTitle, GOTO i*3 + addPreCmd(command_tbl,GOTO(16+nbSelected+a*3+2,1,title->getnumTitle())); + a++; + } + } + addPreCmd( command_tbl,EXIT(0,0)); + + for (int i=0;i<m_dvd->gettitleCount();i++) { + k9DVDTitle *title=m_dvd->gettitle(i); + if (title->isSelected() && title->getIndexed()) { + //initialization of register 1 + addPreCmd(command_tbl,setGPRM(1,0)); + //set default subtitle and audio stream + addPreCmd(command_tbl,(vm_cmd_t*)NOP); + //jump to title + if (title->getnextTitle()!=NULL) + addPreCmd(command_tbl,JUMPTT(title->getnextTitle()->getnumTitle(),0,0)); + else + addPreCmd(command_tbl,EXIT(0,0)); + } + } + + +} + +void k9Script::addPreCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd) { + command_tbl->nr_of_pre++; + if (command_tbl->pre_cmds == NULL) + command_tbl->pre_cmds=(vm_cmd_t*)malloc(sizeof(vm_cmd_t)); + else + command_tbl->pre_cmds=(vm_cmd_t*) realloc(command_tbl->pre_cmds,sizeof(vm_cmd_t)*command_tbl->nr_of_pre); + + memcpy(&(command_tbl->pre_cmds[command_tbl->nr_of_pre-1]),cmd,sizeof(vm_cmd_t)); +} + +void k9Script::insertPreCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd) { + command_tbl->nr_of_pre++; + if (command_tbl->pre_cmds == NULL) + command_tbl->pre_cmds=(vm_cmd_t*)malloc(sizeof(vm_cmd_t)); + else + command_tbl->pre_cmds=(vm_cmd_t*) realloc(command_tbl->pre_cmds,sizeof(vm_cmd_t)*command_tbl->nr_of_pre); + + for (int i=command_tbl->nr_of_pre-2;i>=0;i--) { + memcpy(&(command_tbl->pre_cmds[i+1]),&(command_tbl->pre_cmds[i]),sizeof(vm_cmd_t)); + char *cmd=(char*)&(command_tbl->pre_cmds[i+1]); + if (cmd[0]==0 && cmd[1]&0x01==0x01) + cmd[7]++; + + } + + memcpy(&(command_tbl->pre_cmds[0]),cmd,sizeof(vm_cmd_t)); +} + + + +void k9Script::addPostCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd) { + command_tbl->nr_of_post++; + if (command_tbl->post_cmds == NULL) + command_tbl->post_cmds=(vm_cmd_t*)malloc(sizeof(vm_cmd_t)); + else + command_tbl->post_cmds=(vm_cmd_t*) realloc(command_tbl->post_cmds,sizeof(vm_cmd_t)*command_tbl->nr_of_post); + + memcpy(&(command_tbl->post_cmds[command_tbl->nr_of_post-1]),cmd,sizeof(vm_cmd_t)); +} + +void k9Script::addCellCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd) { + command_tbl->nr_of_cell++; + if (command_tbl->cell_cmds == NULL) + command_tbl->cell_cmds=(vm_cmd_t*)malloc(sizeof(vm_cmd_t)); + else + command_tbl->cell_cmds=(vm_cmd_t*) realloc(command_tbl->cell_cmds,sizeof(vm_cmd_t)*command_tbl->nr_of_cell); + + memcpy(&(command_tbl->cell_cmds[command_tbl->nr_of_cell-1]),cmd,sizeof(vm_cmd_t)); +} diff --git a/libk9copy/k9script.h b/libk9copy/k9script.h new file mode 100644 index 0000000..853e3cb --- /dev/null +++ b/libk9copy/k9script.h @@ -0,0 +1,55 @@ +// +// C++ Interface: k9script +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9SCRIPT_H +#define K9SCRIPT_H +#include "k9common.h" +/** + @author Jean-Michel PETIT <[email protected]> +*/ + +class k9DVD; + +class k9Script{ +private: + ifo_handle_t *m_ifo; + k9DVD *m_dvd; + vm_cmd_t m_cmd; +protected: + vm_cmd_t *JUMPTT(char title,char register1,char register2); + vm_cmd_t *JUMPVMGM_MENU(); + vm_cmd_t *GOTO(char line,char register1,char value); + vm_cmd_t *GOTO(char line); + vm_cmd_t *setGPRM(char numReg,uint16_t value); + vm_cmd_t *setGPRMREG(char numReg,uint16_t value); + + vm_cmd_t *CALLVMGM_MENU(); + vm_cmd_t *setSTN(char numAudio,char numSubpicture); + vm_cmd_t *setSTN(char numAngle); + + vm_cmd_t *EXIT(char register1,char register2); + void addPreCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd); + void insertPreCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd); + void addPostCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd); + void addCellCmd(pgc_command_tbl_t *command_tbl,vm_cmd_t *cmd); + void updatePGCIUT_VMG(pgc_command_tbl_t *command_tbl); + void updatePGCIUT_VTS(pgc_command_tbl_t *command_tbl); + void JumpVmg(vm_cmd_t * cmd) ; + void addTitles(pgc_command_tbl_t *command_tbl); +public: + k9Script(ifo_handle_t *_ifo,k9DVD *_dvd); + void updatePGCIUT(); + void updateFPPGC(); + void updatePGC(pgc_t *_pgc,int numVTS,int numPGC); + ~k9Script(); +}; + +#endif diff --git a/libk9copy/k9titleencopt.cpp b/libk9copy/k9titleencopt.cpp new file mode 100644 index 0000000..8e75919 --- /dev/null +++ b/libk9copy/k9titleencopt.cpp @@ -0,0 +1,159 @@ +// +// C++ Implementation: k9titleencopt +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9common.h" +#include "k9titleencopt.h" +#include "k9config.h" +#include "k9dvdtitle.h" + +k9TitleEncOpt::k9TitleEncOpt(k9DVDTitle *parent) + : QObject(parent, "") +{ + connect (parent,SIGNAL(selectionChanged()),this,SLOT(load())); + load(); +} + + +k9TitleEncOpt::~k9TitleEncOpt() +{ +} + + +void k9TitleEncOpt::load() { + //KSimpleConfig settings("K9Copy"); + k9Config config; + + int size_mb=(int)getTitle()->gettotalsize_mb(); + + m_maxSize=config.getPrefMp4Size(); + if(m_maxSize > size_mb) + m_maxSize=size_mb ; + + m_numParts=config.getPrefMp4NumberCD(); + + m_width=config.getPrefMp4Width(); + m_height=config.getPrefMp4Height(); + + m_keepAspectRatio=config.getPrefMp4AspectRatio(); + + m_2Passes=config.getPrefMp42Passes(); + + m_audioBr=config.getPrefMp4AudioBitrate(); + + m_codec=config.getPrefMp4Codec(); + + m_audioCodec=config.getPrefMp4AudioCodec (); + + m_audioGain=config.getPrefMp4AudioGain(); + + m_videoBr=config.getPrefMp4VideoBitrate(); + + m_useCache=config.getPrefUseCellCache(); + +} + +int k9TitleEncOpt::getMaxSize() { + return m_maxSize; +} + +void k9TitleEncOpt::setMaxSize(int _value) { + m_maxSize=_value; +} + + +int k9TitleEncOpt::getNumParts() { + return m_numParts; +} + +void k9TitleEncOpt::setNumParts(int _value) { + m_numParts=_value; +} + +int k9TitleEncOpt::getAudioGain() { + return m_audioGain; +} + +void k9TitleEncOpt::setAudioGain(int _value) { + m_audioGain=_value; +} + +const QString & k9TitleEncOpt::getWidth() { + return m_width; +} + +void k9TitleEncOpt::setWidth(QString _value) { + m_width=_value; +} + + +const QString & k9TitleEncOpt::getHeight() { + return m_height; +} + +void k9TitleEncOpt::setHeight(QString _value) { + m_height=_value; +} + +const QString & k9TitleEncOpt::getAudioBr() { + return m_audioBr; +} +void k9TitleEncOpt::setAudioBr(QString _value) { + m_audioBr=_value; +} + +const QString & k9TitleEncOpt::getVideoBr() { + return m_videoBr; +} +void k9TitleEncOpt::setVideoBr(QString _value) { + m_videoBr=_value; +} + +bool k9TitleEncOpt::getKeepAspectRatio() { + return m_keepAspectRatio; +} +void k9TitleEncOpt::setKeepAspectRatio(bool _value) { + m_keepAspectRatio=_value; +} + +bool k9TitleEncOpt::get2Passes() { + return m_2Passes; +} +void k9TitleEncOpt::set2Passes(bool _value) { + m_2Passes=_value; +} + +int k9TitleEncOpt::getCodec() { + return m_codec; +} +void k9TitleEncOpt::setCodec(int _value) { + m_codec=_value; +} + +int k9TitleEncOpt::getAudioCodec() { + return m_audioCodec; +} +void k9TitleEncOpt::setAudioCodec(int _value) { + m_audioCodec=_value; +} + +bool k9TitleEncOpt::getUseCache() { + k9Config config; + m_useCache=config.getPrefUseCellCache(); + return m_useCache; +} + +void k9TitleEncOpt::setUseCache(bool _value) { + m_useCache=_value; +} + + + +#include "k9titleencopt.moc" diff --git a/libk9copy/k9titleencopt.h b/libk9copy/k9titleencopt.h new file mode 100644 index 0000000..cb4cde3 --- /dev/null +++ b/libk9copy/k9titleencopt.h @@ -0,0 +1,87 @@ +// +// C++ Interface: k9titleencopt +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9TITLEENCOPT_H +#define K9TITLEENCOPT_H + +#include <qobject.h> + + +/** + @author Jean-Michel PETIT <[email protected]> +*/ + +class k9DVDTitle; + +class k9TitleEncOpt : public QObject +{ +Q_OBJECT +public: + k9TitleEncOpt(k9DVDTitle *parent ); + ~k9TitleEncOpt(); + k9DVDTitle *getTitle() { return (k9DVDTitle*)parent();}; + +public: + int getMaxSize(); + void setMaxSize(int); + + int getNumParts(); + void setNumParts(int); + + int getAudioGain(); + void setAudioGain(int); + + const QString & getWidth(); + void setWidth(QString); + + const QString & getHeight(); + void setHeight(QString); + + const QString & getAudioBr(); + void setAudioBr(QString); + + const QString & getVideoBr(); + void setVideoBr(QString); + + bool getKeepAspectRatio(); + void setKeepAspectRatio(bool); + + bool get2Passes(); + void set2Passes(bool); + + bool getUseCache(); + void setUseCache(bool); + + int getCodec(); + void setCodec(int); + + int getAudioCodec(); + void setAudioCodec(int); + + +private: + int m_maxSize; + int m_numParts; + QString m_width; + QString m_height; + bool m_keepAspectRatio; + bool m_2Passes; + QString m_audioBr,m_videoBr; + int m_codec,m_audioCodec; + int m_audioGain; + bool m_useCache; + +public slots: + void load(); + +}; + +#endif diff --git a/libk9copy/k9tools.cpp b/libk9copy/k9tools.cpp new file mode 100644 index 0000000..1464553 --- /dev/null +++ b/libk9copy/k9tools.cpp @@ -0,0 +1,38 @@ +// +// C++ Implementation: k9tools +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9tools.h" +#include <kstandarddirs.h> +#include <qdir.h> + +bool k9Tools::checkProgram(QString _progName) { + return KStandardDirs::findExe( _progName,NULL,false) !=NULL ; +} + +void k9Tools::clearOutput(QString name) { + QDir dir(name); + //delete files in directory + QStringList lst = dir.entryList( "*",QDir::Files |QDir::Hidden ); + for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + //QString c(( *it ).latin1() ); + dir.remove (*it); + } + //scanning subdir + QStringList lstdir = dir.entryList( "*",QDir::Dirs ); + for ( QStringList::Iterator it = lstdir.begin(); it != lstdir.end(); ++it ) { + QString c=*it; + if ((c!=".") && c!="..") { + clearOutput(dir.absFilePath(c)); + dir.rmdir(c); + } + } + +} diff --git a/libk9copy/k9tools.h b/libk9copy/k9tools.h new file mode 100644 index 0000000..9548511 --- /dev/null +++ b/libk9copy/k9tools.h @@ -0,0 +1,29 @@ +// +// C++ Interface: k9tools +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9TOOLS_H +#define K9TOOLS_H + +#include <qstring.h> + +/** + @author Jean-Michel PETIT <[email protected]> +*/ +class k9Tools{ +private: + k9Tools() {}; + ~k9Tools(){}; +public: + static bool checkProgram(QString _progName); + static void clearOutput(QString name); +}; + +#endif diff --git a/libk9copy/k9videocodecs.cpp b/libk9copy/k9videocodecs.cpp new file mode 100644 index 0000000..8e91793 --- /dev/null +++ b/libk9copy/k9videocodecs.cpp @@ -0,0 +1,174 @@ +// +// C++ Implementation: k9videocodecs +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "k9videocodecs.h" +#include <qstringlist.h> + +class _k9VideoCodec +{ +public: + _k9VideoCodec():name(""),fourcc(""),optPass1(""),optPass2(""),optOnePass(""){}; + _k9VideoCodec(QString _name,QString _fourcc,QString _optOnePass,QString _optPass1,QString _optPass2) { + name=_name; + fourcc=_fourcc; + optOnePass=_optOnePass; + optPass1=_optPass1; + optPass2=_optPass2; + } + QString name; + QString fourcc; + QString optOnePass; + QString optPass1; + QString optPass2; +}; + + +k9VideoCodecs::k9VideoCodecs(QObject *parent, const char *name) + : QObject(parent, name) +{ + m_config=new k9Config(); + QStringList slLabels=m_config->getCodecLabels(); + QStringList slCodecs=m_config->getCodecVideo(); + bool bReset; + bReset=slLabels.count()==0; + if (!bReset) + bReset=slCodecs.count() != slLabels.count()*4; + //adds default codecs + if (bReset) { + reset(); + m_config=new k9Config(); + slLabels=m_config->getCodecLabels(); + slCodecs=m_config->getCodecVideo(); + } + + QStringList::iterator c=slCodecs.begin(); + int cpt=0; + for (QStringList::iterator i=slLabels.begin();i!=slLabels.end() ;++i) { + QString fourcc=(*c); + c++; + QString o1=(*c); + c++; + QString o2=(*c); + c++; + QString o3=(*c); + c++; + + m_codecs[cpt++]=_k9VideoCodec((*i),fourcc,o1,o2,o3); + } + delete m_config; + +} + +void k9VideoCodecs::reset() { + m_codecs[0]=_k9VideoCodec("copy","","-ovc copy","-ovc copy","-ovc copy"); + m_codecs[1]=_k9VideoCodec("XviD","","-ovc xvid -xvidencopts bitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc xvid -xvidencopts bitrate=$VIDBR:turbo:pass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc xvid -xvidencopts bitrate=$VIDBR:turbo:pass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[2]=_k9VideoCodec("x264","","-ovc x264 -x264encopts bitrate=$VIDBR:threads=0 -vf scale=$WIDTH:$HEIGHT","-ovc x264 -x264encopts bitrate=$VIDBR:turbo=1:pass=$PASS:threads=0 -vf scale=$WIDTH:$HEIGHT","-ovc x264 -x264encopts bitrate=$VIDBR:turbo=1:pass=$PASS:threads=0 -vf scale=$WIDTH:$HEIGHT"); + m_codecs[3]=_k9VideoCodec("MJPEG","","-ovc lavc -lavcopts vcodec=mjpeg:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mjpeg:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mjpeg:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[4]=_k9VideoCodec("LJPEG","","-ovc lavc -lavcopts vcodec=ljpeg:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=ljpeg:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=ljpeg:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[5]=_k9VideoCodec("H261","","-ovc lavc -lavcopts vcodec=h261:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=h261:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=h261:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[6]=_k9VideoCodec("H263","","-ovc lavc -lavcopts vcodec=h263:vhq:v4mv:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=h263:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=h263:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[7]=_k9VideoCodec("H263+","","-ovc lavc -lavcopts vcodec=h263p:vhq:v4mv:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=h263p:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=h263p:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[8]=_k9VideoCodec("MPEG-4 (DivX 4/5)","DIVX","-ovc lavc -lavcopts vcodec=mpeg4:vhq:v4mv:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mpeg4:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mpeg4:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[9]=_k9VideoCodec("MS MPEG-4 (DivX 3)","DIVX","-ovc lavc -lavcopts vcodec=msmpeg4:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=msmpeg4:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=msmpeg4:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[10]=_k9VideoCodec("MS MPEG-4 v2","","-ovc lavc -lavcopts vcodec=msmpeg4v2:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=msmpeg4v2:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=msmpeg4v2:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[11]=_k9VideoCodec("WMV7","","-ovc lavc -lavcopts vcodec=wmv1:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=wmv1:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=wmv1:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[12]=_k9VideoCodec("WMV8","","-ovc lavc -lavcopts vcodec=wmv2:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=wmv2:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=wmv2:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + + m_codecs[13]=_k9VideoCodec("RealVideo","","-ovc lavc -lavcopts vcodec=rv10:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=rv10:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=rv10:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[14]=_k9VideoCodec("MPEG-1 Video","","-ovc lavc -lavcopts vcodec=mpeg1video:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mpeg1video:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mpeg1video:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[15]=_k9VideoCodec("MPEG-2 Video","","-ovc lavc -lavcopts vcodec=mpeg2video:vhq:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mpeg2video:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=mpeg2video:vhq:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[16]=_k9VideoCodec("Huffmann yuv","","-ovc lavc -lavcopts vcodec=huffyuv:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:format=422p -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=huffyuv:vhq:v4mv:vqmin=2:vbitrate=$VIDBR::format=422p:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=huffyuv:vhq:v4mv:vqmin=2:vbitrate=$VIDBR::format=422p:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[17]=_k9VideoCodec("ffv Huffmann","","-ovc lavc -lavcopts vcodec=ffvhuff:vhq:v4mv:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=ffvhuff:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=ffvhuff:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[18]=_k9VideoCodec("ASUS v1","","-ovc lavc -lavcopts vcodec=asv1:vhq:v4mv:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=asv1:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=asv1:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[19]=_k9VideoCodec("ASUS v2","","-ovc lavc -lavcopts vcodec=asv2:vhq:v4mv:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=asv2:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=asv2:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + m_codecs[20]=_k9VideoCodec("flv","","-ovc lavc -lavcopts vcodec=flv:vhq:v4mv:vqmin=2:vbitrate=$VIDBR -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=flv:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT","-ovc lavc -lavcopts vcodec=flv:vhq:v4mv:vqmin=2:vbitrate=$VIDBR:turbo:vpass=$PASS -vf scale=$WIDTH:$HEIGHT"); + save(); + +} + +void k9VideoCodecs::save() { + m_config=new k9Config(); + + QStringList labels; + QStringList options; + for (QMap<int,_k9VideoCodec>::iterator i=m_codecs.begin();i!=m_codecs.end();++i) { + labels << i.data().name; + options << i.data().fourcc; + options << i.data().optOnePass; + options << i.data().optPass1; + options << i.data().optPass2; + } + m_config->setCodecLabels(labels); + m_config->setCodecVideo(options); + m_config->save(); + delete m_config; +} + + + + +int k9VideoCodecs::count() { + return m_codecs.count(); +} + +void k9VideoCodecs::setFourcc(int _num,QString _value) { + m_codecs[_num].fourcc=_value; +} +void k9VideoCodecs::setOptions0(int _num,QString _value) { + m_codecs[_num].optOnePass=_value; +} +void k9VideoCodecs::setOptions1(int _num,QString _value) { + m_codecs[_num].optPass1=_value; +} +void k9VideoCodecs::setOptions2(int _num,QString _value) { + m_codecs[_num].optPass2=_value; +} + +void k9VideoCodecs::setCodecName(int _num,QString _value) { + m_codecs[_num].name=_value; +} + +QString k9VideoCodecs::getFourcc(int _num) { + return m_codecs[_num].fourcc; +} + +QString k9VideoCodecs::getOptions0(int _num) { + return m_codecs[_num].optOnePass; +} + +QString k9VideoCodecs::getOptions1(int _num) { + return m_codecs[_num].optPass1; +} + +QString k9VideoCodecs::getOptions2(int _num) { + return m_codecs[_num].optPass2; +} +QString k9VideoCodecs::getCodecName(int _num) { + return m_codecs[_num].name; +} + +void k9VideoCodecs::remove(int _num) { + int nb=count(); + if (nb>0) { + for(int i=_num;i<nb-1;i++) { + m_codecs[i]=m_codecs[i+1]; + } + m_codecs.remove(nb-1); + } +} + +k9VideoCodecs::~k9VideoCodecs() +{ + +} + + +#include "k9videocodecs.moc" diff --git a/libk9copy/k9videocodecs.h b/libk9copy/k9videocodecs.h new file mode 100644 index 0000000..4ef7c77 --- /dev/null +++ b/libk9copy/k9videocodecs.h @@ -0,0 +1,54 @@ +// +// C++ Interface: k9videocodecs +// +// Description: +// +// +// Author: Jean-Michel PETIT <[email protected]>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef K9VIDEOCODECS_H +#define K9VIDEOCODECS_H + +#include "k9common.h" +#include <qobject.h> +#include <qmap.h> +#include "k9config.h" + +/** + @author Jean-Michel PETIT <[email protected]> +*/ +class _k9VideoCodec; + +class k9VideoCodecs : public QObject +{ +Q_OBJECT +public: + k9VideoCodecs(QObject *parent = 0, const char *name = 0); + + ~k9VideoCodecs(); + void save(); + void setFourcc(int _num,QString _value); + void setOptions0(int _num,QString _value); + void setOptions1(int _num,QString _value); + void setOptions2(int _num,QString _value); + void setCodecName(int _num,QString _value); + void remove(int _num); + QString getFourcc(int _num); + QString getOptions0(int _num); + QString getOptions1(int _num); + QString getOptions2(int _num); + QString getCodecName(int _num); + + int count(); + void reset(); +private: + QMap <int,_k9VideoCodec> m_codecs; + k9Config *m_config; + + +}; + +#endif diff --git a/libk9copy/mp4dlg.cpp b/libk9copy/mp4dlg.cpp new file mode 100644 index 0000000..a5854d7 --- /dev/null +++ b/libk9copy/mp4dlg.cpp @@ -0,0 +1,159 @@ +#include <klocale.h> +/**************************************************************************** +** Form implementation generated from reading ui file './mp4dlg.ui' +** +** Created: dim. oct. 26 08:55:59 2008 +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "mp4dlg.h" + +#include <qvariant.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <kprogress.h> +#include <qframe.h> +#include <kpushbutton.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> +#include "kprogress.h" +#include "kpushbutton.h" + +/* + * Constructs a MP4Dlg as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + */ +MP4Dlg::MP4Dlg( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "MP4Dlg" ); + setCursor( QCursor( 3 ) ); + MP4DlgLayout = new QGridLayout( this, 1, 1, 11, 6, "MP4DlgLayout"); + + lblTitle = new QLabel( this, "lblTitle" ); + lblTitle->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)4, (QSizePolicy::SizeType)4, 0, 0, lblTitle->sizePolicy().hasHeightForWidth() ) ); + QFont lblTitle_font( lblTitle->font() ); + lblTitle_font.setBold( TRUE ); + lblTitle->setFont( lblTitle_font ); + lblTitle->setCursor( QCursor( 3 ) ); + + MP4DlgLayout->addWidget( lblTitle, 0, 0 ); + + pbProgress = new KProgress( this, "pbProgress" ); + pbProgress->setCursor( QCursor( 3 ) ); + + MP4DlgLayout->addMultiCellWidget( pbProgress, 3, 3, 0, 2 ); + + frame3 = new QFrame( this, "frame3" ); + frame3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, frame3->sizePolicy().hasHeightForWidth() ) ); + frame3->setCursor( QCursor( 3 ) ); + frame3->setFrameShape( QFrame::NoFrame ); + frame3->setFrameShadow( QFrame::Raised ); + frame3Layout = new QGridLayout( frame3, 1, 1, 11, 6, "frame3Layout"); + + lblfps = new QLabel( frame3, "lblfps" ); + lblfps->setCursor( QCursor( 3 ) ); + lblfps->setAlignment( int( QLabel::AlignVCenter ) ); + + frame3Layout->addWidget( lblfps, 2, 1 ); + + lblRemain = new QLabel( frame3, "lblRemain" ); + lblRemain->setCursor( QCursor( 3 ) ); + lblRemain->setAlignment( int( QLabel::AlignVCenter ) ); + + frame3Layout->addWidget( lblRemain, 3, 1 ); + + lblsize = new QLabel( frame3, "lblsize" ); + lblsize->setCursor( QCursor( 3 ) ); + + frame3Layout->addWidget( lblsize, 0, 1 ); + + lblbitrate = new QLabel( frame3, "lblbitrate" ); + lblbitrate->setCursor( QCursor( 3 ) ); + + frame3Layout->addWidget( lblbitrate, 1, 1 ); + + textLabel2 = new QLabel( frame3, "textLabel2" ); + textLabel2->setCursor( QCursor( 3 ) ); + + frame3Layout->addWidget( textLabel2, 2, 0 ); + + textLabel2_2 = new QLabel( frame3, "textLabel2_2" ); + textLabel2_2->setCursor( QCursor( 3 ) ); + + frame3Layout->addWidget( textLabel2_2, 3, 0 ); + + textLabel1 = new QLabel( frame3, "textLabel1" ); + textLabel1->setCursor( QCursor( 3 ) ); + + frame3Layout->addWidget( textLabel1, 1, 0 ); + + textLabel3 = new QLabel( frame3, "textLabel3" ); + textLabel3->setCursor( QCursor( 3 ) ); + + frame3Layout->addWidget( textLabel3, 0, 0 ); + + MP4DlgLayout->addMultiCellWidget( frame3, 2, 2, 0, 2 ); + + bCancel = new KPushButton( this, "bCancel" ); + bCancel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, bCancel->sizePolicy().hasHeightForWidth() ) ); + bCancel->setCursor( QCursor( 0 ) ); + bCancel->setProperty( "stdItem", 26 ); + + MP4DlgLayout->addWidget( bCancel, 5, 2 ); + spacer1 = new QSpacerItem( 225, 21, QSizePolicy::Expanding, QSizePolicy::Minimum ); + MP4DlgLayout->addMultiCell( spacer1, 5, 5, 0, 1 ); + spacer2 = new QSpacerItem( 20, 16, QSizePolicy::Minimum, QSizePolicy::Fixed ); + MP4DlgLayout->addItem( spacer2, 4, 1 ); + + image = new QLabel( this, "image" ); + image->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)7, 0, 0, image->sizePolicy().hasHeightForWidth() ) ); + image->setMinimumSize( QSize( 0, 250 ) ); + image->setPaletteBackgroundColor( QColor( 0, 0, 0 ) ); + image->setCursor( QCursor( 3 ) ); + image->setScaledContents( TRUE ); + + MP4DlgLayout->addMultiCellWidget( image, 1, 1, 0, 2 ); + languageChange(); + resize( QSize(416, 475).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); + + // signals and slots connections + connect( bCancel, SIGNAL( clicked() ), this, SLOT( Cancel() ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +MP4Dlg::~MP4Dlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void MP4Dlg::languageChange() +{ + setCaption( tr2i18n( "k9Copy - transcoding" ) ); + lblTitle->setText( tr2i18n( "Encoding" ) ); + lblfps->setText( QString::null ); + lblRemain->setText( QString::null ); + lblsize->setText( QString::null ); + lblbitrate->setText( QString::null ); + textLabel2->setText( tr2i18n( "fps" ) ); + textLabel2_2->setText( tr2i18n( "Elapsed Time" ) ); + textLabel1->setText( tr2i18n( "Bitrate" ) ); + textLabel3->setText( tr2i18n( "Size" ) ); +} + +void MP4Dlg::Cancel() +{ + qWarning( "MP4Dlg::Cancel(): Not implemented yet" ); +} + +#include "mp4dlg.moc" diff --git a/libk9copy/mp4dlg.ui b/libk9copy/mp4dlg.ui new file mode 100644 index 0000000..87390ed --- /dev/null +++ b/libk9copy/mp4dlg.ui @@ -0,0 +1,281 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>MP4Dlg</class> +<widget class="QWidget"> + <property name="name"> + <cstring>MP4Dlg</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>416</width> + <height>475</height> + </rect> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="caption"> + <string>k9Copy - transcoding</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>lblTitle</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>4</hsizetype> + <vsizetype>4</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>Encoding</string> + </property> + </widget> + <widget class="KProgress" row="3" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>pbProgress</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + </widget> + <widget class="QFrame" row="2" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>frame3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>lblfps</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + <property name="alignment"> + <set>AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" row="3" column="1"> + <property name="name"> + <cstring>lblRemain</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + <property name="alignment"> + <set>AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>lblsize</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="1" column="1"> + <property name="name"> + <cstring>lblbitrate</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>fps</string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>textLabel2_2</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>Elapsed Time</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>Bitrate</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>Size</string> + </property> + </widget> + </grid> + </widget> + <widget class="KPushButton" row="5" column="2"> + <property name="name"> + <cstring>bCancel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>0</cursor> + </property> + <property name="stdItem" stdset="0"> + <number>26</number> + </property> + </widget> + <spacer row="5" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>225</width> + <height>21</height> + </size> + </property> + </spacer> + <spacer row="4" column="1"> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Fixed</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="1" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>image</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>250</height> + </size> + </property> + <property name="paletteBackgroundColor"> + <color> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>bCancel</sender> + <signal>clicked()</signal> + <receiver>MP4Dlg</receiver> + <slot>Cancel()</slot> + </connection> +</connections> +<slots> + <slot>Cancel()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kprogress.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/libk9copy/processList.cpp b/libk9copy/processList.cpp new file mode 100644 index 0000000..b5aa5e0 --- /dev/null +++ b/libk9copy/processList.cpp @@ -0,0 +1,81 @@ +#include <klocale.h> +/**************************************************************************** +** Form implementation generated from reading ui file './processList.ui' +** +** Created: dim. oct. 26 08:55:59 2008 +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "processList.h" + +#include <qvariant.h> +#include <qheader.h> +#include <qlistview.h> +#include <kpushbutton.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> +#include "kpushbutton.h" + +/* + * Constructs a processList as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + */ +processList::processList( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "processList" ); + processListLayout = new QGridLayout( this, 1, 1, 11, 6, "processListLayout"); + + lProcess = new QListView( this, "lProcess" ); + lProcess->addColumn( tr2i18n( "Processes" ) ); + lProcess->addColumn( tr2i18n( "Elapsed" ) ); + lProcess->addColumn( tr2i18n( "..." ) ); + + processListLayout->addMultiCellWidget( lProcess, 0, 0, 0, 1 ); + + bCancel = new KPushButton( this, "bCancel" ); + bCancel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, bCancel->sizePolicy().hasHeightForWidth() ) ); + bCancel->setProperty( "stdItem", 2 ); + + processListLayout->addWidget( bCancel, 1, 1 ); + spacer1 = new QSpacerItem( 361, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + processListLayout->addItem( spacer1, 1, 0 ); + languageChange(); + resize( QSize(600, 480).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); + + // signals and slots connections + connect( bCancel, SIGNAL( clicked() ), this, SLOT( bCancelClick() ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +processList::~processList() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void processList::languageChange() +{ + setCaption( tr2i18n( "Process List" ) ); + lProcess->header()->setLabel( 0, tr2i18n( "Processes" ) ); + lProcess->header()->setLabel( 1, tr2i18n( "Elapsed" ) ); + lProcess->header()->setLabel( 2, tr2i18n( "..." ) ); + bCancel->setText( tr2i18n( "&Cancel" ) ); + bCancel->setAccel( QKeySequence( tr2i18n( "Alt+C" ) ) ); +} + +void processList::bCancelClick() +{ + qWarning( "processList::bCancelClick(): Not implemented yet" ); +} + +#include "processList.moc" diff --git a/libk9copy/processList.ui b/libk9copy/processList.ui new file mode 100644 index 0000000..efd924c --- /dev/null +++ b/libk9copy/processList.ui @@ -0,0 +1,116 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>processList</class> +<widget class="QWidget"> + <property name="name"> + <cstring>processList</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>Process List</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QListView" row="0" column="0" rowspan="1" colspan="2"> + <column> + <property name="text"> + <string>Processes</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Elapsed</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>...</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>lProcess</cstring> + </property> + </widget> + <widget class="KPushButton" row="1" column="1"> + <property name="name"> + <cstring>bCancel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string>Alt+C</string> + </property> + <property name="stdItem" stdset="0"> + <number>2</number> + </property> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>361</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> +</widget> +<connections> + <connection> + <sender>bCancel</sender> + <signal>clicked()</signal> + <receiver>processList</receiver> + <slot>bCancelClick()</slot> + </connection> +</connections> +<slots> + <slot>bCancelClick()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/libk9copy/progress.cpp b/libk9copy/progress.cpp new file mode 100644 index 0000000..f4794a6 --- /dev/null +++ b/libk9copy/progress.cpp @@ -0,0 +1,127 @@ +#include <klocale.h> +/**************************************************************************** +** Form implementation generated from reading ui file './progress.ui' +** +** Created: dim. oct. 26 08:55:59 2008 +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "progress.h" + +#include <qvariant.h> +#include <qlabel.h> +#include <kpushbutton.h> +#include <kprogress.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> +#include "kpushbutton.h" +#include "kprogress.h" + +/* + * Constructs a Progress as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + */ +Progress::Progress( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "Progress" ); + setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, 0, 0, sizePolicy().hasHeightForWidth() ) ); + setMinimumSize( QSize( 0, 0 ) ); + setCursor( QCursor( 3 ) ); + setMouseTracking( FALSE ); + ProgressLayout = new QGridLayout( this, 1, 1, 11, 6, "ProgressLayout"); + + lblTitle = new QLabel( this, "lblTitle" ); + lblTitle->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, lblTitle->sizePolicy().hasHeightForWidth() ) ); + QFont lblTitle_font( lblTitle->font() ); + lblTitle_font.setBold( TRUE ); + lblTitle->setFont( lblTitle_font ); + lblTitle->setCursor( QCursor( 3 ) ); + + ProgressLayout->addMultiCellWidget( lblTitle, 0, 0, 0, 2 ); + + bCancel = new KPushButton( this, "bCancel" ); + bCancel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, bCancel->sizePolicy().hasHeightForWidth() ) ); + bCancel->setCursor( QCursor( 0 ) ); + bCancel->setProperty( "stdItem", 26 ); + + ProgressLayout->addWidget( bCancel, 6, 2 ); + spacer1 = new QSpacerItem( 161, 21, QSizePolicy::Expanding, QSizePolicy::Minimum ); + ProgressLayout->addMultiCell( spacer1, 6, 6, 0, 1 ); + + ProgressBar = new KProgress( this, "ProgressBar" ); + ProgressBar->setCursor( QCursor( 3 ) ); + + ProgressLayout->addMultiCellWidget( ProgressBar, 4, 4, 0, 2 ); + spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Fixed ); + ProgressLayout->addItem( spacer2, 5, 1 ); + + image = new QLabel( this, "image" ); + image->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)7, 0, 0, image->sizePolicy().hasHeightForWidth() ) ); + image->setMinimumSize( QSize( 0, 250 ) ); + image->setPaletteBackgroundColor( QColor( 0, 0, 0 ) ); + image->setFrameShape( QLabel::NoFrame ); + image->setFrameShadow( QLabel::Plain ); + image->setAlignment( int( QLabel::AlignCenter ) ); + + ProgressLayout->addMultiCellWidget( image, 1, 1, 0, 2 ); + + textLabel1 = new QLabel( this, "textLabel1" ); + textLabel1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, textLabel1->sizePolicy().hasHeightForWidth() ) ); + textLabel1->setCursor( QCursor( 3 ) ); + + ProgressLayout->addWidget( textLabel1, 2, 0 ); + + lblElapsed = new QLabel( this, "lblElapsed" ); + lblElapsed->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, lblElapsed->sizePolicy().hasHeightForWidth() ) ); + lblElapsed->setCursor( QCursor( 3 ) ); + + ProgressLayout->addMultiCellWidget( lblElapsed, 2, 2, 1, 2 ); + + LabelText = new QLabel( this, "LabelText" ); + LabelText->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, LabelText->sizePolicy().hasHeightForWidth() ) ); + QFont LabelText_font( LabelText->font() ); + LabelText_font.setItalic( TRUE ); + LabelText->setFont( LabelText_font ); + LabelText->setCursor( QCursor( 3 ) ); + LabelText->setAlignment( int( QLabel::AlignVCenter ) ); + + ProgressLayout->addMultiCellWidget( LabelText, 3, 3, 0, 2 ); + languageChange(); + resize( QSize(473, 467).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); + + // signals and slots connections + connect( bCancel, SIGNAL( clicked() ), this, SLOT( bCancelClick() ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +Progress::~Progress() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void Progress::languageChange() +{ + setCaption( tr2i18n( "k9Copy" ) ); + lblTitle->setText( QString::null ); + textLabel1->setText( tr2i18n( "Elapsed Time" ) ); + lblElapsed->setText( QString::null ); + LabelText->setText( QString::null ); +} + +void Progress::bCancelClick() +{ + qWarning( "Progress::bCancelClick(): Not implemented yet" ); +} + +#include "progress.moc" diff --git a/libk9copy/progress.ui b/libk9copy/progress.ui new file mode 100644 index 0000000..21ee06b --- /dev/null +++ b/libk9copy/progress.ui @@ -0,0 +1,245 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>Progress</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Progress</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>473</width> + <height>467</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="caption"> + <string>k9Copy</string> + </property> + <property name="mouseTracking"> + <bool>false</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>lblTitle</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="KPushButton" row="6" column="2"> + <property name="name"> + <cstring>bCancel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>0</cursor> + </property> + <property name="stdItem" stdset="0"> + <number>26</number> + </property> + </widget> + <spacer row="6" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>161</width> + <height>21</height> + </size> + </property> + </spacer> + <widget class="KProgress" row="4" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>ProgressBar</cstring> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + </widget> + <spacer row="5" column="1"> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Fixed</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="1" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>image</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>250</height> + </size> + </property> + <property name="paletteBackgroundColor"> + <color> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string>Elapsed Time</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>lblElapsed</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="3" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>LabelText</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <italic>1</italic> + </font> + </property> + <property name="cursor"> + <cursor>3</cursor> + </property> + <property name="text"> + <string></string> + </property> + <property name="alignment"> + <set>AlignVCenter</set> + </property> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>bCancel</sender> + <signal>clicked()</signal> + <receiver>Progress</receiver> + <slot>bCancelClick()</slot> + </connection> +</connections> +<slots> + <slot>bCancelClick()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> + <includehint>kprogress.h</includehint> +</includehints> +</UI> |