diff options
Diffstat (limited to 'libk3b/videodvd')
-rw-r--r-- | libk3b/videodvd/Makefile.am | 19 | ||||
-rw-r--r-- | libk3b/videodvd/configure.in.bot | 11 | ||||
-rw-r--r-- | libk3b/videodvd/configure.in.in | 28 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvd.cpp | 327 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvd.h | 91 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdaudiostream.h | 112 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdptt.h | 50 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdsubpicturestream.h | 68 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdtime.cpp | 106 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdtime.h | 59 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdtitle.h | 112 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdvideostream.cpp | 60 | ||||
-rw-r--r-- | libk3b/videodvd/k3bvideodvdvideostream.h | 107 |
13 files changed, 1150 insertions, 0 deletions
diff --git a/libk3b/videodvd/Makefile.am b/libk3b/videodvd/Makefile.am new file mode 100644 index 0000000..0225117 --- /dev/null +++ b/libk3b/videodvd/Makefile.am @@ -0,0 +1,19 @@ +AM_CPPFLAGS = -I$(srcdir) \ + -I$(srcdir)/../core \ + -I$(srcdir)/../../libk3bdevice \ + -I$(srcdir)/../tools \ + -I$(srcdir)/../plugin \ + $(all_includes) + +METASOURCES = AUTO + +noinst_LTLIBRARIES = libvideodvd.la +libvideodvd_la_LIBADD = -ldvdread + +libvideodvd_la_SOURCES = k3bvideodvd.cpp k3bvideodvdtime.cpp \ + k3bvideodvdvideostream.cpp + +include_HEADERS = k3bvideodvd.h k3bvideodvdtitle.h \ + k3bvideodvdaudiostream.h k3bvideodvdsubpicturestream.h \ + k3bvideodvdvideostream.h k3bvideodvdtime.h \ + k3bvideodvdptt.h diff --git a/libk3b/videodvd/configure.in.bot b/libk3b/videodvd/configure.in.bot new file mode 100644 index 0000000..7ed988b --- /dev/null +++ b/libk3b/videodvd/configure.in.bot @@ -0,0 +1,11 @@ +echo "" + +echo "K3b - Include libdvdread (Video DVD ripping) support:" +if test "$have_libdvdread" = "yes"; then + echo "K3b - yes" +else + echo "K3b - no" + if test "$ac_cv_use_libdvdread" = "yes"; then + echo "K3b - You are missing the libdvdread library." + fi +fi diff --git a/libk3b/videodvd/configure.in.in b/libk3b/videodvd/configure.in.in new file mode 100644 index 0000000..f5ec969 --- /dev/null +++ b/libk3b/videodvd/configure.in.in @@ -0,0 +1,28 @@ +AC_ARG_WITH( + libdvdread, + AS_HELP_STRING( + [--without-libdvdread], + [build K3b without libdvdread (Video DVD ripping) support (default=no)]), + [ac_cv_use_libdvdread=$withval], + [ac_cv_use_libdvdread=yes] +) + +have_libdvdread=no +if test "$ac_cv_use_libdvdread" = "yes"; then + KDE_CHECK_HEADERS(dvdread/dvd_reader.h, + [ + AC_CHECK_LIB(dvdread, + DVDOpen, + [ + AC_DEFINE(HAVE_LIBDVDREAD,1,[Defined if you have libdvdread headers and libs installed.]) + have_libdvdread=yes + ] + ) + ]) +fi +AM_CONDITIONAL(include_videodvdrip, [test x$have_libdvdread = xyes]) + +#if test "$have_libdvdread" = "no"; then +# AC_MSG_ERROR([Could not find libdvdread. Please install.]) +# DO_NOT_COMPILE="$DO_NOT_COMPILE k3b" +#fi diff --git a/libk3b/videodvd/k3bvideodvd.cpp b/libk3b/videodvd/k3bvideodvd.cpp new file mode 100644 index 0000000..8692c04 --- /dev/null +++ b/libk3b/videodvd/k3bvideodvd.cpp @@ -0,0 +1,327 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + + +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS // needed for *_MAX macros in dvdread headers +#endif + +#include "k3bvideodvd.h" + +#include <k3bdevice.h> + +#include <qfile.h> + +#include <klocale.h> + +#include <inttypes.h> // needed by dvdreads headers +#include <dvdread/dvd_reader.h> +#include <dvdread/ifo_types.h> +#include <dvdread/ifo_read.h> + + +// I don't get this stuff, I should read something about VideoDVD some day... +#define CONVERT_TIME(x) (((x & 0xf0) >> 3) * 5 + (x & 0x0f)) +#define CONVERT_FRAME(x) (((x & 0x30) >> 3) * 5 + (x & 0x0f)) + + +K3bVideoDVD::VideoDVD::VideoDVD() +{ +} + + +K3bVideoDVD::VideoDVD::~VideoDVD() +{ +} + + +bool K3bVideoDVD::VideoDVD::valid() const +{ + return ( m_device != 0 ); +} + + +bool K3bVideoDVD::VideoDVD::open( K3bDevice::Device* dev ) +{ + m_device = 0; + m_titles.clear(); + + // + // Initialize libdvdread + // + dvd_reader_t* dvdReaderT = DVDOpen( QFile::encodeName(dev->blockDeviceName()) ); + if( !dvdReaderT ) { + kdDebug() << "(K3bVideoDVD) Could not open device " << dev->blockDeviceName() << endl; + return false; + } + + // + // Read volume id + // + char v[33]; + if( DVDUDFVolumeInfo( dvdReaderT, v, 33, 0, 0 ) != 0 && + DVDISOVolumeInfo( dvdReaderT, v, 33, 0, 0 ) != 0 ) { + kdDebug() << "(K3bVideoDVD) Could not read volume info." << endl; + DVDClose( dvdReaderT ); + return false; + } + m_volumeIdentifier = QString::fromLatin1( v, 32 ); + + // + // Open the VMG info + // + ifo_handle_t* vmg = ifoOpen( dvdReaderT, 0 ); + if( !vmg ) { + kdDebug() << "(K3bVideoDVD) Can't open VMG info." << endl; + DVDClose( dvdReaderT ); + return false; + } + + // + // parse titles + // + m_titles.resize( vmg->tt_srpt->nr_of_srpts ); + for( unsigned int i = 0; i < vmg->tt_srpt->nr_of_srpts; ++i ) { + title_info_t& title = vmg->tt_srpt->title[i]; + + // m_titles[i].m_videoDVD = this; + + // + // general title info + // + m_titles[i].m_titleNum = i+1; + m_titles[i].m_numPTTs = title.nr_of_ptts; + m_titles[i].m_numAngles = title.nr_of_angles; + m_titles[i].m_titleSet = title.title_set_nr; + m_titles[i].m_ttn = title.vts_ttn; + + // + // Open the title set the current title is a part of + // + ifo_handle_t* titleIfo = ifoOpen( dvdReaderT, vmg->tt_srpt->title[i].title_set_nr ); + if( !titleIfo ) { + kdDebug() << "(K3bVideoDVD) Can't open Title ifo." << endl; + ifoClose( vmg ); + DVDClose( dvdReaderT ); + return false; + } + + // + // Length of this title + // + // the program chain number of the first partoftitle of the current title (FIXME: but a title may contain multiple pgcs) + int pgc_id = titleIfo->vts_ptt_srpt->title[ m_titles[i].ttn() - 1 ].ptt[0].pgcn; + // (first?) program chain of the first partoftitle of the current title + pgc_t* cur_pgc = titleIfo->vts_pgcit->pgci_srp[ pgc_id - 1 ].pgc; + + m_titles[i].m_playbackTime = Time( CONVERT_TIME(cur_pgc->playback_time.hour), + CONVERT_TIME(cur_pgc->playback_time.minute), + CONVERT_TIME(cur_pgc->playback_time.second), + CONVERT_FRAME(cur_pgc->playback_time.frame_u) ); + + // + // Video stream information + // + m_titles[i].m_videoStream.m_permittedDf = titleIfo->vtsi_mat->vts_video_attr.permitted_df; + m_titles[i].m_videoStream.m_displayAspectRatio = titleIfo->vtsi_mat->vts_video_attr.display_aspect_ratio; + m_titles[i].m_videoStream.m_videoFormat = titleIfo->vtsi_mat->vts_video_attr.video_format; + m_titles[i].m_videoStream.m_mpegVersion = titleIfo->vtsi_mat->vts_video_attr.mpeg_version; + m_titles[i].m_videoStream.m_filmMode = titleIfo->vtsi_mat->vts_video_attr.film_mode; + m_titles[i].m_videoStream.m_letterboxed = titleIfo->vtsi_mat->vts_video_attr.letterboxed; + m_titles[i].m_videoStream.m_pictureSize = titleIfo->vtsi_mat->vts_video_attr.picture_size; + m_titles[i].m_videoStream.m_bitRate = titleIfo->vtsi_mat->vts_video_attr.bit_rate; + + // + // Audio stream information + // + m_titles[i].m_audioStreams.resize( titleIfo->vtsi_mat->nr_of_vts_audio_streams ); + for( unsigned int j = 0; j < titleIfo->vtsi_mat->nr_of_vts_audio_streams; ++j ) { + m_titles[i].m_audioStreams[j].m_format = titleIfo->vtsi_mat->vts_audio_attr[j].audio_format; + m_titles[i].m_audioStreams[j].m_applicationMode = titleIfo->vtsi_mat->vts_audio_attr[j].application_mode; + m_titles[i].m_audioStreams[j].m_quantization = titleIfo->vtsi_mat->vts_audio_attr[j].quantization; + m_titles[i].m_audioStreams[j].m_sampleFrequency = titleIfo->vtsi_mat->vts_audio_attr[j].sample_frequency; + m_titles[i].m_audioStreams[j].m_codeExtension = titleIfo->vtsi_mat->vts_audio_attr[j].code_extension; + m_titles[i].m_audioStreams[j].m_multiChannelExt = titleIfo->vtsi_mat->vts_audio_attr[j].multichannel_extension; + m_titles[i].m_audioStreams[j].m_channels = titleIfo->vtsi_mat->vts_audio_attr[j].channels+1; + if( titleIfo->vtsi_mat->vts_audio_attr[j].lang_type == 1 ) + m_titles[i].m_audioStreams[j].m_langCode.sprintf( "%c%c", + titleIfo->vtsi_mat->vts_audio_attr[j].lang_code>>8, + titleIfo->vtsi_mat->vts_audio_attr[j].lang_code & 0xff ); + else + m_titles[i].m_audioStreams[j].m_langCode = QString::null; + } + + // + // SubPicture stream information + // + m_titles[i].m_subPictureStreams.resize( titleIfo->vtsi_mat->nr_of_vts_subp_streams ); + for( unsigned int j = 0; j < titleIfo->vtsi_mat->nr_of_vts_subp_streams; ++j ) { + m_titles[i].m_subPictureStreams[j].m_codeMode = titleIfo->vtsi_mat->vts_subp_attr[j].code_mode; + m_titles[i].m_subPictureStreams[j].m_codeExtension = titleIfo->vtsi_mat->vts_subp_attr[j].code_extension; + if( titleIfo->vtsi_mat->vts_subp_attr[j].type == 1 ) + m_titles[i].m_subPictureStreams[j].m_langCode.sprintf( "%c%c", + titleIfo->vtsi_mat->vts_subp_attr[j].lang_code>>8, + titleIfo->vtsi_mat->vts_subp_attr[j].lang_code & 0xff ); + else + m_titles[i].m_subPictureStreams[j].m_langCode = QString::null; + } + + // + // add chapter info + // + m_titles[i].m_ptts.resize( m_titles[i].numPTTs() ); + for( unsigned int j = 0; j < m_titles[i].numPTTs(); ++j ) { + m_titles[i].m_ptts[j].m_pttNum = j+1; + m_titles[i].m_ptts[j].m_playbackTime = Time( CONVERT_TIME(cur_pgc->cell_playback[j].playback_time.hour), + CONVERT_TIME(cur_pgc->cell_playback[j].playback_time.minute), + CONVERT_TIME(cur_pgc->cell_playback[j].playback_time.second), + CONVERT_FRAME(cur_pgc->cell_playback[j].playback_time.frame_u) ); + m_titles[i].m_ptts[j].m_firstSector = cur_pgc->cell_playback[j].first_sector; + m_titles[i].m_ptts[j].m_lastSector = cur_pgc->cell_playback[j].last_sector; + } + + ifoClose( titleIfo ); + } + + ifoClose( vmg ); + DVDClose( dvdReaderT ); + + // + // Setting the device makes this a valid instance + // + m_device = dev; + + return true; +} + + +const K3bVideoDVD::Title& K3bVideoDVD::VideoDVD::title( unsigned int num ) const +{ + return m_titles[num]; +} + + +const K3bVideoDVD::Title& K3bVideoDVD::VideoDVD::operator[]( unsigned int num ) const +{ + return title( num ); +} + + +void K3bVideoDVD::VideoDVD::debug() const +{ + kdDebug() << "VideoDVD information:" << endl + << "=====================" << endl + << "Volume ID: " << volumeIdentifier() << endl << endl; + + for( unsigned int i = 0; i < numTitles(); ++i ) { + kdDebug() << "Title " << title(i).titleNumber() << " (" << title(i).playbackTime().toString() << ")" << endl + << " Chapters: " << title(i).numPTTs() << endl + << " Angles: " << title(i).numAngles() << endl + << " VTS,TTN: " << title(i).titleSet() << "," << title(i).ttn() << endl + << " Audio Streams:" << endl; + for( unsigned int j = 0; j < title(i).numAudioStreams(); ++j ) + kdDebug() << " " << title(i).audioStream(j).langCode() << ": " + << audioFormatString( title(i).audioStream(j).format() ) << ", " + << audioCodeExtensionString( title(i).audioStream(j).codeExtension() ) << endl; + kdDebug() << " SubPicture Streams:" << endl; + for( unsigned int j = 0; j < title(i).numSubPictureStreams(); ++j ) + kdDebug() << " " << title(i).subPictureStream(j).langCode() << ": " + << subPictureCodeModeString( title(i).subPictureStream(j).codeMode() ) << ", " + << subPictureCodeExtensionString( title(i).subPictureStream(j).codeExtension() ) << endl; + } +} + + +QString K3bVideoDVD::audioFormatString( int format ) +{ + switch( format ) { + case AUDIO_FORMAT_AC3: + return i18n("AC3"); + case AUDIO_FORMAT_MPEG1: + return i18n("MPEG1"); + case AUDIO_FORMAT_MPEG2EXT: + return i18n("MPEG2 Extended"); + case AUDIO_FORMAT_LPCM: + return i18n("LPCM"); + case AUDIO_FORMAT_DTS: + return i18n("DTS"); + default: + return i18n("unknown audio format"); + } +} + + +QString K3bVideoDVD::audioCodeExtensionString( int ext ) +{ + switch( ext ) { + case AUDIO_CODE_EXT_UNSPECIFIED: + return i18n("Unspecified"); + case AUDIO_CODE_EXT_NORMAL: + return i18n("Normal"); + case AUDIO_CODE_EXT_VISUALLY_IMPAIRED: + return i18n("For the visually impaired"); + case AUDIO_CODE_EXT_DIR_COMMENTS_1: + return i18n("Director's comments 1"); + case AUDIO_CODE_EXT_DIR_COMMENTS_2: + return i18n("Director's comments 2"); + default: + return i18n("unknown audio code extension"); + } +} + + +QString K3bVideoDVD::subPictureCodeModeString( int mode ) +{ + switch( mode ) { + case SUBPIC_CODE_MODE_RLE: + return i18n("RLE"); + case SUBPIC_CODE_MODE_EXT: + return i18n("Extended"); + default: + return i18n("unknown coding mode"); + } +} + + +QString K3bVideoDVD::subPictureCodeExtensionString( int ext ) +{ + switch( ext ) { + case SUBPIC_CODE_EXT_UNSPECIFIED: + return i18n("Unspecified"); + case SUBPIC_CODE_EXT_CAPTION_NORMAL_SIZE: + return i18n("Caption with normal size character"); + case SUBPIC_CODE_EXT_CAPTION_BIGGER_SIZE: + return i18n("Caption with bigger size character"); + case SUBPIC_CODE_EXT_CAPTION_FOR_CHILDREN: + return i18n("Caption for children"); + case SUBPIC_CODE_EXT_CLOSED_CAPTION_NORMAL_SIZE: + return i18n("Closed caption with normal size character"); + case SUBPIC_CODE_EXT_CLOSED_CAPTION_BIGGER_SIZE: + return i18n("Closed caption with bigger size character"); + case SUBPIC_CODE_EXT_CLOSED_CAPTION_FOR_CHILDREN: + return i18n("Closed caption for children"); + case SUBPIC_CODE_EXT_FORCED_CAPTION: + return i18n("Forced caption"); + case SUBPIC_CODE_EXT_DIR_COMMENTS_NORMAL_SIZE: + return i18n("Director's comments with normal size characters"); + case SUBPIC_CODE_EXT_DIR_COMMENTS_BIGGER_SIZE: + return i18n("Director's comments with bigger size characters"); + case SUBPIC_CODE_EXT_DIR_COMMENTS_FOR_CHILDREN: + return i18n("Director's comments for children"); + default: + return i18n("unknown code extension"); + } +} + diff --git a/libk3b/videodvd/k3bvideodvd.h b/libk3b/videodvd/k3bvideodvd.h new file mode 100644 index 0000000..180a6f5 --- /dev/null +++ b/libk3b/videodvd/k3bvideodvd.h @@ -0,0 +1,91 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_VIDEOVD_H_ +#define _K3B_VIDEOVD_H_ + +#include <k3bvideodvdtitle.h> + +#include <k3b_export.h> + +#include <qstring.h> +#include <qvaluevector.h> + + +namespace K3bDevice { + class Device; +} + +/** + * The K3bVideoDVD classes do not provide a complete playback frontend to + * libdvdread but are merely intended for Video DVD analysis. + * + * They are title based and thus treat a Video DVD to be a set of titles. + * Additional Video DVD constructs such as title sets, parts of titles (chapters), + * program chanins, or cells are not handled explicitly. + * + * The usage is very simple. One creates a VideoDVD instance and calls the open() + * method with a device containing a Video DVD. If the method returns true the + * analysis was successful and the structures are filled. + * + * After open() has returned the device has already been closed. + */ +namespace K3bVideoDVD +{ + /** + * libdvdread wrapper class + */ + class LIBK3B_EXPORT VideoDVD + { + public: + VideoDVD(); + ~VideoDVD(); + + /** + * \return true if a Video DVD was successfully opened via open() + */ + bool valid() const; + + /** + * Open a video dvd and parse it's contents. The device will be closed after this + * method returns, regardless of it's success. + */ + bool open( K3bDevice::Device* dev ); + + K3bDevice::Device* device() const { return m_device; } + const QString& volumeIdentifier() const { return m_volumeIdentifier; } + unsigned int numTitles() const { return m_titles.count(); } + + /** + * Get a title from the Video DVD. Index starts at 0. + */ + const Title& title( unsigned int num ) const; + const Title& operator[]( unsigned int num ) const; + + void debug() const; + + private: + K3bDevice::Device* m_device; + QValueVector<Title> m_titles; + QString m_volumeIdentifier; + }; + + LIBK3B_EXPORT QString audioFormatString( int format ); + LIBK3B_EXPORT QString audioCodeExtensionString( int ext ); + LIBK3B_EXPORT QString subPictureCodeModeString( int mode ); + LIBK3B_EXPORT QString subPictureCodeExtensionString( int ext ); +} + +#endif diff --git a/libk3b/videodvd/k3bvideodvdaudiostream.h b/libk3b/videodvd/k3bvideodvdaudiostream.h new file mode 100644 index 0000000..78068f0 --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdaudiostream.h @@ -0,0 +1,112 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_VIDEODVD_AUDIO_STREAM_H_ +#define _K3B_VIDEODVD_AUDIO_STREAM_H_ + +#include <k3b_export.h> + +#include <qstring.h> + + +namespace K3bVideoDVD +{ + enum AudioFormat { + AUDIO_FORMAT_AC3 = 0, + AUDIO_FORMAT_MPEG1 = 2, + AUDIO_FORMAT_MPEG2EXT = 3, + AUDIO_FORMAT_LPCM = 4, + AUDIO_FORMAT_DTS = 6 + }; + + enum AudioApplicationMode { + AUDIO_APPLICATION_KARAOKE = 1, + AUDIO_APPLICATION_SURROUND = 2 + }; + + enum AudioQuantization { + AUDIO_QUANTIZATION_16BIT = 0, + AUDIO_QUANTIZATION_20BIT = 1, + AUDIO_QUANTIZATION_24BIT = 2 + }; + + enum AudioSampleFrequency { + AUDIO_SAMPLE_FREQ_48HZ = 0, + AUDIO_SAMPLE_FREQ_96HZ = 1 + }; + + enum AudioCodeExtension { + AUDIO_CODE_EXT_UNSPECIFIED = 0, + AUDIO_CODE_EXT_NORMAL = 1, + AUDIO_CODE_EXT_VISUALLY_IMPAIRED = 2, + AUDIO_CODE_EXT_DIR_COMMENTS_1 = 3, + AUDIO_CODE_EXT_DIR_COMMENTS_2 = 4 + }; + + class LIBK3B_EXPORT AudioStream + { + public: + AudioStream() {} + + /** + * \return A two chars language code or the empty string + * if the language is undefined. + */ + const QString& langCode() const { return m_langCode; } + + /** + * \see AudioFormat + */ + unsigned short format() const { return m_format; } + + /** + * \see AudioApplicationMode + */ + unsigned short applicationMode() const { return m_applicationMode; } + + /** + * \see AudioQuantization + */ + unsigned short quantization() const { return m_quantization; } + + /** + * \see AudioSampleFrequency + */ + unsigned short sampleFrequency() const { return m_sampleFrequency; } + + /** + * \see AudioCodeExtension + */ + unsigned short codeExtension() const { return m_codeExtension; } + + bool multiChannelExt() const { return m_multiChannelExt; } + + unsigned short channels() const { return m_channels; } + + private: + unsigned short m_format:3; + unsigned short m_applicationMode:2; + unsigned short m_quantization:2; + unsigned short m_sampleFrequency:2; + unsigned short m_codeExtension; + bool m_multiChannelExt; + unsigned short m_channels:3; + QString m_langCode; + + friend class VideoDVD; + }; +} + +#endif diff --git a/libk3b/videodvd/k3bvideodvdptt.h b/libk3b/videodvd/k3bvideodvdptt.h new file mode 100644 index 0000000..f0dca91 --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdptt.h @@ -0,0 +1,50 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_VIDEODVD_PTT_H_ +#define _K3B_VIDEODVD_PTT_H_ + +#include <k3b_export.h> + +#include <k3bvideodvd.h> +#include <k3bvideodvdtime.h> + + +namespace K3bVideoDVD +{ + class LIBK3B_EXPORT PTT + { + public: + PTT() {} + + unsigned int pttNumber() const { return m_pttNum; } + + const Time& playbackTime() const { return m_playbackTime; } + + unsigned int firstSector() const { return m_firstSector; } + unsigned int lastSector() const { return m_lastSector; } + + private: + unsigned int m_pttNum; + Time m_playbackTime; + + unsigned int m_firstSector; + unsigned int m_lastSector; + + friend class VideoDVD; + }; +} + +#endif diff --git a/libk3b/videodvd/k3bvideodvdsubpicturestream.h b/libk3b/videodvd/k3bvideodvdsubpicturestream.h new file mode 100644 index 0000000..b32407d --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdsubpicturestream.h @@ -0,0 +1,68 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_VIDEODVD_SUBPICTURE_STREAM_H_ +#define _K3B_VIDEODVD_SUBPICTURE_STREAM_H_ + +#include <k3b_export.h> + +#include <qstring.h> + + +namespace K3bVideoDVD +{ + enum SubPictureCodeMode { + SUBPIC_CODE_MODE_RLE = 0, + SUBPIC_CODE_MODE_EXT = 1 + }; + + enum SubPictureCodeExtension { + SUBPIC_CODE_EXT_UNSPECIFIED = 0, + SUBPIC_CODE_EXT_CAPTION_NORMAL_SIZE = 1, + SUBPIC_CODE_EXT_CAPTION_BIGGER_SIZE = 2, + SUBPIC_CODE_EXT_CAPTION_FOR_CHILDREN = 3, + SUBPIC_CODE_EXT_CLOSED_CAPTION_NORMAL_SIZE = 5, + SUBPIC_CODE_EXT_CLOSED_CAPTION_BIGGER_SIZE = 6, + SUBPIC_CODE_EXT_CLOSED_CAPTION_FOR_CHILDREN = 7, + SUBPIC_CODE_EXT_FORCED_CAPTION = 9, + SUBPIC_CODE_EXT_DIR_COMMENTS_NORMAL_SIZE = 13, + SUBPIC_CODE_EXT_DIR_COMMENTS_BIGGER_SIZE = 14, + SUBPIC_CODE_EXT_DIR_COMMENTS_FOR_CHILDREN = 15 + }; + + class LIBK3B_EXPORT SubPictureStream + { + public: + SubPictureStream() {} + + unsigned int codeMode() const { return m_codeMode; } + unsigned int codeExtension() const { return m_codeExtension; } + + /** + * \return A two chars language code or the empty string + * if the language is undefined. + */ + const QString& langCode() const { return m_langCode; } + + private: + unsigned int m_codeMode:3; + QString m_langCode; + unsigned int m_codeExtension; + + friend class VideoDVD; + }; +} + +#endif diff --git a/libk3b/videodvd/k3bvideodvdtime.cpp b/libk3b/videodvd/k3bvideodvdtime.cpp new file mode 100644 index 0000000..acc6aec --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdtime.cpp @@ -0,0 +1,106 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#include "k3bvideodvdtime.h" + +K3bVideoDVD::Time::Time() + : m_hour(0), + m_minute(0), + m_second(0), + m_frame(0) +{ +} + + +K3bVideoDVD::Time::Time( unsigned short hour, + unsigned short min, + unsigned short sec, + unsigned short frame ) + : m_hour(hour), + m_minute(min), + m_second(sec), + m_frame(frame) +{ +} + + +double K3bVideoDVD::Time::totalSeconds() const +{ + double s = (double)second(); + s += 60.0 * (double)minute(); + s += 3600.0 * (double)hour(); + + return s + (double)( frame() / frameRate() ); +} + + +unsigned int K3bVideoDVD::Time::totalFrames() const +{ + double f = (double)second(); + f += 60.0 * (double)minute(); + f += 3600.0 * (double)hour(); + + return (int)( f * frameRate() ) + frame(); +} + + +double K3bVideoDVD::Time::frameRate() const +{ + // + // This is how it is done in libdvdread + // I don't really understand it, though... :( + // + switch( (frame() & 0xc0) >> 6 ) { + case 1: + // PAL? + return 25.0; + case 3: + // NTSC? + return 29.97; + default: + // should only happen for time == 0? + return 0.0; + } +} + + +QString K3bVideoDVD::Time::toString( bool includeFrames ) const +{ + // FIXME: use a d-pointer + const_cast<K3bVideoDVD::Time*>(this)->makeValid(); + + if( includeFrames ) + return QString().sprintf( "%02d:%02d:%02d.%02d", + m_hour, + m_minute, + m_second, + m_frame & 0x3f ); + else + return QString().sprintf( "%02d:%02d:%02d", + m_hour, + m_minute, + m_second + ( m_frame > 0 ? 1 : 0 ) ); +} + + +void K3bVideoDVD::Time::makeValid() +{ + // FIXME: how to handle the frames? + + m_minute += m_second/60; + m_second = m_second % 60; + m_hour += m_minute/60; + m_minute = m_minute % 60; +} diff --git a/libk3b/videodvd/k3bvideodvdtime.h b/libk3b/videodvd/k3bvideodvdtime.h new file mode 100644 index 0000000..f486741 --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdtime.h @@ -0,0 +1,59 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_VIDEODVD_TIME_H_ +#define _K3B_VIDEODVD_TIME_H_ + +#include <k3b_export.h> + +#include <qstring.h> + +/** + * This should not be confused with K3b::Msf + */ +namespace K3bVideoDVD +{ + class LIBK3B_EXPORT Time + { + public: + Time(); + Time( unsigned short hour, + unsigned short min, + unsigned short sec, + unsigned short frame ); + + unsigned short hour() const { return m_hour; } + unsigned short minute() const { return m_minute; } + unsigned short second() const { return m_second; } + unsigned short frame() const { return m_frame; } + + double totalSeconds() const; + unsigned int totalFrames() const; + + // FIXME: is this useful? + double frameRate() const; + + QString toString( bool includeFrames = true ) const; + + private: + void makeValid(); + + unsigned int m_hour; + unsigned int m_minute; + unsigned int m_second; + unsigned int m_frame; + }; + } +#endif diff --git a/libk3b/videodvd/k3bvideodvdtitle.h b/libk3b/videodvd/k3bvideodvdtitle.h new file mode 100644 index 0000000..17f31a3 --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdtitle.h @@ -0,0 +1,112 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_VIDEODVD_TITLE_H_ +#define _K3B_VIDEODVD_TITLE_H_ + +#include <k3b_export.h> + +#include <k3bvideodvdtime.h> +#include <k3bvideodvdvideostream.h> +#include <k3bvideodvdaudiostream.h> +#include <k3bvideodvdsubpicturestream.h> +#include <k3bvideodvdptt.h> + +#include <qvaluevector.h> + + +namespace K3bVideoDVD +{ + class LIBK3B_EXPORT Title + { + public: + Title() {} + + unsigned int titleNumber() const { return m_titleNum; } + + /** + * \return The number of PTTs (Part of Title), commonly known + * as chapters + */ + unsigned int numPTTs() const { return m_numPTTs; } + + /** + * This method is just here for convenience. It returns the same as the above. + */ + unsigned int numChapters() const { return m_numPTTs; } + unsigned int numAngles() const { return m_numAngles; } + + /** + * \return The number of the titleset this title is a part of. + */ + unsigned int titleSet() const { return m_titleSet; } + + /** + * \return Number of the title in it's titleset. + */ + unsigned int ttn() const { return m_ttn; } + + unsigned int numAudioStreams() const { return m_audioStreams.count(); } + unsigned int numSubPictureStreams() const { return m_subPictureStreams.count(); } + + const VideoStream& videoStream() const { return m_videoStream; } + const AudioStream& audioStream( unsigned int i ) const { return m_audioStreams[i]; } + const SubPictureStream& subPictureStream( unsigned int i ) const { return m_subPictureStreams[i]; } + + /** + * Access to the PTTs of the title + */ + const PTT& operator[]( int i ) const { return ptt( i ); } + + /** + * Access to the PTTs of the title + */ + const PTT& ptt( int i ) const { return m_ptts[i]; } + + /** + * Access to the PTTs (chapters) of the title + */ + const PTT& chapter( int i ) const { return ptt( i ); } + + const Time& playbackTime() const { return m_playbackTime; } + + /** + * \return A video capture + */ + // QBitmap videoCapture( const Time& ) const; + + private: + unsigned int m_titleNum; + unsigned int m_numPTTs; + unsigned int m_titleSet; + // FIXME: find a proper name for ttn + unsigned int m_ttn; + unsigned int m_numAngles; + + Time m_playbackTime; + + VideoStream m_videoStream; + QValueVector<AudioStream> m_audioStreams; + QValueVector<SubPictureStream> m_subPictureStreams; + + QValueVector<PTT> m_ptts; + + // VideoDVD* m_videoDVD; + + friend class VideoDVD; + }; +} + +#endif diff --git a/libk3b/videodvd/k3bvideodvdvideostream.cpp b/libk3b/videodvd/k3bvideodvdvideostream.cpp new file mode 100644 index 0000000..e7b6e9e --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdvideostream.cpp @@ -0,0 +1,60 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#include "k3bvideodvdvideostream.h" + +unsigned int K3bVideoDVD::VideoStream::pictureWidth() const +{ + switch( pictureSize() ) { + case VIDEO_PICTURE_SIZE_720: + return 720; + case VIDEO_PICTURE_SIZE_704: + return 704; + case VIDEO_PICTURE_SIZE_352: + case VIDEO_PICTURE_SIZE_352_2: + return 352; + default: + return 0; + } +} + + +unsigned int K3bVideoDVD::VideoStream::pictureHeight() const +{ + int height = 480; + if( format() != 0 ) + height = 576; + if( pictureSize() == VIDEO_PICTURE_SIZE_352_2 ) + height /= 2; + + return height; +} + + +unsigned int K3bVideoDVD::VideoStream::realPictureWidth() const +{ + double aspectRatio = 0.0; + if( displayAspectRatio() == K3bVideoDVD::VIDEO_ASPECT_RATIO_4_3 ) + aspectRatio = 4.0/3.0; + else + aspectRatio = 16.0/9.0; + return (int)(aspectRatio * (double)realPictureHeight()); +} + + +unsigned int K3bVideoDVD::VideoStream::realPictureHeight() const +{ + return pictureHeight(); +} diff --git a/libk3b/videodvd/k3bvideodvdvideostream.h b/libk3b/videodvd/k3bvideodvdvideostream.h new file mode 100644 index 0000000..c6c9d95 --- /dev/null +++ b/libk3b/videodvd/k3bvideodvdvideostream.h @@ -0,0 +1,107 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org> + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org> + * + * 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. + * See the file "COPYING" for the exact licensing terms. + */ + +#ifndef _K3B_VIDEODVD_VIDEO_STREAM_H_ +#define _K3B_VIDEODVD_VIDEO_STREAM_H_ + +#include <k3b_export.h> + +namespace K3bVideoDVD +{ + enum VideoMPEGVersion { + MPEG1 = 0, + MPEG2 = 1 + }; + + enum VideoFormat { + VIDEO_FORMAT_NTSC = 0, + VIDEO_FORMAT_PAL = 1 + }; + + enum VideoAspectRatio { + VIDEO_ASPECT_RATIO_4_3 = 0, + VIDEO_ASPECT_RATIO_16_9 = 1 + }; + + enum VideoPermitedDf { + VIDEO_PERMITTED_DF_BOTH = 0, + VIDEO_PERMITTED_DF_PAN_SCAN = 1, + VIDEO_PERMITTED_DF_LETTERBOXED = 2, + VIDEO_PERMITTED_DF_UNSPECIFIED = 3 + }; + + enum VideoBitRate { + VIDEO_BITRATE_VARIABLE = 0, + VIDEO_BITRATE_CONSTANT = 1 + }; + + enum VideoPicureSize { + VIDEO_PICTURE_SIZE_720 = 0, + VIDEO_PICTURE_SIZE_704 = 1, + VIDEO_PICTURE_SIZE_352 = 2, + VIDEO_PICTURE_SIZE_352_2 = 3 + }; + + class LIBK3B_EXPORT VideoStream + { + public: + VideoStream() {} + + unsigned int permittedDf() const { return m_permittedDf; } + unsigned int displayAspectRatio() const { return m_displayAspectRatio; } + unsigned int format() const { return m_videoFormat; } + unsigned int mpegVersion() const { return m_mpegVersion; } + unsigned int filmMode() const { return m_filmMode; } + unsigned int letterboxed() const { return m_letterboxed; } + unsigned int pictureSize() const { return m_pictureSize; } + unsigned int bitRate() const { return m_bitRate; } + + /** + * The picture width of the video stream + */ + unsigned int pictureWidth() const; + + /** + * The picture height of the video stream + */ + unsigned int pictureHeight() const; + + /** + * The width of the "real" video after applying aspect ratio + * correction + */ + unsigned int realPictureWidth() const; + + /** + * The height of the "real" video after applying aspect ratio + * correction + */ + unsigned int realPictureHeight() const; + + private: + unsigned int m_permittedDf:2; + unsigned int m_displayAspectRatio:2; + unsigned int m_videoFormat:2; + unsigned int m_mpegVersion:2; + unsigned int m_filmMode:1; + unsigned int m_letterboxed:1; + unsigned int m_pictureSize:2; + unsigned int m_bitRate:1; + + friend class VideoDVD; + }; +} + +#endif |