diff --git a/CMakeLists.txt b/CMakeLists.txt index f21136dc..e909b7d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,13 @@ set_package_properties(SharedMimeInfo PROPERTIES PURPOSE "Allows KDE applications to determine file types" ) +find_package(MPV) +set_package_properties(MPV PROPERTIES + DESCRIPTION "A fork of mplayer2 and MPlayer" + URL "https://mpv.io/" + TYPE REQUIRED +) + #optional features if(X11_FOUND) #X11_Xrender discovery is done by FindX11 @@ -227,7 +234,6 @@ set(KDE4_KJS_INCLUDES ${CMAKE_BINARY_DIR}/kjs ) - ################# configure checks and create the configured files ################# set(LIBRARY_TYPE SHARED) @@ -262,7 +268,6 @@ add_subdirectory( dnssd ) add_subdirectory( includes ) add_subdirectory( interfaces ) add_subdirectory( kcddb ) -add_subdirectory( kcompactdisc ) add_subdirectory( kdcraw ) add_subdirectory( kdeclarative ) add_subdirectory( kdecore ) @@ -301,7 +306,6 @@ add_subdirectory( solid ) add_subdirectory( sonnet ) add_subdirectory( threadweaver ) - ################# write kdelibs package config files which will be installed ################# macro_bool_to_01(HAVE_UTEMPTER KDE4_KPTY_BUILT_WITH_UTEMPTER) diff --git a/Messages.sh b/Messages.sh index 7f49b938..0bf90a64 100644 --- a/Messages.sh +++ b/Messages.sh @@ -1,5 +1,5 @@ #! /usr/bin/env bash -find . -type d | fgrep -v '.svn' | fgrep -v '.pc' | sed -e 's,$,/,' > dirs +find . -type d | fgrep -v '.git' | fgrep -v '.pc' | sed -e 's,$,/,' > dirs msh=`find . -name Messages.sh` for dir in $msh; do dir=`dirname $dir` diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index 31fa58ee..b9e4185a 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -101,7 +101,6 @@ set(cmakeFiles FindPAM.cmake FindPCIUTILS.cmake FindPCRE.cmake - FindPhonon.cmake FindPoppler.cmake FindPopplerQt4.cmake FindPostgreSQL.cmake diff --git a/cmake/modules/FindKDE4Internal.cmake b/cmake/modules/FindKDE4Internal.cmake index 6695a685..f044e35e 100644 --- a/cmake/modules/FindKDE4Internal.cmake +++ b/cmake/modules/FindKDE4Internal.cmake @@ -52,7 +52,6 @@ # KDE4_KPRINTUTILS_LIBRARY - the kprintutils library # KDE4_KFILE_LIBRARY - the kfile library # KDE4_KDNSSD_LIBRARY - the kdnssd library -# KDE4_PHONON_LIBRARY - the phonon library # KDE4_THREADWEAVER_LIBRARY- the threadweaver library # KDE4_SOLID_LIBRARY - the solid library # KDE4_KNOTIFYCONFIG_LIBRARY- the knotifyconfig library @@ -62,7 +61,6 @@ # KDE4_KUNITCONVERSION_LIBRARY - the kunitconversion library # KDE4_KDEWEBKIT_LIBRARY - the kdewebkit library # KDE4_KCDDB_LIBRARY - the kcddb library -# KDE4_KCOMPACTDISC_LIBRARY - the kcompactdisc library # KDE4_KDCRAW_LIBRARY - the kdcraw library # KDE4_KEXIV2_LIBRARY - the kexiv2 library # @@ -82,7 +80,6 @@ # KDE4_KDNSSD_LIBS - the kdnssd library and all depending libraries # KDE4_KDESU_LIBS - the kdesu library and all depending libraries # KDE4_KPTY_LIBS - the kpty library and all depending libraries -# KDE4_PHONON_LIBS - the phonon library and all depending librairies # KDE4_THREADWEAVER_LIBS - the threadweaver library and all depending libraries # KDE4_SOLID_LIBS - the solid library and all depending libraries # KDE4_KNOTIFYCONFIG_LIBS - the knotify config library and all depending libraries @@ -93,7 +90,6 @@ # KDE4_KUNITCONVERSION_LIBS - the kunitconversion library and all depending libraries # KDE4_KDEWEBKIT_LIBS - the kdewebkit library and all depending libraries # KDE4_KCDDB_LIBS - the kcddb library and all depending libraries -# KDE4_KCOMPACTDISC_LIBS - the kcompactdisc library and all depending libraries # KDE4_KDCRAW_LIBS - the kdcraw library and all depending libraries # KDE4_KEXIV2_LIBS - the kexiv2 library and all depending libraries # @@ -431,7 +427,6 @@ endif(_kdeBootStrapping) set(_kde_libraries kcddb kcmutils - kcompactdisc kdcraw kdeclarative kdecore @@ -471,31 +466,6 @@ foreach(_lib ${_kde_libraries}) endif() endforeach() -################### try to find Phonon ############################################ - -# we do this here instead of above together with the checks for Perl etc. -# since FindPhonon.cmake also uses ${KDE4_LIB_INSTALL_DIR} to check for Phonon, -# which helps with finding the phonon installed as part of kdesupport: - -# only make Phonon REQUIRED if KDE4 itself is REQUIRED -if(NOT KATIE_FOUND AND NOT KATIE_PHONON_FOUND) - find_package(Phonon 4.7.0 ${_REQ_STRING_KDE4}) - set(KDE4_PHONON_LIBRARY ${PHONON_LIBRARY}) - set(KDE4_PHONON_LIBS ${PHONON_LIBS}) - set(KDE4_PHONON_INCLUDES ${PHONON_INCLUDES}) -else() - set(PHONON_FOUND TRUE) - set(KDE4_PHONON_LIBRARY ${KATIE_PHONON_LIBRARIES}) - set(KDE4_PHONON_LIBS ${KATIE_PHONON_LIBRARIES}) - set(KDE4_PHONON_INCLUDES ${KATIE_PHONON_INCLUDES}) -endif() - -if(NOT PHONON_FOUND) - message(STATUS "KDE4 not found, because Phonon was not found") - return() -endif() - - ##################### provide some options ########################################## if(ENABLE_TESTING) @@ -969,7 +939,6 @@ endif() set(KDE4_INCLUDES ${KDE4_INCLUDE_DIR} ${KDE4_INCLUDE_DIR}/KDE - ${KDE4_PHONON_INCLUDES} ${QT_INCLUDES} ${_KDE4_PLATFORM_INCLUDE_DIRS} ) diff --git a/cmake/modules/FindMPV.cmake b/cmake/modules/FindMPV.cmake new file mode 100644 index 00000000..2e0e5e9e --- /dev/null +++ b/cmake/modules/FindMPV.cmake @@ -0,0 +1,46 @@ +# - Try to find MPV +# Once done this will define +# +# MPV_FOUND - system has MPV +# MPV_INCLUDES - the MPV include directory +# MPV_LIBRARIES - The libraries needed to use MPV +# +# Copyright (c) 2015, Ivailo Monev, +# +# Redistribution and use is allowed according to the terms of the BSD license. + +if(MPV_INCLUDES AND MPV_LIBRARIES) + set(MPV_FIND_QUIETLY TRUE) +endif() + +if(NOT WIN32) + include(FindPkgConfig) + pkg_check_modules(PC_MPV QUIET mpv) +endif() + +find_path(MPV_INCLUDES + NAMES + client.h + PATH_SUFFIXES mpv + HINTS + $ENV{MPVDIR}/include + ${PC_MPV_INCLUDEDIR} + /usr/include + /usr/local/include + ${INCLUDE_INSTALL_DIR} +) + +find_library(MPV_LIBRARIES + mpv + HINTS + $ENV{MPVDIR}/lib + ${PC_MPV_LIBDIR} + /usr/lib + /usr/local/lib + ${LIB_INSTALL_DIR} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MPV DEFAULT_MSG MPV_INCLUDES MPV_LIBRARIES) + +mark_as_advanced(MPV_INCLUDES MPV_LIBRARIES) diff --git a/cmake/modules/FindPhonon.cmake b/cmake/modules/FindPhonon.cmake deleted file mode 100644 index cd9e5cb4..00000000 --- a/cmake/modules/FindPhonon.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# Find libphonon -# Once done this will define -# -# PHONON_FOUND - system has Phonon Library -# PHONON_INCLUDES - the Phonon include directory -# PHONON_LIBS - link these to use Phonon -# PHONON_VERSION - the version of the Phonon Library - -# Copyright (c) 2008, Matthias Kretz -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -macro(_phonon_find_version) - set(_phonon_namespace_header_file "${PHONON_INCLUDE_DIR}/phonon/phononnamespace.h") - if (APPLE AND EXISTS "${PHONON_INCLUDE_DIR}/Headers/phononnamespace.h") - set(_phonon_namespace_header_file "${PHONON_INCLUDE_DIR}/Headers/phononnamespace.h") - endif (APPLE AND EXISTS "${PHONON_INCLUDE_DIR}/Headers/phononnamespace.h") - file(READ ${_phonon_namespace_header_file} _phonon_header LIMIT 5000 OFFSET 1000) - string(REGEX MATCH "define PHONON_VERSION_STR \"(4\\.[0-9]+\\.[0-9a-z]+)\"" _phonon_version_match "${_phonon_header}") - set(PHONON_VERSION "${CMAKE_MATCH_1}") -endmacro(_phonon_find_version) - -# the dirs listed with HINTS are searched before the default sets of dirs -find_library(PHONON_LIBRARY NAMES phonon HINTS ${KDE4_LIB_INSTALL_DIR} ${QT_LIBRARY_DIR}) -find_path(PHONON_INCLUDE_DIR NAMES phonon/phonon_export.h HINTS ${KDE4_INCLUDE_INSTALL_DIR} ${QT_INCLUDE_DIR} ${INCLUDE_INSTALL_DIR} ${QT_LIBRARY_DIR}) - -if(PHONON_INCLUDE_DIR AND PHONON_LIBRARY) - set(PHONON_LIBS ${phonon_LIB_DEPENDS} ${PHONON_LIBRARY}) - set(PHONON_INCLUDES ${PHONON_INCLUDE_DIR}/KDE ${PHONON_INCLUDE_DIR}) - _phonon_find_version() -endif(PHONON_INCLUDE_DIR AND PHONON_LIBRARY) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Phonon DEFAULT_MSG PHONON_INCLUDE_DIR PHONON_LIBRARY) - -mark_as_advanced(PHONON_INCLUDE_DIR PHONON_LIBRARY) diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 267a7c04..6bd4a9ec 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -422,6 +422,8 @@ install( KPixmapSequenceWidget KPixmapSequenceOverlayPainter KGraphicsWebView + KMediaPlayer + KMediaWidget KWebPage KWebView KWebPluginFactory @@ -525,14 +527,6 @@ install( COMPONENT Devel ) -install( - FILES - KMediaPlayer/Player - KMediaPlayer/View - DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/KMediaPlayer - COMPONENT Devel -) - install( FILES KParts/BrowserExtension @@ -804,7 +798,6 @@ install( Plasma/ToolTipManager Plasma/TreeView Plasma/Version - Plasma/VideoWidget Plasma/View Plasma/Wallpaper Plasma/WallpaperScript diff --git a/includes/KMediaPlayer b/includes/KMediaPlayer new file mode 100644 index 00000000..8f925dcc --- /dev/null +++ b/includes/KMediaPlayer @@ -0,0 +1 @@ +#include "../kmediaplayer.h" diff --git a/includes/KMediaPlayer/Player b/includes/KMediaPlayer/Player deleted file mode 100644 index 5fdd759d..00000000 --- a/includes/KMediaPlayer/Player +++ /dev/null @@ -1 +0,0 @@ -#include "../../kmediaplayer/player.h" diff --git a/includes/KMediaPlayer/View b/includes/KMediaPlayer/View deleted file mode 100644 index 98952e0d..00000000 --- a/includes/KMediaPlayer/View +++ /dev/null @@ -1 +0,0 @@ -#include "../../kmediaplayer/view.h" diff --git a/includes/KMediaWidget b/includes/KMediaWidget new file mode 100644 index 00000000..73f5d78e --- /dev/null +++ b/includes/KMediaWidget @@ -0,0 +1 @@ +#include "../kmediawidget.h" diff --git a/includes/Plasma/VideoWidget b/includes/Plasma/VideoWidget deleted file mode 100644 index 8b6995e3..00000000 --- a/includes/Plasma/VideoWidget +++ /dev/null @@ -1 +0,0 @@ -#include "../../plasma/widgets/videowidget.h" diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index db5edc45..1376e41a 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -4,7 +4,6 @@ project(interfaces) add_subdirectory( ktexteditor ) add_subdirectory( kregexpeditor ) -add_subdirectory( kmediaplayer ) add_subdirectory( kio ) add_subdirectory( terminal ) add_subdirectory( khexedit ) diff --git a/interfaces/kmediaplayer/CMakeLists.txt b/interfaces/kmediaplayer/CMakeLists.txt deleted file mode 100644 index 2eacee09..00000000 --- a/interfaces/kmediaplayer/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -add_subdirectory(kfileaudiopreview) - -include_directories(${KDE4_KPARTS_INCLUDES}) - -########### next target ############### - -set(kmediaplayer_LIB_SRCS - player.cpp - view.cpp - kmediaplayeradaptor.cpp -) - -add_library(kmediaplayer ${LIBRARY_TYPE} ${kmediaplayer_LIB_SRCS}) - -target_link_libraries(kmediaplayer PUBLIC - ${KDE4_KPARTS_LIBS} - ${QT_QTGUI_LIBRARY} -) - -set_target_properties(kmediaplayer PROPERTIES - VERSION ${GENERIC_LIB_VERSION} - SOVERSION ${GENERIC_LIB_SOVERSION} -) -install( - TARGETS kmediaplayer - EXPORT kdelibsLibraryTargets - ${INSTALL_TARGETS_DEFAULT_ARGS} -) - - -########### install files ############### - -install( - FILES - kmediaplayer_export.h - player.h - view.h - DESTINATION ${INCLUDE_INSTALL_DIR}/kmediaplayer - COMPONENT Devel -) - -install( - FILES - kmediaplayerengine.desktop - kmediaplayer.desktop - DESTINATION - ${SERVICETYPES_INSTALL_DIR} -) - -install( - FILES - org.kde.KMediaPlayer.xml - DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} -) diff --git a/interfaces/kmediaplayer/kfileaudiopreview/CMakeLists.txt b/interfaces/kmediaplayer/kfileaudiopreview/CMakeLists.txt deleted file mode 100644 index 218e1773..00000000 --- a/interfaces/kmediaplayer/kfileaudiopreview/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -include_directories(${KDE4_PHONON_INCLUDES} ${KDE4_KIO_INCLUDES}) - -set(kfileaudiopreview_PART_SRCS - kfileaudiopreview.cpp - mediacontrols.cpp -) - -kde4_add_plugin(kfileaudiopreview ${kfileaudiopreview_PART_SRCS}) - -target_link_libraries(kfileaudiopreview ${KDE4_KIO_LIBS} ${KDE4_PHONON_LIBS}) - -install( - TARGETS kfileaudiopreview - DESTINATION ${PLUGIN_INSTALL_DIR} -) diff --git a/interfaces/kmediaplayer/kfileaudiopreview/Messages.sh b/interfaces/kmediaplayer/kfileaudiopreview/Messages.sh deleted file mode 100644 index 71c7067f..00000000 --- a/interfaces/kmediaplayer/kfileaudiopreview/Messages.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /usr/bin/env bash -$XGETTEXT *.h *.cpp -o $podir/kfileaudiopreview4.pot diff --git a/interfaces/kmediaplayer/kfileaudiopreview/kfileaudiopreview.cpp b/interfaces/kmediaplayer/kfileaudiopreview/kfileaudiopreview.cpp deleted file mode 100644 index f7ee5747..00000000 --- a/interfaces/kmediaplayer/kfileaudiopreview/kfileaudiopreview.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2003 Carsten Pfeiffer - Copyright (C) 2006 Matthias Kretz - - library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation, version 2. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kfileaudiopreview.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include "mediacontrols.h" -#include - -K_PLUGIN_FACTORY( KFileAudioPreviewFactory, registerPlugin(); ) -K_EXPORT_PLUGIN( KFileAudioPreviewFactory ) - - -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// - -using namespace Phonon; - -class KFileAudioPreview::Private -{ -public: - Private() - : player( 0 ) - , audioOutput( 0 ) - , videoWidget( 0 ) - { - } - - MediaObject* player; - AudioOutput* audioOutput; - VideoWidget* videoWidget; - MediaControls* controls; -}; - - -KFileAudioPreview::KFileAudioPreview( QWidget *parent, const QVariantList & ) - : KPreviewWidgetBase( parent ) - , d( new Private ) -{ - KGlobal::locale()->insertCatalog("kfileaudiopreview4"); - - setSupportedMimeTypes(BackendCapabilities::availableMimeTypes()); - - d->audioOutput = new AudioOutput(Phonon::NoCategory, this); - - d->videoWidget = new VideoWidget( this ); - d->videoWidget->hide(); - - d->controls = new MediaControls( this ); - d->controls->setEnabled( false ); - d->controls->setAudioOutput( d->audioOutput ); - - m_autoPlay = new QCheckBox( i18n("Play &automatically"), this ); - KConfigGroup config( KGlobal::config(), ConfigGroup ); - m_autoPlay->setChecked( config.readEntry( "Autoplay sounds", true ) ); - connect( m_autoPlay, SIGNAL(toggled(bool)), SLOT(toggleAuto(bool)) ); - - QVBoxLayout* layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->addWidget(d->videoWidget); - layout->addWidget(d->controls); - layout->addWidget(m_autoPlay, 0, Qt::AlignHCenter); - layout->addStretch(); -} - -KFileAudioPreview::~KFileAudioPreview() -{ - KConfigGroup config( KGlobal::config(), ConfigGroup ); - config.writeEntry( "Autoplay sounds", m_autoPlay->isChecked() ); - - delete d; -} - -void KFileAudioPreview::stateChanged( Phonon::State newstate, Phonon::State oldstate ) -{ - if( oldstate == Phonon::LoadingState && newstate != Phonon::ErrorState ) - d->controls->setEnabled( true ); -} - -void KFileAudioPreview::showPreview( const KUrl &url ) -{ - d->controls->setEnabled(false); - if (!d->player) { - d->player = new MediaObject(this); - Phonon::createPath(d->player, d->videoWidget); - Phonon::createPath(d->player, d->audioOutput); - connect(d->player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - SLOT(stateChanged(Phonon::State,Phonon::State))); - d->videoWidget->setVisible(d->player->hasVideo()); - connect(d->player, SIGNAL(hasVideoChanged(bool)), d->videoWidget, SLOT(setVisible(bool))); - d->controls->setMediaObject(d->player); - } - d->player->setCurrentSource(url); - - if( m_autoPlay->isChecked() ) - d->player->play(); -} - -void KFileAudioPreview::clearPreview() -{ - if( d->player ) - { - delete d->player; - d->player = 0; - d->controls->setEnabled( false ); - } -} - -void KFileAudioPreview::toggleAuto( bool on ) -{ - if( !d->player ) - return; - - if( on && d->controls->isEnabled() ) - d->player->play(); - else - d->player->stop(); -} - -#include "moc_kfileaudiopreview.cpp" diff --git a/interfaces/kmediaplayer/kfileaudiopreview/kfileaudiopreview.h b/interfaces/kmediaplayer/kfileaudiopreview/kfileaudiopreview.h deleted file mode 100644 index ea929705..00000000 --- a/interfaces/kmediaplayer/kfileaudiopreview/kfileaudiopreview.h +++ /dev/null @@ -1,59 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2003 Carsten Pfeiffer - Copyright (C) 2006 Matthias Kretz - - library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation, version 2. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KFILEAUDIOPREVIEW_H -#define KFILEAUDIOPREVIEW_H - -#include -#include -#include - -class QCheckBox; - - -/** - * Audio "preview" widget for the file dialog. - */ -class KFileAudioPreview : public KPreviewWidgetBase -{ - Q_OBJECT - -public: - //TODO: make explicit in KDE5 - KFileAudioPreview( QWidget *parent = 0, //krazy:exclude=explicit until KDE5 - const QVariantList &args = QVariantList() ); - ~KFileAudioPreview(); - -public Q_SLOTS: - virtual void showPreview(const KUrl &url); - virtual void clearPreview(); - -private Q_SLOTS: - void toggleAuto( bool ); - void stateChanged( Phonon::State, Phonon::State ); - -private: - QCheckBox *m_autoPlay; - -private: - class Private; - Private *d; -}; - -#endif // KFILEAUDIOPREVIEW_H diff --git a/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols.cpp b/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols.cpp deleted file mode 100644 index 40d3b649..00000000 --- a/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2006-2007 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "mediacontrols.h" -#include "mediacontrols_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Phonon -{ - -MediaControls::MediaControls(QWidget *parent) - : QWidget(parent), - d_ptr(new MediaControlsPrivate(this)) -{ - setMaximumHeight(32); -} - -MediaControls::~MediaControls() -{ - delete d_ptr; -} - -bool MediaControls::isSeekSliderVisible() const -{ - Q_D(const MediaControls); - return d->seekSlider.isVisible(); -} - -bool MediaControls::isVolumeControlVisible() const -{ - Q_D(const MediaControls); - return d->volumeSlider.isVisible(); -} - -void MediaControls::setMediaObject(MediaObject *media) -{ - Q_D(MediaControls); - if (d->media) { - disconnect(d->media, SIGNAL(destroyed()), this, SLOT(_k_mediaDestroyed())); - disconnect(d->media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, - SLOT(_k_stateChanged(Phonon::State,Phonon::State))); - disconnect(&d->playButton, SIGNAL(clicked()), d->media, SLOT(play())); - disconnect(&d->pauseButton, SIGNAL(clicked()), d->media, SLOT(pause())); - } - d->media = media; - if (media) { - connect(media, SIGNAL(destroyed()), SLOT(_k_mediaDestroyed())); - connect(media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - SLOT(_k_stateChanged(Phonon::State,Phonon::State))); - connect(&d->playButton, SIGNAL(clicked()), media, SLOT(play())); - connect(&d->pauseButton, SIGNAL(clicked()), media, SLOT(pause())); - } - - d->seekSlider.setMediaObject(media); -} - -void MediaControls::setAudioOutput(AudioOutput *audioOutput) -{ - Q_D(MediaControls); - d->volumeSlider.setAudioOutput(audioOutput); - d->updateVolumeSliderVisibility(); - d->volumeSlider.setVisible(audioOutput != 0); -} - -void MediaControls::setSeekSliderVisible(bool vis) -{ - Q_D(MediaControls); - d->seekSlider.setVisible(vis); -} - -void MediaControls::setVolumeControlVisible(bool vis) -{ - Q_D(MediaControls); - d->volumeSlider.setVisible(vis); -} - -void MediaControls::resizeEvent(QResizeEvent*) -{ - Q_D(MediaControls); - d->updateVolumeSliderVisibility(); -} - -void MediaControlsPrivate::updateVolumeSliderVisibility() -{ - bool isWide = q_ptr->width() > playButton.sizeHint().width() + seekSlider.sizeHint().width() + volumeSlider.sizeHint().width(); - bool hasAudio = volumeSlider.audioOutput() != 0; - volumeSlider.setVisible(isWide && hasAudio); -} - -void MediaControlsPrivate::_k_stateChanged(State newstate, State) -{ - switch(newstate) - { - case Phonon::LoadingState: - case Phonon::PausedState: - case Phonon::StoppedState: - playButton.show(); - pauseButton.hide(); - break; - case Phonon::BufferingState: - case Phonon::PlayingState: - playButton.hide(); - pauseButton.show(); - break; - case Phonon::ErrorState: - return; - } -} - -void MediaControlsPrivate::_k_mediaDestroyed() -{ - media = 0; -} - -} // namespace Phonon - -#include "moc_mediacontrols.cpp" -// vim: sw=4 ts=4 diff --git a/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols.h b/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols.h deleted file mode 100644 index fbe27e39..00000000 --- a/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols.h +++ /dev/null @@ -1,102 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2006 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef PHONON_UI_MEDIACONTROLS_H -#define PHONON_UI_MEDIACONTROLS_H - -#include -#include - -namespace Phonon -{ -class MediaObject; -class AudioOutput; -class MediaControlsPrivate; - -/** - * \short Simple widget showing buttons to control an MediaObject - * object. - * - * This widget shows the standard player controls. There's at least the - * play/pause and stop buttons. If the media is seekable it shows a seek-slider. - * Optional controls include a volume control and a loop control button. - * - * \author Matthias Kretz - */ -class MediaControls : public QWidget -{ - Q_OBJECT - Q_DECLARE_PRIVATE(MediaControls) - /** - * This property holds whether the slider showing the progress of the - * playback is visible. - * - * By default the slider is visible. It is enabled/disabled automatically - * depending on whether the media can be seeked or not. - */ - Q_PROPERTY(bool seekSliderVisible READ isSeekSliderVisible WRITE setSeekSliderVisible) - - /** - * This property holds whether the slider controlling the volume is visible. - * - * By default the slider is visible if an AudioOutput has been set with - * setAudioOutput. - * - * \see setAudioOutput - */ - Q_PROPERTY(bool volumeControlVisible READ isVolumeControlVisible WRITE setVolumeControlVisible) - - public: - /** - * Constructs a media control widget with a \p parent. - */ - MediaControls(QWidget *parent = 0); - ~MediaControls(); - - bool isSeekSliderVisible() const; - bool isVolumeControlVisible() const; - - public Q_SLOTS: - void setSeekSliderVisible(bool); - void setVolumeControlVisible(bool); - - /** - * Sets the media object to be controlled by this widget. - */ - void setMediaObject(MediaObject *); - - /** - * Sets the audio output object to be controlled by this widget. - */ - void setAudioOutput(AudioOutput *audioOutput); - - protected: - void resizeEvent(QResizeEvent*); - - private: - Q_PRIVATE_SLOT(d_func(), void _k_stateChanged(Phonon::State, Phonon::State)) - Q_PRIVATE_SLOT(d_func(), void _k_mediaDestroyed()) - - MediaControlsPrivate *const d_ptr; -}; - -} // namespace Phonon - -// vim: sw=4 ts=4 tw=80 -#endif // PHONON_UI_MEDIACONTROLS_H diff --git a/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols_p.h b/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols_p.h deleted file mode 100644 index 751943be..00000000 --- a/interfaces/kmediaplayer/kfileaudiopreview/mediacontrols_p.h +++ /dev/null @@ -1,90 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2007 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef PHONON_MEDIACONTROLS_P_H -#define PHONON_MEDIACONTROLS_P_H - -#include "mediacontrols.h" -#include -#include -#include -#include -#include -#include -#include - -namespace Phonon -{ -class MediaControlsPrivate -{ - Q_DECLARE_PUBLIC(MediaControls) - protected: - MediaControlsPrivate(MediaControls *parent) - : q_ptr(parent), - layout(parent), - playButton(parent), - pauseButton(parent), - seekSlider(parent), - volumeSlider(parent), - media(0) - { - int size = KIconLoader::global()->currentSize(KIconLoader::Toolbar); - QSize iconSize(size, size); - playButton.setIconSize(iconSize); - playButton.setIcon(KIcon("media-playback-start")); - playButton.setToolTip(i18n("start playback")); - playButton.setAutoRaise(true); - - pauseButton.setIconSize(iconSize); - pauseButton.setIcon(KIcon("media-playback-pause")); - pauseButton.setToolTip(i18n("pause playback")); - pauseButton.hide(); - pauseButton.setAutoRaise(true); - - seekSlider.setIconVisible(false); - - volumeSlider.setOrientation(Qt::Horizontal); - volumeSlider.setMaximumWidth(80); - volumeSlider.hide(); - - layout.setMargin(0); - layout.setSpacing(0); - layout.addWidget(&playButton); - layout.addWidget(&pauseButton); - layout.addWidget(&seekSlider, 1); - layout.addWidget(&volumeSlider); - } - - MediaControls *q_ptr; - QHBoxLayout layout; - QToolButton playButton; - QToolButton pauseButton; - SeekSlider seekSlider; - VolumeSlider volumeSlider; - MediaObject *media; - - private: - void _k_stateChanged(Phonon::State, Phonon::State); - void _k_mediaDestroyed(); - void updateVolumeSliderVisibility(); -}; -} // namespace Phonon - -#endif // PHONON_MEDIACONTROLS_P_H -// vim: sw=4 sts=4 et tw=100 diff --git a/interfaces/kmediaplayer/kmediaplayer.desktop b/interfaces/kmediaplayer/kmediaplayer.desktop deleted file mode 100644 index 31024733..00000000 --- a/interfaces/kmediaplayer/kmediaplayer.desktop +++ /dev/null @@ -1,4 +0,0 @@ -[Desktop Entry] -Type=ServiceType -X-KDE-ServiceType=KMediaPlayer/Player -X-KDE-Derived=KParts/ReadOnlyPart diff --git a/interfaces/kmediaplayer/kmediaplayeradaptor.cpp b/interfaces/kmediaplayer/kmediaplayeradaptor.cpp deleted file mode 100644 index 77ca8f8c..00000000 --- a/interfaces/kmediaplayer/kmediaplayeradaptor.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * This file was generated by dbusidl2cpp version 0.4 - * when processing input file org.kde.KMediaPlayer.xml - * - * dbusidl2cpp is Copyright (C) 2006 Trolltech AS. All rights reserved. - * - * This is an auto-generated file. - */ - -#include "kmediaplayeradaptor_p.h" -#include -#include -#include -#include -#include -#include -#include - -/* - * Implementation of adaptor class KMediaPlayerAdaptor - */ - -KMediaPlayerAdaptor::KMediaPlayerAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ - // constructor - setAutoRelaySignals(true); -} - -KMediaPlayerAdaptor::~KMediaPlayerAdaptor() -{ - // destructor -} - -bool KMediaPlayerAdaptor::hasLength() const -{ - // get the value of property hasLength - return qvariant_cast< bool >(parent()->property("hasLength")); -} - -qlonglong KMediaPlayerAdaptor::length() const -{ - // get the value of property length - return qvariant_cast< qlonglong >(parent()->property("length")); -} - -bool KMediaPlayerAdaptor::isLooping() const -{ - // get the value of property looping - return qvariant_cast< bool >(parent()->property("looping")); -} - -void KMediaPlayerAdaptor::setLooping(bool value) -{ - // set the value of property looping - parent()->setProperty("looping", value); -} - -qlonglong KMediaPlayerAdaptor::position() const -{ - // get the value of property position - return qvariant_cast< qlonglong >(parent()->property("position")); -} - -bool KMediaPlayerAdaptor::isSeekable() const -{ - // get the value of property seekable - return qvariant_cast< bool >(parent()->property("seekable")); -} - -int KMediaPlayerAdaptor::state() const -{ - // get the value of property state - return qvariant_cast< int >(parent()->property("state")); -} - -void KMediaPlayerAdaptor::setState(int value) -{ - // set the value of property state - parent()->setProperty("state", value); -} - -bool KMediaPlayerAdaptor::openUrl(const QString &file) -{ - // handle method call org.kde.KMediaPlayer.openUrl - bool out0; - QMetaObject::invokeMethod(parent(), "openUrl", Q_RETURN_ARG(bool, out0), Q_ARG(QString, file)); - - // Alternative: - //out0 = static_cast(parent())->openUrl(file); - return out0; -} - -void KMediaPlayerAdaptor::pause() -{ - // handle method call org.kde.KMediaPlayer.pause - QMetaObject::invokeMethod(parent(), "pause"); - - // Alternative: - //static_cast(parent())->pause(); -} - -void KMediaPlayerAdaptor::play() -{ - // handle method call org.kde.KMediaPlayer.play - QMetaObject::invokeMethod(parent(), "play"); - - // Alternative: - //static_cast(parent())->play(); -} - -void KMediaPlayerAdaptor::seek(qlonglong msec) -{ - // handle method call org.kde.KMediaPlayer.seek - QMetaObject::invokeMethod(parent(), "seek", Q_ARG(qlonglong, msec)); - - // Alternative: - //static_cast(parent())->seek(msec); -} - -void KMediaPlayerAdaptor::stop() -{ - // handle method call org.kde.KMediaPlayer.stop - QMetaObject::invokeMethod(parent(), "stop"); - - // Alternative: - //static_cast(parent())->stop(); -} - - -#include "moc_kmediaplayeradaptor_p.cpp" diff --git a/interfaces/kmediaplayer/kmediaplayeradaptor_p.h b/interfaces/kmediaplayer/kmediaplayeradaptor_p.h deleted file mode 100644 index 6fb6ecbf..00000000 --- a/interfaces/kmediaplayer/kmediaplayeradaptor_p.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file was generated by dbusidl2cpp version 0.4 - * when processing input file org.kde.KMediaPlayer.xml - * - * dbusidl2cpp is Copyright (C) 2006 Trolltech AS. All rights reserved. - * - * This is an auto-generated file. - */ - -#ifndef KMEDIAPLAYERADAPTOR_H_19781146507443 -#define KMEDIAPLAYERADAPTOR_H_19781146507443 - -#include -#include - -template class QList; -template class QMap; -class QString; - -/* - * Adaptor class for interface org.kde.KMediaPlayer - */ -class KMediaPlayerAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.kde.KMediaPlayer") - Q_CLASSINFO("D-Bus Introspection", "" -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " - "") -public: - KMediaPlayerAdaptor(QObject *parent); - virtual ~KMediaPlayerAdaptor(); - -public: // PROPERTIES - Q_PROPERTY(bool hasLength READ hasLength) - bool hasLength() const; - - Q_PROPERTY(qlonglong length READ length) - qlonglong length() const; - - Q_PROPERTY(bool looping READ isLooping WRITE setLooping) - bool isLooping() const; - void setLooping(bool value); - - Q_PROPERTY(qlonglong position READ position) - qlonglong position() const; - - Q_PROPERTY(bool seekable READ isSeekable) - bool isSeekable() const; - - Q_PROPERTY(int state READ state WRITE setState) - int state() const; - void setState(int value); - -public Q_SLOTS: // METHODS - bool openUrl(const QString &file); - void pause(); - void play(); - void seek(qlonglong msec); - void stop(); -Q_SIGNALS: // SIGNALS -}; - -#endif diff --git a/interfaces/kmediaplayer/kmediaplayerengine.desktop b/interfaces/kmediaplayer/kmediaplayerengine.desktop deleted file mode 100644 index 3fa56fae..00000000 --- a/interfaces/kmediaplayer/kmediaplayerengine.desktop +++ /dev/null @@ -1,3 +0,0 @@ -[Desktop Entry] -Type=ServiceType -X-KDE-ServiceType=KMediaPlayer/Engine diff --git a/interfaces/kmediaplayer/org.kde.KMediaPlayer.xml b/interfaces/kmediaplayer/org.kde.KMediaPlayer.xml deleted file mode 100644 index 6da6e8d6..00000000 --- a/interfaces/kmediaplayer/org.kde.KMediaPlayer.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/interfaces/kmediaplayer/player.cpp b/interfaces/kmediaplayer/player.cpp deleted file mode 100644 index c050a6d3..00000000 --- a/interfaces/kmediaplayer/player.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2002 Neil Stevens -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name(s) of the author(s) shall not be -// used in advertising or otherwise to promote the sale, use or other dealings -// in this Software without prior written authorization from the author(s). - -#include -#include - -KMediaPlayer::Player::Player(QWidget *, const char *, QObject *parent) - : KParts::ReadOnlyPart(parent) - , currentLooping(false) - , currentState(Empty) - , d(0) -{ - (void)new KMediaPlayerAdaptor(this); -} - -KMediaPlayer::Player::Player(QObject *parent ) - : KParts::ReadOnlyPart(parent) - , currentLooping(false) - , currentState(Empty) - , d(0) -{ - (void)new KMediaPlayerAdaptor(this); -} - -KMediaPlayer::Player::~Player(void) -{ -} - -void KMediaPlayer::Player::setLooping(bool b) -{ - if(b != currentLooping) - { - currentLooping = b; - emit loopingChanged(b); - } -} - -bool KMediaPlayer::Player::isLooping(void) const -{ - return currentLooping; -} - -void KMediaPlayer::Player::setState(int s) -{ - if(s != currentState) - { - currentState = (State)s; - emit stateChanged(s); - } -} - -int KMediaPlayer::Player::state(void) const -{ - return (int)currentState; -} - -#include "moc_player.cpp" diff --git a/interfaces/kmediaplayer/player.h b/interfaces/kmediaplayer/player.h deleted file mode 100644 index 64275e12..00000000 --- a/interfaces/kmediaplayer/player.h +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (C) 2002 Neil Stevens -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name(s) of the author(s) shall not be -// used in advertising or otherwise to promote the sale, use or other dealings -// in this Software without prior written authorization from the author(s). - -#ifndef KMEDIAPLAYERPLAYER_H -#define KMEDIAPLAYERPLAYER_H - -#include -#include - -/** KMediaPlayer contains an interface to reusable media player components. -*/ -namespace KMediaPlayer -{ - -/** Player is the center of the KMediaPlayer interface. It provides all of - * the necessary media player operations, and optionally provides the GUI to - * control them. - * - * There are two servicetypes for Player: KMediaPlayer/Player and - * KMediaPlayer/Engine. KMediaPlayer/Player provides a widget (accessable - * through view as well as XML GUI KActions. KMediaPlayer/Engine omits - * the user interface facets, for those who wish to provide their own - * interface. - */ -class KMEDIAPLAYER_EXPORT Player : public KParts::ReadOnlyPart -{ -Q_OBJECT -Q_PROPERTY(bool hasLength READ hasLength) -Q_PROPERTY(qlonglong length READ length) -Q_PROPERTY(bool looping READ isLooping WRITE setLooping) -Q_PROPERTY(qlonglong position READ position) -Q_PROPERTY(bool seekable READ isSeekable) -Q_PROPERTY(int state READ state WRITE setState) - -public: - /** This constructor is what to use when no GUI is required, as in the - * case of a KMediaPlayer/Engine. - */ - Player(QObject *parent); - - /** This constructor is what to use when a GUI is required, as in the - * case of a KMediaPlayer/Player. - */ - Player(QWidget *parentWidget, const char *widgetName, QObject *parent ); - - virtual ~Player(void); - - /** A convenience function returning a pointer to the View for this - * Player, or 0 if this Player has no GUI. - */ - virtual View *view(void) = 0; - -public Q_SLOTS: - /** Pause playback of the media track.*/ - virtual void pause(void) = 0; - - /** Begin playing the media track.*/ - virtual void play(void) = 0; - - /** Stop playback of the media track and return to the beginning.*/ - virtual void stop(void) = 0; - - /** Move the current playback position to the specified time in - * milliseconds, if the track is seekable. Some streams may not be - * seeked. - */ - virtual void seek(qlonglong msec) = 0; -public: - /** Returns whether the current track honors seek requests.*/ - virtual bool isSeekable(void) const = 0; - - /** Returns the current playback position in the track.*/ - virtual qlonglong position(void) const = 0; - - /** Returns whether the current track has a length. Some streams are - * endless, and do not have one. */ - virtual bool hasLength(void) const = 0; - - /** Returns the length of the current track.*/ - virtual qlonglong length(void) const = 0; - -public Q_SLOTS: - /** Set whether the Player should continue playing at the beginning of - * the track when the end of the track is reached. - */ - void setLooping(bool); -public: - /** Return the current looping state. */ - bool isLooping(void) const; -Q_SIGNALS: - /** Emitted when the looping state is changed. */ - void loopingChanged(bool); - -public: - /** The possible states of the Player */ - enum State - { - /** No track is loaded. */ - Empty, - /** Not playing. */ - Stop, - /** Playing is temporarily suspended. */ - Pause, - /** The media is currently being output. */ - Play - }; - /** Return the current state of the player. */ - int state(void) const; -Q_SIGNALS: - /** Emitted when the state changes. */ - void stateChanged(int); - -protected Q_SLOTS: - /** Implementers use this to control what users see as the current - * state.*/ - void setState(int); - -protected: - /* Enable the stateChanged(QString&, ...) method that was hidden by - the stateChanged(int) signal */ - using KXMLGUIClient::stateChanged; - -private: - bool currentLooping; - State currentState; - - struct Data; - Data *d; -}; - -} - -#endif diff --git a/interfaces/kmediaplayer/view.cpp b/interfaces/kmediaplayer/view.cpp deleted file mode 100644 index 72fdef26..00000000 --- a/interfaces/kmediaplayer/view.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2002 Neil Stevens -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name(s) of the author(s) shall not be -// used in advertising or otherwise to promote the sale, use or other dealings -// in this Software without prior written authorization from the author(s). - -#include - -struct KMediaPlayer::View::Data -{ - Data() : videoWidget(0L) {} - - QWidget *videoWidget; -}; - -KMediaPlayer::View::View(QWidget *parent) - : QWidget(parent) - , currentButtons((int)All) - , d(new Data()) -{ -} - -KMediaPlayer::View::~View(void) -{ - delete d; -} - -int KMediaPlayer::View::buttons(void) -{ - return currentButtons; -} - -void KMediaPlayer::View::setButtons(int buttons) -{ - if(buttons != currentButtons) - { - currentButtons = buttons; - emit buttonsChanged(buttons); - } -} - -bool KMediaPlayer::View::button(int b) -{ - return currentButtons & b; -} - -void KMediaPlayer::View::showButton(int b) -{ - setButtons(currentButtons | b); -} - -void KMediaPlayer::View::hideButton(int b) -{ - setButtons(currentButtons & ~b); -} - -void KMediaPlayer::View::toggleButton(int b) -{ - setButtons(currentButtons ^ b); -} - -void KMediaPlayer::View::setVideoWidget(QWidget *videoWidget) -{ - d->videoWidget = videoWidget; -} - -QWidget* KMediaPlayer::View::videoWidget() -{ - return d->videoWidget; -} - -#include "moc_view.cpp" diff --git a/interfaces/kmediaplayer/view.h b/interfaces/kmediaplayer/view.h deleted file mode 100644 index 63423374..00000000 --- a/interfaces/kmediaplayer/view.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2002 Neil Stevens -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -// Except as contained in this notice, the name(s) of the author(s) shall not be -// used in advertising or otherwise to promote the sale, use or other dealings -// in this Software without prior written authorization from the author(s). - -#ifndef KMEDIAPLAYERVIEW_H -#define KMEDIAPLAYERVIEW_H - -#include -#include - -namespace KMediaPlayer -{ - -/** View is part of the user interface of a Player. */ -class KMEDIAPLAYER_EXPORT View : public QWidget -{ -Q_OBJECT - -public: - /** Your typical QWidget constructor. */ - View(QWidget *parent); - virtual ~View(void); - - /** The Possible buttons that can appear in the UI. */ - enum Button - { - /** Button that connects to Player::play */ - Play = 1, - /** Button that connects to Player::stop */ - Stop = 2, - /** Button that connects to Player::pause */ - Pause = 4, - /** A seeker that interfaces with Player::seek */ - Seeker = 8, - /** Show all buttons. */ - All = 255 - }; - - /** Return which buttons are being displayed. */ - int buttons(void); - - /** Return the QWidget in which video is displayed. - May Return 0L if there is none. */ - QWidget *videoWidget(); - -public Q_SLOTS: - /** Set which buttons to display. See Button. */ - void setButtons(int); - - /** Returns if a particular button is being displayed. */ - bool button(int); - /** Display a particular button. */ - void showButton(int); - /** Stop displaying a particular button. */ - void hideButton(int); - /** Toggle the display of a particular button. */ - void toggleButton(int); - -Q_SIGNALS: - /** Emitted when the set of displayed buttons changes. */ - void buttonsChanged(int); - -protected: - /** The implementing view should set the widget in which - the video will be displayed. KMediaPlayer users may - reparent() it to somewhere else, for example. - */ - void setVideoWidget(QWidget *videoWidget); - -private: - int currentButtons; - - struct Data; - Data *d; -}; - -} - -#endif diff --git a/kcompactdisc/CMakeLists.txt b/kcompactdisc/CMakeLists.txt deleted file mode 100644 index c7d41408..00000000 --- a/kcompactdisc/CMakeLists.txt +++ /dev/null @@ -1,92 +0,0 @@ -project(libkcompactdisc) - -include_directories( - ${QT_INCLUDES} - ${KDE4_INCLUDES} - ${KDE4_KDECORE_INCLUDES} - ${CMAKE_BINARY_DIR}/solid - ${CMAKE_SOURCE_DIR}/solid -) - -find_package(Alsa) -alsa_configure_file(${CMAKE_CURRENT_BINARY_DIR}/config-alsa.h) - -# TODO: drop wmlib entirely? -if(CMAKE_SYSTEM_NAME STREQUAL Linux) - set(USE_WMLIB FALSE) -else () - set(USE_WMLIB TRUE) -endif() - -set(kcompactdisc_LIB_SRCS - kcompactdisc.cpp - kcompactdisc_p.cpp - phonon_interface.cpp -) - -if(USE_WMLIB) - set(kcompactdisc_LIB_SRCS - ${kcompactdisc_LIB_SRCS} - wmlib_interface.cpp - wmlib/audio/audio.c - wmlib/audio/audio_arts.c - wmlib/audio/audio_alsa.c - wmlib/audio/audio_sun.c - wmlib/cdda.c - wmlib/cddb.c - wmlib/cdrom.c - wmlib/wm_helpers.c - wmlib/cdtext.c - wmlib/scsi.c - wmlib/plat_aix.c - wmlib/plat_bsd386.c - wmlib/plat_freebsd.c - wmlib/plat_hpux.c - wmlib/plat_irix.c - wmlib/plat_linux.c - wmlib/plat_svr4.c - wmlib/plat_ultrix.c - wmlib/plat_news.c - wmlib/plat_openbsd.c - wmlib/plat_osf1.c - wmlib/plat_sun.c - wmlib/plat_scor5.c - wmlib/drv_sony.c - wmlib/drv_toshiba.c - ) - add_definitions(-DUSE_WMLIB=1) -endif(USE_WMLIB) - -add_library(kcompactdisc SHARED ${kcompactdisc_LIB_SRCS}) - -target_link_libraries(kcompactdisc - ${KDE4_KDECORE_LIBS} - ${KDE4_PHONON_LIBS} - ${KDE4_SOLID_LIBS} -) - -if(HAVE_LIBASOUND2) - target_link_libraries(kcompactdisc ${ASOUND_LIBRARY}) -endif(HAVE_LIBASOUND2) -if (USE_WMLIB) - target_link_libraries(kcompactdisc ${CMAKE_THREAD_LIBS_INIT}) -endif(USE_WMLIB) - -set_target_properties(kcompactdisc PROPERTIES - VERSION ${GENERIC_LIB_VERSION} - SOVERSION ${GENERIC_LIB_SOVERSION} -) - -########### install files ############### - -install( - FILES kcompactdisc.h - DESTINATION ${INCLUDE_INSTALL_DIR}/libkcompactdisc - COMPONENT Devel -) - -install( - TARGETS kcompactdisc - EXPORT kdelibsLibraryTargets - ${INSTALL_TARGETS_DEFAULT_ARGS} -) diff --git a/kcompactdisc/Mainpage.dox b/kcompactdisc/Mainpage.dox deleted file mode 100644 index 5620e6d9..00000000 --- a/kcompactdisc/Mainpage.dox +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @mainpage KCompactDisk - * - **/ -// DOXYGEN_EXCLUDE = wmlib diff --git a/kcompactdisc/Messages.sh b/kcompactdisc/Messages.sh deleted file mode 100755 index 4fa949c2..00000000 --- a/kcompactdisc/Messages.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/sh -$XGETTEXT *.cpp -o $podir/libkcompactdisc.pot diff --git a/kcompactdisc/kcompactdisc.cpp b/kcompactdisc/kcompactdisc.cpp deleted file mode 100644 index 23779c33..00000000 --- a/kcompactdisc/kcompactdisc.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/* - * KCompactDisc - A CD drive interface for the KDE Project. - * - * Copyright (C) 2005 Shaheedur R. Haque - * Copyright (C) 2007 Alexander Kern - * - * 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, 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 "kcompactdisc.h" -#include "kcompactdisc_p.h" - -#include - -#include -#include -#include - -#include -#include -#include - -static QMap cdromsNameToDeviceUrl; -static QMap cdromsNameToUdi; -static QString ___null = QString(); - -static void refreshListOfCdromDevices() -{ - cdromsNameToDeviceUrl.clear(); - cdromsNameToUdi.clear(); - QString name, type; - KUrl url; - - //get a list of all devices that are Cdrom - foreach(const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::OpticalDrive)) { - kDebug() << device.udi().toLatin1().constData(); - const Solid::Block *b = device.as(); - - if(!b) { - continue; - } - - const Solid::OpticalDrive *o = device.as(); - Solid::OpticalDrive::MediumTypes mediumType = o->supportedMedia(); - - url = KUrl::fromPath(QLatin1String( b->device().toLatin1() )); - //TODO translate them ? - if(mediumType < Solid::OpticalDrive::Cdrw) { - type = QLatin1String( "CD-ROM" ); - } else if(mediumType < Solid::OpticalDrive::Dvd) { - type = QLatin1String( "CDRW" ); - } else if(mediumType < Solid::OpticalDrive::Dvdr) { - type = QLatin1String( "DVD-ROM" ); - } else if(mediumType < Solid::OpticalDrive::Bd) { - type = QLatin1String( "DVDRW" ); - } else if(mediumType < Solid::OpticalDrive::HdDvd) { - type = QLatin1String( "Blu-ray" ); - } else { - type = QLatin1String( "High Density DVD" ); - } - - if(!device.vendor().isEmpty()) - name = (QLatin1Char('[') + type + QLatin1String( " - " ) + device.vendor() + QLatin1String( " - " ) + device.product() + QLatin1Char( ']' )); - else - name = (QLatin1Char('[') + type + QLatin1String( " - unknown vendor - " ) + device.product() + QLatin1Char( ']' )); - - cdromsNameToDeviceUrl.insert(name, url); - cdromsNameToUdi.insert(name, device.udi()); - } -#if 0 - if(cdromsNameToDeviceUrl.empty()) { - cdromsNameToDeviceUrl.insert(QString("Generic CDROM []"), KUrl::fromPath(wm_drive_default_device())); - } -#endif -} - -static QMap &getListOfCdromDevicesNamesAndUrl() -{ - if(cdromsNameToDeviceUrl.empty()) - refreshListOfCdromDevices(); - - return cdromsNameToDeviceUrl; -} - -static QMap &getListOfCdromDevicesNamesAndUdi() -{ - if(cdromsNameToUdi.empty()) - refreshListOfCdromDevices(); - - return cdromsNameToUdi; -} - -QString KCompactDisc::urlToDevice(const KUrl& deviceUrl) -{ - if(deviceUrl.protocol() == QLatin1String( "media" ) || deviceUrl.protocol() == QLatin1String( "system" )) { - kDebug() << "Asking mediamanager for " << deviceUrl.fileName(); - - QDBusInterface mediamanager( QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/mediamanager" ), QLatin1String( "org.kde.MediaManager" ) ); - QDBusReply reply = mediamanager.call(QLatin1String( "properties" ), deviceUrl.fileName()); - - QStringList properties = reply; - if(!reply.isValid() || properties.count() < 6) { - kError() << "Invalid reply from mediamanager" << endl; - return deviceUrl.path(); - } else { - kDebug() << "Reply from mediamanager " << properties[5]; - return properties[5]; - } - } else if(deviceUrl.protocol() == QLatin1String( "file" )) { - return deviceUrl.path(); - } else { - return QString(); - } -} - -const QStringList KCompactDisc::audioSystems() -{ - QStringList list; - - list << QLatin1String( "phonon" ) -#if defined(HAVE_LIBASOUND2) - << QLatin1String( "alsa" ) -#endif -#if defined(sun) || defined(__sun__) - << QLatin1String( "sun" ) -#endif - ; - return list; -} - -const QStringList KCompactDisc::cdromDeviceNames() -{ - return getListOfCdromDevicesNamesAndUrl().keys(); -} - -const QString KCompactDisc::defaultCdromDeviceName() -{ - const QStringList names = getListOfCdromDevicesNamesAndUrl().keys(); - if (!names.isEmpty()) return names[0]; - else return QString(); -} - -const KUrl KCompactDisc::defaultCdromDeviceUrl() -{ - const QList urls = getListOfCdromDevicesNamesAndUrl().values(); - if (!urls.isEmpty()) return urls[0]; - else return KUrl(); -} - -const KUrl KCompactDisc::cdromDeviceUrl(const QString &cdromDeviceName) -{ - const QMap &nameUrls = getListOfCdromDevicesNamesAndUrl(); - KUrl result = nameUrls.value(cdromDeviceName); - if (!result.isValid()) - { - const KUrl passedUrl(cdromDeviceName); - foreach(const KUrl &url, nameUrls) - { - if (url == passedUrl) - { - return passedUrl; - } - } - result = KCompactDisc::defaultCdromDeviceUrl(); - } - return result; -} - -const QString KCompactDisc::defaultCdromDeviceUdi() -{ - const QStringList udis = getListOfCdromDevicesNamesAndUdi().values(); - if (!udis.isEmpty()) return udis[0]; - else return QString(); -} - -const QString KCompactDisc::cdromDeviceUdi(const QString &cdromDeviceName) -{ - return getListOfCdromDevicesNamesAndUdi().value(cdromDeviceName, KCompactDisc::defaultCdromDeviceUdi()); -} - -KCompactDisc::KCompactDisc(InformationMode infoMode) : - d_ptr(new KCompactDiscPrivate(this, KCompactDisc::defaultCdromDeviceName())) -{ - Q_D(KCompactDisc); - d->m_infoMode = infoMode; -} - -KCompactDisc::~KCompactDisc() -{ - stop(); - delete d_ptr; -} - -const QString &KCompactDisc::deviceVendor() -{ - Q_D(KCompactDisc); - return d->m_deviceVendor; -} - -const QString &KCompactDisc::deviceModel() -{ - Q_D(KCompactDisc); - return d->m_deviceModel; -} - -const QString &KCompactDisc::deviceRevision() -{ - Q_D(KCompactDisc); - return d->m_deviceRevision; -} - -const QString &KCompactDisc::deviceName() -{ - Q_D(KCompactDisc); - return d->m_deviceName; -} - -const KUrl KCompactDisc::deviceUrl() -{ - Q_D(KCompactDisc); - return KCompactDisc::cdromDeviceUrl(d->m_deviceName); -} - -unsigned KCompactDisc::discId() -{ - Q_D(KCompactDisc); - return d->m_discId; -} - -const QList &KCompactDisc::discSignature() -{ - Q_D(KCompactDisc); - return d->m_trackStartFrames; -} - -const QString &KCompactDisc::discArtist() -{ - Q_D(KCompactDisc); - if (!d->m_tracks) - return ___null; - return d->m_trackArtists[0]; -} - -const QString &KCompactDisc::discTitle() -{ - Q_D(KCompactDisc); - if (!d->m_tracks) - return ___null; - return d->m_trackTitles[0]; -} - -unsigned KCompactDisc::discLength() -{ - Q_D(KCompactDisc); - if (!d->m_tracks) - return 0; - return d->m_discLength; -} - -unsigned KCompactDisc::discPosition() -{ - Q_D(KCompactDisc); - return d->m_discPosition; -} - -KCompactDisc::DiscStatus KCompactDisc::discStatus() -{ - Q_D(KCompactDisc); - return d->m_status; -} - -QString KCompactDisc::discStatusString(KCompactDisc::DiscStatus status) -{ - return KCompactDiscPrivate::discStatusI18n(status); -} - -QString KCompactDisc::trackArtist() -{ - Q_D(KCompactDisc); - return trackArtist(d->m_track); -} - -QString KCompactDisc::trackArtist(unsigned track) -{ - Q_D(KCompactDisc); - if (!track) - return QString(); - return d->m_trackArtists[track]; -} - -QString KCompactDisc::trackTitle() -{ - Q_D(KCompactDisc); - return trackTitle(d->m_track); -} - -QString KCompactDisc::trackTitle(unsigned track) -{ - Q_D(KCompactDisc); - if (!track) - return QString(); - return d->m_trackTitles[track]; -} - -unsigned KCompactDisc::trackLength() -{ - Q_D(KCompactDisc); - return trackLength(d->m_track); -} - -unsigned KCompactDisc::trackLength(unsigned track) -{ - Q_D(KCompactDisc); - if (!track) - return 0; - return d->trackLength(track); -} - -unsigned KCompactDisc::track() -{ - Q_D(KCompactDisc); - return d->m_track; -} - -unsigned KCompactDisc::trackPosition() -{ - Q_D(KCompactDisc); - return d->m_trackPosition; -} - -unsigned KCompactDisc::tracks() -{ - Q_D(KCompactDisc); - return d->m_tracks; -} - -bool KCompactDisc::isPlaying() -{ - Q_D(KCompactDisc); - return (d->m_status == KCompactDisc::Playing); -} - -bool KCompactDisc::isPaused() -{ - Q_D(KCompactDisc); - return (d->m_status == KCompactDisc::Paused); -} - -bool KCompactDisc::isNoDisc() -{ - Q_D(KCompactDisc); - return (d->m_status == KCompactDisc::NoDisc); -} - -bool KCompactDisc::isAudio(unsigned track) -{ - Q_D(KCompactDisc); - if (!track) - return 0; - return d->isTrackAudio(track); -} - -void KCompactDisc::playTrack(unsigned track) -{ - Q_D(KCompactDisc); - - d->m_statusExpected = KCompactDisc::Playing; - d->m_trackExpectedPosition = 0; - d->m_seek = abs( (double) d->m_trackExpectedPosition - trackPosition()); - - d->playTrackPosition(track, 0); -} - -void KCompactDisc::playPosition(unsigned position) -{ - Q_D(KCompactDisc); - - d->m_statusExpected = Playing; - d->m_trackExpectedPosition = position; - d->m_seek = abs( (double) d->m_trackExpectedPosition - trackPosition()); - - d->playTrackPosition(d->m_track, position); -} - -void KCompactDisc::play() -{ - doCommand(KCompactDisc::Play); -} - -void KCompactDisc::next() -{ - doCommand(KCompactDisc::Next); -} - -void KCompactDisc::prev() -{ - doCommand(KCompactDisc::Prev); -} - -void KCompactDisc::pause() -{ - doCommand(KCompactDisc::Pause); -} - -void KCompactDisc::stop() -{ - doCommand(KCompactDisc::Stop); -} - -void KCompactDisc::eject() -{ - doCommand(KCompactDisc::Eject); -} - -void KCompactDisc::loop() -{ - doCommand(KCompactDisc::Loop); -} - -void KCompactDisc::random() -{ - doCommand(KCompactDisc::Random); -} - -void KCompactDisc::doCommand(KCompactDisc::DiscCommand cmd) -{ - Q_D(KCompactDisc); - unsigned track; - - switch(cmd) { - case Play: - if(d->m_status == KCompactDisc::Playing) - return; - next(); - break; - - case Next: - track = d->getNextTrackInPlaylist(); - if(track) - playTrack(track); - break; - - case Prev: - track = d->getPrevTrackInPlaylist(); - if(track) - playTrack(track); - break; - - case Pause: - if(d->m_status == KCompactDisc::Paused) - d->m_statusExpected = KCompactDisc::Playing; - else - d->m_statusExpected = KCompactDisc::Paused; - - d->pause(); - break; - - case Stop: - d->m_statusExpected = KCompactDisc::Stopped; - d->stop(); - break; - - case Eject: - if(d->m_status != KCompactDisc::Ejected) { - if(d->m_status != KCompactDisc::Stopped) { - d->m_statusExpected = KCompactDisc::Ejected; - d->stop(); - } else { - d->eject(); - } - } else { - d->m_statusExpected = KCompactDisc::Stopped; - d->closetray(); - } - break; - - case Loop: - setLoopPlaylist(!d->m_loopPlaylist); - break; - - case Random: - setRandomPlaylist(!d->m_randomPlaylist); - break; - } -} - -void KCompactDisc::metadataLookup() -{ - Q_D(KCompactDisc); - d->queryMetadata(); -} - -void KCompactDisc::setRandomPlaylist(bool random) -{ - Q_D(KCompactDisc); - d->m_randomPlaylist = random; - d->make_playlist(); - emit randomPlaylistChanged(d->m_randomPlaylist); -} - -void KCompactDisc::setLoopPlaylist(bool loop) -{ - Q_D(KCompactDisc); - d->m_loopPlaylist = loop; - emit loopPlaylistChanged(d->m_loopPlaylist); -} - -void KCompactDisc::setAutoMetadataLookup(bool autoMetadata) -{ - Q_D(KCompactDisc); - d->m_autoMetadata = autoMetadata; - if(d->m_autoMetadata) - metadataLookup(); -} - -bool KCompactDisc::setDevice(const QString &deviceName, unsigned volume, - bool digitalPlayback, const QString &audioSystem, const QString &audioDevice) -{ - const QString as = digitalPlayback ? audioSystem : QLatin1String("cdin"); - const QString ad = digitalPlayback ? audioDevice : QString(); - kDebug() << "Device init: " << deviceName << ", " << as << ", " << ad; - - if(d_ptr->moveInterface(deviceName, as, ad)) { - setVolume(volume); - return 1; - } else { - // Severe (OS-level) error. - return 0; - } -} - -void KCompactDisc::setVolume(unsigned volume) -{ - Q_D(KCompactDisc); - kDebug() << "change volume: " << volume; - d->setVolume(volume); -} - -void KCompactDisc::setBalance(unsigned balance) -{ - Q_D(KCompactDisc); - kDebug() << "change balance: " << balance; - d->setBalance(balance); -} - -#include "moc_kcompactdisc.cpp" diff --git a/kcompactdisc/kcompactdisc.h b/kcompactdisc/kcompactdisc.h deleted file mode 100644 index 0edd0116..00000000 --- a/kcompactdisc/kcompactdisc.h +++ /dev/null @@ -1,552 +0,0 @@ -/* - * KCompactDisc - A CD drive interface for the KDE Project. - * - * Copyright (C) 2005 Shaheedur R. Haque - * Copyright (C) 2007 Alexander Kern - * - * 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, 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 KCOMPACTDISC_H -#define KCOMPACTDISC_H - -#include -#include -#include - -#include -#include - -#if defined Q_OS_WIN - -#ifndef KCOMPACTDISC_EXPORT -# ifdef MAKE_KCOMPACTDISC_LIB -# define KCOMPACTDISC_EXPORT KDE_EXPORT -# else -# define KCOMPACTDISC_EXPORT KDE_IMPORT -# endif -#endif - -#else /* UNIX */ - -/* export statements for unix */ -#define KCOMPACTDISC_EXPORT KDE_EXPORT -#endif - -class KCompactDiscPrivate; - -/** - * KCompactDisc - A CD drive interface for the KDE Project. - * - * The disc interface is modelled by these slots: - * - * @see #playoutTrack(unsigned track): Play specified track. - * @see #playoutPosition(unsigned position): seek to specified position. - * @see #playNext(): Play next track in the playlist. - * @see #playPrev(): Play previous track in the playlist. - * @see #pauseResumePlayout(): Toggle between pause/resume. - * @see #stopPlayout(): Stop playout: - * @see #eject(): Stop playout and eject disc or Close - * tray and try to read TOC from disc. - * - * The progress of playout is modelled by these signals: - * - * @see #playoutPositionChanged(unsigned position): A position in a track. - * @see #playoutTrackChanged(unsigned track): A playout of this track is started. - * - * - * The shape of playlist is controlled by these accessors. - * - * @see #setRandomPlaylist(bool): Shuffle the playlist. - * @see #setLoopPlaylist(bool): Couple begin and end of playlist. - * - * - * The disc lifecycle is modelled by these signals: - * - * @see #discChanged(...): A new disc was inserted. - * @see #discStatusChanged(KCompactDisc::Playing): A disc started playout. - * @see #discStatusChanged(KCompactDisc::Paused): A disc was paused. - * @see #discStatusChanged(KCompactDisc::Stopped): The disc stopped. - * @see #discStatusChanged(KCompactDisc::NoDisc): The disc is removed. No disc in tray or data disc. - * @see #discStatusChanged(KCompactDisc::NotReady): The disc is present. But playout is not possible. - * @see #discInformation(QStringList info): A content for disc information is arrived. - * - * - * The volume control is modelled by these slots: - * - * @see #setVolume(unsigned): A new volume value. - * @see #setBalance(unsigned): A new balance value. - * - * - * And these signals: - * - * @see #volumeChanged(unsigned): A current volume value. - * @see #balanceChanged(unsigned): A current balance value. - * - * - * All times in this interface are in seconds. Valid track numbers are - * positive numbers; zero is not a valid track number. - */ -class KCOMPACTDISC_EXPORT KCompactDisc : public QObject -{ - Q_OBJECT -/* - Q_CLASSINFO("D-Bus Interface", "org.kde.KSCD") - -public Q_SLOTS: - Q_SCRIPTABLE bool playing(); - Q_SCRIPTABLE void play() { play(); } - Q_SCRIPTABLE void stop() { stop(); } - Q_SCRIPTABLE void previous() { prev(); } - Q_SCRIPTABLE void next() { next(); } - Q_SCRIPTABLE void jumpTo(int seconds) { jumpToTime(seconds); } - Q_SCRIPTABLE void eject() { eject(); } - Q_SCRIPTABLE void toggleLoop() { loop(); } - Q_SCRIPTABLE void toggleShuffle() { random(); } - Q_SCRIPTABLE void toggleTimeDisplay() { cycleplaytimemode(); } - Q_SCRIPTABLE void cddbDialog() { CDDialogSelected(); } - Q_SCRIPTABLE void optionDialog() { showConfig(); } - Q_SCRIPTABLE void setTrack(int t) { trackSelected(t > 0 ? t - 1 : 0); } - Q_SCRIPTABLE void volumeDown() { decVolume(); } - Q_SCRIPTABLE void volumeUp() { incVolume(); } - Q_SCRIPTABLE void setVolume(int v); - Q_SCRIPTABLE void setDevice(const QString& dev); - Q_SCRIPTABLE int getVolume() { return Prefs::volume(); } - Q_SCRIPTABLE int currentTrack(); - Q_SCRIPTABLE int currentTrackLength(); - Q_SCRIPTABLE int currentPosition(); - Q_SCRIPTABLE int getStatus(); - Q_SCRIPTABLE QString currentTrackTitle(); - Q_SCRIPTABLE QString currentAlbum(); - Q_SCRIPTABLE QString currentArtist(); - Q_SCRIPTABLE QStringList trackList(); -*/ -public: - enum InformationMode - { - Synchronous, // Return and emit signal when cdrom and cddb information arrives. - Asynchronous // Block until cdrom and cddb infromation has been obtained - }; - - enum DiscCommand - { - Play, - Pause, - Next, - Prev, - Stop, - Eject, - Loop, - Random - }; - - enum DiscStatus - { - Playing, - Paused, - Stopped, - Ejected, - NoDisc, - NotReady, - Error - }; - - enum DiscInfo - { - Cdtext, - Cddb, - PhononMetadata - }; - - KCompactDisc(InformationMode = KCompactDisc::Synchronous); - virtual ~KCompactDisc(); - - /** - * @param device Name of CD device, e.g. /dev/cdrom. - * @param digitalPlayback Select digital or analog playback. - * @param audioSystem For digital playback, system to use, e.g. "phonon". - * @param audioDevice For digital playback, device to use. - * @return true if the device seemed usable. - */ - bool setDevice( - const QString &device, - unsigned volume = 50, - bool digitalPlayback = true, - const QString &audioSystem = QString(), - const QString &audioDevice = QString()); - - /** - * If the url is a media:/ or system:/ URL returns - * the device it represents, otherwise returns device - */ - static QString urlToDevice(const KUrl& url); - - /** - * All installed audio backends. - */ - static const QStringList audioSystems(); - - /** - * All present CDROM devices. - */ - static const QStringList cdromDeviceNames(); - - /** - * The default CDROM device for this system. - */ - static const QString defaultCdromDeviceName(); - - /** - * The Url of default CDROM device for this system. - */ - static const KUrl defaultCdromDeviceUrl(); - - /** - * The Url of named CDROM device for this system. - */ - static const KUrl cdromDeviceUrl(const QString &); - - /** - * The Udi of default CDROM device for this system. - */ - static const QString defaultCdromDeviceUdi(); - - /** - * The Udi of named CDROM device for this system. - */ - static const QString cdromDeviceUdi(const QString &); - - /** - * SCSI parameter VENDOR of current CDROM device. - * - * @return Null string if no usable device set. - */ - const QString &deviceVendor(); - - /** - * SCSI parameter MODEL of current CDROM device. - * - * @return Null string if no usable device set. - */ - const QString &deviceModel(); - - /** - * SCSI parameter REVISION of current CDROM device. - * - * @return Null string if no usable device set. - */ - const QString &deviceRevision(); - - /** - * Current CDROM device. - * - * @return Null string if no usable device set. - */ - const QString &deviceName(); - - /** - * Current device as Kurl. - */ - const KUrl deviceUrl(); - - /** - * Current disc, 0 if no disc or impossible to calculate id. - */ - unsigned discId(); - - /** - * CDDB signature of disc, empty if no disc or not possible to deliever. - */ - const QList &discSignature(); - - /** - * Artist for whole disc. - * - * @return Disc artist or null string. - */ - const QString &discArtist(); - - /** - * Title of disc. - * - * @return Disc title or null string. - */ - const QString &discTitle(); - - /** - * Known length of disc. - * - * @return Disc length in seconds. - */ - unsigned discLength(); - - /** - * Current position on the disc. - * - * @return Position in seconds. - */ - unsigned discPosition(); - - /** - * Current status. - * - * @return Current status. - */ - KCompactDisc::DiscStatus discStatus(); - - /** - * Status as string. - * - * @return Status as QString. - */ - QString discStatusString(KCompactDisc::DiscStatus status); - - /** - * Artist of current track. - * - * @return Track artist or null string. - */ - QString trackArtist(); - - /** - * Artist of given track. - * - * @return Track artist or null string. - */ - QString trackArtist(unsigned track); - - /** - * Title of current track. - * - * @return Track title or null string. - */ - QString trackTitle(); - - /** - * Title of given track. - * - * @return Track title or null string. - */ - QString trackTitle(unsigned track); - - /** - * Length of current track. - * - * @return Track length in seconds. - */ - unsigned trackLength(); - - /** - * Length of given track. - * - * @param track Track number. - * @return Track length in seconds. - */ - unsigned trackLength(unsigned track); - - /** - * Current track. - * - * @return Track number. - */ - unsigned track(); - - /** - * Current track position. - * - * @return Track position in seconds. - */ - unsigned trackPosition(); - - /** - * Number of tracks. - */ - unsigned tracks(); - - /** - * Is status playing. - */ - bool isPlaying(); - - /** - * Is status pausing. - */ - bool isPaused(); - - /** - * Is status no disc. - */ - bool isNoDisc(); - - /** - * @return if the track is actually an audio track. - */ - bool isAudio(unsigned track); - - -public Q_SLOTS: - - /** - * Start playout of track. - */ - void playTrack(unsigned int track); - - /** - * Start playout or seek to given position of track. - */ - void playPosition(unsigned int position); - - /* GUI bindings */ - /** - * Start playout. - */ - void play(); - - /** - * Start playout of next track. - */ - void next(); - - /** - * Start playout of previous track. - */ - void prev(); - - /** - * Pause/resume playout. - */ - void pause(); - - /** - * Stop playout. - */ - void stop(); - - /** - * Open/close tray. - */ - void eject(); - - /** - * Switch endless playout on/off. - */ - void loop(); - - /** - * Switch random playout on/off. - */ - void random(); - - /** - * Pipe GUI command. - */ - void doCommand(KCompactDisc::DiscCommand); - - - void metadataLookup(); - - -Q_SIGNALS: - /** - * A new position in a track. This signal is delivered at - * approximately 1 second intervals while a track is playing. At first sight, - * this might seem overzealous, but it is likely that any CD player UI will use - * this to track the second-by-second position, so we may as well do it for - * them. - * - * @param position Position within track in seconds. - */ - void playoutPositionChanged(unsigned int position); - - /** - * A new track is started. - * - * @param track Track number. - */ - void playoutTrackChanged(unsigned int track); - - -public Q_SLOTS: - - void setRandomPlaylist(bool); - void setLoopPlaylist(bool); - void setAutoMetadataLookup(bool); - - -Q_SIGNALS: - - void randomPlaylistChanged(bool); - void loopPlaylistChanged(bool); - - -Q_SIGNALS: - - /** - * A new Disc is inserted - * - */ - void discChanged(unsigned int tracks); - - /** - * A new Disc information is arrived - * - */ - void discInformation(KCompactDisc::DiscInfo info); - - /** - * A Disc status changed - * - */ - void discStatusChanged(KCompactDisc::DiscStatus status); - - -public Q_SLOTS: - - /** - * Set volume - */ - void setVolume(unsigned int volume); - - /** - * Set balance - */ - void setBalance(unsigned int balance); - -Q_SIGNALS: - - /** - * New volume - */ - void volumeChanged(unsigned int volume); - - /** - * New balance - */ - void balanceChanged(unsigned int balance); - - -protected: - KCompactDiscPrivate * d_ptr; - KCompactDisc(KCompactDiscPrivate &dd, QObject *parent); - -private: - Q_DECLARE_PRIVATE(KCompactDisc) -#ifdef USE_WMLIB - friend class KWMLibCompactDiscPrivate; -#endif - friend class KPhononCompactDiscPrivate; -}; - -#endif diff --git a/kcompactdisc/kcompactdisc_p.cpp b/kcompactdisc/kcompactdisc_p.cpp deleted file mode 100644 index a1cbf1e6..00000000 --- a/kcompactdisc/kcompactdisc_p.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/* - * KCompactDisc - A CD drive interface for the KDE Project. - * - * Copyright (C) 2007 Alexander Kern - * - * 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, 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 "kcompactdisc_p.h" - -#include "wmlib_interface.h" -#include "phonon_interface.h" - -#include -#include - -KCompactDiscPrivate::KCompactDiscPrivate(KCompactDisc *p, const QString& dev) : - m_infoMode(KCompactDisc::Synchronous), - m_deviceName(dev), - - m_status(KCompactDisc::NoDisc), - m_statusExpected(KCompactDisc::NoDisc), - m_discId(0), - m_discLength(0), - m_track(0), - m_tracks(0), - m_trackPosition(0), - m_discPosition(0), - m_trackExpectedPosition(0), - m_seek(0), - - m_randSequence(0), - m_loopPlaylist(false), - m_randomPlaylist(false), - m_autoMetadata(true), - - m_deviceVendor(QString()), - m_deviceModel(QString()), - m_deviceRevision(QString()), - - q_ptr(p) -{ - m_interface = QLatin1String("dummy"); - m_trackStartFrames.clear(); - m_trackArtists.clear(); - m_trackTitles.clear(); - m_playlist.clear(); -} - -bool KCompactDiscPrivate::moveInterface(const QString &deviceName, - const QString &audioSystem, const QString &audioDevice) -{ - Q_Q(KCompactDisc); - - KCompactDiscPrivate *pOld, *pNew; - - kDebug() << "switch from " << q->d_ptr->m_interface << " on " << q->d_ptr->m_deviceName; - kDebug() << " to " << audioSystem << " on " << deviceName; - - /* switch temporary to dummy implementation */ - if(q->d_ptr != this) { - pOld = q->d_ptr; - q->d_ptr = this; - delete pOld; - } - -#ifdef USE_WMLIB - if(audioSystem == QLatin1String("phonon")) -#endif - pNew = new KPhononCompactDiscPrivate(q, deviceName); -#ifdef USE_WMLIB - else - pNew = new KWMLibCompactDiscPrivate(q, deviceName, - audioSystem, audioDevice); -#endif - - pNew->m_infoMode = m_infoMode; - - if(pNew->createInterface()) { - q->d_ptr = pNew; - return true; - } else { - delete pNew; - return false; - } -} - -bool KCompactDiscPrivate::createInterface() -{ - return true; -} - -void KCompactDiscPrivate::make_playlist() -{ - /* koz: 15/01/00. I want a random list that does not repeat tracks. Ie, */ - /* a list is created in which each track is listed only once. The tracks */ - /* are picked off one by one until the end of the list */ - - unsigned selected = 0, size = m_tracks; - bool rejected = false; - - kDebug(67000) << "Playlist has " << size << " entries\n"; - m_playlist.clear(); - for(unsigned i = 0; i < size; i++) { - if(m_randomPlaylist) { - do { - selected = 1 + m_randSequence.getLong(size); - rejected = (m_playlist.indexOf(selected) != -1); - } while(rejected == true); - } else { - selected = 1 + i; - } - m_playlist.append(selected); - } - - kDebug(67000) << "dump playlist"; - QList::const_iterator it; - for(it = m_playlist.constBegin(); it != m_playlist.constEnd(); it++) { - kDebug(67000) << " " << *it; - } - kDebug(67000) << "dump playlist end"; -} - -unsigned KCompactDiscPrivate::getNextTrackInPlaylist() -{ - int current_index, min_index, max_index; - - if(m_playlist.empty()) - return 0; - - min_index = 0; - max_index = m_playlist.size() - 1; - - current_index = m_playlist.indexOf(m_track); - if(current_index < 0) - current_index = min_index; - else if(current_index >= max_index) { - if(m_loopPlaylist) { - //wrap around - if(m_randomPlaylist) - make_playlist(); - current_index = min_index; - } else { - return 0; - } - } else { - ++current_index; - } - - return m_playlist[current_index]; -} - -unsigned KCompactDiscPrivate::getPrevTrackInPlaylist() -{ - int current_index, min_index, max_index; - - if(m_playlist.empty()) - return 0; - - min_index = 0; - max_index = m_playlist.size() - 1; - - current_index = m_playlist.indexOf(m_track); - if(current_index < 0) - current_index = min_index; - else if(current_index <= min_index) { - if(m_loopPlaylist) { - //wrap around - if(m_randomPlaylist) - make_playlist(); - - current_index = max_index; - } else { - return 0; - } - } else { - --current_index; - } - - return m_playlist[current_index]; -} - -bool KCompactDiscPrivate::skipStatusChange(KCompactDisc::DiscStatus status) -{ - Q_Q(KCompactDisc); - - if(m_status != status) { - if(status == KCompactDisc::Stopped) { - if(m_statusExpected == KCompactDisc::Ejected) { - eject(); - } else if(m_statusExpected != KCompactDisc::Stopped) { - unsigned track = getNextTrackInPlaylist(); - if(track) { - playTrackPosition(track, 0); - return true; - } - } - } - - emit q->discStatusChanged(status); - } - - return false; -} - -const QString KCompactDiscPrivate::discStatusI18n(KCompactDisc::DiscStatus status) -{ - switch (status) { - case KCompactDisc::Playing: - return i18n("Playing"); - case KCompactDisc::Paused: - return i18n("Paused"); - case KCompactDisc::Stopped: - return i18n("Stopped"); - case KCompactDisc::Ejected: - return i18n("Ejected"); - case KCompactDisc::NoDisc: - return i18n("No Disc"); - case KCompactDisc::NotReady: - return i18n("Not Ready"); - case KCompactDisc::Error: - default: - return i18n("Error"); - } -} - -void KCompactDiscPrivate::clearDiscInfo() -{ - Q_Q(KCompactDisc); - - m_discId = 0; - m_discLength = 0; - m_seek = 0; - m_track = 0; - m_tracks = 0; - m_trackArtists.clear(); - m_trackTitles.clear(); - m_trackStartFrames.clear(); - emit q->discChanged(m_tracks); -} - -unsigned KCompactDiscPrivate::trackLength(unsigned) -{ - return 0; -} - -bool KCompactDiscPrivate::isTrackAudio(unsigned) -{ - return false; -} - -void KCompactDiscPrivate::playTrackPosition(unsigned, unsigned) -{ -} - -void KCompactDiscPrivate::pause() -{ -} - -void KCompactDiscPrivate::stop() -{ -} - -void KCompactDiscPrivate::eject() -{ -} - -void KCompactDiscPrivate::closetray() -{ -} - -void KCompactDiscPrivate::setVolume(unsigned) -{ -} - -void KCompactDiscPrivate::setBalance(unsigned) -{ -} - -unsigned KCompactDiscPrivate::volume() -{ - return 0; -} - -unsigned KCompactDiscPrivate::balance() -{ - return 50; -} - -void KCompactDiscPrivate::queryMetadata() -{ -} - -#include "moc_kcompactdisc_p.cpp" diff --git a/kcompactdisc/kcompactdisc_p.h b/kcompactdisc/kcompactdisc_p.h deleted file mode 100644 index 7355cb5f..00000000 --- a/kcompactdisc/kcompactdisc_p.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * KCompactDisc - A CD drive interface for the KDE Project. - * - * Copyright (C) 2007 Alexander Kern - * - * 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, 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 KCOMPACTDISC_P_H -#define KCOMPACTDISC_P_H - -#include -#include - -#include -#include -#include "kcompactdisc.h" - -class KCompactDiscPrivate : public QObject -{ - Q_OBJECT - - public: - KCompactDiscPrivate(KCompactDisc *, const QString&); - virtual ~KCompactDiscPrivate() { }; - - bool moveInterface(const QString &, const QString &, const QString &); - virtual bool createInterface(); - - QString m_interface; - KCompactDisc::InformationMode m_infoMode; - QString m_deviceName; - - KCompactDisc::DiscStatus m_status; - KCompactDisc::DiscStatus m_statusExpected; - unsigned m_discId; - unsigned m_discLength; - unsigned m_track; - unsigned m_tracks; - unsigned m_trackPosition; - unsigned m_discPosition; - unsigned m_trackExpectedPosition; - int m_seek; - - QList m_trackStartFrames; - QStringList m_trackArtists; - QStringList m_trackTitles; - - KRandomSequence m_randSequence; - QList m_playlist; - bool m_loopPlaylist; - bool m_randomPlaylist; - bool m_autoMetadata; - - void make_playlist(); - unsigned getNextTrackInPlaylist(); - unsigned getPrevTrackInPlaylist(); - bool skipStatusChange(KCompactDisc::DiscStatus); - static const QString discStatusI18n(KCompactDisc::DiscStatus); - - void clearDiscInfo(); - - virtual unsigned trackLength(unsigned); - virtual bool isTrackAudio(unsigned); - virtual void playTrackPosition(unsigned, unsigned); - virtual void pause(); - virtual void stop(); - virtual void eject(); - virtual void closetray(); - - virtual void setVolume(unsigned); - virtual void setBalance(unsigned); - virtual unsigned volume(); - virtual unsigned balance(); - - virtual void queryMetadata(); - - QString m_deviceVendor; - QString m_deviceModel; - QString m_deviceRevision; - - public: - Q_DECLARE_PUBLIC(KCompactDisc) - KCompactDisc * const q_ptr; -}; - - -#define SEC2FRAMES(sec) ((sec) * 75) -#define FRAMES2SEC(frames) ((frames) / 75) -#define MS2SEC(ms) ((ms) / 1000) -#define SEC2MS(sec) ((sec) * 1000) -#define MS2FRAMES(ms) (((ms) * 75) / 1000) -#define FRAMES2MS(frames) (((frames) * 1000) / 75) - -#endif /* KCOMPACTDISC_P_H */ diff --git a/kcompactdisc/phonon_interface.cpp b/kcompactdisc/phonon_interface.cpp deleted file mode 100644 index a942a7ad..00000000 --- a/kcompactdisc/phonon_interface.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/* - * - * Copyright (C) 2004-2007 Matthias Kretz - * Copyright (C) by Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * CDDA version taken from guitest in phonon test directory - */ - -#include "phonon_interface.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -using namespace Phonon; - -class ProducerWidget : public QObject -{ - public: - ProducerWidget(KPhononCompactDiscPrivate *, const QString &); - ~ProducerWidget(); - - public: - MediaObject *m_media; - AudioOutput *m_output; - MediaController *m_mediaController; -}; - -ProducerWidget::ProducerWidget(KPhononCompactDiscPrivate *p, const QString &Udi) : - m_media(0), - m_output(0), - m_mediaController(0) -{ - m_media = new MediaObject(this); - connect(m_media, SIGNAL(metaDataChanged()), SLOT(updateMetaData())); - m_media->setTickInterval(1000); - - m_output = new AudioOutput(Phonon::MusicCategory, this); - Phonon::createPath(m_media, m_output); - - connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - p, SLOT(stateChanged(Phonon::State,Phonon::State))); - - connect(m_media, SIGNAL(tick(qint64)), p, SLOT(tick(qint64))); - - MediaSource *m_mediaSource = new MediaSource(Phonon::Cd, Udi); - m_media->setCurrentSource(*m_mediaSource); - - m_mediaController = new MediaController(m_media); -} - -ProducerWidget::~ProducerWidget() -{ - delete(m_mediaController); - delete(m_output); - delete(m_media); -} - -KPhononCompactDiscPrivate::KPhononCompactDiscPrivate(KCompactDisc *p, - const QString &dev) : - KCompactDiscPrivate(p, dev), - m_producerWidget(NULL), - m_udi(KCompactDisc::cdromDeviceUdi(dev)) -{ - m_interface = QLatin1String("phonon"); -} - -KPhononCompactDiscPrivate::~KPhononCompactDiscPrivate() -{ - delete m_producerWidget; - m_producerWidget = NULL; -} - -bool KPhononCompactDiscPrivate::createInterface() -{ - Solid::Device opticalDevice(m_udi); - Solid::OpticalDrive *opticalDrive = opticalDevice.as(); - - if(opticalDrive) { - Q_Q(KCompactDisc); - - m_deviceVendor = opticalDevice.vendor(); - m_deviceModel = opticalDevice.product(); - - emit q->discChanged(0); - - producer(); - - return true; - } - - return false; -} - -ProducerWidget *KPhononCompactDiscPrivate::producer() -{ - //try to create - if(!m_producerWidget) { - Solid::Device opticalDevice(m_udi); - Solid::OpticalDrive *opticalDrive = opticalDevice.as(); - - if(opticalDrive) { - Solid::OpticalDisc *opticalDisc = opticalDevice.as(); - kDebug() << "opticalDisc " << opticalDisc; - //if(opticalDisc && (opticalDisc->availableContent() == Solid::OpticalDisc::Audio)) { - m_producerWidget = new ProducerWidget(this, m_udi); - //} - } - } - - return m_producerWidget; -} - -unsigned KPhononCompactDiscPrivate::trackLength(unsigned track) -{ - if(!producer() || m_producerWidget->m_mediaController->currentTitle() != track) - return 0; - - return MS2SEC(m_producerWidget->m_media->totalTime()); -} - -bool KPhononCompactDiscPrivate::isTrackAudio(unsigned) -{ - return true; -} - -void KPhononCompactDiscPrivate::playTrackPosition(unsigned track, unsigned position) -{ - if(!producer()) - return; - - kDebug() << "play track " << track << " position " << position; - - m_producerWidget->m_mediaController->setCurrentTitle(track); - m_producerWidget->m_media->seek(SEC2MS(position)); - emit m_producerWidget->m_media->play(); -} - -void KPhononCompactDiscPrivate::pause() -{ - if(!producer()) - return; - - emit m_producerWidget->m_media->pause(); -} - -void KPhononCompactDiscPrivate::stop() -{ - if(!producer()) - return; - - emit m_producerWidget->m_media->stop(); -} - -void KPhononCompactDiscPrivate::eject() -{ - Solid::Device opticalDevice(m_udi); - Solid::OpticalDrive *opticalDrive = opticalDevice.as(); - Solid::OpticalDisc *opticalDisc = opticalDevice.as(); - - if(!opticalDrive || !opticalDisc) - return; - - opticalDrive->eject(); -} - -void KPhononCompactDiscPrivate::closetray() -{ - Solid::Device opticalDevice(m_udi); - Solid::OpticalDrive *opticalDrive = opticalDevice.as(); - Solid::OpticalDisc *opticalDisc = opticalDevice.as(); - - if(!opticalDrive || opticalDisc) - return; - - opticalDrive->eject(); -} - -void KPhononCompactDiscPrivate::setVolume(unsigned volume) -{ - if(!producer()) - return; - - /* 1.0 = 100% */ - m_producerWidget->m_output->setVolume(volume * 0.01); -} - -void KPhononCompactDiscPrivate::setBalance(unsigned) -{ -} - -unsigned KPhononCompactDiscPrivate::volume() -{ - if(!producer()) - return 0; - - return (unsigned)(m_producerWidget->m_output->volume() * 100.0); -} - -unsigned KPhononCompactDiscPrivate::balance() -{ - return 50; -} - -void KPhononCompactDiscPrivate::queryMetadata() -{ - Q_Q(KCompactDisc); - - if(!producer()) - return; - - QMultiMap data = m_producerWidget->m_media->metaData(); - kDebug() << "METADATA"; - //kDebug() << data; - - m_trackArtists[0] = data.take(QLatin1String( "ARTIST" )); - m_trackTitles[0] = data.take(QLatin1String( "ALBUM" )); - - m_trackArtists[m_track] = data.take(QLatin1String( "ARTIST" )); - m_trackTitles[m_track] = data.take(QLatin1String( "TITLE" )); - - emit q->discInformation(KCompactDisc::PhononMetadata); -} - -KCompactDisc::DiscStatus KPhononCompactDiscPrivate::discStatusTranslate(Phonon::State state) -{ - switch (state) { - case Phonon::PlayingState: - return KCompactDisc::Playing; - case Phonon::PausedState: - return KCompactDisc::Paused; - case Phonon::StoppedState: - return KCompactDisc::Stopped; - case Phonon::ErrorState: - return KCompactDisc::NoDisc; - case Phonon::LoadingState: - case Phonon::BufferingState: - return KCompactDisc::NotReady; - default: - return KCompactDisc::Error; - } -} - -void KPhononCompactDiscPrivate::tick(qint64 t) -{ - unsigned track; - Q_Q(KCompactDisc); - - track = m_producerWidget->m_mediaController->currentTitle(); - if(track != m_track) { - m_track = track; - m_discLength = trackLength(m_track); - emit q->playoutTrackChanged(m_track); - - /* phonon gives us Metadata only per Track */ - if(m_autoMetadata) - queryMetadata(); - } - - m_trackPosition = MS2SEC(t); - m_discPosition = m_trackPosition; - // Update the current playing position. - if(m_seek) { - kDebug() << "seek: " << m_seek << " trackPosition " << m_trackPosition; - if(abs((long)(m_trackExpectedPosition - m_trackPosition)) > m_seek) - m_seek = 0; - else - m_seek = abs((long)(m_trackExpectedPosition - m_trackPosition)); - } - - if(!m_seek) { - emit q->playoutPositionChanged(m_trackPosition); - } -} - -void KPhononCompactDiscPrivate::stateChanged(Phonon::State newstate, Phonon::State) -{ - KCompactDisc::DiscStatus status; - Q_Q(KCompactDisc); - - status = discStatusTranslate(newstate); - - if(m_status != status) { - if(skipStatusChange(status)) - return; - - m_status = status; - - switch(m_status) { - case KCompactDisc::Ejected: - case KCompactDisc::NoDisc: - clearDiscInfo(); - break; - default: - if(m_tracks == 0) { - m_tracks = m_producerWidget->m_mediaController->availableTitles(); - if(m_tracks > 0) { - kDebug() << "New disc with " << m_tracks << " tracks"; - - make_playlist(); - - m_trackArtists.append(i18n("Unknown Artist")); - m_trackTitles.append(i18n("Unknown Title")); - for(unsigned i = 1; i <= m_tracks; i++) { - m_trackArtists.append(i18n("Unknown Artist")); - m_trackTitles.append(ki18n("Track %1").subs(i, 2).toString()); - } - - emit q->discChanged(m_tracks); - - if(m_autoMetadata) - queryMetadata(); - } - } - - break; - } - } -} - -#include "moc_phonon_interface.cpp" - diff --git a/kcompactdisc/phonon_interface.h b/kcompactdisc/phonon_interface.h deleted file mode 100644 index f587a3c5..00000000 --- a/kcompactdisc/phonon_interface.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * Copyright (C) 2004-2007 Matthias Kretz - * Copyright (C) by Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * CDDA version taken from guitest in phonon test directory - */ - -#ifndef PHONON_INTERFACE_H -#define PHONON_INTERFACE_H - -#include "kcompactdisc_p.h" -#include - -class ProducerWidget; - -class KPhononCompactDiscPrivate : public KCompactDiscPrivate -{ - Q_OBJECT - - public: - KPhononCompactDiscPrivate(KCompactDisc *, const QString &); - virtual ~KPhononCompactDiscPrivate(); - - virtual bool createInterface(); - - virtual unsigned trackLength(unsigned); - virtual bool isTrackAudio(unsigned); - virtual void playTrackPosition(unsigned, unsigned); - virtual void pause(); - virtual void stop(); - virtual void eject(); - virtual void closetray(); - - virtual void setVolume(unsigned); - virtual void setBalance(unsigned); - virtual unsigned volume(); - virtual unsigned balance(); - - virtual void queryMetadata(); - - - private: - ProducerWidget *m_producerWidget; - ProducerWidget *producer(); - QString m_udi; - - KCompactDisc::DiscStatus discStatusTranslate(Phonon::State); - - public Q_SLOTS: - void tick(qint64); - void stateChanged(Phonon::State, Phonon::State); -}; - -#endif // PHONON_INTERFACE_H diff --git a/kcompactdisc/wmlib/README b/kcompactdisc/wmlib/README deleted file mode 100644 index d3ee9057..00000000 --- a/kcompactdisc/wmlib/README +++ /dev/null @@ -1,19 +0,0 @@ -$Id: README 211917 2003-03-06 21:46:03Z kernalex $ - -This directory contains the WorkMan library. - -libworkman is a multi-plaform CD-Player library for creating various -CD-Player-UIs. - -06.03.2003 Alexander Kern - I have reworked most part of libworkman, get rid of most of externals - add cdda support for linux and, I hope not breaked it for SUN ;-) - - Interface was cleaned, that means for a potentialy application developers - new rules: - 1. please include only wm_cdrom.h. It has all defines and functions, what - you need. You have any exceptions. - 2. for cdtext, include wm_cdtext.h also. - 3. for cddb, include wm_cddb.h (think, it's not so powerfull and can be replaced with - some new external library. - 4. wm_cdinfo declares some externals now, I will change it in the future. diff --git a/kcompactdisc/wmlib/audio/audio.c b/kcompactdisc/wmlib/audio/audio.c deleted file mode 100644 index 7101d234..00000000 --- a/kcompactdisc/wmlib/audio/audio.c +++ /dev/null @@ -1,54 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2006 Alexander Kern - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "audio.h" -#include "../include/wm_config.h" - -#include -#include - -struct audio_oops *setup_phonon(const char *dev, const char *ctl); -struct audio_oops *setup_arts(const char *dev, const char *ctl); -struct audio_oops *setup_alsa(const char *dev, const char *ctl); - -struct audio_oops *setup_soundsystem(const char *ss, const char *dev, const char *ctl) -{ - if(!ss) { - ERRORLOG("audio: Internal error, trying to setup a NULL soundsystem.\n"); - return NULL; - } - - if(!strcmp(ss, "phonon")) { - ERRORLOG("audio: phonon has own reader and output driver.\n"); - return NULL; - } -#ifdef USE_ARTS - if(!strcmp(ss, "arts")) - return setup_arts(dev, ctl); -#endif -#if defined(HAVE_LIBASOUND2) - if(!strcmp(ss, "alsa")) - return setup_alsa(dev, ctl); -#endif -#if defined(sun) || defined(__sun__) - if(!strcmp(ss, "sun")) - return setup_sun_audio(dev, ctl); -#endif - ERRORLOG("audio: unknown soundsystem '%s'\n", ss); - return NULL; -} diff --git a/kcompactdisc/wmlib/audio/audio.h b/kcompactdisc/wmlib/audio/audio.h deleted file mode 100644 index e821e7d9..00000000 --- a/kcompactdisc/wmlib/audio/audio.h +++ /dev/null @@ -1,47 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2006 Alexander Kern - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __AUDIO_H__ -#define __AUDIO_H__ - -#ifndef NULL -#define NULL 0 -#endif -struct wm_cdda_block; - -struct audio_oops { - int (*wmaudio_open)(void); - int (*wmaudio_close)(void); - int (*wmaudio_play)(struct wm_cdda_block*); - int (*wmaudio_pause)(void); - int (*wmaudio_stop)(void); - int (*wmaudio_state)(struct wm_cdda_block*); - int (*wmaudio_balvol)(int, int *, int *); -}; - -#ifdef __cplusplus - extern "C" { -#endif - -struct audio_oops *setup_soundsystem(const char *, const char *, const char *); - -#ifdef __cplusplus - } -#endif - -#endif /* __AUDIO_H__ */ diff --git a/kcompactdisc/wmlib/audio/audio_alsa.c b/kcompactdisc/wmlib/audio/audio_alsa.c deleted file mode 100644 index bc9f99af..00000000 --- a/kcompactdisc/wmlib/audio/audio_alsa.c +++ /dev/null @@ -1,358 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) Alexander Kern - - Adapted to support both ALSA V0.x and V1.x APIs for PCM calls - (Philip Nelson 2004-03-15) - - based on mpg123 , Anders Semb Hermansen , - Jaroslav Kysela , Ville Syrjala - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "audio.h" -#include "../include/wm_struct.h" -#include "../include/wm_config.h" - -#include - -#if defined(HAVE_LIBASOUND2) - -#ifdef HAVE_ALSA_ASOUNDLIB_H -# include -#elif defined(HAVE_SYS_ASOUNDLIB_H) -# include -#endif - -static char *device = NULL; -static snd_pcm_t *handle; - -static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */ - -#if (SND_LIB_MAJOR < 1) -int rate = 44100; /* stream rate */ -int new_rate; -int channels = 2; /* count of channels */ -int buffer_time = 2000000; /* ring buffer length in us */ -int period_time = 100000; /* period time in us */ -#else -unsigned int rate = 44100; /* stream rate */ -unsigned int new_rate; -int channels = 2; /* count of channels */ -unsigned int buffer_time = 2000000; /* ring buffer length in us */ -unsigned int period_time = 100000; /* period time in us */ -#endif - -#if (SND_LIB_MAJOR < 1) -snd_pcm_sframes_t buffer_size; -snd_pcm_sframes_t period_size; -#else -snd_pcm_uframes_t buffer_size; -snd_pcm_uframes_t period_size; -#endif - - -int alsa_open(void); -int alsa_close(void); -int alsa_stop(void); -int alsa_play(struct wm_cdda_block *blk); -int alsa_state(struct wm_cdda_block *blk); -struct audio_oops* setup_alsa(const char *dev, const char *ctl); - -static int set_hwparams(snd_pcm_hw_params_t *params, - snd_pcm_access_t accesspar) -{ - int err, dir; - - /* choose all parameters */ - err = snd_pcm_hw_params_any(handle, params); - if (err < 0) { - ERRORLOG("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err)); - return err; - } - /* set the interleaved read/write format */ - err = snd_pcm_hw_params_set_access(handle, params, accesspar); - if (err < 0) { - ERRORLOG("Access type not available for playback: %s\n", snd_strerror(err)); - return err; - } - /* set the sample format */ - err = snd_pcm_hw_params_set_format(handle, params, format); - if (err < 0) { - ERRORLOG("Sample format not available for playback: %s\n", snd_strerror(err)); - return err; - } - /* set the count of channels */ - err = snd_pcm_hw_params_set_channels(handle, params, channels); - if (err < 0) { - ERRORLOG("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err)); - return err; - } - /* set the stream rate */ -#if (SND_LIB_MAJOR < 1) - err = new_rate = snd_pcm_hw_params_set_rate_near(handle, params, rate, 0); -#else - new_rate = rate; - err = snd_pcm_hw_params_set_rate_near(handle, params, &rate, 0); -#endif - if (err < 0) { - ERRORLOG("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); - return err; - } - if (new_rate != rate) { - ERRORLOG("Rate does not match (requested %iHz, get %iHz)\n", rate, new_rate); - return -EINVAL; - } - /* set the buffer time */ -#if (SND_LIB_MAJOR < 1) - err = snd_pcm_hw_params_set_buffer_time_near(handle, params, buffer_time, &dir); -#else - err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir); -#endif - if (err < 0) { - ERRORLOG("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err)); - return err; - } -#if (SND_LIB_MAJOR < 1) - buffer_size = snd_pcm_hw_params_get_buffer_size(params); -#else - err = snd_pcm_hw_params_get_buffer_size(params, &buffer_size); - if (err < 0) { - ERRORLOG("Unable to get buffer size : %s\n", snd_strerror(err)); - return err; - } -#endif - DEBUGLOG("buffersize %lu\n", buffer_size); - - /* set the period time */ -#if (SND_LIB_MAJOR < 1) - err = snd_pcm_hw_params_set_period_time_near(handle, params, period_time, &dir); -#else - err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, &dir); -#endif - if (err < 0) { - ERRORLOG("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err)); - return err; - } - -#if (SND_LIB_MAJOR < 1) - period_size = snd_pcm_hw_params_get_period_size(params, &dir); -#else - err = snd_pcm_hw_params_get_period_size(params, &period_size, &dir); - if (err < 0) { - ERRORLOG("Unable to get hw period size: %s\n", snd_strerror(err)); - } -#endif - - DEBUGLOG("period_size %lu\n", period_size); - - /* write the parameters to device */ - err = snd_pcm_hw_params(handle, params); - if (err < 0) { - ERRORLOG("Unable to set hw params for playback: %s\n", snd_strerror(err)); - return err; - } - return 0; -} - -static int set_swparams(snd_pcm_sw_params_t *swparams) -{ - int err; - - /* get the current swparams */ - err = snd_pcm_sw_params_current(handle, swparams); - if (err < 0) { - ERRORLOG("Unable to determine current swparams for playback: %s\n", snd_strerror(err)); - return err; - } - /* start the transfer when the buffer is full */ - err = snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); - if (err < 0) { - ERRORLOG("Unable to set start threshold mode for playback: %s\n", snd_strerror(err)); - return err; - } - /* allow the transfer when at least period_size samples can be processed */ - err = snd_pcm_sw_params_set_avail_min(handle, swparams, period_size); - if (err < 0) { - ERRORLOG("Unable to set avail min for playback: %s\n", snd_strerror(err)); - return err; - } -#if (SND_LIB_SUBMINOR < 16) - /* align all transfers to 1 sample */ - err = snd_pcm_sw_params_set_xfer_align(handle, swparams, 1); - if (err < 0) { - ERRORLOG("Unable to set transfer align for playback: %s\n", snd_strerror(err)); - return err; - } -#endif - /* write the parameters to the playback device */ - err = snd_pcm_sw_params(handle, swparams); - if (err < 0) { - ERRORLOG("Unable to set sw params for playback: %s\n", snd_strerror(err)); - return err; - } - return 0; -} - -int alsa_open( void ) -{ - int err; - - snd_pcm_hw_params_t *hwparams; - snd_pcm_sw_params_t *swparams; - - DEBUGLOG("alsa_open\n"); - - snd_pcm_hw_params_alloca(&hwparams); - snd_pcm_sw_params_alloca(&swparams); - - if((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0/*SND_PCM_NONBLOCK*/)) < 0 ) { - ERRORLOG("open failed: %s\n", snd_strerror(err)); - return -1; - } - - if((err = set_hwparams(hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { - ERRORLOG("Setting of hwparams failed: %s\n", snd_strerror(err)); - return -1; - } - if((err = set_swparams(swparams)) < 0) { - ERRORLOG("Setting of swparams failed: %s\n", snd_strerror(err)); - return -1; - } - - return 0; -} - -int alsa_close( void ) -{ - int err; - - DEBUGLOG("alsa_close\n"); - - err = alsa_stop(); - -#if (SND_LIB_MAJOR < 1) - err = snd_pcm_close(handle); -#else - err = snd_pcm_close(handle); -#endif - - free(device); - - return err; -} - -/* - * Play some audio and pass a status message upstream, if applicable. - * Returns 0 on success. - */ -int -alsa_play(struct wm_cdda_block *blk) -{ - signed short *ptr; - int err = 0, frames; - - ptr = (signed short *)blk->buf; - frames = blk->buflen / (channels * 2); - DEBUGLOG("play %i frames, %lu bytes\n", frames, blk->buflen); - while (frames > 0) { - err = snd_pcm_writei(handle, ptr, frames); - - if (err == -EAGAIN) - continue; - if(err == -EPIPE) { - err = snd_pcm_prepare(handle); - continue; - } else if (err < 0) - break; - - ptr += err * channels; - frames -= err; - DEBUGLOG("played %i, rest %i\n", err, frames); - } - - if (err < 0) { - ERRORLOG("alsa_write failed: %s\n", snd_strerror(err)); - err = snd_pcm_prepare(handle); - - if (err < 0) { - ERRORLOG("Unable to snd_pcm_prepare pcm stream: %s\n", snd_strerror(err)); - } - blk->status = WM_CDM_CDDAERROR; - return err; - } - - return 0; -} - -/* - * Stop the audio immediately. - */ -int -alsa_stop( void ) -{ - int err; - - DEBUGLOG("alsa_stop\n"); - - err = snd_pcm_drop(handle); - if (err < 0) { - ERRORLOG("Unable to drop pcm stream: %s\n", snd_strerror(err)); - } - - err = snd_pcm_prepare(handle); - if (err < 0) { - ERRORLOG("Unable to snd_pcm_prepare pcm stream: %s\n", snd_strerror(err)); - } - - return err; -} - -static struct audio_oops alsa_oops = { - .wmaudio_open = alsa_open, - .wmaudio_close = alsa_close, - .wmaudio_play = alsa_play, - .wmaudio_stop = alsa_stop, - .wmaudio_state = NULL, - .wmaudio_balvol = NULL -}; - -struct audio_oops* -setup_alsa(const char *dev, const char *ctl) -{ - static int init_complete = 0; - - DEBUGLOG("setup_alsa\n"); - - if(init_complete) { - alsa_close(); - init_complete = 0; - } - - if(dev && strlen(dev) > 0) { - device = strdup(dev); - } else { - device = strdup("plughw:0,0"); /* playback device */ - } - - if(!alsa_open()) - init_complete = 1; - else - return NULL; - - return &alsa_oops; -} - -#endif /* HAVE_LIBASOUND2 */ diff --git a/kcompactdisc/wmlib/audio/audio_arts.c b/kcompactdisc/wmlib/audio/audio_arts.c deleted file mode 100644 index 23b5a63a..00000000 --- a/kcompactdisc/wmlib/audio/audio_arts.c +++ /dev/null @@ -1,126 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2006 Alexander Kern - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - Linux digital audio functions. - */ - -#ifdef USE_ARTS - -#include "audio.h" - -#include - -arts_stream_t arts_stream = NULL; - -int arts_open(void); -int arts_close(void); -int arts_stop(void); -int arts_play(struct cdda_block *blk); -int arts_state(struct cdda_block *blk); -struct audio_oops* setup_arts(const char *dev, const char *ctl); - -/* - * Initialize the audio device. - */ -int -arts_open(void) -{ - int err; - - DEBUGLOG("arts_open\n"); - - if(!(arts_stream = arts_play_stream(44100, 16, 2, "cddaslave"))) { - ERRORLOG("cannot open ARTS stream for playback\n"); - return -1; - } - /* 1000 ms because we read 75 frames = 1 sec */ - if((err = arts_stream_set(arts_stream, ARTS_P_BUFFER_TIME, 1000)) < 0) { - ERRORLOG("arts_stream_set failed (%s)\n", arts_error_text(err)); - return -1; - } - return 0; -} - -/* - * Close the audio device. - */ -int -arts_close(void) -{ - arts_stop(); - - DEBUGLOG("arts_close\n"); - arts_close_stream(arts_stream); - - arts_free(); - - return 0; -} - -/* - * Play some audio and pass a status message upstream, if applicable. - * Returns 0 on success. - */ -int -arts_play(struct cdda_block *blk) -{ - int err; - - if((err = arts_write(arts_stream, blk->buf, blk->buflen)) < 0) { - ERRORLOG("arts_write failed (%s)\n", arts_error_text(err)); - blk->status = WM_CDM_CDDAERROR; - return -1; - } - - return 0; -} - -/* - * Stop the audio immediately. - */ -int -arts_stop(void) -{ - DEBUGLOG("arts_stop\n"); - - return 0; -} - -static struct audio_oops arts_oops = { - .wmaudio_open = arts_open, - .wmaudio_close = arts_close, - .wmaudio_play = arts_play, - .wmaudio_stop = arts_stop, - .wmaudio_state = NULL, - .wmaudio_balvol = NULL -}; - -struct audio_oops* -setup_arts(const char *dev, const char *ctl) -{ - int err; - - if((err = arts_init())) { - ERRORLOG("cannot initialize ARTS audio subsystem (%s)\n", arts_error_text(err)); - return NULL; - } - - arts_open(); - - return &arts_oops; -} -#endif diff --git a/kcompactdisc/wmlib/audio/audio_phonon.cpp b/kcompactdisc/wmlib/audio/audio_phonon.cpp deleted file mode 100644 index 24e7c78c..00000000 --- a/kcompactdisc/wmlib/audio/audio_phonon.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2006 Alexander Kern - - based on example for Phonon Architecture, Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "audio_phonon.h" -#include "audio.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -LibWMPcmPlayer::LibWMPcmPlayer() : AbstractMediaStream(NULL), - m_media(NULL), - m_cmd(WM_CDM_UNKNOWN), - m_blk(NULL) -{ - Phonon::AudioOutput* m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); - Phonon::AudioPath* m_path = new Phonon::AudioPath(this); - m_path->addOutput(m_output); - m_media = new Phonon::MediaObject(this); - m_media->addAudioPath(m_path); - m_media->setCurrentSource(this); - setStreamSeekable(false); - setStreamSize(0xffffffff); - - connect(this, SIGNAL(cmdChanged(int)), this, SLOT(executeCmd(int))); - connect(this, SIGNAL(nextBuffer(cdda_block*)), this, SLOT(playBuffer(cdda_block*))); - connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this, SLOT(stateChanged(Phonon::State,Phonon::State))); - - DEBUGLOG("writeHeader\n"); - writeData( wavHeader() ); - DEBUGLOG("writeHeader end\n"); -} - -LibWMPcmPlayer::~LibWMPcmPlayer() -{ - stop(); -} - -QByteArray LibWMPcmPlayer::wavHeader() const -{ - QByteArray data; - QDataStream stream( &data, QIODevice::WriteOnly ); - stream.setByteOrder( QDataStream::LittleEndian ); - stream - << 0x46464952 //"RIFF" - << static_cast( 0x7FFFFFFF ) - << 0x45564157 //"WAVE" - << 0x20746D66 //"fmt " //Subchunk1ID - << static_cast( 16 ) //Subchunk1Size - << static_cast( 1 ) //AudioFormat - << static_cast( 2 ) //NumChannels - << static_cast( 44100 ) //SampleRate - << static_cast( 2*2*44100 )//ByteRate - << static_cast( 2*2 ) //BlockAlign - << static_cast( 16 ) //BitsPerSample - << 0x61746164 //"data" //Subchunk2ID - << static_cast( 0x7FFFFFFF-36 )//Subchunk2Size - ; - - return data; -} - -void LibWMPcmPlayer::reset() -{ - setStreamSeekable(false); - setStreamSize(0xffffffff); - DEBUGLOG("writeHeader\n"); - writeData( wavHeader() ); - DEBUGLOG("writeHeader end\n"); -} - -void LibWMPcmPlayer::needData() -{ - DEBUGLOG("needData\n"); - m_mutex.lock(); - m_readyToPlay.wakeAll(); - m_mutex.unlock(); - -} - -void LibWMPcmPlayer::setNextBuffer(struct cdda_block *blk) -{ - emit nextBuffer(blk); - m_mutex.lock(); - m_readyToPlay.wait(&m_mutex); - m_mutex.unlock(); -} - -void LibWMPcmPlayer::playBuffer(struct cdda_block *blk) -{ - if(m_cmd != WM_CDM_PLAYING) { - emit cmdChanged(WM_CDM_PLAYING); - m_cmd = WM_CDM_PLAYING; - } - writeData(QByteArray(blk->buf, blk->buflen)); - -} - -void LibWMPcmPlayer::pause(void) -{ - if(m_cmd != WM_CDM_PAUSED) { - emit cmdChanged(WM_CDM_PAUSED); - m_cmd = WM_CDM_PAUSED; - - m_readyToPlay.wakeAll(); - } -} - -void LibWMPcmPlayer::stop(void) -{ - if(m_cmd != WM_CDM_STOPPED) { - emit cmdChanged(WM_CDM_STOPPED); - m_cmd = WM_CDM_STOPPED; - - m_readyToPlay.wakeAll(); - } -} - -void LibWMPcmPlayer::executeCmd(int cmd) -{ - switch(cmd) { - case WM_CDM_PLAYING: -DEBUGLOG("set play\n"); - m_media->play(); - break; - case WM_CDM_PAUSED: -DEBUGLOG("set pause\n"); - m_media->pause(); - break; - case WM_CDM_STOPPED: -DEBUGLOG("set stop\n"); - m_media->stop(); - break; - default: - cmd = WM_CDM_STOPPED; - break; - } -} - -void LibWMPcmPlayer::stateChanged( Phonon::State newstate, Phonon::State oldstate ) -{ - DEBUGLOG("stateChanged from %i to %i\n", oldstate, newstate); -} - -static LibWMPcmPlayer *PhononObject = NULL; - -int phonon_open(void) -{ - DEBUGLOG("phonon_open\n"); - - if(PhononObject) { - ERRORLOG("Already initialized!\n"); - return -1; - } - - PhononObject = new LibWMPcmPlayer(); - - return 0; -} - -int phonon_close(void) -{ - DEBUGLOG("phonon_close\n"); - - if(!PhononObject) { - ERRORLOG("Unable to close\n"); - return -1; - } - - delete PhononObject; - - PhononObject = NULL; - - return 0; -} - -/* - * Play some audio and pass a status message upstream, if applicable. - * Returns 0 on success. - */ -int -phonon_play(struct cdda_block *blk) -{ - DEBUGLOG("phonon_play %ld samples, frame %i\n", - blk->buflen / (2 * 2), blk->frame); - - if(!PhononObject) { - ERRORLOG("Unable to play\n"); - blk->status = WM_CDM_CDDAERROR; - return -1; - } - - PhononObject->setNextBuffer(blk); - - return 0; -} - -/* - * Pause the audio immediately. - */ -int -phonon_pause(void) -{ - DEBUGLOG("phonon_pause\n"); - - if(!PhononObject) { - ERRORLOG("Unable to pause\n"); - return -1; - } - - PhononObject->pause(); - - return 0; -} - -/* - * Stop the audio immediately. - */ -int -phonon_stop(void) -{ - DEBUGLOG("phonon_stop\n"); - - if(!PhononObject) { - ERRORLOG("Unable to stop\n"); - return -1; - } - - PhononObject->stop(); - - return 0; -} - -/* - * Get the current audio state. - */ -int -phonon_state(struct cdda_block *blk) -{ - DEBUGLOG("phonon_state\n"); - - return -1; /* not implemented yet for PHONON */ -} - -static struct audio_oops phonon_oops = { - phonon_open, - phonon_close, - phonon_play, - phonon_pause, - phonon_stop, - phonon_state, - NULL, - NULL -}; - -extern "C" struct audio_oops* -setup_phonon(const char *dev, const char *ctl) -{ - DEBUGLOG("setup_phonon\n"); - - phonon_open(); - - return &phonon_oops; -} - -#include "moc_audio_phonon.cpp" diff --git a/kcompactdisc/wmlib/audio/audio_phonon.h b/kcompactdisc/wmlib/audio/audio_phonon.h deleted file mode 100644 index f7d27b67..00000000 --- a/kcompactdisc/wmlib/audio/audio_phonon.h +++ /dev/null @@ -1,66 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2006 Alexander Kern - - based on example for Phonon Architecture, Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __AUDIO_PHONON_H__ -#define __AUDIO_PHONON_H__ - -#include -#include -#include -#include - -#include - -namespace Phonon { class MediaObject; } - -class LibWMPcmPlayer : public Phonon::AbstractMediaStream { - Q_OBJECT - -public: - LibWMPcmPlayer(); - ~LibWMPcmPlayer(); - - QByteArray wavHeader() const; - void setNextBuffer(struct cdda_block *blk); - -public slots: - void playBuffer(struct cdda_block *blk); - void pause(void); - void stop(void); - void executeCmd(int cmd); - void stateChanged( Phonon::State newstate, Phonon::State oldstate ); - -protected: - void reset(); - void needData(); - -signals: - void cmdChanged(int cmd); - void nextBuffer(struct cdda_block *blk); - -private: - Phonon::MediaObject* m_media; - unsigned char m_cmd; - struct cdda_block *m_blk; - QWaitCondition m_readyToPlay; - QMutex m_mutex; -}; - -#endif /* __AUDIO_PHONON_H__ */ diff --git a/kcompactdisc/wmlib/audio/audio_sun.c b/kcompactdisc/wmlib/audio/audio_sun.c deleted file mode 100644 index 97744de0..00000000 --- a/kcompactdisc/wmlib/audio/audio_sun.c +++ /dev/null @@ -1,493 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 1991-1997 by Steven Grimm - Copyright (C) by Dirk Försterling - Copyright (C) 2006 Alexander Kern - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - Sun (really Solaris) digital audio functions. -*/ - -#if defined(sun) || defined(__sun__) - -#include "audio.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -/* - * Since there's a lag time between writing audio to the audio device and - * hearing it, we need to make sure the status indicators correlate to what's - * playing out the speaker. Luckily, Solaris gives us some audio - * synchronization facilities that make this pretty easy. - * - * We maintain a circular queue of status information. When we write some - * sound to the audio device, we put its status info into the queue. We write - * a marker into the audio stream; when the audio device driver encounters the - * marker, it increments a field in a status structure. When we see that - * field go up, we grab the next status structure from the queue and send it - * to the parent process. - * - * The minimum size of the queue depends on the latency of the audio stream. - */ -#define QSIZE 500 - -struct cdda_block queue[QSIZE]; -int qtail; -int qstart; - -/* - * We only send WM_CDM_PLAYING status messages upstream when the CD is supposed - * to be playing; this is used to keep track. - */ -extern int playing; - -static int aufd, aucfd; -static int raw_audio = 1; /* Can /dev/audio take 44.1KHz stereo? */ - -/* - * For fast linear-to-ulaw mapping, we use a lookup table that's generated - * at startup. - */ -unsigned char *ulawmap, linear_to_ulaw(); - -char *getenv(); - -/* - * Dummy signal handler so writes to /dev/audio will interrupt. - */ -static void -dummy( void ) -{ - signal(SIGALRM, dummy); -} - -/* - * Initialize the audio device. - */ -void -sun_audio_init( void ) -{ - audio_info_t info; - char *audiodev, *acdev; - int linval; - - audiodev = getenv("AUDIODEV"); - if (audiodev == NULL || - strncmp("/dev/", audiodev, 5) || - strstr(audiodev, "/../") ) - audiodev = "/dev/audio"; - - acdev = malloc(strlen(audiodev) + 4); - if (acdev == NULL) - { - perror("Cannot allocate audio control filename"); - exit(1); - } - strcpy(acdev, audiodev); - strcat(acdev, "ctl"); - - aucfd = open(acdev, O_WRONLY, 0); - if (aucfd < 0) - { - perror(acdev); - exit(1); - } - free(acdev); - - aufd = open(audiodev, O_WRONLY, 0); - if (aufd < 0) - { - perror(audiodev); - exit(1); - } - - signal(SIGALRM, dummy); - - /* - * Try to set the device to CD-style audio; we can process it - * with the least CPU overhead. - */ - AUDIO_INITINFO(&info); - info.play.sample_rate = 44100; - info.play.channels = 2; - info.play.precision = 16; - info.play.encoding = AUDIO_ENCODING_LINEAR; - info.play.pause = 0; - info.record.pause = 0; - info.monitor_gain = 0; - - if (ioctl(aufd, AUDIO_SETINFO, &info) < 0) - if (errno == EINVAL) - { - /* - * Oh well, so much for that idea. - */ - AUDIO_INITINFO(&info); - info.play.sample_rate = 8000; - info.play.channels = 1; - info.play.precision = 8; - info.play.encoding = AUDIO_ENCODING_ULAW; - info.play.pause = 0; - info.record.pause = 0; - info.monitor_gain = 0; - if (ioctl(aufd, AUDIO_SETINFO, &info) < 0) - { - perror("Can't set up audio device"); - exit(1); - } - - /* - * Initialize the linear-to-ulaw mapping table. - */ - if (ulawmap == NULL) - ulawmap = malloc(65536); - if (ulawmap == NULL) - { - perror("malloc"); - exit(1); - } - for (linval = 0; linval < 65536; linval++) - ulawmap[linval] = linear_to_ulaw(linval-32768); - ulawmap += 32768; - raw_audio = 0; - } - else - { - perror(audiodev); - exit(1); - } -} - -/* - * Get ready to play some sound. - */ -void -sun_audio_ready( void ) -{ - audio_info_t info; - - /* - * Start at the correct queue position. - */ - if (ioctl(aucfd, AUDIO_GETINFO, &info) < 0) perror("AUDIO_GETINFO"); - qtail = info.play.eof % QSIZE; - qstart = qtail; - - queue[qtail].status = WM_CDM_PLAYING; -} - -/* - * Stop the audio immediately. - */ -int -sun_audio_stop( void ) -{ - if (ioctl(aufd, I_FLUSH, FLUSHRW) < 0) - perror("flush"); - return 0; -} - -/* - * Close the audio device. - */ -int -sun_audio_close( void ) -{ - wmaudio_stop(); - close(aufd); - close(aucfd); - return 0; -} - -/* - * Set/get the balance and volume level. - */ -int -sun_audio_balvol(int setget, unsigned char *balance, unsigned char *volume) -{ - audio_info_t info; - AUDIO_INITINFO(&info); - if (ioctl(aucfd, AUDIO_GETINFO, &info) < 0) { - perror("AUDIO_GETINFO"); - return -1; - } - - if(setget) { - balance *= AUDIO_RIGHT_BALANCE; - info.play.balance = *balance / 255; - info.play.gain = *volume; - if (ioctl(aucfd, AUDIO_SETINFO, &info) < 0) { - perror("AUDIO_SETINFO"); - return -1; - } - } else { - *volume = info.play.gain; - *balance = (info.play.balance * 255) / AUDIO_RIGHT_BALANCE; - } - return 0; -} - -/* - * Mark the most recent audio block on the queue as the last one. - */ -void -sun_audio_mark_last( void ) -{ - queue[qtail].status = WM_CDM_TRACK_DONE; -} - -/* - * Figure out the most recent status information and send it upstream. - */ -int -sun_audio_send_status( void ) -{ - audio_info_t info; - int qhead; - - /* - * Now send the most current status information to our parent. - */ - if (ioctl(aucfd, AUDIO_GETINFO, &info) < 0) - perror("AUDIO_GETINFO"); - qhead = info.play.eof % QSIZE; - - if (qhead != qstart && playing) - { - int balance; - - if (queue[qhead].status != WM_CDM_TRACK_DONE) - queue[qhead].status = WM_CDM_PLAYING; - queue[qhead].volume = info.play.gain; - queue[qhead].balance = (info.play.balance * 255) / - AUDIO_RIGHT_BALANCE; - - send_status(queue + qhead); - qstart = -1; - } - - return (queue[qhead].status == WM_CDM_TRACK_DONE); -} - -/* - * Play some audio and pass a status message upstream, if applicable. - * Returns 0 on success. - */ -int -sun_audio_play(unsigned char *rawbuf, long buflen, struct cdda_block *blk) -{ - int i; - short *buf16; - int alarmcount = 0; - struct itimerval it; - long playablelen; - - alarm(1); - playablelen = dev_audio_convert(rawbuf, buflen, blk); - while (write(aufd, rawbuf, playablelen) <= 0) - if (errno == EINTR) - { - if (! raw_audio && alarmcount++ < 5) - { - /* - * 8KHz /dev/audio blocks for several seconds - * waiting for its queue to drop below a low - * water mark. - */ - wmaudio_send_status(); - timerclear(&it.it_interval); - timerclear(&it.it_value); - it.it_value.tv_usec = 500000; - setitimer(ITIMER_REAL, &it, NULL); - continue; - } - -/* close(aufd); - close(aucfd); - wmaudio_init(); -*/ sun_audio_stop(); - alarm(2); - continue; - } - else - { - blk->status = WM_CDM_CDDAERROR; - return (-1); - } - alarm(0); - - /* - * Mark this spot in the audio stream. - * - * Marks don't always succeed (if the audio buffer is empty - * this call will block forever) so do it asynchronously. - */ - fcntl(aufd, F_SETFL, O_NONBLOCK); - if (write(aufd, rawbuf, 0) < 0) - { - if (errno != EAGAIN) - perror("audio mark"); - } - else - qtail = (qtail + 1) % QSIZE; - - fcntl(aufd, F_SETFL, 0); - - queue[qtail] = *blk; - - if (wmaudio_send_status() < 0) - return (-1); - else - return (0); -} - -/* -** This routine converts from linear to ulaw. -** -** Craig Reese: IDA/Supercomputing Research Center -** Joe Campbell: Department of Defense -** 29 September 1989 -** -** References: -** 1) CCITT Recommendation G.711 (very difficult to follow) -** 2) "A New Digital Technique for Implementation of Any -** Continuous PCM Companding Law," Villeret, Michel, -** et al. 1973 IEEE Int. Conf. on Communications, Vol 1, -** 1973, pg. 11.12-11.17 -** 3) MIL-STD-188-113,"Interoperability and Performance Standards -** for Analog-to_Digital Conversion Techniques," -** 17 February 1987 -** -** Input: Signed 16 bit linear sample -** Output: 8 bit ulaw sample -*/ -#define ZEROTRAP /* turn on the trap as per the MIL-STD */ -#define BIAS 0x84 /* define the add-in bias for 16 bit samples */ -#define CLIP 32635 - -unsigned char -linear_to_ulaw( sample ) -int sample; -{ - static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, - 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7}; - int sign, exponent, mantissa; - unsigned char ulawbyte; - - /* Get the sample into sign-magnitude. */ - sign = (sample >> 8) & 0x80; /* set aside the sign */ - if ( sign != 0 ) sample = -sample; /* get magnitude */ - if ( sample > CLIP ) sample = CLIP; /* clip the magnitude */ - - /* Convert from 16 bit linear to ulaw. */ - sample = sample + BIAS; - exponent = exp_lut[( sample >> 7 ) & 0xFF]; - mantissa = ( sample >> ( exponent + 3 ) ) & 0x0F; - ulawbyte = ~ ( sign | ( exponent << 4 ) | mantissa ); -#ifdef ZEROTRAP - if ( ulawbyte == 0 ) ulawbyte = 0x02; /* optional CCITT trap */ -#endif - - return ulawbyte; -} - -/* - * Downsample a block of CDDA data, if necessary, for playing out an old-style - * audio device. - */ -long -dev_audio_convert(unsigned char *rawbuf, long buflen, struct cdda_block *blk) -{ - short *buf16 = (short *)rawbuf; - int i, j, samples; - int mono_value; - unsigned char *rbend = rawbuf + buflen; - - /* Don't do anything if the audio device can take the raw values. */ - if (raw_audio) - return (buflen); - - for (i = 0; buf16 < (short *)(rbend); i++) - { - /* Downsampling to 8KHz is a little irregular. */ - samples = (i & 1) ? ((i % 20) ? 10 : 12) : 12; - - /* And unfortunately, we don't always end on a nice boundary. */ - if (buf16 + samples > (short *)(rbend)) - samples = ((short *)rbend) - buf16; - - /* - * No need to average all the values; taking the first one - * is sufficient and less CPU-intensive. But we do need to - * do both channels. - */ - mono_value = (buf16[0] + buf16[1]) / 2; - buf16 += samples; - rawbuf[i] = ulawmap[mono_value]; - } - - return (i); -} - -static struct audio_oops sun_audio_oops = { - .wmaudio_open = sun_audio_open, - .wmaudio_close = sun_audio_close, - .wmaudio_play = sun_audio_play, - .wmaudio_stop = sun_audio_stop, - .wmaudio_state = NULL, - .wmaudio_balvol = sun_audio_balvol -}; - -struct audio_oops* -setup_sun_audio(const char *dev, const char *ctl) -{ - int err; - - if((err = sun_audio_init())) { - ERRORLOG("cannot initialize SUN /dev/audio subsystem \n"); - return NULL; - } - - sun_audio_open(); - - return &sun_audio_oops; -} - -#endif diff --git a/kcompactdisc/wmlib/cdda.c b/kcompactdisc/wmlib/cdda.c deleted file mode 100644 index 560e8bdc..00000000 --- a/kcompactdisc/wmlib/cdda.c +++ /dev/null @@ -1,405 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include /* For htonl(3) */ -#include -#include -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cdda.h" -#include "include/wm_cdrom.h" -#include "include/wm_helpers.h" -#include "include/wm_scsi.h" -#include "audio/audio.h" - -#include - -static pthread_t thread_read; -static pthread_t thread_play; - -/* CDDABLKSIZE give us the 588 samples 4 bytes each(16 bit x 2 channel) - by rate 44100 HZ, 588 samples are 1/75 sec - if we read 15 frames(8820 samples), we get in each block, data for 1/5 sec */ -#define COUNT_CDDA_FRAMES_PER_BLOCK 15 - -/* Only Linux and Sun define the number of blocks explicitly; assume all - other systems are like Linux and have 10 blocks. -*/ -#ifndef COUNT_CDDA_BLOCKS -#define COUNT_CDDA_BLOCKS 10 -#endif - -static struct wm_cdda_block blks[COUNT_CDDA_BLOCKS]; -static pthread_mutex_t blks_mutex[COUNT_CDDA_BLOCKS]; -static pthread_cond_t wakeup_audio; - -/* - * This is non-null if we're saving audio to a file. - */ -static FILE *output = NULL; - -/* - * These are driverdependent oops - * - */ -static struct audio_oops *oops = NULL; - -/* - * Audio file header format. - */ -typedef unsigned long u_32; -struct auheader { - u_32 magic; - u_32 hdr_size; - u_32 data_size; - u_32 encoding; - u_32 sample_rate; - u_32 channels; -}; - -static int cdda_status(struct wm_drive *d, int oldmode, - int *mode, int *frame, int *track, int *ind) -{ - if (d->cddax) { - if(d->status) - *mode = d->status; - else - *mode = oldmode; - - if (*mode == WM_CDM_PLAYING) { - *track = d->track; - *ind = d->index; - *frame = d->frame; - } else if (*mode == WM_CDM_CDDAERROR) { - /* - * An error near the end of the CD probably - * just means we hit the end. - */ - *mode = WM_CDM_TRACK_DONE; - } - - return 0; - } - - return -1; -} - -static int cdda_play(struct wm_drive *d, int start, int end) -{ - if (d->cddax) { - d->command = WM_CDM_STOPPED; - oops->wmaudio_stop(); - - /* wait before reader, stops */ - while(d->status != d->command) - wm_susleep(1000); - - d->current_position = start; - d->ending_position = end; - - d->track = -1; - d->index = 0; - d->frame = start; - d->status = d->command = WM_CDM_PLAYING; - - return 0; - } - - return -1; -} - -static int cdda_pause(struct wm_drive *d) -{ - if (d->cddax) { - if(WM_CDM_PLAYING == d->command) { - d->command = WM_CDM_PAUSED; - if(oops->wmaudio_pause) - oops->wmaudio_pause(); - } else { - d->command = WM_CDM_PLAYING; - } - - return 0; - } - - return -1; -} - -static int cdda_stop(struct wm_drive *d) -{ - if (d->cddax) { - d->command = WM_CDM_STOPPED; - oops->wmaudio_stop(); - return 0; - } - - return -1; -} - -static int cdda_set_volume(struct wm_drive *d, int left, int right) -{ - if (d->cddax) { - if(oops->wmaudio_balvol && !oops->wmaudio_balvol(1, &left, &right)) - return 0; - } - - return -1; -} - -static int cdda_get_volume(struct wm_drive *d, int *left, int *right) -{ - if (d->cddax) { - if(oops->wmaudio_balvol && !oops->wmaudio_balvol(0, left, right)) - return 0; - } - - return -1; -} - - #if 0 -/* - * Tell the CDDA slave to start (or stop) saving to a file. - */ -void -cdda_save(struct wm_drive *, char *) -{ - - int len; - - if (filename == NULL || filename[0] == '\0') - len = 0; - else - len = strlen(filename); - write(d->cdda_slave, "F", 1); - write(d->cdda_slave, &len, sizeof(len)); - if (len) - write(d->cdda_slave, filename, len); - - - read(0, &namelen, sizeof(namelen)); - if (output != NULL) { - fclose(output); - output = NULL; - } - if (namelen) { - filename = malloc(namelen + 1); - if (filename == NULL) { - perror("cddas"); - wmcdda_close(cdda_device); - oops->wmaudio_close(); - exit(1); - } - - read(0, filename, namelen); - filename[namelen] = '\0'; - output = fopen(filename, "w"); - if (output == NULL) { - perror(filename); - } else { - /* Write an .au file header. */ - hdr.magic = htonl(0x2e736e64); - hdr.hdr_size = htonl(sizeof(hdr) + 28); - hdr.data_size = htonl(~0); - hdr.encoding = htonl(3); /* linear-16 */ - hdr.sample_rate = htonl(44100); - hdr.channels = htonl(2); - - fwrite(&hdr, sizeof(hdr), 1, output); - fwrite("Recorded from CD by WorkMan", 28, 1, output); - } - free(filename); - -} -#endif - -static int get_next_block(int x) -{ - int y = ++x; - return (y < COUNT_CDDA_BLOCKS)?y:0; -} - -static void *cdda_fct_read(void* arg) -{ - struct wm_drive *d = (struct wm_drive *)arg; - int i, j, wakeup; - long result; - - while (d->blocks) { - while(d->command != WM_CDM_PLAYING) { - d->status = d->command; - wm_susleep(1000); - } - - i = 0; - (void) pthread_mutex_lock(&blks_mutex[i]); - wakeup = 1; - - while(d->command == WM_CDM_PLAYING) { - result = gen_cdda_read(d, &blks[i]); - if (result <= 0 && blks[i].status != WM_CDM_TRACK_DONE) { - ERRORLOG("cdda: wmcdda_read failed, stop playing\n"); - d->command = WM_CDM_STOPPED; - break; - } else { - if (output) - fwrite(blks[i].buf, blks[i].buflen, 1, output); - } - - j = get_next_block(i); - (void) pthread_mutex_lock(&blks_mutex[j]); - - if(wakeup) { - wakeup = 0; - pthread_cond_signal(&wakeup_audio); - } - - (void) pthread_mutex_unlock(&blks_mutex[i]); - /* audio can start here */ - - i = j; - } - - (void) pthread_mutex_unlock(&blks_mutex[i]); - } - - return 0; -} - -static void *cdda_fct_play(void* arg) -{ - struct wm_drive *d = (struct wm_drive *)arg; - int i = 0; - - while (d->blocks) { - if(d->command != WM_CDM_PLAYING) { - i = 0; - (void) pthread_mutex_lock(&blks_mutex[i]); - pthread_cond_wait(&wakeup_audio, &blks_mutex[i]); - } else { - i = get_next_block(i); - (void) pthread_mutex_lock(&blks_mutex[i]); - } - - if (oops->wmaudio_play(&blks[i])) { - oops->wmaudio_stop(); - ERRORLOG("cdda: wmaudio_play failed\n"); - d->command = WM_CDM_STOPPED; - } - if (oops->wmaudio_state) - oops->wmaudio_state(&blks[i]); - - d->frame = blks[i].frame; - d->track = blks[i].track; - d->index = blks[i].index; - if ((d->status = blks[i].status) == WM_CDM_TRACK_DONE) - d->command = WM_CDM_STOPPED; - - (void) pthread_mutex_unlock(&blks_mutex[i]); - } - - return 0; -} - -/* - * Try to initialize the CDDA slave. Returns 0 on success. - */ -int wm_cdda_init(struct wm_drive *d) -{ - int ret = 0; - - if (d->cddax) { - wm_cdda_destroy(d); - - wm_susleep(1000); - d->blocks = 0; - wm_susleep(1000); - } - - memset(blks, 0, sizeof(blks)); - - d->blocks = blks; - d->frames_at_once = COUNT_CDDA_FRAMES_PER_BLOCK; - d->numblocks = COUNT_CDDA_BLOCKS; - d->status = WM_CDM_UNKNOWN; - - if ((ret = gen_cdda_init(d))) - return ret; - - if ((ret = gen_cdda_open(d))) - return ret; - - wm_scsi_set_speed(d, 4); - - oops = setup_soundsystem(d->soundsystem, d->sounddevice, d->ctldevice); - if (!oops) { - ERRORLOG("cdda: setup_soundsystem failed\n"); - gen_cdda_close(d); - return -1; - } - - if(pthread_create(&thread_read, NULL, cdda_fct_read, d)) { - ERRORLOG("error by create pthread"); - oops->wmaudio_close(); - gen_cdda_close(d); - return -1; - } - - if(pthread_create(&thread_play, NULL, cdda_fct_play, d)) { - ERRORLOG("error by create pthread"); - oops->wmaudio_close(); - gen_cdda_close(d); - return -1; - } - - d->proto.get_drive_status = cdda_status; - d->proto.pause = cdda_pause; - d->proto.resume = NULL; - d->proto.stop = cdda_stop; - d->proto.play = cdda_play; - d->proto.set_volume = cdda_set_volume; - d->proto.get_volume = cdda_get_volume; - d->proto.scale_volume = NULL; - d->proto.unscale_volume = NULL; - - d->cddax = (void *)1; - - return 0; -} - -int wm_cdda_destroy(struct wm_drive *d) -{ - if (d->cddax) { - wm_scsi_set_speed(d, -1); - - d->command = WM_CDM_STOPPED; - oops->wmaudio_stop(); - wm_susleep(2000); - gen_cdda_close(d); - oops->wmaudio_close(); - - d->numblocks = 0; - d->blocks = NULL; - wait(NULL); - d->cddax = NULL; - } - return 0; -} diff --git a/kcompactdisc/wmlib/cddb.c b/kcompactdisc/wmlib/cddb.c deleted file mode 100644 index f8af715a..00000000 --- a/kcompactdisc/wmlib/cddb.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm (original author) - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * establish connection to cddb server and get data - * socket stuff gotten from gnu port of the finger command - * - * provided by Sven Oliver Moll - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_helpers.h" -#include "include/wm_cddb.h" -#include "include/wm_cdrom.h" - -/* - * Subroutine from cddb_discid - */ -static int cddb_sum(int n) -{ - char buf[12], - *p; - int ret = 0; - - /* For backward compatibility this algorithm must not change */ - sprintf(buf, "%lu", (unsigned long)n); - for (p = buf; *p != '\0'; p++) - ret += (*p - '0'); - - return (ret); -} /* cddb_sum() */ - - -/* - * Calculate the discid of a CD according to cddb - */ -unsigned long cddb_discid(struct wm_drive *pdrive) -{ - int i, - t, - n = 0, tracks; - - tracks = wm_cd_getcountoftracks(pdrive); - if(!tracks) - return (unsigned)-1; - - /* For backward compatibility this algorithm must not change */ - for (i = 0; i < tracks; i++) { - - n += cddb_sum(wm_cd_gettrackstart(pdrive, i + 1)); - /* - * Just for demonstration (See below) - * - * t += (wm_cd_getref()->trk[i+1].start / 75) - - * (wm_cd_getref()->trk[i ].start / 75); - */ - } - - /* - * Mathematics can be fun. Example: How to reduce a full loop to - * a simple statement. The discid algorhythm is so half-hearted - * developed that it doesn't even use the full 32bit range. - * But it seems to be always this way: The bad standards will be - * accepted, the good ones turned down. - * Boy, you pulled out the /75. This is not correct here, because - * this calculation needs the integer division for both .start - * fields. - */ - - t = (wm_cd_gettrackstart(pdrive, tracks + 1)) - (wm_cd_gettrackstart(pdrive, 1)); - return ((n % 0xff) << 24 | t << 8 | tracks); -} /* cddb_discid() */ - diff --git a/kcompactdisc/wmlib/cdrom.c b/kcompactdisc/wmlib/cdrom.c deleted file mode 100644 index 4d995854..00000000 --- a/kcompactdisc/wmlib/cdrom.c +++ /dev/null @@ -1,818 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm (original author) - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Interface between most of WorkMan and the low-level CD-ROM library - * routines defined in plat_*.c and drv_*.c. The goal is to have no - * platform- or drive-dependent code here. - */ - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cddb.h" -#include "include/wm_cdrom.h" -#include "include/wm_platform.h" -#include "include/wm_helpers.h" -#include "include/wm_cdtext.h" -#include "include/wm_scsi.h" - -#include -#include -#include -#include -#include -#include - -#ifdef CAN_CLOSE -#include -#endif - -/* local prototypes */ -static int fixup_drive_struct(struct wm_drive *); -static int read_toc(struct wm_drive *); -static const char* gen_status(int); - -#define WM_MSG_CLASS WM_MSG_CLASS_CDROM - -/* extern struct wm_drive generic_proto, toshiba_proto, sony_proto; */ -/* toshiba33_proto; <=== Somehow, this got lost */ - -/* - * The supported drive types are listed here. NULL means match anything. - * The first match in the list is used, and substring matches are done (so - * put long names before their shorter prefixes.) - */ -static struct drivelist { - const char *vendor; - const char *model; - const char *revision; - int (*fixup)(struct wm_drive *d); -} drives[] = { -{ "TOSHIBA", "XM-3501", NULL, toshiba_fixup }, -{ "TOSHIBA", "XM-3401", NULL, toshiba_fixup }, -{ "TOSHIBA", "XM-3301", NULL, toshiba_fixup }, -{ "SONY", "CDU-8012", NULL, sony_fixup }, -{ "SONY", "CDU 561", NULL, sony_fixup }, -{ "SONY", "CDU-76S", NULL, sony_fixup }, -{ NULL, NULL, NULL, NULL } -}; - -/* - * Solaris 2.2 will remove the device out from under us. Getting an ENOENT - * is therefore sometimes not a problem. - */ -int intermittent_dev = 0; - - -/* - * Macro magic - * - */ - -#define CARRAY(id) ((id)-1) - -#define DATATRACK 1 - -/* - * get the current position - */ -int wm_get_cur_pos_rel(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - return pdrive->thiscd.cur_pos_rel; -} - -/* - * get the current position - */ -int wm_get_cur_pos_abs(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - return pdrive->thiscd.cur_pos_abs; -} - -/* - * init the workmanlib - */ -int wm_cd_init(const char *cd_device, const char *soundsystem, - const char *sounddevice, const char *ctldevice, void **ppdrive) -{ - int err; - struct wm_drive *pdrive; - - if(!ppdrive) - return -1; - - pdrive = *ppdrive = (struct wm_drive *)malloc(sizeof(struct wm_drive)); - if(!pdrive) - return -1; - memset(pdrive, 0, sizeof(*pdrive)); - - pdrive->cdda = (soundsystem && strcasecmp(soundsystem, "cdin")); - - pdrive->cd_device = cd_device ? strdup(cd_device) : strdup(DEFAULT_CD_DEVICE); - pdrive->soundsystem = soundsystem ? strdup(soundsystem): NULL; - pdrive->sounddevice = sounddevice ? strdup(sounddevice) : NULL; - pdrive->ctldevice = ctldevice ? strdup(ctldevice) : NULL; - if(!pdrive->cd_device) { - err = -ENOMEM; - goto init_failed; - } - pdrive->fd = -1; - - pdrive->proto.open = gen_open; - pdrive->proto.close = gen_close; - pdrive->proto.get_trackcount = gen_get_trackcount; - pdrive->proto.get_cdlen = gen_get_cdlen; - pdrive->proto.get_trackinfo = gen_get_trackinfo; - pdrive->proto.get_drive_status = gen_get_drive_status; - pdrive->proto.pause = gen_pause; - pdrive->proto.resume = gen_resume; - pdrive->proto.stop = gen_stop; - pdrive->proto.play = gen_play; - pdrive->proto.eject = gen_eject; - pdrive->proto.closetray = gen_closetray; - pdrive->proto.scsi = gen_scsi; - pdrive->proto.set_volume = gen_set_volume; - pdrive->proto.get_volume = gen_get_volume; - pdrive->proto.scale_volume = gen_scale_volume; - pdrive->proto.unscale_volume = gen_unscale_volume; - pdrive->oldmode = WM_CDM_UNKNOWN; - - if((err = gen_init(pdrive)) < 0) - goto init_failed; - - if ((err = pdrive->proto.open(pdrive)) < 0) - goto open_failed; - - /* Can we figure out the drive type? */ - if (wm_scsi_get_drive_type(pdrive)) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "plat_open(): inquiry failed\n"); - } - - /* let it override some functions */ - fixup_drive_struct(pdrive); -#ifdef WMLIB_CDDA_BUILD - if(pdrive->cdda && (err = wm_cdda_init(pdrive))) - goto open_failed; -#endif - return wm_cd_status(pdrive); - -open_failed: - wm_cd_destroy(pdrive); - -init_failed: - free(pdrive->cd_device); - free(pdrive->soundsystem); - free(pdrive->sounddevice); - free(pdrive->ctldevice); - free(pdrive); - - return err; -} - -int wm_cd_destroy(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - free_cdtext(); - - if(pdrive->cdda) - wm_cdda_destroy(pdrive); - - pdrive->proto.close(pdrive); - - return 0; -} -/* - * Give information about the drive we found during wmcd_open() - */ -const char *wm_drive_vendor(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - return pdrive->vendor?pdrive->vendor:""; -} - -const char *wm_drive_model(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - return pdrive->model?pdrive->model:""; -} - -const char *wm_drive_revision(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - return pdrive->revision?pdrive->revision:""; -} - -const char *wm_drive_default_device() -{ - return DEFAULT_CD_DEVICE; -} - -unsigned long wm_cddb_discid(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - return cddb_discid(pdrive); -} - -/* - * Figure out which prototype drive structure we should be using based - * on the vendor, model, and revision of the current pdrive-> - */ -static int fixup_drive_struct(struct wm_drive *d) -{ - struct drivelist *driver; - - for (driver = drives; driver->vendor; driver++) { - if((strncmp(driver->vendor, d->vendor, strlen(d->vendor))) || - ((driver->model != NULL) && strncmp(driver->model, d->model, strlen(d->model))) || - ((d->revision != NULL) && strncmp(driver->revision, d->revision, strlen(d->revision)))) - continue; - - if(!(driver->fixup)) - goto fail; - - driver->fixup(d); - return 0; - } - -fail: - return -1; -} /* find_drive_struct() */ - -/* - * read_toc() - * - * Read the table of contents from the CD. Return a pointer to a wm_cdinfo - * struct containing the relevant information (minus artist/cdname/etc.) - * This is a static struct. Returns NULL if there was an error. - * - * XXX allocates one trackinfo too many. - */ -static int read_toc(struct wm_drive *pdrive) -{ - int i; - int pos; - - if(!pdrive->proto.get_trackcount || - pdrive->proto.get_trackcount(pdrive, &pdrive->thiscd.ntracks) < 0) { - return -1 ; - } - - pdrive->thiscd.length = 0; - pdrive->thiscd.cur_cdmode = WM_CDM_UNKNOWN; - pdrive->thiscd.cd_cur_balance = WM_BALANCE_SYMMETRED; - - if (pdrive->thiscd.trk != NULL) - free(pdrive->thiscd.trk); - - pdrive->thiscd.trk = malloc((pdrive->thiscd.ntracks + 1) * sizeof(struct wm_trackinfo)); - if (pdrive->thiscd.trk == NULL) { - perror("malloc"); - return -1; - } - - for (i = 0; i < pdrive->thiscd.ntracks; i++) { - if(!pdrive->proto.get_trackinfo || - pdrive->proto.get_trackinfo(pdrive, i + 1, &pdrive->thiscd.trk[i].data, - &pdrive->thiscd.trk[i].start) < 0) { - return -1; - } - - pdrive->thiscd.trk[i].length = pdrive->thiscd.trk[i].start / 75; - - pdrive->thiscd.trk[i].track = i + 1; - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "track %i, start frame %i\n", - pdrive->thiscd.trk[i].track, pdrive->thiscd.trk[i].start); - } - - if(!pdrive->proto.get_cdlen || - pdrive->proto.get_cdlen(pdrive, &pdrive->thiscd.trk[i].start) < 0) { - return -1; - } - pdrive->thiscd.trk[i].length = pdrive->thiscd.trk[i].start / 75; - - /* Now compute actual track lengths. */ - pos = pdrive->thiscd.trk[0].length; - for (i = 0; i < pdrive->thiscd.ntracks; i++) { - pdrive->thiscd.trk[i].length = pdrive->thiscd.trk[i+1].length - pos; - pos = pdrive->thiscd.trk[i+1].length; - if (pdrive->thiscd.trk[i].data) - pdrive->thiscd.trk[i].length = (pdrive->thiscd.trk[i + 1].start - pdrive->thiscd.trk[i].start) * 2; - } - - pdrive->thiscd.length = pdrive->thiscd.trk[pdrive->thiscd.ntracks].length; - - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "read_toc() successful\n"); - return 0; -} /* read_toc() */ - -/* - * wm_cd_status(pdrive) - * - * Return values: - * see wm_cdrom.h - * - * Updates variables. - */ -int wm_cd_status(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int mode = -1, tmp; - - if(!pdrive->proto.get_drive_status || - (tmp = pdrive->proto.get_drive_status(pdrive, pdrive->oldmode, &mode, - &pdrive->thiscd.cur_frame, - &pdrive->thiscd.curtrack, - &pdrive->thiscd.cur_index)) < 0) { - perror("WM get_drive_status"); - return -1; - } - - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, - "get_drive_status returns status %s, track %i, frame %i\n", - gen_status(mode), pdrive->thiscd.curtrack, pdrive->thiscd.cur_frame); - - if(WM_CDS_NO_DISC(pdrive->oldmode) && WM_CDS_DISC_READY(mode)) { - /* device changed */ - pdrive->thiscd.ntracks = 0; - - if(read_toc(pdrive) || 0 == pdrive->thiscd.ntracks) { - - mode = WM_CDM_NO_DISC; - } else /* refresh cdtext info */ - get_glob_cdtext(pdrive, 1); - - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, - "device status changed() from %s to %s\n", - gen_status(pdrive->oldmode), gen_status(mode)); - } - pdrive->oldmode = mode; - - /* - * it seems all driver have'nt state for stop - */ - if(WM_CDM_PAUSED == mode && 0 == pdrive->thiscd.cur_frame) { - mode = WM_CDM_STOPPED; - pdrive->thiscd.curtrack = 0; - } - - switch (mode) { - case WM_CDM_PLAYING: - case WM_CDM_PAUSED: - pdrive->thiscd.cur_pos_abs = pdrive->thiscd.cur_frame / 75; - /* search for right track */ - for(tmp = pdrive->thiscd.ntracks; - tmp > 1 && pdrive->thiscd.cur_frame < pdrive->thiscd.trk[CARRAY(tmp)].start; - tmp--) - ; - pdrive->thiscd.curtrack = tmp; - /* Fall through */ - - - case WM_CDM_UNKNOWN: - if (mode == WM_CDM_UNKNOWN) - { - mode = WM_CDM_NO_DISC; - } - /* Fall through */ - - case WM_CDM_STOPPED: -/*assert(thiscd.trk != NULL);*/ - if(pdrive->thiscd.curtrack >= 1 && pdrive->thiscd.curtrack <= pdrive->thiscd.ntracks) { - pdrive->thiscd.cur_pos_rel = (pdrive->thiscd.cur_frame - - pdrive->thiscd.trk[CARRAY(pdrive->thiscd.curtrack)].start) / 75; - if (pdrive->thiscd.cur_pos_rel < 0) - pdrive->thiscd.cur_pos_rel = -pdrive->thiscd.cur_pos_rel; - } - - if (pdrive->thiscd.cur_pos_abs < 0) - pdrive->thiscd.cur_pos_abs = pdrive->thiscd.cur_frame = 0; - - if (pdrive->thiscd.curtrack < 1) - pdrive->thiscd.curtracklen = pdrive->thiscd.length; - else - pdrive->thiscd.curtracklen = pdrive->thiscd.trk[CARRAY(pdrive->thiscd.curtrack)].length; - /* Fall through */ - - case WM_CDM_TRACK_DONE: - pdrive->thiscd.cur_cdmode = mode; - break; - case WM_CDM_FORWARD: - case WM_CDM_EJECTED: - pdrive->thiscd.cur_cdmode = mode; - break; - } - - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, - "wm_cd_status returns %s\n", gen_status(pdrive->thiscd.cur_cdmode)); - - return pdrive->thiscd.cur_cdmode; -} - -int wm_cd_getcurtrack(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - if(WM_CDS_NO_DISC(pdrive->thiscd.cur_cdmode)) - return 0; - return pdrive->thiscd.curtrack; -} - -int wm_cd_getcurtracklen(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - if(WM_CDS_NO_DISC(pdrive->thiscd.cur_cdmode)) - return 0; - - return pdrive->thiscd.curtracklen; -} - -int wm_cd_getcountoftracks(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - if(WM_CDS_NO_DISC(pdrive->thiscd.cur_cdmode)) - return 0; - - return pdrive->thiscd.ntracks; -} - -int wm_cd_gettracklen(void *p, int track) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - if (track < 1 || - track > pdrive->thiscd.ntracks || - pdrive->thiscd.trk == NULL) - return 0; - - return pdrive->thiscd.trk[CARRAY(track)].length; -} - -int wm_cd_gettrackstart(void *p, int track) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - if (track < 1 || - track > (pdrive->thiscd.ntracks+1) || - pdrive->thiscd.trk == NULL) - return 0; - - return pdrive->thiscd.trk[CARRAY(track)].start; -} - -int wm_cd_gettrackdata(void *p, int track) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - if (track < 1 || - track > pdrive->thiscd.ntracks || - pdrive->thiscd.trk == NULL) - return 0; - - return pdrive->thiscd.trk[CARRAY(track)].data; -} - -/* - * wm_cd_play(starttrack, pos, endtrack) - * - * Start playing the CD or jump to a new position. "pos" is in seconds, - * relative to start of track. - */ -int wm_cd_play(void *p, int start, int pos, int end) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int real_start, real_end, status; - int play_start, play_end; - - status = wm_cd_status(pdrive); - if(WM_CDS_NO_DISC(status) || pdrive->thiscd.ntracks < 1) - return -1; - - /* - * check ranges - */ - for(real_end = pdrive->thiscd.ntracks; - (pdrive->thiscd.trk[CARRAY(real_end)].data == DATATRACK); - real_end--) - ; - for(real_start = 1; - (pdrive->thiscd.trk[CARRAY(real_start)].data == DATATRACK); - real_start++) - ; - - if(end == WM_ENDTRACK) - end = real_end; - else if(end > real_end) - end = real_end; - - /* - * handle as overrun - */ - if(start < real_start) - start = real_start; - if(start > real_end) - start = real_end; - - /* - * Try to avoid mixed mode and CD-EXTRA data tracks - */ - if(start > end || pdrive->thiscd.trk[CARRAY(start)].data == DATATRACK) { - wm_cd_stop(pdrive); - return -1; - } - - play_start = pdrive->thiscd.trk[CARRAY(start)].start + pos * 75; - play_end = (end == pdrive->thiscd.ntracks) ? pdrive->thiscd.length * 75 : - pdrive->thiscd.trk[CARRAY(end)].start - 1; - - --play_end; - - if (play_start >= play_end) - play_start = play_end-1; - - if(pdrive->proto.play) - pdrive->proto.play(pdrive, play_start, play_end); - else - return -1; - - /* So we don't update the display with the old frame number */ - wm_cd_status(pdrive); - - return pdrive->thiscd.curtrack; -} - -/* - * wm_cd_pause() - * - * Pause the CD, if it's in play mode. If it's already paused, go back to - * play mode. - */ -int wm_cd_pause(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - static int paused_pos; - int status; - - status = wm_cd_status(pdrive); - if(WM_CDS_NO_DISC(status)) - return -1; - - if(WM_CDM_PLAYING == pdrive->thiscd.cur_cdmode) { - paused_pos = pdrive->thiscd.cur_pos_rel; - if(pdrive->proto.pause) - return pdrive->proto.pause(pdrive); - } else if(WM_CDM_PAUSED == status) { - if(pdrive->proto.resume) - return pdrive->proto.resume(pdrive); - else if(pdrive->proto.play) - return pdrive->proto.play(pdrive, pdrive->thiscd.cur_pos_rel, -1); - } - - return -1; -} /* wm_cd_pause() */ - -/* - * wm_cd_stop() - * - * Stop the CD if it's not already stopped. - */ -int wm_cd_stop(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int status; - - status = wm_cd_status(pdrive); - if(WM_CDS_NO_DISC(status)) - return -1; - - if (status != WM_CDM_STOPPED) { - - if(pdrive->proto.stop) - pdrive->proto.stop(pdrive); - - status = wm_cd_status(pdrive); - } - - return (status != WM_CDM_STOPPED); -} /* wm_cd_stop() */ - -/* - * Eject the current CD, if there is one, and set the mode to 5. - * - * Returns 0 on success, 1 if the CD couldn't be ejected, or 2 if the - * CD contains a mounted filesystem. - */ -int wm_cd_eject(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int err = -1; - - if(pdrive->proto.eject) - err = pdrive->proto.eject(pdrive); - - if (err < 0) { - if (err == -3) { - return 2; - } else { - return 1; - } - } - - return (WM_CDM_EJECTED == wm_cd_status(pdrive)) ? 0 : -1; -} - -int wm_cd_closetray(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int status, err = -1; - - status = wm_cd_status(pdrive); - if (status == WM_CDM_UNKNOWN || status == WM_CDM_NO_DISC) - return -1; - -#ifdef CAN_CLOSE - err = pdrive->proto.closetray(pdrive); - - if(err) { - /* do close/open */ - if(!pdrive->proto.close(pdrive)) { - wm_susleep( 1000 ); - err = pdrive->proto.open(pdrive); - wm_susleep( 1000 ); - } - } - -#else - err = 0; -#endif - - return (err ? 0 : ((wm_cd_status(pdrive) == 2) ? 1 : 0)); -} /* wm_cd_closetray() */ - -struct cdtext_info* wm_cd_get_cdtext(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int status; - - status = wm_cd_status(pdrive); - - if(WM_CDS_NO_DISC(status)) - return NULL; - - return get_glob_cdtext(pdrive, 0); -} - -int wm_cd_set_verbosity(int level) -{ - wm_lib_set_verbosity(level); - return wm_lib_get_verbosity(); -} - -/* - * volume is valid WM_VOLUME_MUTE <= vol <= WM_VOLUME_MAXIMAL, - * balance is valid WM_BALANCE_ALL_LEFTS <= balance <= WM_BALANCE_ALL_RIGHTS - */ - -int wm_cd_volume(void *p, int vol, int bal) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int left, right; - const int bal1 = (vol - WM_VOLUME_MUTE)/(WM_BALANCE_ALL_RIGHTS - WM_BALANCE_SYMMETRED); - -/* - * Set "left" and "right" to volume-slider values accounting for the - * balance setting. - * - */ - if(vol < WM_VOLUME_MUTE) - vol = WM_VOLUME_MUTE; - if(vol > WM_VOLUME_MAXIMAL) - vol = WM_VOLUME_MAXIMAL; - if(bal < WM_BALANCE_ALL_LEFTS) - bal = WM_BALANCE_ALL_LEFTS; - if(bal > WM_BALANCE_ALL_RIGHTS) - bal = WM_BALANCE_ALL_RIGHTS; - - left = vol - (bal * bal1); - right = vol + (bal * bal1); - - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calculate volume left %i, right %i\n", left, right); - - if (left > WM_VOLUME_MAXIMAL) - left = WM_VOLUME_MAXIMAL; - if (right > WM_VOLUME_MAXIMAL) - right = WM_VOLUME_MAXIMAL; - - if(pdrive->proto.scale_volume) - pdrive->proto.scale_volume(&left, &right); - - if(pdrive->proto.set_volume) - return pdrive->proto.set_volume(pdrive, left, right); - - return -1; -} /* cd_volume() */ - -int wm_cd_getvolume(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int left, right; - - if(!pdrive->proto.get_volume || - pdrive->proto.get_volume(pdrive, &left, &right) < 0 || left == -1) - return -1; - - if(pdrive->proto.unscale_volume) - pdrive->proto.unscale_volume(&left, &right); - - if (left < right) { - pdrive->thiscd.cd_cur_balance = (right - left) / 2; - if (pdrive->thiscd.cd_cur_balance > WM_BALANCE_ALL_RIGHTS) - pdrive->thiscd.cd_cur_balance = WM_BALANCE_ALL_RIGHTS; - return right; - } else if (left == right) { - pdrive->thiscd.cd_cur_balance = WM_BALANCE_SYMMETRED; - return left; - } else { - pdrive->thiscd.cd_cur_balance = (right - left) / 2; - if (pdrive->thiscd.cd_cur_balance < WM_BALANCE_ALL_LEFTS) - pdrive->thiscd.cd_cur_balance = WM_BALANCE_ALL_LEFTS; - return left; - } -} - -int wm_cd_getbalance(void *p) -{ - struct wm_drive *pdrive = (struct wm_drive *)p; - int left, right; - - if(!pdrive->proto.get_volume || - pdrive->proto.get_volume(pdrive, &left, &right) < 0 || left == -1) - return WM_BALANCE_SYMMETRED; - - if(pdrive->proto.unscale_volume) - pdrive->proto.unscale_volume(&left, &right); - - if (left < right) { - pdrive->thiscd.cd_cur_balance = (right - left) / 2; - if (pdrive->thiscd.cd_cur_balance > WM_BALANCE_ALL_RIGHTS) - pdrive->thiscd.cd_cur_balance = WM_BALANCE_ALL_RIGHTS; - } else if (left == right) { - pdrive->thiscd.cd_cur_balance = WM_BALANCE_SYMMETRED; - } else { - pdrive->thiscd.cd_cur_balance = (right - left) / 2; - if (pdrive->thiscd.cd_cur_balance < WM_BALANCE_ALL_LEFTS) - pdrive->thiscd.cd_cur_balance = WM_BALANCE_ALL_LEFTS; - } - return pdrive->thiscd.cd_cur_balance; -} - -static const char *gen_status(int status) -{ - static char tmp[250]; - - switch(status) { - case WM_CDM_TRACK_DONE: - return "WM_CDM_TRACK_DONE"; - case WM_CDM_PLAYING: - return "WM_CDM_PLAYING"; - case WM_CDM_FORWARD: - return "WM_CDM_FORWARD"; - case WM_CDM_PAUSED: - return "WM_CDM_PAUSED"; - case WM_CDM_STOPPED: - return "WM_CDM_STOPPED"; - case WM_CDM_EJECTED: - return "WM_CDM_EJECTED"; - case WM_CDM_DEVICECHANGED: - return "WM_CDM_DEVICECHANGED"; - case WM_CDM_NO_DISC: - return "WM_CDM_NO_DISC"; - case WM_CDM_UNKNOWN: - return "WM_CDM_UNKNOWN"; - case WM_CDM_CDDAERROR: - return "WM_CDM_CDDAERROR"; - case WM_CDM_CDDAACK: - return "WM_CDM_CDDAACK"; - case WM_CDM_LOADING: - return "WM_CDM_LOADING"; - case WM_CDM_BUFFERING: - return "WM_CDM_BUFFERING"; - default: - sprintf(tmp, "unexpected status %i", status); - return tmp; - } -} diff --git a/kcompactdisc/wmlib/cdtext.c b/kcompactdisc/wmlib/cdtext.c deleted file mode 100644 index 3a045be3..00000000 --- a/kcompactdisc/wmlib/cdtext.c +++ /dev/null @@ -1,426 +0,0 @@ -/*************************************************************************** - cdtext.c - description - ------------------- - begin : Mon Feb 12 2001 - copyright : (C) 2001,2003 by Alex Kern - email : alex.kern@gmx.de - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#ifdef libunicode - #include -#endif - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cdrom.h" -#include "include/wm_platform.h" -#include "include/wm_helpers.h" -#include "include/wm_cdtext.h" -#include "include/wm_scsi.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_MISC - -/* local prototypes */ -int free_cdtext_info_block(struct cdtext_info_block* cdtextinfoblock); -int free_cdtext_info(struct cdtext_info* cdtextinfo); -struct cdtext_info_block* malloc_cdtext_info_block(int count_of_tracks); -void get_data_from_cdtext_pack( - const struct cdtext_pack_data_header *pack, - cdtext_string *p_componente); - -struct cdtext_info wm_cdtext_info; - -int free_cdtext_info_block(struct cdtext_info_block* cdtextinfoblock) -{ - if(cdtextinfoblock) - { - if(cdtextinfoblock->name) - free(cdtextinfoblock->name); - if(cdtextinfoblock->performer) - free(cdtextinfoblock->performer); - if(cdtextinfoblock->songwriter) - free(cdtextinfoblock->songwriter); - if(cdtextinfoblock->composer) - free(cdtextinfoblock->composer); - if(cdtextinfoblock->arranger) - free(cdtextinfoblock->arranger); - if(cdtextinfoblock->message) - free(cdtextinfoblock->message); - if(cdtextinfoblock->UPC_EAN_ISRC_code) - free(cdtextinfoblock->UPC_EAN_ISRC_code); - - if(cdtextinfoblock->block_encoding_text) - free(cdtextinfoblock->block_encoding_text); - } - - return 0; -} - -int free_cdtext_info(struct cdtext_info* cdtextinfo) -{ - int i; - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT INFO: free_cdtext_info() called\n"); - - if(cdtextinfo) - { - for(i = 0; i < 8; i++) - { - if(cdtextinfo->blocks[i]) - { - free_cdtext_info_block(cdtextinfo->blocks[i]); - } - } - memset(cdtextinfo, 0, sizeof(struct cdtext_info)); - } - - return 0; -} - -struct cdtext_info_block* malloc_cdtext_info_block(int count_of_tracks) -{ - int memamount; - struct cdtext_info_block* lp_block; - - lp_block = malloc(sizeof(struct cdtext_info_block)); - if(!lp_block) - { - return (struct cdtext_info_block*)0; - } - memset(lp_block, 0, sizeof(struct cdtext_info_block)); - - memamount = count_of_tracks * sizeof(cdtext_string); - - lp_block->name = malloc(memamount); - if(!lp_block->name) - goto bail_out; - memset(lp_block->name, 0, memamount); - - lp_block->performer = malloc(memamount); - if(!lp_block->performer) - goto bail_out; - memset(lp_block->performer, 0, memamount); - - lp_block->songwriter = malloc(memamount); - if(!lp_block->songwriter) - goto bail_out; - memset(lp_block->songwriter, 0, memamount); - - lp_block->composer = malloc(memamount); - if(!lp_block->composer) - goto bail_out; - memset(lp_block->composer, 0, memamount); - - lp_block->arranger = malloc(memamount); - if(!lp_block->arranger) - goto bail_out; - memset(lp_block->arranger, 0, memamount); - - lp_block->message = malloc(memamount); - if(!lp_block->message) - goto bail_out; - memset(lp_block->message, 0, memamount); - - lp_block->UPC_EAN_ISRC_code = malloc(memamount); - if(!lp_block->UPC_EAN_ISRC_code) - goto bail_out; - memset(lp_block->UPC_EAN_ISRC_code, 0, memamount); - - return lp_block; - -bail_out: - free_cdtext_info_block(lp_block); - free(lp_block); - return 0; -} - -void get_data_from_cdtext_pack( - const struct cdtext_pack_data_header *pack, - cdtext_string *p_componente) -{ - - int arr = pack->header_field_id2_tracknumber; - int i; - int language_block; - int unicode; - - language_block = (pack->header_field_id4_block_no >> 4) & 0x07; - unicode = pack->header_field_id4_block_no & 0x80; - - if(!unicode) - { - for(i = 0; i < DATAFIELD_LENGHT_IN_PACK; i++) - { - if(pack->text_data_field[i] == 0x00) /* end marker */ - { - arr++; - } - else if(pack->text_data_field[i] == 0x09) /* repeat last marker */ - { - /* ASSERT(arr > 0) */ - strcat((char*)(p_componente[arr]), (char*)(p_componente[arr-1])); - arr++; - } - else - { - strncat((char*)(p_componente[arr]), (char*)(&(pack->text_data_field[i])), 1); - } - } - } -#ifdef libunicode - else /* doublebytes ;-) */ - { - for(i = 0; i < DATAFIELD_LENGHT_IN_PACK; i += 2) - { - if((Uchar)(pack->text_data_field[i]) == 0x0000) /* end marker */ - { - arr++; - } - else if((Uchar)(pack->text_data_field[i]) == 0x0909) /* repeat last marker */ - { - /* ASSERT(arr > 0) */ - strcat((char*)(p_componente[arr]), (char*)(p_componente[arr-1])); - arr++; - } - else - { - strncat((char*)(p_componente[arr]), u_uc_to_utf8((Uchar*)(&(pack->text_data_field[i]))), 1); - } - } - } -#else - else { - wm_lib_message(WM_MSG_LEVEL_ERROR | WM_MSG_CLASS, "cannot handle unicode"); - } -#endif -} - -struct cdtext_info *get_glob_cdtext(struct wm_drive *d, int redo) -{ - /* alloc cdtext_info */ - - unsigned char *buffer; - int buffer_length; - int ret; - int i; - struct cdtext_pack_data_header *pack, *pack_previous; - cdtext_string *p_componente; - struct cdtext_info_block *lp_block; - - if(!redo && wm_cdtext_info.valid) { - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, "CDTEXT DEBUG: recycle cdtext\n"); - return &wm_cdtext_info; - } else { - free_cdtext_info(&wm_cdtext_info); - } - - lp_block = 0; - p_componente = 0; - buffer = 0; - buffer_length = 0; - - ret = wm_scsi_get_cdtext(d, &buffer, &buffer_length); - if(!ret) - { - if(!d->proto.get_trackcount || d->proto.get_trackcount(d, &wm_cdtext_info.count_of_entries) < 0) - wm_cdtext_info.count_of_entries = 1; - else - wm_cdtext_info.count_of_entries++; - - i = 0; - - pack = 0; /* NULL pointer*/ - while(i < buffer_length) - { - pack_previous = pack; - pack = (struct cdtext_pack_data_header*)(buffer+i); - /* to implement: check_crc(pack); */ - - /* only for valid packs */ - if(pack->header_field_id1_typ_of_pack >= 0x80 && pack->header_field_id1_typ_of_pack < 0x90) - { - int code, j; - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT DEBUG: valid packet at 0x%08X: 0x %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", - i, - pack->header_field_id1_typ_of_pack, - pack->header_field_id2_tracknumber, - pack->header_field_id3_sequence, - pack->header_field_id4_block_no, - pack->text_data_field[0], - pack->text_data_field[1], - pack->text_data_field[2], - pack->text_data_field[3], - pack->text_data_field[4], - pack->text_data_field[5], - pack->text_data_field[6], - pack->text_data_field[7], - pack->text_data_field[8], - pack->text_data_field[9], - pack->text_data_field[10], - pack->text_data_field[11], - pack->crc_byte1, - pack->crc_byte2); - wm_cdtext_info.count_of_valid_packs++; - - code = (pack->header_field_id4_block_no >> 4) & 0x07; - if(0 == lp_block || lp_block->block_code != code) /* find or create one new block */ - { - lp_block = 0; - for(j = 0; j < MAX_LANGUAGE_BLOCKS && wm_cdtext_info.blocks[j] != 0 && 0 == lp_block; j++) - { - if(wm_cdtext_info.blocks[j]->block_code == code) - { - lp_block = wm_cdtext_info.blocks[j]; - } - } - - if(MAX_LANGUAGE_BLOCKS <= j) - { - free_cdtext_info(&wm_cdtext_info); - wm_lib_message(WM_MSG_LEVEL_ERROR | WM_MSG_CLASS, - "CDTEXT ERROR: more as 8 languageblocks defined\n"); - return NULL; - } - - if(0 == lp_block) - { - /* make next new block */ - lp_block = malloc_cdtext_info_block(wm_cdtext_info.count_of_entries); - if(0 == lp_block) - { - wm_lib_message(WM_MSG_LEVEL_ERROR | WM_MSG_CLASS, - "CDTEXT ERROR: out of memory, cannot create a new language block\n"); - free_cdtext_info(&wm_cdtext_info); - return NULL /*ENOMEM*/; - } - else - { - wm_cdtext_info.blocks[j] = lp_block; - wm_cdtext_info.blocks[j]->block_code = code; - wm_cdtext_info.blocks[j]->block_unicode = pack->header_field_id4_block_no & 0x80; - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT INFO: created a new language block; code %i, %s characters\n", code, lp_block->block_unicode?"doublebyte":"singlebyte"); -/* - unsigned char block_encoding; not jet! - cdtext_string* block_encoding_text; -*/ - } - } - } - } - - switch(pack->header_field_id1_typ_of_pack) - { - case 0x80: - p_componente = (lp_block->name); - get_data_from_cdtext_pack(pack, p_componente); - break; - case 0x81: - p_componente = (lp_block->performer); - get_data_from_cdtext_pack(pack, p_componente); - break; - case 0x82: - p_componente = (lp_block->songwriter); - get_data_from_cdtext_pack(pack, p_componente); - break; - case 0x83: - p_componente = (lp_block->composer); - get_data_from_cdtext_pack(pack, p_componente); - break; - case 0x84: - p_componente = (lp_block->arranger); - get_data_from_cdtext_pack(pack, p_componente); - break; - case 0x85: - p_componente = (lp_block->message); - get_data_from_cdtext_pack(pack, p_componente); - break; - case 0x86: - memcpy((char*)(lp_block->binary_disc_identification_info), - (char*)(pack->text_data_field), DATAFIELD_LENGHT_IN_PACK); - break; - case 0x87: - memcpy((char*)(lp_block->binary_genreidentification_info), - (char*)(pack->text_data_field), DATAFIELD_LENGHT_IN_PACK); - break; - case 0x88: - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT INFO: PACK with code 0x88 (TOC)\n"); - break; - case 0x89: - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT INFO: PACK with code 0x89 (second TOC)\n"); - break; - case 0x8A: - case 0x8B: - case 0x8C: - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT INFO: PACK with code 0x%02X (reserved)\n", pack->header_field_id1_typ_of_pack); - break; - case 0x8D: - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT INFO: PACK with code 0x8D (for content provider only)\n"); - break; - case 0x8E: - p_componente = (lp_block->UPC_EAN_ISRC_code); - get_data_from_cdtext_pack(pack, p_componente); - break; - case 0x8F: - memcpy((char*)(lp_block->binary_size_information), - (char*)(pack->text_data_field), DATAFIELD_LENGHT_IN_PACK); - break; - default: - wm_lib_message(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS, - "CDTEXT ERROR: invalid packet at 0x%08X: 0x %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", - i, - pack->header_field_id1_typ_of_pack, - pack->header_field_id2_tracknumber, - pack->header_field_id3_sequence, - pack->header_field_id4_block_no, - pack->text_data_field[0], - pack->text_data_field[1], - pack->text_data_field[2], - pack->text_data_field[3], - pack->text_data_field[4], - pack->text_data_field[5], - pack->text_data_field[6], - pack->text_data_field[7], - pack->text_data_field[8], - pack->text_data_field[9], - pack->text_data_field[10], - pack->text_data_field[11], - pack->crc_byte1, - pack->crc_byte2); - wm_cdtext_info.count_of_invalid_packs++; - } - i += sizeof(struct cdtext_pack_data_header); - } /* while */ - } - - if(0 == ret && wm_cdtext_info.count_of_valid_packs > 0) - wm_cdtext_info.valid = 1; - - return &wm_cdtext_info; -} - -void free_cdtext(void) -{ - if (wm_cdtext_info.valid) - free_cdtext_info(&wm_cdtext_info); -} diff --git a/kcompactdisc/wmlib/drv_sony.c b/kcompactdisc/wmlib/drv_sony.c deleted file mode 100644 index 7d6a33ab..00000000 --- a/kcompactdisc/wmlib/drv_sony.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm (original author) - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Vendor-specific drive control routines for Sony CDU-8012 series. - */ - -#include -#include -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_scsi.h" - -#define PAGE_AUDIO 0x0e - -static int max_volume = 255; - -/* - * On the Sony CDU-8012 drive, the amount of sound coming out the jack - * increases much faster toward the top end of the volume scale than it - * does at the bottom. To make up for this, we make the volume scale look - * sort of logarithmic (actually an upside-down inverse square curve) so - * that the volume value passed to the drive changes less and less as you - * approach the maximum slider setting. Additionally, only the top half - * of the volume scale is valid; the bottom half is all silent. The actual - * formula looks like - * - * max^2 - (max - vol)^2 max - * v = --------------------- + --- - * max * 2 2 - * - * Where "max" is the maximum value of the volume scale, usually 100. - */ -static int scale_volume(int vol, int max) -{ - vol = (max*max - (max - vol) * (max - vol)) / max; - return ((vol + max) / 2); -} - -/* - * Given a value between min_volume and max_volume, return the standard-scale - * volume value needed to achieve that hardware value. - * - * Rather than perform floating-point calculations to reverse the above - * formula, we simply do a binary search of scale_volume()'s return values. - */ -static int unscale_volume(int vol, int max) -{ - int ret_vol = 0, top = max, bot = 0, scaled = 0; - - vol = (vol * 100 + (max_volume - 1)) / max_volume; - - while (bot <= top) - { - ret_vol = (top + bot) / 2; - scaled = scale_volume(ret_vol, max); - if (vol <= scaled) - top = ret_vol - 1; - else - bot = ret_vol + 1; - } - - /* Might have looked down too far for repeated scaled values */ - if (vol < scaled) - ret_vol++; - - if (ret_vol < 0) - ret_vol = 0; - else if (ret_vol > max) - ret_vol = max; - - return ret_vol; -} - -/* - * Set the volume using the wacky scale outlined above. The Sony drive - * responds to the standard set-volume command. - * - * Get the volume. Sun's CD-ROM driver doesn't support this operation, even - * though their drive does. Dumb. - */ -static int sony_get_volume( struct wm_drive *d, int *left, int *right ) -{ - unsigned char mode[16]; - - /* Get the current audio parameters first. */ - if (wm_scsi_mode_sense(d, PAGE_AUDIO, mode)) - return -1; - - *left = mode[9]; - *right = mode[11]; - - return 0; -} - -static int sony_scale_volume(int *left, int *right) -{ - *left = scale_volume(*left, 100); - *right = scale_volume(*right, 100); - - return 0; -} - -static int sony_unscale_volume(int *left, int *right) -{ - *left = unscale_volume(*left, 100); - *right = unscale_volume(*right, 100); - - return 0; -} - -int sony_fixup(struct wm_drive *d) -{ - d->proto.get_volume = sony_get_volume; - d->proto.scale_volume = sony_scale_volume; - d->proto.unscale_volume = sony_unscale_volume; - - return 0; -} diff --git a/kcompactdisc/wmlib/drv_toshiba.c b/kcompactdisc/wmlib/drv_toshiba.c deleted file mode 100644 index 78323c2f..00000000 --- a/kcompactdisc/wmlib/drv_toshiba.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm (original author) - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Vendor-specific drive control routines for Toshiba XM-3401 series. - */ - -#include -#include -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_scsi.h" - -#define SCMD_TOSH_EJECT 0xc4 - -/* local prototypes */ -/* static int min_volume = 0, max_volume = 255; */ - -/* - * Undo the transformation above using a binary search (so no floating-point - * math is required.) - */ -static int unscale_volume(int cd_vol, int max) -{ - int vol = 0, top = max, bot = 0, scaled = 0; - - /*cd_vol = (cd_vol * 100 + (max_volume - 1)) / max_volume;*/ - - while (bot <= top) - { - vol = (top + bot) / 2; - scaled = (vol * vol) / max; - if (cd_vol <= scaled) - top = vol - 1; - else - bot = vol + 1; - } - - /* Might have looked down too far for repeated scaled values */ - if (cd_vol < scaled) - vol++; - - if (vol < 0) - vol = 0; - else if (vol > max) - vol = max; - - return (vol); -} - -/* - * Send the Toshiba code to eject the CD. - */ -static int tosh_eject(struct wm_drive *d) -{ - return sendscsi(d, NULL, 0, 0, SCMD_TOSH_EJECT, 1, 0,0,0,0,0,0,0,0,0,0); -} - -/* - * Set the volume. The low end of the scale is more sensitive than the high - * end, so make up for that by transforming the volume parameters to a square - * curve. - */ -static int tosh_scale_volume(int *left, int *right) -{ - *left = (*left * *left * *left) / 10000; - *right = (*right * *right * *right) / 10000; - - return 0; -} - -static int tosh_unscale_volume(int *left, int *right) -{ - *left = unscale_volume(*left, 100); - *right = unscale_volume(*right, 100); - - return 0; -} - -int toshiba_fixup(struct wm_drive *d) -{ - d->proto.eject = tosh_eject; - d->proto.scale_volume = tosh_scale_volume; - d->proto.unscale_volume = tosh_unscale_volume; - - return 0; -} diff --git a/kcompactdisc/wmlib/include/wm_cdda.h b/kcompactdisc/wmlib/include/wm_cdda.h deleted file mode 100644 index 56033118..00000000 --- a/kcompactdisc/wmlib/include/wm_cdda.h +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef WM_CDDA_H -#define WM_CDDA_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "wm_cdrom.h" -#include "wm_config.h" -#include "wm_struct.h" -/* - * cdda_block status codes. - */ - -/* - * Enable or disable CDDA building depending on platform capabilities, and - * determine endianness based on architecture. (Gross!) - * - * For header-comfort, the macros LITTLE_ENDIAN and BIG_ENDIAN had to be - * renamed. At least Linux does have bytesex.h and endian.h for easy - * byte-order examination. - */ - -#ifdef HAVE_MACHINE_ENDIAN_H - #include - #if BYTE_ORDER == LITTLE_ENDIAN - #define WM_LITTLE_ENDIAN 1 - #define WM_BIG_ENDIAN 0 - #else - #define WM_LITTLE_ENDIAN 0 - #define WM_BIG_ENDIAN 1 - #endif -#elif defined(__sun) || defined(sun) -# ifdef SYSV -# include -# include -# ifndef CDROMCDDA -# error what to do? -# endif -# ifdef i386 -# define WM_LITTLE_ENDIAN 1 -# define WM_BIG_ENDIAN 0 -# else -# define WM_BIG_ENDIAN 1 -# define WM_LITTLE_ENDIAN 0 -# endif -# endif - -/* Linux only allows definition of endianness, because there's no - * standard interface for CDROM CDDA functions that aren't available - * if there is no support. - */ -#elif defined(__linux__) -/*# include */ -# include -/* - * XXX could this be a problem? The results are only 0 and 1 because - * of the ! operator. How about other linux compilers than gcc ? - */ -# define WM_LITTLE_ENDIAN !(__BYTE_ORDER - __LITTLE_ENDIAN) -# define WM_BIG_ENDIAN !(__BYTE_ORDER - __BIG_ENDIAN) -#elif defined WORDS_BIGENDIAN - #define WM_LITTLE_ENDIAN 0 - #define WM_BIG_ENDIAN 1 -#else - #define WM_LITTLE_ENDIAN 1 - #define WM_BIG_ENDIAN 0 -#endif - -/* - * The following code shouldn't take effect now. - * In 1998, the WorkMan platforms don't support __PDP_ENDIAN - * architectures. - * - */ - -#if !defined(WM_LITTLE_ENDIAN) -# if !defined(WM_BIG_ENDIAN) -# error yet unsupported architecture - foo bar this is to stop the compiler. -# endif -#endif - -/* - * Information about a particular block of CDDA data. - */ -struct cdda_block { - unsigned char status; - unsigned char track; - unsigned char index; - unsigned char reserved; - - int frame; - char *buf; - long buflen; -}; - -struct cdda_device { - int fd; - int cdda_slave; - const char *devname; - - unsigned char status; - unsigned char track; - unsigned char index; - unsigned char command; - - int frame; - int frames_at_once; - - /* Average volume levels, for level meters */ - unsigned char lev_chan0; - unsigned char lev_chan1; - - /* Current volume setting (0-255) */ - unsigned char volume; - - /* Current balance setting (0-255, 128 = balanced) */ - unsigned char balance; - - struct cdda_block *blocks; - int numblocks; - - struct cdda_proto *proto; -}; - -#endif /* WM_CDDA_H */ diff --git a/kcompactdisc/wmlib/include/wm_cddb.h b/kcompactdisc/wmlib/include/wm_cddb.h deleted file mode 100644 index 292896ff..00000000 --- a/kcompactdisc/wmlib/include/wm_cddb.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WM_CDDB_H -#define WM_CDDB_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -unsigned long cddb_discid(struct wm_drive *); - -#endif /* WM_CDDB_H */ diff --git a/kcompactdisc/wmlib/include/wm_cdinfo.h b/kcompactdisc/wmlib/include/wm_cdinfo.h deleted file mode 100644 index a001bb80..00000000 --- a/kcompactdisc/wmlib/include/wm_cdinfo.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef WM_CDINFO_H -#define WM_CDINFO_H -/* - * $Id: wm_cdinfo.h 486075 2005-12-06 18:29:02Z thiago $ - * - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm (original author) - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Prototypes from cdinfo.c - * - * This is just one more step to a more modular and understandable code. - */ - -#include "wm_struct.h" -extern char *cur_trackname; /* Take a guess */ -extern int cur_index; /* Current index mark */ -extern int cur_frame; /* Current frame number */ -extern struct wm_play *playlist; /* = NULL */ - -/*extern int cur_track;*/ /* Current track number, starting at 1 */ -extern char *cur_artist; /* Name of current CD's artist */ -extern char cur_avoid; /* Avoid flag */ -extern char cur_contd; /* Continued flag */ -extern char *cur_cdname; /* Album name */ -extern int cur_nsections; /* Number of sections currently defined */ -extern int exit_on_eject; -extern int cur_pos_abs; -extern int cur_pos_rel; -extern int cur_cdlen; - -extern int cur_ntracks; -extern int cur_lasttrack; -extern int cur_firsttrack; -extern int cur_listno; -extern int cur_stopmode; - -void wipe_cdinfo( void ); -void play_next_entry( int forward ); -void make_playlist( int playmode, int starttrack ); -int get_autoplay( void ); -int get_playmode( void ); -void pl_find_track( int track ); -void play_prev_track( int forward ); -void play_next_track( int forward ); -int tracklen( int num ); -int get_default_volume( int track ); -int split_trackinfo( int pos ); -int remove_trackinfo( int num ); -void freeup( char **x ); -int get_runtime( void ); -const char *trackname( int num ); -void stash_cdinfo( char *artist, char *cdname, int autoplay, int playmode ); -void stash_trkinfo( int track, char *songname, int contd, int avoid ); -int get_avoid( int num ); -int get_contd( int num ); -void default_volume( int track, int vol ); -char *listentry( int num ); - -#endif /* WM_CDINFO_H */ diff --git a/kcompactdisc/wmlib/include/wm_cdrom.h b/kcompactdisc/wmlib/include/wm_cdrom.h deleted file mode 100644 index 03a53cb9..00000000 --- a/kcompactdisc/wmlib/include/wm_cdrom.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef WM_CDROM_H -#define WM_CDROM_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Prototypes from cdrom.c - * - * This is just one more step to a more modular and understandable code. - */ - -#include "wm_platform.h" - -#define WM_CDIN 0 -#define WM_CDDA 1 - -#define WM_ENDTRACK 0 - -#define WM_BALANCE_SYMMETRED 0 -#define WM_BALANCE_ALL_LEFTS -10 -#define WM_BALANCE_ALL_RIGHTS 10 - -#define WM_VOLUME_MUTE 0 -#define WM_VOLUME_MAXIMAL 100 - -/* - * for valid values see wm_helpers.h - */ -int wm_cd_set_verbosity(int); -const char *wm_drive_default_device(); - -int wm_cd_init(const char *cd_device, const char *soundsystem, - const char *sounddevice, const char *ctldevice, void **); -int wm_cd_destroy(void *); - -int wm_cd_status(void *); -int wm_cd_getcurtrack(void *); -int wm_cd_getcurtracklen(void *); -int wm_get_cur_pos_rel(void *); -int wm_get_cur_pos_abs(void *); - -int wm_cd_getcountoftracks(void *); -int wm_cd_gettracklen(void *, int track); -int wm_cd_gettrackstart(void *, int track); -int wm_cd_gettrackdata(void *, int track); - -int wm_cd_play(void *, int start, int pos, int end); -int wm_cd_pause(void *); -int wm_cd_stop(void *); -int wm_cd_eject(void *); -int wm_cd_closetray(void *); - - - -const char *wm_drive_vendor(void *); -const char *wm_drive_model(void *); -const char *wm_drive_revision(void *); -unsigned long wm_cddb_discid(void *); - -/* - * volume is valid WM_VOLUME_MUTE <= vol <= WM_VOLUME_MAXIMAL, - * balance is valid WM_BALANCE_ALL_LEFTS <= balance <= WM_BALANCE_ALL_RIGHTS - */ -int wm_cd_volume(void *, int volume, int balance); - -/* - * please notice, that more OSs don't allow to read balance and volume - * in this case you get -1 for volume and WM_BALANCE_SYMMETRED for balance - */ -int wm_cd_getvolume(void *); -int wm_cd_getbalance(void *); - -#endif /* WM_CDROM_H */ diff --git a/kcompactdisc/wmlib/include/wm_cdtext.h b/kcompactdisc/wmlib/include/wm_cdtext.h deleted file mode 100644 index bf97caa6..00000000 --- a/kcompactdisc/wmlib/include/wm_cdtext.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef WM_CDTEXT_H -#define WM_CDTEXT_H - -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * cdtext base structure and defines - */ - -#define MAX_LENGHT_OF_CDTEXT_STRING 162 /* max 160 bytes + 2 * 0x00 by UNICODES */ -#define DATAFIELD_LENGHT_IN_PACK 12 -#define MAX_LANGUAGE_BLOCKS 8 - -struct cdtext_pack_data_header { - unsigned char header_field_id1_typ_of_pack; - unsigned char header_field_id2_tracknumber; - unsigned char header_field_id3_sequence; - unsigned char header_field_id4_block_no; - unsigned char text_data_field[DATAFIELD_LENGHT_IN_PACK]; - unsigned char crc_byte1; - unsigned char crc_byte2; -}; - -typedef unsigned char cdtext_string[MAX_LENGHT_OF_CDTEXT_STRING]; - -/* meke it more generic - it can be up to 8 blocks with different encoding */ - -struct cdtext_info_block { - /* management */ - unsigned char block_code; - unsigned char block_unicode; /* 0 - single chars, 1 - doublebytes */ - unsigned char block_encoding; /* orange book -? */ - cdtext_string* block_encoding_text; - - /* variable part of cdtext */ - cdtext_string* name; - cdtext_string* performer; - cdtext_string* songwriter; - cdtext_string* composer; - cdtext_string* arranger; - cdtext_string* message; - cdtext_string* UPC_EAN_ISRC_code; - - /* fix part of cdtext */ - unsigned char binary_disc_identification_info[DATAFIELD_LENGHT_IN_PACK]; - unsigned char binary_genreidentification_info[DATAFIELD_LENGHT_IN_PACK]; - unsigned char binary_size_information[DATAFIELD_LENGHT_IN_PACK]; -}; - -struct cdtext_info { - /* somethimes i get hunderts of bytes, without anyone valid pack - my CDU-561 for example */ - int count_of_entries; /* one more because album need one too */ - int count_of_valid_packs; - int count_of_invalid_packs; - int valid; - - struct cdtext_info_block *blocks[MAX_LANGUAGE_BLOCKS]; -}; - -#ifndef IGNORE_FEATURE_LIST - -struct feature_list_header { - unsigned char lenght_msb; - unsigned char lenght_1sb; - unsigned char lenght_2sb; - unsigned char lenght_lsb; - unsigned char reserved1; - unsigned char reserved2; - unsigned char profile_msb; - unsigned char profile_lsb; -}; - -struct feature_descriptor_cdread { - unsigned char feature_code_msb; - unsigned char feature_code_lsb; - unsigned char settings; - unsigned char add_lenght; - unsigned char add_settings; - unsigned char reserved1; - unsigned char reserved2; - unsigned char reserved3; -}; - -#endif /* IGNORE_FEATURE_LIST */ - -struct cdtext_info* wm_cd_get_cdtext(void *p); - -#endif /* WM_CDTEXT_H */ diff --git a/kcompactdisc/wmlib/include/wm_config.h b/kcompactdisc/wmlib/include/wm_config.h deleted file mode 100644 index b1e47b8a..00000000 --- a/kcompactdisc/wmlib/include/wm_config.h +++ /dev/null @@ -1,377 +0,0 @@ -#ifndef WM_CONFIG_H -#define WM_CONFIG_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - ********************************************************************** - * - * This file consists of several parts. First, there's a generic, - * platform independent part. Set needed options there. - * The following parts are platform dependent. You may search for the - * names listed below and then set your OS specific options there. - * Don't be surprised, if there are no options for your OS. They aren't - * needed in any case. - * - * The default values should produce a functional WorkMan on every - * platform. - * - ********************* - * Current platforms: - ********************* - * BSD386 - * FreeBSD - * HP-UX - * Irix (SGI) - * Linux - * News (Sony NewsOS) - * OpenBSD - * OSF1 - * Sun (SunOS/Solaris, Sparc or x86) - * SVR4 - * Ultrix - * AIX - * - * The above order corresponds with the order of the platform specific - * options below. - */ - -/****************************************************************** - * generic options - ****************************************************************** - ** ** *** **** ** **** ** * ** ** ** * ** - * * * *** **** * * *** * ** ** *** * * * * * * ** - * * *** **** ** *** ** ** ** * * ** * * ** - * * * *** **** **** *** * ** ** *** * * * * *** ** - * * * * ** **** * * ** ** **** ** * * *** ** - ******************************************************************/ - -/* - * If your CD-ROM drive closes its tray if the device is opened, then - * the next define can make WorkMans "Eject" button an "open/close" - * button. If it disturbs you, just comment it out. - * - * ### this is preliminary. It may have no effect for you ### - */ -#define CAN_CLOSE 1 - -/* - * Define the following if you want the balance slider to - * decrease one channel's volume while increasing the other's - */ -/* #define SYMETRIC_BALANCE 1 */ - - -/****************************************************************** - * BSD386 - ****************************************************************** - *** **** *** ******* ** **** **** ************ - *** ** ** ****** * ***** ****** ** ** ** *************** - *** ****** **** ** *** ***** ***** *** ************ - *** ** ****** ** * *** ******** ** ** ** ** *********** - *** **** *** *** ****** **** **** ************ - ******************************************************************/ -#if defined(__bsdi__) || defined(__bsdi) - -/* - * This lets you use the SoundBlaster Mixer on BSD/386 - */ -#define SOUNDBLASTER 1 - -#define DEFAULT_CD_DEVICE "/dev/rsr2c" - -#endif /* __bsdi__ (BSD/386) */ - -/****************************************************************** - * FreeBSD - ****************************************************************** - *** ** *** ** ** **** *** *********** - *** ****** ** ** ****** ****** ** ** ****** * ********** - *** **** *** **** **** ****** **** ** ********* - *** ****** ** ** ****** ****** ** ****** ** * ********** - *** ****** ** ** ** ** **** *** *********** - ******************************************************************/ -#if defined(__FreeBSD__) || defined(__FreeBSD) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) - -#if (defined(__FreeBSD_version) && __FreeBSD_version >= 500100) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) -#define DEFAULT_CD_DEVICE "/dev/acd0" -#else -#define DEFAULT_CD_DEVICE "/dev/acd0c" -#endif - -#endif /* freebsd */ - -#if defined(__OpenBSD__) -#define DEFAULT_CD_DEVICE find_cdrom() -#endif - -/****************************************************************** - * NetBSD - ****************************************************************** - *** *** ** ** ** **** *** ***************** - *** ** ** ******** **** ** ** ****** * **************** - *** * * ** ****** **** ****** **** ** *************** - *** ** ** ******** **** ** ****** ** * **************** - *** *** ** **** **** **** *** ***************** - ******************************************************************/ -#if defined(__NetBSD__) || defined(__NetBSD) - -#if defined(__i386__) - #define DEFAULT_CD_DEVICE "/dev/rcd0d" -#else - #define DEFAULT_CD_DEVICE "/dev/rcd0c" -#endif - -#endif /* netbsd */ - -/****************************************************************** - * HP-UX - ****************************************************************** - *** ** ** ********* ** ** ** *************************** - *** ** ** ** ******** ** *** **************************** - *** ** *** ** ** **** ***************************** - *** ** ** ************ ** *** **************************** - *** ** ** ************* *** ** *************************** - ******************************************************************/ -#if defined(hpux) || defined (__hpux) - -#define DEFAULT_CD_DEVICE "/dev/rscsi" - -#endif /* hpux */ - -/****************************************************************** - * Irix - ****************************************************************** - *** ** *** ** ** ********************************* - ***** **** ** **** ***** ********************************** - ***** **** ***** ****** *********************************** - ***** **** ** **** ***** ********************************** - *** ** ** ** ** ** ********************************* - ******************************************************************/ -#if defined(sgi) || defined(__sgi) - -#define DEFAULT_CD_DEVICE "/dev/scsi/sc0d6l0" - -#endif /* sgi IRIX */ - -/****************************************************************** - * Linux - ****************************************************************** - *** ****** ** *** ** ** ** ** *********************** - *** ******** **** ** ** ** *** ************************ - *** ******** **** * * ** ** **** ************************* - *** ******** **** ** ** ** *** ************************ - *** ** ** *** *** *** ** *********************** - ******************************************************************/ -#if defined(__linux__) - -/* - * Uncomment the following line to have WorkMan send SCSI commands - * directly to the CD-ROM drive. If you have a SCSI drive you - * probably want this, but it will cause WorkMan to not work on IDE - * drives. - */ -/*#define LINUX_SCSI_PASSTHROUGH 1*/ - -/* - * Which device should be opened by WorkMan at default? - */ -#define DEFAULT_CD_DEVICE "/dev/cdrom" -#define WMLIB_CDDA_BUILD 1 -#define COUNT_CDDA_BLOCKS 10 - -/* - * Uncomment the following if you use the sbpcd or mcdx device driver. - * It shouldn't hurt if you use it on other devices. It'll be nice to - * hear from non-sbpcd (or mcdx) users if this is right. - */ -/*#define SBPCD_HACK 1*/ - -/* - * Linux Soundcard support - * Disabled by default, because some people rely on it - */ -/* #define OSS_SUPPORT 1 */ - -/* - * This has nothing to do with the above. - */ - -/* #define CURVED_VOLUME */ - -/* - * Uncomment the following if you want to try out a better responding - * WorkMan, especially with IDE drives. This may work with non-IDE - * drives as well. But it may be possible, that it doesn't work at all. - * If your drive/driver combination cannot handle the faster access, - * the driver will usually hang and you have to reboot your machine. - */ -/* #define FAST_IDE 1 */ - -/* - * There are two alternative ways of checking a device containing a - * mounted filesystem. Define BSD_MOUNTTEST for the test using - * getmntent(). Undefine it for using the SVR4 ustat(). - * I built in the choice, because it's not clear which method should - * be used in Linux. The ustat manpage tells us since 1995, that - * fstat() should be used, but I'm too dumb to do so. - */ - -#define BSD_MOUNTTEST - -#endif /* __linux */ - -/****************************************************************** - * Sony NewsOS - ****************************************************************** - *** *** ** ** ***** *** ***************************** - *** ** ** ****** ***** ** ******************************** - *** * * ** **** ** ** **** ****************************** - *** ** ** ****** * * ****** **************************** - *** *** ** ** * *** ***************************** - ******************************************************************/ -#if defined(__sony_news) || defined(sony_news) - -#define DEFAULT_CD_DEVICE "/dev/rsd/b0i6u0p2\0" - -#endif - -/****************************************************************** - * OSF1 - ****************************************************************** - **** **** *** *** *** ******************************* - *** ** ** ****** ****** ** ******************************* - *** ** **** **** *** ***** ******************************* - *** ** ****** ** **** ****** ******************************* - **** **** *** *** ***** ***************************** - ******************************************************************/ -#if defined(__osf__) || defined(__osf) - -#define DEFAULT_CD_DEVICE find_cdrom() - -#endif - -/****************************************************************** - * SunOS/Solaris - ****************************************************************** - **** *** ** ** *** *************************************** - *** ****** ** ** ** *************************************** - ***** **** ** ** * * *************************************** - ******* ** ** ** ** *************************************** - **** **** *** *** *************************************** - ******************************************************************/ -#if defined(sun) || defined(__sun) - -/* - * Define the following for Solaris 2.x - * If you don't want WorkMan to try to activate the SPARCstation 5 - * internal audio input so you get sound from the workstation, comment - * out the CODEC define. - */ - -#define SYSV 1 -#define CODEC 1 -#define DEFAULT_CD_DEVICE find_cdrom() -#define WMLIB_CDDA_BUILD 1 -#define COUNT_CDDA_BLOCKS 15 - -/* - * set the following to "SUNW,CS4231" for Sun and to "SUNW,sb16" - * for PC (with SoundBlaster 16) running Solaris x86 - * (only important if you define CODEC above) - */ -#define SUN_AUD_DEV "SUNW,CS4231" -/*#define SUN_AUD_DEV "SUNW,sbpro"*/ - - -#endif - -/****************************************************************** - * SVR4 - ****************************************************************** - **** *** **** ** *** * ******************************** - *** ****** **** ** ** ** * ******************************** - ***** ***** ** *** *** ******************************* - ******* *** ** *** ** ***** ******************************** - **** ***** **** ** ***** ******************************** - ******************************************************************/ -#if (defined(SVR4) || defined(__SVR4)) && !defined(sun) && !defined(__sun) && !defined(sony_news) && !defined(__sony_news) - -#define DEFAULT_CD_DEVICE "/dev/rcdrom/cd0" - -#endif - -/****************************************************************** - * Ultrix - ****************************************************************** - *** ** ** ***** ** *** ** ** ****************** - *** ** ** ******* **** ** **** ***** ******************* - *** ** ** ******* **** ***** ****** ******************** - *** ** ** ******* **** ** **** ***** ******************* - **** *** *** **** ** ** ** ** ****************** - ******************************************************************/ -#if defined(ultrix) || defined(__ultrix) - -#define DEFAULT_CD_DEVICE find_cdrom() - -#endif - -/****************************************************************** - * IBM AIX - ****************************************************************** - **** *** ** ** ***************************************** - *** ** **** ***** ****************************************** - *** **** ****** ******************************************* - *** ** **** ***** ****************************************** - *** ** ** ** ** ***************************************** - ******************************************************************/ -#if defined(AIXV3) || defined(__AIXV3) - -#define DEFAULT_CD_DEVICE "/dev/cd0" - -#endif /* IBM AIX */ - -/******************************************************************/ - -#include - -#define DEBUG -#ifdef DEBUG - #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) - #define DEBUGLOG(...) fprintf(stderr, __VA_ARGS__) - #else - #define DEBUGLOG(fmt, args...) fprintf(stderr, fmt, ##args) - #endif -#else - #define DEBUGLOG(fmt, args...) -#endif -#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) - #define ERRORLOG(...) fprintf(stderr, __VA_ARGS__) -#else - #define ERRORLOG(fmt, args...) fprintf(stderr, fmt, ##args) -#endif - -#endif /* WM_CONFIG_H */ - - - - - - - - diff --git a/kcompactdisc/wmlib/include/wm_helpers.h b/kcompactdisc/wmlib/include/wm_helpers.h deleted file mode 100644 index ca8d22f1..00000000 --- a/kcompactdisc/wmlib/include/wm_helpers.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef WM_HELPERS_H -#define WM_HELPERS_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Here to be found: Prototypes. Including variable names to be easier - * to read. - * This is just one more step to a more modular and understandable code. - * - */ - -/* - * LibWorkMan message levels. I'm not sure how to call them all and which - * use they should fulfill. This is not very urgent now, because there - * aren't many messages in LibWorkMan now. - */ -#define WM_MSG_LEVEL_NONE 0 /**/ -#define WM_MSG_LEVEL_ERROR 1 /**/ -#define WM_MSG_LEVEL_TWO 2 -#define WM_MSG_LEVEL_THREE 3 -#define WM_MSG_LEVEL_FOUR 4 -#define WM_MSG_LEVEL_INFO 5 /**/ -#define WM_MSG_LEVEL_SIX 6 -#define WM_MSG_LEVEL_VERB 7 /**/ -#define WM_MSG_LEVEL_EIGHT 8 -#define WM_MSG_LEVEL_DEBUG 9 /**/ - -#define WM_MSG_LEVEL_ALL 0xf /**/ -/* - * Message classes. This is somehow a definition of - * the message's source. - */ - -#define WM_MSG_CLASS_PLATFORM 0x010 -#define WM_MSG_CLASS_SCSI 0x020 -#define WM_MSG_CLASS_CDROM 0x040 -#define WM_MSG_CLASS_DB 0x080 -#define WM_MSG_CLASS_MISC 0x100 - -#define WM_MSG_CLASS_ALL 0xff0 - -/* - * I did not know any better place... - */ -#ifdef DEBUG -#define CHECKPOINT(t) fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, t ); -#else -#define CHECKPOINT(t) -#endif - -#ifdef __linux__ -#include -/* Linux doesn't have a SIGEMT */ -#if !defined( SIGEMT ) -# define SIGEMT SIGUNUSED -#endif -#endif /* linux */ - -void freeup( char **x ); -void wm_strmcat( char **t, const char *s); -void wm_strmcpy( char **t, const char *s ); -char * wm_strdup( char *s ); -/* Somebody's version query unsatisfied? */ -int wm_libver_major( void ); /* return major internal version number */ -int wm_libver_minor( void ); /* return minor internal version number */ -int wm_libver_pl( void ); /* return internal patchlevel number */ -char * wm_libver_name( void ); /* return internal name (LibWorkMan) */ -char * wm_libver_number( void ); /* returns string: ".." */ -char * wm_libver_string( void ); /* returns string: " " */ -char * wm_libver_date( void ); /* returns string: date of compilation */ -void wm_lib_set_verbosity( int level ); /* set verbosity level */ -int wm_lib_get_verbosity( void ); /* get verbosity level */ - -void wm_lib_message( unsigned int level, const char *format, ... ) -#ifdef __GNUC__ - __attribute__ ((format(printf,2,3))) -#endif - ; /* put out a message on stderr */ -int wm_susleep( int usec ); - -#endif /* WM_HELPERS_H */ diff --git a/kcompactdisc/wmlib/include/wm_platform.h b/kcompactdisc/wmlib/include/wm_platform.h deleted file mode 100644 index d8ca5e1f..00000000 --- a/kcompactdisc/wmlib/include/wm_platform.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef WM_PLATFORM_H -#define WM_PLATFORM_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * The platform interface - * - * This is just one more step to a more modular and understandable code. - */ - -#define WM_CDS_ERROR(status) ((status) < 0 ||\ - (status) == WM_CDM_UNKNOWN) - -#define WM_CDS_NO_DISC(status) ((status) < 0 ||\ - (status) == WM_CDM_UNKNOWN ||\ - (status) == WM_CDM_EJECTED ||\ - (status) == WM_CDM_NO_DISC) - -#define WM_CDS_DISC_READY(status) ((status) == WM_CDM_TRACK_DONE ||\ - (status) == WM_CDM_PLAYING ||\ - (status) == WM_CDM_FORWARD ||\ - (status) == WM_CDM_PAUSED ||\ - (status) == WM_CDM_STOPPED ||\ - (status) == WM_CDM_LOADING ||\ - (status) == WM_CDM_BUFFERING) - -#define WM_CDS_DISC_PLAYING(status) ((status) == WM_CDM_TRACK_DONE ||\ - (status) == WM_CDM_PLAYING ||\ - (status) == WM_CDM_FORWARD ||\ - (status) == WM_CDM_PAUSED) -#define WM_CDM_BACK 1 -#define WM_CDM_TRACK_DONE 1 -#define WM_CDM_PLAYING 2 -#define WM_CDM_FORWARD 3 -#define WM_CDM_PAUSED 4 -#define WM_CDM_STOPPED 5 -#define WM_CDM_EJECTED 6 -#define WM_CDM_DEVICECHANGED 9 /* deprecated */ -#define WM_CDM_NO_DISC 10 -#define WM_CDM_UNKNOWN 11 -#define WM_CDM_CDDAERROR 12 -#define WM_CDM_LOADING 13 /* tribute to phonon state mashine */ -#define WM_CDM_BUFFERING 14 /* tribute to phonon state mashine */ -#define WM_CDM_CDDAACK 0xF0 - -#endif /* WM_PLATFORM_H */ diff --git a/kcompactdisc/wmlib/include/wm_scsi.h b/kcompactdisc/wmlib/include/wm_scsi.h deleted file mode 100644 index 652a9a75..00000000 --- a/kcompactdisc/wmlib/include/wm_scsi.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef WM_SCSI_H -#define WM_SCSI_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * SCSI prototypes (scsi.c) - * - * This is just one more step to a more modular and understandable code. - */ - -#include "wm_struct.h" - -#define WM_ERR_SCSI_INQUIRY_FAILED -1 - -int wm_scsi_mode_sense( struct wm_drive *d, unsigned char page, - unsigned char *buf ); -int sendscsi( struct wm_drive *d, void *buf, - unsigned int len, int dir, - unsigned char a0, unsigned char a1, - unsigned char a2, unsigned char a3, - unsigned char a4, unsigned char a5, - unsigned char a6, unsigned char a7, - unsigned char a8, unsigned char a9, - unsigned char a10, unsigned char a11 ); -int wm_scsi_get_drive_type( struct wm_drive *d); -int wm_scsi_get_cdtext( struct wm_drive *d, - unsigned char **pp_buffer, int *p_buffer_length ); -int wm_scsi_set_speed( struct wm_drive *d, int read_speed ); - -#endif /* WM_SCSI_H */ diff --git a/kcompactdisc/wmlib/include/wm_struct.h b/kcompactdisc/wmlib/include/wm_struct.h deleted file mode 100644 index 2f94755b..00000000 --- a/kcompactdisc/wmlib/include/wm_struct.h +++ /dev/null @@ -1,187 +0,0 @@ -#ifndef WM_STRUCT_H -#define WM_STRUCT_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "wm_platform.h" - -#define WM_STR_GENVENDOR "Generic" -#define WM_STR_GENMODEL "drive" -#define WM_STR_GENREV "type" - -struct wm_drive; - -/* - * Structure for a single track. This is pretty much self-explanatory -- - * one of these exists for each track on the current CD. - */ -struct wm_trackinfo -{ - int length; /* Length of track in seconds or Kbytes */ - int start; /* Starting position (f+s*75+m*60*75) */ - int track; /* Physical track number */ - int data; /* Flag: data track */ -}; - -struct wm_cdinfo -{ - int ntracks; /* Number of tracks on the disc */ - int curtrack; - int curtracklen; - int cur_cdmode; - int cur_index; /* Current index mark */ - int cur_pos_rel; /* Current track-relative position in seconds */ - int cur_pos_abs; /* Current absolute position in seconds */ - int cur_frame; /* Current frame number */ - int length; /* Total running time in seconds */ - int cd_cur_balance; - struct wm_trackinfo *trk; /* struct wm_trackinfo[ntracks] */ -}; - -/* - * Each platform has to define generic functions, so may as well declare - * them all here to save space. - * These functions should never be seen outside libworkman. So I don't care - * about the wm_ naming convention here. - */ -struct wm_drive_proto -{ - int (*open)(struct wm_drive *d); - int (*close)(struct wm_drive *d); - int (*get_trackcount)(struct wm_drive *d, int *tracks); - int (*get_cdlen)(struct wm_drive *d, int *frames); - int (*get_trackinfo)(struct wm_drive *d, int track, int *data, int *startframe); - int (*get_drive_status)(struct wm_drive *d, int oldmode, int *mode, int *pos, int *track, int *ind); - int (*pause)(struct wm_drive *d); - int (*resume)(struct wm_drive *d); - int (*stop)(struct wm_drive *d); - int (*play)(struct wm_drive *d, int start, int end); - int (*eject)(struct wm_drive *d); - int (*closetray)(struct wm_drive *d); - int (*scsi)(struct wm_drive *d, unsigned char *cdb, int cdb_len, void *ret_buf, int ret_buflen, int get_reply); - int (*set_volume)(struct wm_drive *d, int left, int right); - int (*get_volume)(struct wm_drive *d, int *left, int *right); - int (*scale_volume)(int *left, int *right); - int (*unscale_volume)(int *left, int *right); -}; - -/* forward declaration */ -int gen_init(struct wm_drive *d); -int gen_open(struct wm_drive *d); -int gen_close(struct wm_drive *d); -int gen_get_trackcount(struct wm_drive *d, int *tracks); -int gen_get_cdlen(struct wm_drive *d, int *frames); -int gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe); -int gen_get_drive_status(struct wm_drive *d, int oldmode, int *mode, int *pos, int *track, int *ind); -int gen_pause(struct wm_drive *d); -int gen_resume(struct wm_drive *d); -int gen_stop(struct wm_drive *d); -int gen_play(struct wm_drive *d, int start, int end); -int gen_eject(struct wm_drive *d); -int gen_closetray(struct wm_drive *d); -int gen_scsi(struct wm_drive *d, unsigned char *cdb, int cdb_len, void *ret_buf, int ret_buflen, int get_reply); -int gen_set_volume(struct wm_drive *d, int left, int right); -int gen_get_volume(struct wm_drive *d, int *left, int *right); -int gen_scale_volume(int *left, int *right); -int gen_unscale_volume(int *left, int *right); - -/* - * Information about a particular block of CDDA data. - */ -struct wm_cdda_block -{ - unsigned char status; - unsigned char track; - unsigned char index; - unsigned char reserved; - - int frame; - char *buf; - long buflen; -}; - -#ifdef WMLIB_CDDA_BUILD -int gen_cdda_init(struct wm_drive *d); -int gen_cdda_open(struct wm_drive* d); -int gen_cdda_read(struct wm_drive* d, struct wm_cdda_block *block); -int gen_cdda_close(struct wm_drive* d); -#else - #define gen_cdda_init(x) (-1) - #define gen_cdda_open(x) (-1) - #define gen_cdda_read(x, y) (-1) - #define gen_cdda_close(x) (-1) -#endif - - -/* - * Drive descriptor structure. Used for access to low-level routines. - */ -struct wm_drive -{ - int cdda; /* cdda 1, cdin 0 */ - - /* commpn section */ - char *cd_device; - char *soundsystem; - char *sounddevice; - char *ctldevice; - - char vendor[9]; /* Vendor name */ - char model[17]; /* Drive model */ - char revision[5]; /* Revision of the drive */ - void *aux; /* Pointer to optional platform-specific info */ - - struct wm_cdinfo thiscd; - int cur_cdmode; - - /* cdin section */ - int fd; /* file descriptor */ - void *daux; /* Pointer to optional drive-specific info etc. */ - struct wm_drive_proto proto; - - /* cdda section */ - unsigned char status; - unsigned char track; - unsigned char index; - unsigned char command; - - int current_position; - int ending_position; - - int frame; - int frames_at_once; - - struct wm_cdda_block *blocks; - int numblocks; - void *cddax; /* Pointer to optional drive-specific info etc. */ - int oldmode; -}; - -int toshiba_fixup(struct wm_drive *d); -int sony_fixup(struct wm_drive *d); - -struct cdtext_info* get_glob_cdtext(struct wm_drive*, int); -void free_cdtext(void); - -int wm_cdda_init(struct wm_drive *d); -int wm_cdda_destroy(struct wm_drive *d); - -#endif /* WM_STRUCT_H */ diff --git a/kcompactdisc/wmlib/include/wm_version.h b/kcompactdisc/wmlib/include/wm_version.h deleted file mode 100644 index 4c5459a9..00000000 --- a/kcompactdisc/wmlib/include/wm_version.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WM_VERSION_H -#define WM_VERSION_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Version information - * - */ - -#define WM_LIBVER_MAJOR 1 -#define WM_LIBVER_MINOR 4 -#define WM_LIBVER_PL 3 -#define WM_LIBVER_NAME "LibWorkMan" - -#endif /* WM_VERSION_H */ diff --git a/kcompactdisc/wmlib/include/workman.h b/kcompactdisc/wmlib/include/workman.h deleted file mode 100644 index c6c5fe3f..00000000 --- a/kcompactdisc/wmlib/include/workman.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef WORKMAN_H -#define WORKMAN_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * all-in-one libworkman include file. - * - */ - - -/* - * wm_config should always be included first - */ -#include "wm_config.h" -#include "workman_defs.h" -#include "wm_cdda.h" -#include "wm_cddb.h" -#include "wm_cdrom.h" -#include "wm_helpers.h" -#include "wm_platform.h" -#include "wm_scsi.h" -#include "wm_struct.h" -#include "wm_cdtext.h" - -#endif /* WORKMAN_H */ - diff --git a/kcompactdisc/wmlib/include/workman_defs.h b/kcompactdisc/wmlib/include/workman_defs.h deleted file mode 100644 index 00a86209..00000000 --- a/kcompactdisc/wmlib/include/workman_defs.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef WORKMAN_DEFS_H -#define WORKMAN_DEFS_H -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * 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. - * - * #defined CONSTANTS - * - * Too bad this file seems to be so empty... - * - */ - -#include "wm_version.h" - -#endif /* WORKMAN_DEFS_H */ diff --git a/kcompactdisc/wmlib/plat_aix.c b/kcompactdisc/wmlib/plat_aix.c deleted file mode 100644 index 7ea25d38..00000000 --- a/kcompactdisc/wmlib/plat_aix.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * plat_aix - AIX 4.x IDE and SCSI support 16 Dec 1998 - * - * AIX 4.x Port: Erik O'Shaughnessy - * Original AIX IDE Code: Cloyce Spradling (xmcd libdi_d/aixioc.c ) - * - * Taken from the ascd distribution. - * - */ - -#if defined(AIXV3) || defined(__AIXV3) - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -#define LEADOUT 0xaa - -int min_volume = 128; -int max_volume = 255; - - - -/* NAME: gen_init - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_init(struct wm_drive *d) -{ - return 0; -} /* gen_init() */ - - -/* NAME: gen_open - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_open(struct wm_drive *d) -{ - int fd; - - if( ! d ) - { - errno = EFAULT; - return -1; - } - - if(d->fd > -1) /* device already open? */ - { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - if( (fd = openx(d->cd_device,O_RDONLY,NULL,SC_SINGLE)) < 0 ) - { - perror("openx"); - return -6; - /* return 1 */ - } - - d->fd = fd; - - return 0; -} - -/* NAME: gen_scsi - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_scsi(struct wm_drive *d, - uchar_t *cdb, int cdblen, - void *retbuf, int retbuflen, - int getreply) -{ - return -1; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/* NAME: gen_get_drive_status - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_get_drive_status(struct wm_drive *d, - int oldmode, - int *mode, - int *pos, - int *track, - int *index) -{ - struct cd_audio_cmd cmd; - - *mode = WM_CDM_EJECTED; - - if(d->fd < 0) - switch(d->proto.open(d)) - { - case -1: - return -1; - case 1: - return 0; - } - - cmd.audio_cmds = CD_INFO_AUDIO; - - if( ioctl(d->fd,DKAUDIO,&cmd) < 0) - return -1; - - switch(cmd.status) - { - case CD_PLAY_AUDIO: - *mode = WM_CDM_PLAYING; - *track = cmd.indexing.info_audio.current_track; - *index = cmd.indexing.info_audio.current_index; - *pos = cmd.indexing.info_audio.current_mins * 60 * 75 + - cmd.indexing.info_audio.current_secs * 75 + - cmd.indexing.info_audio.current_frames; - break; - - case CD_PAUSE_AUDIO: - *mode = WM_CDM_PAUSED; - *track = cmd.indexing.info_audio.current_track; - *index = cmd.indexing.info_audio.current_index; - *pos = cmd.indexing.info_audio.current_mins * 60 * 75 + - cmd.indexing.info_audio.current_secs * 75 + - cmd.indexing.info_audio.current_frames; - - break; - case CD_NO_AUDIO: /* no play audio in progress */ - case CD_COMPLETED: /* play operation completed successfully */ - case CD_STATUS_ERROR: /* invalid status or play stopped due to err */ - case CD_NOT_VALID: /* audio status is invalid or not supported */ - *mode = WM_CDM_STOPPED; - break; - default: - *mode = WM_CDM_UNKNOWN; - break; - } - - return 0; -} /* gen_get_drive_status() */ - - - -/* NAME: gen_get_trackcount - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_get_trackcount(struct wm_drive *d,int *tracks) -{ - struct cd_audio_cmd cmd; - - cmd.audio_cmds = CD_TRK_INFO_AUDIO; - cmd.msf_flag = 0; - - if( ioctl(d->fd,DKAUDIO,&cmd) < 0) - { - perror("DKAUDIO"); - return -1; - } - - *tracks = cmd.indexing.track_index.last_track; - - return 0; -} /* gen_get_trackcount() */ - -/* NAME: gen_get_trackinfo - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_get_trackinfo(struct wm_drive *d,int track,int *data,int *startframe) -{ - struct cd_audio_cmd cmd; - - cmd.audio_cmds = CD_GET_TRK_MSF; - cmd.msf_flag = 1; - - cmd.indexing.track_msf.track = track; - - if( ioctl(d->fd,DKAUDIO,&cmd) < 0) - return -1; - - *startframe = cmd.indexing.track_msf.mins * 60 * 75 + - cmd.indexing.track_msf.secs * 75 + - cmd.indexing.track_msf.frames; - - *data = 0; - - return 0; -} /* gen_get_trackinfo() */ - -/* NAME: gen_get_cdlen - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_get_cdlen(struct wm_drive *d,int *frames) -{ - int tmp; - - return gen_get_trackinfo(d,LEADOUT,&tmp,frames); -} /* gen_get_cdlen() */ - - -/* NAME: gen_play - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_play(struct wm_drive *d,int start,int end) -{ - struct cd_audio_cmd cmd; - - cmd.audio_cmds = CD_PLAY_AUDIO; - cmd.msf_flag = 1; - - cmd.indexing.msf.first_mins = start / (60*75); - cmd.indexing.msf.first_secs = (start % (60*75)) / 75; - cmd.indexing.msf.first_frames = start % 75; - - cmd.indexing.msf.last_mins = end / (60*75); - cmd.indexing.msf.last_secs = (end % (60*75)) / 75; - cmd.indexing.msf.last_frames = end % 75; - - if( ioctl(d->fd,DKAUDIO,&cmd) < 0) - { - perror("DKAUDIO:CD_PLAY_AUDIO"); - return -1; - } - return 0; -} /* gen_play() */ - -/* NAME: gen_pause - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_pause(struct wm_drive *d) -{ - struct cd_audio_cmd cmd; - - cmd.audio_cmds = CD_PAUSE_AUDIO; - - return ioctl(d->fd,DKAUDIO,&cmd); -} /* gen_pause() */ - - -/* NAME: gen_resume - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_resume(struct wm_drive *d) -{ - struct cd_audio_cmd cmd; - - cmd.audio_cmds = CD_RESUME_AUDIO; - return ioctl(d->fd,DKAUDIO,&cmd); -} /* gen_resume() */ - -/* NAME: gen_stop - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_stop(struct wm_drive *d) -{ - struct cd_audio_cmd cmd; - - cmd.audio_cmds = CD_STOP_AUDIO; - return ioctl(d->fd,DKAUDIO,&cmd); -} /* gen_stop() */ - -/* NAME: gen_eject - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_eject(struct wm_drive *d) -{ - return ioctl(d->fd,DKEJECT,NULL); -} - -/*----------------------------------------* - * Close the CD tray - *----------------------------------------*/ -int -gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - - -int -scale_volume(int vol,int max) -{ - return ((vol * (max_volume - min_volume)) / max + min_volume); -} - -int -unscale_volume(int vol,int max) -{ - int n; - n = ( vol - min_volume ) * max_volume / (max - min_volume); - return (n <0)?0:n; -} - -/* NAME: gen_set_volume - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_set_volume(struct wm_drive *d,int left,int right) -{ - struct cd_audio_cmd cmd; - - cmd.audio_cmds = CD_SET_VOLUME; - cmd.volume_type = CD_VOLUME_CHNLS; - - cmd.out_port_0_vol = scale_volume(left,100); - cmd.out_port_1_vol = scale_volume(right,100); - - if( ioctl(d->fd,DKAUDIO,&cmd) < 0) - { - perror("CD_SET_VOLUME"); - return -1; - } - - return 0; -} /* gen_set_volume() */ - -/* NAME: gen_get_volume - * - * FUNCTION: - * - * RETURNS: - */ -int -gen_get_volume(struct wm_drive *d,int *left,int *right) -{ - struct cd_audio_cmd cmd; - int l,r; - - fprintf(stderr,"gen_get_volume\n"); - - cmd.audio_cmds = CD_INFO_AUDIO; - if( ioctl(d->fd,DKAUDIO,&cmd) < 0) - return -1; - - *left = unscale_volume(cmd.out_port_0_vol,100); - *right = unscale_volume(cmd.out_port_1_vol,100); - - return 0; -} /* gen_get_volume() */ - -#endif /* _AIX */ - - - - - diff --git a/kcompactdisc/wmlib/plat_bsd386.c b/kcompactdisc/wmlib/plat_bsd386.c deleted file mode 100644 index 6f9fd0ee..00000000 --- a/kcompactdisc/wmlib/plat_bsd386.c +++ /dev/null @@ -1,456 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * BSD/386-specific drive control routines. - */ - -#if defined(__bsdi__) || defined(__bsdi) - -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" - -/* - * The following is included from the Linux module. However, I didn't - * see a check here if the CD to be ejected is mounted... - */ -#if defined(BSD_MOUNTTEST) - #include -#endif - - -#include -#include -#include -#ifdef SOUNDBLASTER -# include -#endif - -#include "include/wm_struct.h" -#include "include/wm_helpers.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - - -/* - * Since we can't sense the drive type with libcdrom anyway, and since the - * library doesn't provide "pause" or "resume" functions, use the daux field - * to point to the frame number at which we paused. - */ -struct pause_info -{ - int frame; - int endframe; -}; - -#define PAUSE_FRAME (((struct pause_info *) d->daux)->frame) -#define END_FRAME (((struct pause_info *) d->daux)->endframe) -#define CUR_CD ((struct cdinfo *) d->aux) - -void *malloc(); - -#ifdef SOUNDBLASTER - int min_volume = 0; - int max_volume = 100; - int min_volume_drive = 10; /* Toshiba drive does low values. */ - int max_volume_drive = 255; -#else - int min_volume = 10; - int max_volume = 255; -#endif - -/*--------------------------------------------------------* - * Initialize the drive. A no-op for the generic driver. - *--------------------------------------------------------*/ -int -gen_init(struct wm_drive *d) -{ - return 0; -} /* gen_init() */ - -/*-----------------------------------------------------------------------* - * Open the CD device. We can't determine the drive type under BSD/386. - *-----------------------------------------------------------------------*/ -int -gen_open(struct wm_drvie *d) -{ - void *aux = NULL, *daux = NULL; - int fd = -1; - - if (d->aux) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (aux=%d)]\n", d->aux); - return 0; - } - - if ((aux = cdopen(d->cd_device)) == NULL) { - fprintf(stderr, "No cdrom found by libcdrom\n"); - return -6; - } - - if ((daux = malloc(sizeof(struct pause_info))) == NULL) { - cdclose( aux ); - return -1; - } - -#ifdef SOUNDBLASTER - fd = open("/dev/mixer", O_RDWR, 0); -#endif - - d->aux = aux; - d->daux = daux; - d->fd = fd; - PAUSE_FRAME = 0; - END_FRAME = 0; - - return 0; -} - -/*---------------------------------------------* - * Send an arbitrary SCSI command to a device. - *---------------------------------------------*/ -int -gen_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen, - void *retbuf, int retbuflen, int getreply) -{ - /* Don't know how to do SCSI passthrough... */ - return (-1); -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); /* close mixer if open */ - d->fd = -1; - cdclose( d->aux ); /* close the cdrom drive! */ - d->aux = NULL; - free(d->daux); - d->daux = NULL; - } - return 0; -} - -/*--------------------------------------------------------------------------* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - *--------------------------------------------------------------------------*/ -#define DOPOS \ - *pos = status.abs_frame; \ -*track = status.track_num; \ -*index = status.index_num - -int -gen_get_drive_status(struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *index) -{ - struct cdstatus status; - extern enum wm_cd_modes cur_cdmode; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - /* Is the device open? */ - if (d->aux == NULL) { - switch (d->proto.open(d)) { - case -1: /* error */ - return -1; - - case 1: /* retry */ - return 0; - } - } - - if (cdstatus (CUR_CD, &status) < 0) { - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - return 0; - } - - switch (status.state) { - case cdstate_playing: - *mode = WM_CDM_PLAYING; - break; - - case cdstate_stopped: - /* the MITSUMI drive doesn't have a "paused" state, - so it always comes here and not to the paused section. - The PAUSE_FRAME stuff below (in gen_pause()) - fakes out the paused state. */ - if (oldmode == WM_CDM_PLAYING) { - *mode = WM_CDM_TRACK_DONE; - break; - } else if (cur_cdmode != WM_CDM_PAUSED) { - *mode = WM_CDM_STOPPED; - break; - } - /* fall through if paused */ - - case cdstate_paused: - /* the SCSI2 code in the cdrom library only pauses with - cdstop(); it never truly stops a disc (until an in-progress - play reaches the end). So it always comes here. */ - if (cur_cdmode == WM_CDM_STOPPED) - *mode = WM_CDM_STOPPED; - else if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) - *mode = WM_CDM_PAUSED; - else - *mode = WM_CDM_STOPPED; - break; - - default: - *mode = WM_CDM_STOPPED; - } - - switch (*mode) { - case WM_CDM_PLAYING: - case WM_CDM_PAUSED: - case WM_CDM_STOPPED: - *pos = status.abs_frame; - *track = status.track_num; - *index = status.index_num; - break; - } - - return 0; -} /* gen_get_drive_status() */ - - -/*-------------------------------------* - * Get the number of tracks on the CD. - *-------------------------------------*/ -int -gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - *tracks = CUR_CD->ntracks; - - return 0; -} /* gen_get_trackcount() */ - -/*---------------------------------------------------------* - * Get the start time and mode (data or audio) of a track. - *---------------------------------------------------------*/ -int -gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - *data = (CUR_CD->tracks[track - 1].control & 4) ? 1 : 0; - *startframe = CUR_CD->tracks[track - 1].start_frame; - - return 0; -} /* gen_get_trackinfo() */ - -/*-------------------------------------* - * Get the number of frames on the CD. - *-------------------------------------*/ -int -gen_get_cdlen(struct wm_drive *d, int *frames) -{ - *frames = CUR_CD->total_frames; - - return 0; -} /* gen_get_cdlen() */ - -/*------------------------------------------------------------* - * Play the CD from one position to another (both in frames.) - *------------------------------------------------------------*/ -int -gen_play(struct wm_drive *d, int start, int end) -{ - END_FRAME = end; - if (cdplay(d->aux, start, end) < 0) - return -1; - else - return 0; -} /* gen_play() */ - -/*--------------------------------------------------------------------* - * Pause the CD. This is a bit of a trick since there's no cdpause() - * function in the library. We fake it by saving the frame number - * and stopping. - *--------------------------------------------------------------------*/ -int -gen_pause(struct wm_drive *d) -{ - struct cdstatus status; - - if (cdstatus(d->aux, &status) < 0) - return -1; - if (status.state != cdstate_playing) - PAUSE_FRAME = CUR_CD->tracks[0].start_frame; - else - PAUSE_FRAME = status.abs_frame; - if (cdstop(d->aux) < 0) - return -1; - - return 0; -} /* gen_pause() */ - -/*-------------------------------------------------* - * Resume playing the CD (assuming it was paused.) - *-------------------------------------------------*/ -int -gen_resume(struct wm_drive *d) -{ - int status; - - status = (d->play)(d, PAUSE_FRAME, END_FRAME); - PAUSE_FRAME = 0; - return status; -} /* gen_resume() */ - -/*--------------* - * Stop the CD. - *--------------*/ -int -gen_stop(struct wm_drive *d) -{ - return cdstop(d->aux); -} /* gen_stop() */ - -/*----------------------------------------* - * Eject the current CD, if there is one. - *----------------------------------------*/ -int -gen_eject(struct wm_drive *d) -{ - cdeject(d->aux); - cdclose(d->aux); - d->aux = NULL; - free(d->daux); - d->daux = NULL; - - if (d->fd >= 0) - close(d->fd); /* close mixer */ - d->fd = -1; - return 0; -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - *----------------------------------------*/ -int -gen_closetray(struct wm_drive *d) -{ - if (!cdload(d->aux)) - return 0; - return -1; -} /* gen_closetray() */ - - -/*------------------------------------------------------------------------* - * Return a volume value suitable for passing to the CD-ROM drive. "vol" - * is a volume slider setting; "max" is the slider's maximum value. - *------------------------------------------------------------------------*/ -static int -scale_volume(int vol, int max) -{ - /* on Toshiba XM-3401B drive, and on soundblaster, this works fine. */ - return ((vol * (max_volume - min_volume)) / max + min_volume); -} /* scale_volume() */ - -/*---------------------------------------------------------------------------* - * unscale_volume(cd_vol, max) - * - * Given a value between min_volume and max_volume, return the volume slider - * value needed to achieve that value. - * - * Rather than perform floating-point calculations to reverse the above - * formula, we simply do a binary search of scale_volume()'s return values. - *--------------------------------------------------------------------------*/ -static int -unscale_volume(int cd_vol, int max) -{ - int vol = 0, top = max, bot = 0, scaled; - - while (bot <= top) { - vol = (top + bot) / 2; - scaled = scale_volume(vol, max); - if (cd_vol == scaled) - break; - if (cd_vol < scaled) - top = vol - 1; - else - bot = vol + 1; - } - - if (vol < 0) - vol = 0; - else if (vol > max) - vol = max; - - return vol; -} /* unscale_volume() */ - -/*---------------------------------------------------------------------* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - *---------------------------------------------------------------------*/ -int -gen_set_volume(struct wm_drive *d, int left, int right) -{ - int level; - - left = scale_volume(left, 100); - right = scale_volume(right, 100); - level = right << 8 | left; - - /* Send a Mixer IOCTL */ - if (d->fd >= 0) - (void) ioctl(d->fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level); -#ifdef notnow - /* NOTE: the cdvolume2() call is an addition to the cdrom library. - Pick it up from the archives on bsdi.com */ - cdvolume2 (CUR_CD, left < 0 ? 0 : left > 255 ? 255 : left, - right < 0 ? 0 : right > 255 ? 255 : right); - -#endif - return 0; -} - -/*---------------------------------------------------------------------* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - *---------------------------------------------------------------------*/ -int -gen_get_volume(struct wm_drive *d, int *left, int *right) -{ - int level; - - /* Most systems can't seem to do this... */ - *left = *right = -1; - - /* Send a Mixer IOCTL */ - if (d->fd >= 0) { - if (ioctl(d->fd, MIXER_READ(SOUND_MIXER_VOLUME), &level) == 0) { - *left = unscale_volume((level & 0xff) & 0xff, 100); - *right = unscale_volume((level >> 8) & 0xff, 100); - } - } - return 0; -} - -#endif /* __bsdi__ */ diff --git a/kcompactdisc/wmlib/plat_freebsd.c b/kcompactdisc/wmlib/plat_freebsd.c deleted file mode 100644 index 7cc31e61..00000000 --- a/kcompactdisc/wmlib/plat_freebsd.c +++ /dev/null @@ -1,527 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * plat_freebsd.c - * - * FreeBSD-specific drive control routines. - * - * Todd Pfaff, 3/20/94 - * - */ - -#if defined(__FreeBSD__) || defined(__FreeBSD) || defined(__NetBSD__) || defined (__NetBSD) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" - -#include -#include -#include - -#if defined(__OpenBSD__) -# define MSF_MINUTES 1 -# define MSF_SECONDS 2 -# define MSF_FRAMES 3 -# include -# include "/sys/scsi/scsi_all.h" -# include "/sys/scsi/scsi_cd.h" - -#elif defined(__NetBSD__) - -# include -# include - -/* Fix http://bugs.kde.org/show_bug.cgi?id=154718 by wrapping calls to removed - * functions with their replacements in NetBSD 3.0 - */ -# if __NetBSD_Version__ >= 299000900 /* 2.99.9 */ -# include -# define statfs statvfs -# define fstatfs fstatvfs -# endif - -#else /* Not OpenBSD, not NetBSD, therefore (probably) FreeBSD */ -# define LEFT_PORT 0 -# define RIGHT_PORT 1 -# if defined (__FreeBSD__) -# if (__FreeBSD_version < 300000) && (__FreeBSD_kernel_version < 300000) -# include -# endif -# endif - -#endif /* if defined(__OpenBSD__) */ - -#include "include/wm_struct.h" -#include "include/wm_platform.h" -#include "include/wm_cdrom.h" -#include "include/wm_scsi.h" -#include "include/wm_helpers.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -void *malloc(); - -int min_volume = 10; -int max_volume = 255; - - -/*--------------------------------------------------------* - * Initialize the drive. A no-op for the generic driver. - *--------------------------------------------------------*/ -int -gen_init(struct wm_drive *d) -{ - return 0; -} /* gen_init() */ - - -/*-------------------------------------------------------------------* - * Open the CD device and figure out what kind of drive is attached. - *-------------------------------------------------------------------*/ -int -gen_open(struct wm_drive *d) -{ - if (d->fd > -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - d->fd = open(d->cd_device, 0); - if (d->fd < 0) { - if (errno == EACCES) - return -EACCES; - - /* No CD in drive. */ - return 1; - } - - return 0; -} /* gen_open() */ - -/*---------------------------------------------* - * Send an arbitrary SCSI command to a device. - * - *---------------------------------------------*/ -int -gen_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen, - void *retbuf, int retbuflen, int getreply) -{ - return -1; -} /* wm_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd > -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/*--------------------------------------------------------------------------* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - *--------------------------------------------------------------------------*/ -int -gen_get_drive_status(struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *index) -{ - struct ioc_read_subchannel sc; - struct cd_sub_channel_info scd; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - sc.address_format = CD_MSF_FORMAT; - sc.data_format = CD_CURRENT_POSITION; - sc.track = 0; - sc.data_len = sizeof(scd); - sc.data = (struct cd_sub_channel_info *)&scd; - - /* Is the device open? */ - if (d->fd < 0) { - switch (d->proto.open(d)) { - case -1: /* error */ - return -1; - - case 1: /* retry */ - return 0; - } - } - - if (ioctl(d->fd, CDIOCREADSUBCHANNEL, &sc)) { - /* - * #ifdef __NetBSD__ - * - * Denis Bourez told me, that closing the - * device is mandatory for FreeBSD, too. - */ - /* we need to release the device so the kernel will notice - reloaded media */ - d->proto.close(d); - /* - * #endif - */ - return 0; /* ejected */ - } - - switch (scd.header.audio_status) { - case CD_AS_PLAY_IN_PROGRESS: - *mode = WM_CDM_PLAYING; - break; - - case CD_AS_PLAY_PAUSED: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) - *mode = WM_CDM_PAUSED; - else - *mode = WM_CDM_STOPPED; - break; - - case CD_AS_PLAY_COMPLETED: - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - break; - - case CD_AS_NO_STATUS: - case 0: - *mode = WM_CDM_STOPPED; - break; - } - - switch(*mode) { - case WM_CDM_PLAYING: - case WM_CDM_PAUSED: - *pos = scd.what.position.absaddr.msf.minute * 60 * 75 + - scd.what.position.absaddr.msf.second * 75 + - scd.what.position.absaddr.msf.frame; - *track = scd.what.position.track_number; - *index = scd.what.position.index_number; - break; - } - - return 0; -} /* gen_get_drive_status() */ - - -/*-------------------------------------* - * Get the number of tracks on the CD. - *-------------------------------------*/ -int -gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - struct ioc_toc_header hdr; - - if (ioctl(d->fd, CDIOREADTOCHEADER, &hdr) == -1) - return -1; - - *tracks = hdr.ending_track - hdr.starting_track + 1; - - return 0; -} /* gen_get_trackcount() */ - -/*-----------------------------------------------------------------------* - * Get the start time and mode (data or audio) of a track. - * - * XXX - this should get cached, but that means keeping track of ejects. - *-----------------------------------------------------------------------*/ -int -gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - struct ioc_read_toc_entry toc; - struct cd_toc_entry toc_buffer; - - bzero((char *)&toc_buffer, sizeof(toc_buffer)); - toc.address_format = CD_MSF_FORMAT; - toc.starting_track = track; - toc.data_len = sizeof(toc_buffer); - toc.data = &toc_buffer; - - if (ioctl(d->fd, CDIOREADTOCENTRYS, &toc)) - return -1; - - *data = ((toc_buffer.control & 0x4) != 0); - - *startframe = toc_buffer.addr.msf.minute*60*75 + - toc_buffer.addr.msf.second * 75 + - toc_buffer.addr.msf.frame; - - return 0; -} /* gen_get_trackinfo() */ - -/*-------------------------------------* - * Get the number of frames on the CD. - *-------------------------------------*/ -int -gen_get_cdlen(struct wm_drive *d, int *frames) -{ - int tmp; - struct ioc_toc_header hdr; - int status; - -#define LEADOUT 0xaa /* see scsi.c. what a hack! */ - return gen_get_trackinfo(d, LEADOUT, &tmp, frames); -} /* gen_get_cdlen() */ - - -/*------------------------------------------------------------* - * Play the CD from one position to another (both in frames.) - *------------------------------------------------------------*/ -int -gen_play(struct wm_drive *d, int start, int end) -{ - struct ioc_play_msf msf; - - msf.start_m = start / (60*75); - msf.start_s = (start % (60*75)) / 75; - msf.start_f = start % 75; - msf.end_m = end / (60*75); - msf.end_s = (end % (60*75)) / 75; - msf.end_f = end % 75; - - if (ioctl(d->fd, CDIOCSTART)) - return -1; - - if (ioctl(d->fd, CDIOCPLAYMSF, &msf)) - return -2; - - return 0; -} /* gen_play() */ - -/*---------------* - * Pause the CD. - *---------------*/ -int -gen_pause( struct wm_drive *d ) -{ - return ioctl(d->fd, CDIOCPAUSE); -} /* gen_pause() */ - -/*-------------------------------------------------* - * Resume playing the CD (assuming it was paused.) - *-------------------------------------------------*/ -int -gen_resume( struct wm_drive *d ) -{ - return ioctl(d->fd, CDIOCRESUME); -} /* gen_resume() */ - -/*--------------* - * Stop the CD. - *--------------*/ -int -gen_stop( struct wm_drive *d) -{ - return ioctl(d->fd, CDIOCSTOP); -} /* gen_stop() */ - -/*----------------------------------------* - * Eject the current CD, if there is one. - *----------------------------------------*/ -int -gen_eject( struct wm_drive *d ) -{ - /* On some systems, we can check to see if the CD is mounted. */ - struct stat stbuf; - struct statfs buf; - int rval; - - if (fstat(d->fd, &stbuf) != 0) - return -2; - - /* Is this a mounted filesystem? */ - if (fstatfs(stbuf.st_rdev, &buf) == 0) - return -3; - - rval = ioctl(d->fd, CDIOCALLOW); - - if (rval == 0) - rval = ioctl(d->fd, CDIOCEJECT); - - if (rval == 0) - rval = ioctl(d->fd, CDIOCPREVENT); - - d->proto.close(d); - - return rval; -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - *----------------------------------------*/ - -int -gen_closetray(struct wm_drive *d) -{ -#ifdef CAN_CLOSE - if(!d->proto.close(d)) { - return d->proto.open(d); - } else { - return -1; - } -#else - /* Always succeed if the drive can't close */ - return 0; -#endif /* CAN_CLOSE */ -} /* gen_closetray() */ - - -/*---------------------------------------------------------------------------* - * scale_volume(vol, max) - * - * Return a volume value suitable for passing to the CD-ROM drive. "vol" - * is a volume slider setting; "max" is the slider's maximum value. - * - * On Sun and DEC CD-ROM drives, the amount of sound coming out the jack - * increases much faster toward the top end of the volume scale than it - * does at the bottom. To make up for this, we make the volume scale look - * sort of logarithmic (actually an upside-down inverse square curve) so - * that the volume value passed to the drive changes less and less as you - * approach the maximum slider setting. The actual formula looks like - * - * (max^2 - (max - vol)^2) * (max_volume - min_volume) - * v = --------------------------------------------------- + min_volume - * max^2 - * - * If your system's volume settings aren't broken in this way, something - * like the following should work: - * - * return ((vol * (max_volume - min_volume)) / max + min_volume); - *---------------------------------------------------------------------------*/ -static int -scale_volume(int vol, int max) -{ - return ((vol * (max_volume - min_volume)) / max + min_volume); -} /* scale_volume() */ - -/*---------------------------------------------------------------------------* - * unscale_volume(cd_vol, max) - * - * Given a value between min_volume and max_volume, return the volume slider - * value needed to achieve that value. - * - * Rather than perform floating-point calculations to reverse the above - * formula, we simply do a binary search of scale_volume()'s return values. - *--------------------------------------------------------------------------*/ -static int -unscale_volume( int cd_vol, int max ) -{ - int vol = 0, top = max, bot = 0, scaled; - - while (bot <= top) { - vol = (top + bot) / 2; - scaled = scale_volume(vol, max); - if (cd_vol == scaled) - break; - if (cd_vol < scaled) - top = vol - 1; - else - bot = vol + 1; - } - - if (vol < 0) - vol = 0; - else if (vol > max) - vol = max; - - return vol; -} /* unscale_volume() */ - -/*---------------------------------------------------------------------* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - *---------------------------------------------------------------------*/ -int -gen_set_volume(struct wm_drive *d, int left, int right) -{ - struct ioc_vol vol; - - if (left < 0) /* don't laugh, I saw this happen once! */ - left = 0; - if (right < 0) - right = 0; - - bzero((char *)&vol, sizeof(vol)); - - vol.vol[LEFT_PORT] = left; - vol.vol[RIGHT_PORT] = right; - - if (ioctl(d->fd, CDIOCSETVOL, &vol)) - return -1; - - return 0; -} /* gen_set_volume() */ - -/*---------------------------------------------------------------------* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - *---------------------------------------------------------------------*/ -int -gen_get_volume( struct wm_drive *d, int *left, int *right ) -{ - struct ioc_vol vol; - - if (d->fd > -1) { - bzero((char *)&vol, sizeof(vol)); - - if (ioctl(d->fd, CDIOCGETVOL, &vol)) - *left = *right = -1; - else { - *left = vol.vol[LEFT_PORT]; - *right = vol.vol[RIGHT_PORT]; - } - } else { - *left = *right = -1; - } - - return 0; -} /* gen_get_volume() */ - -int gen_scale_volume(int *left, int *right) -{ - /* Adjust the volume to make up for the CD-ROM drive's weirdness. */ - *left = scale_volume(*left, 100); - *right = scale_volume(*right, 100); - - return 0; -} - -int gen_unscale_volume(int *left, int *right) -{ - *left = unscale_volume(*left, 100); - *right = unscale_volume(*right, 100); - - return 0; -} - -#endif /* If FreeBSD or NetBSD */ - diff --git a/kcompactdisc/wmlib/plat_hpux.c b/kcompactdisc/wmlib/plat_hpux.c deleted file mode 100644 index 9b981488..00000000 --- a/kcompactdisc/wmlib/plat_hpux.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * HP/UX-specific drive control routines. - */ - -#if defined(hpux) || defined(__hpux) - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" - -/* - * this is for glibc 2.x which the ust structure in - * ustat.h not stat.h - */ -#ifdef __GLIBC__ -#include -#endif - -#include -#include - -#include "include/wm_struct.h" -#include "include/wm_helpers.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -void *malloc(); -char *strchr(); - -int min_volume = 0; -int max_volume = 255; - -/*--------------------------------------------------------* - * Initialize the drive. A no-op for the generic driver. - *--------------------------------------------------------*/ -int -gen_init( struct wm_drive *d ) -{ - return 0; -} /* gen_init() */ - - -/*-------------------------------------------------------------* - * Open the CD and figure out which kind of drive is attached. - *-------------------------------------------------------------*/ -int -gen_open( struct wm_drive *d ) -{ - int flag = 1; - - if (d->fd >= 0) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - - d->fd = open(d->cd_device, O_RDWR); - if (d->fd < 0) { - if (errno == EACCES) { - return -EACCES; - } else if (errno != EINTR) { - return -6; - } - - /* No CD in drive. */ - return 1; - } - - /* Prepare the device to receive raw SCSI commands. */ - if (ioctl(d->fd, SIOC_CMD_MODE, &flag) < 0) { - fprintf(stderr, "%s: SIOC_CMD_MODE: true: %s\n", - d->cd_device, strerror(errno)); - /*exit(1);*/ - } - - /* Default drive is the HP one, which might not respond to INQUIRY */ - strcpy(d->vendor, "TOSHIBA"); - strcpy(d->model, "XM-3301"); - d->rev[0] = '\0'; - - return 0; -} /* gen_open() */ - -/*----------------------------------* - * Send a SCSI command out the bus. - *----------------------------------*/ -int -gen_scsi( struct wm_drive *d, unsigned char *cdb, int cdblen, - void *retbuf, int retbuflen, int getreply ) -{ -#ifdef SIOC_IO - struct sctl_io cmd; - - memset(&cmd, 0, sizeof(cmd)); - cmd.cdb_length = cdblen; - cmd.data = retbuf; - cmd.data_length = retbuflen; - cmd.max_msecs = 1000; - cmd.flags = getreply ? SCTL_READ : 0; - memcpy(cmd.cdb, cdb, cdblen); - - return ioctl(d->fd, SIOC_IO, &cmd); -#else - /* this code, for pre-9.0, is BROKEN! ugh. */ - char reply_buf[12]; - struct scsi_cmd_parms cmd; - - memset(&cmd, 0, sizeof(cmd)); - cmd.clock_ticks = 500; - cmd.cmd_mode = 1; - cmd.cmd_type = cdblen; - memcpy(cmd.command, cdb, cdblen); - if (ioctl(d->fd, SIOC_SET_CMD, &cmd) < 0) - return -1; - - if (! retbuf || ! retbuflen) - read(d->fd, reply_buf, sizeof(reply_buf)); - else if (getreply) { - if (read(d->fd, retbuf, retbuflen) < 0) - return -1; - } else if (write(d->fd, retbuf, retbuflen) < 0) - return -1; - - return 0; -#endif -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/*--------------------------------------------------------------------------* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - *--------------------------------------------------------------------------*/ -int -gen_get_drive_status( struct wm_drive *d, int oldmode, int *mode, - int *pos, int *track, int *index ) -{ - return wm_scsi2_get_drive_status(d, oldmode, mode, pos, track, index); -} /* gen_get_drive_status() */ - -/*-------------------------------------* - * Get the number of tracks on the CD. - *-------------------------------------*/ -int -gen_get_trackcount(struct wm_drive *d, int *tracks ) -{ - return wm_scsi2_get_trackcount(d, tracks); -} /* gen_get_trackcount() */ - -/*---------------------------------------------------------* - * Get the start time and mode (data or audio) of a track. - *---------------------------------------------------------*/ -int -gen_get_trackinfo( struct wm_drive *d, int *track, int *data, int *startframe) -{ - return wm_scsi2_get_trackinfo(d, track, data, startframe); -} /* gen_get_trackinfo() */ - -/*-------------------------------------* - * Get the number of frames on the CD. - *-------------------------------------*/ -int gen_get_cdlen(struct wm_drive *d, int *frames) -{ - return wm_scsi2_get_cdlen(d, frames); -} /* gen_get_cdlen() */ - -/*------------------------------------------------------------* - * Play the CD from one position to another (both in frames.) - *------------------------------------------------------------*/ -int -gen_play( struct wm_drive *d, int start, int end ) -{ - return wm_scsi2_play(d, start, end); -} /* gen_play() */ - -/*---------------* - * Pause the CD. - *---------------*/ -int -gen_pause( struct wm_drive *d ) -{ - return wm_scsi2_pause(d); -} /* gen_pause() */ - -/*-------------------------------------------------* - * Resume playing the CD (assuming it was paused.) - *-------------------------------------------------*/ -int -gen_resume( struct wm_drive *d ) -{ - return wm_scsi2_resume(d); -} /* gen_resume() */ - -/*--------------* - * Stop the CD. - *--------------*/ -int -gen_stop( struct wm_drive *d ) -{ - return wm_scsi2_stop(d); -} /* gen_stop() */ - - -/*----------------------------------------* - * Eject the current CD, if there is one. - *----------------------------------------*/ -int -gen_eject( struct wm_drive *d ) -{ - struct stat stbuf; - struct ustat ust; - - if (fstat(d->fd, &stbuf) != 0) - return -2; - - /* Is this a mounted filesystem? */ - if (ustat(stbuf.st_rdev, &ust) == 0) - return -3; - - return wm_scsi2_eject(d); -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - *----------------------------------------*/ -int -gen_closetray(struct wm_drive *d) -{ - return wm_scsi2_closetray(d); -} /* gen_closetray() */ - - -/*---------------------------------------------------------------------* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - *---------------------------------------------------------------------*/ -int -gen_set_volume( struct wm_drive *d, int left, int right ) -{ - return wm_scsi2_set_volume(d, left, right); -} /* gen_set_volume() */ - -/*---------------------------------------------------------------------* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - *---------------------------------------------------------------------*/ -int -gen_get_volume( struct wm_drive *d, int *left, int *right ) -{ - return wm_scsi2_get_volume(d, left, right); -} /* gen_get_volume() */ - -#endif - - diff --git a/kcompactdisc/wmlib/plat_irix.c b/kcompactdisc/wmlib/plat_irix.c deleted file mode 100644 index e3b667cd..00000000 --- a/kcompactdisc/wmlib/plat_irix.c +++ /dev/null @@ -1,416 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * IRIX specific. - * - * Taken from the kscd distribution - * - * Paul Kendall - * paul@orion.co.nz, or - * paul@kcbbs.gen.nz - */ - -#if defined(sgi) || defined(__sgi) - -#include "include/wm_config.h" - -/* - * Yes, it was designed for WorkMan 1.4b3 - * Because I did start over from 1.3a, I disable it here. - * There is no guarantee of getting working code by defining - * CDDA yourself. - * - */ -#undef CDDA -/*#define CDDA*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_struct.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -void *malloc(); -char *strchr(); - -int min_volume = 0; -int max_volume = 255; - -#ifdef CDDA -static int playing = STOPPED; -static CDPLAYER *icd; -static CDPARSER *icdp; -static CDFRAME cdbuf[12]; -static ALport audioport; -static ALconfig aconfig; -static struct itimerval audiotimer = { {0,0}, {0,25000} }; -static int cdtrack=0; -static int cdframe=0; -static int cdstopframe=0; - -/* - * Platform specific internal functions for CDDA - */ -void -cbprognum(void *arg, CDDATATYPES type, CDPROGNUM* prognum) -{ - cdtrack = prognum->value; -} /* cbprognum() */ - -void -cbabstime(void *arg, CDDATATYPES type, struct cdtimecode* atime) -{ - cdframe = CDtctoframe(atime); - if( cdframe == cdstopframe ) - playing = STOPPED; -} /* cbabstime() */ - -void -cbplayaudio(void *arg, CDDATATYPES type, short* audio) -{ - if(playing != PLAYING) return; - ALwritesamps(audioport, audio, CDDA_NUMSAMPLES); -} /* cbplayaudio() */ - -static void -alarmsignal() -{ - int n, i; - if(playing != PLAYING) return; - if( ALgetfilled(audioport) < CDDA_NUMSAMPLES*8 ) - { - /* Only get more samples and play them if we're getting low - * this ensures that the CD stays close to the sound - */ - n = CDreadda(icd, cdbuf, 12); - if( n == 0 ) return; - for( i=0 ; i<12 ; i++ ) - CDparseframe(icdp, &cdbuf[i]); - } - signal(SIGALRM, alarmsignal); - setitimer(ITIMER_REAL, &audiotimer, NULL); -} /* alarmsignal() */ -#endif - -/*--------------------------------------------------------* - * Initialize the drive. A no-op for the generic driver. - *--------------------------------------------------------*/ -int -gen_init( struct wm_drive *d ) -{ -#ifdef CDDA - long Param[4]; - /* Set the audio rate to 44100Hz 16bit 2s-comp stereo */ - aconfig = ALnewconfig(); - ALsetwidth(aconfig, AL_SAMPLE_16); - ALsetsampfmt(aconfig, AL_SAMPFMT_TWOSCOMP); - ALsetchannels(aconfig, 2); - Param[0] = AL_OUTPUT_RATE; Param[1] = AL_RATE_44100; - Param[2] = AL_CHANNEL_MODE; Param[3] = AL_STEREO; - ALsetparams(AL_DEFAULT_DEVICE, Param, 4); - audioport = ALopenport("KDE KSCD Audio", "w", aconfig); - - /* setup cdparser */ - icdp = CDcreateparser(); - CDaddcallback(icdp, cd_audio, (CDCALLBACKFUNC)cbplayaudio, 0); - CDaddcallback(icdp, cd_pnum, (CDCALLBACKFUNC)cbprognum, 0); - CDaddcallback(icdp, cd_atime, (CDCALLBACKFUNC)cbabstime, 0); - - /* Lets handle those floating point exceptions expeditiously. */ - sigfpe_[_UNDERFL].repls = _ZERO; - handle_sigfpes(_ON, _EN_UNDERFL, NULL, _ABORT_ON_ERROR, NULL); -#endif - return 0; -} /* gen_init() */ - -/*-------------------------------------------------------------* - * Open the CD and figure out which kind of drive is attached. - *-------------------------------------------------------------*/ -int -gen_open( struct wm_drive *d ) -{ - CDSTATUS s; - - if (d->fd < 0) /* Device already open? */ - { - d->daux = CDopen(d->cd_device, "r"); - if (d->daux == 0) { - return -6; - } - - d->fd = 1; -#ifdef CDDA - icd = d->daux; -#endif - } else { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - } - - CDgetstatus(d->daux, &s); - if( s.state == CD_NODISC || s.state == CD_ERROR ) - return 1; - - return 0; -} /* gen_open() */ - -/*----------------------------------* - * Send a SCSI command out the bus. - *----------------------------------*/ -int -gen_scsi( struct wm_drive *d, unsigned char *xcdb, int cdblen, - char *retbuf, int retbuflen, int getreply) -{ - return -1; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/*--------------------------------------------------------------------------* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - *--------------------------------------------------------------------------*/ -int -gen_get_drive_status( struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, - int *index ) -{ -#ifdef CDDA - *mode = playing; - *track = cdtrack; - *pos = cdframe; - *index = 0; -#else - CDSTATUS s; - if( CDgetstatus(d->daux, &s)==0 ) - return -1; - *pos = CDmsftoframe(s.min,s.sec,s.frame); - *track = s.track; - *index = 0; - switch( s.state ) - { - case CD_READY: *mode = WM_CDM_STOPPED; - break; - case CD_STILL: - case CD_PAUSED: *mode = WM_CDM_PAUSED; - break; - case CD_PLAYING: *mode = WM_CDM_PLAYING; - break; - default: *mode = WM_CDM_UNKNOWN; - } -#endif - return 0; -} /* gen_get_drive_status() */ - -/*-------------------------------------* - * Get the number of tracks on the CD. - *-------------------------------------*/ -int -gen_get_trackcount( struct wm_drive *d, int *tracks ) -{ - CDSTATUS s; - if( CDgetstatus(d->daux, &s)==0 ) - return -1; - *tracks = s.last; - return 0; -} /* gen_get_trackcount() */ - -/*---------------------------------------------------------* - * Get the start time and mode (data or audio) of a track. - *---------------------------------------------------------*/ -int -gen_get_trackinfo( struct wm_drive *d, int track, int *data, int *startframe) -{ - CDTRACKINFO i; - int ret = CDgettrackinfo(d->daux, track, &i); - if( ret == 0 ) - return -1; - *data = 0; - *startframe = CDmsftoframe(i.start_min,i.start_sec,i.start_frame); - return 0; -} /* gen_get_trackinfo() */ - -/*-------------------------------------* - * Get the number of frames on the CD. - *-------------------------------------*/ -int -gen_get_cdlen( struct wm_drive *d, int *frames ) -{ - CDSTATUS s; - if( CDgetstatus(d->daux, &s)==0 ) - return -1; - *frames = CDmsftoframe(s.total_min,s.total_sec,s.total_frame); - return 0; -} /* gen_get_cdlen() */ - -/*------------------------------------------------------------* - * Play the CD from one position to another (both in frames.) - *------------------------------------------------------------*/ -int -gen_play( struct wm_drive *d, int start, int end ) -{ -#ifdef CDDA - int m, s, f; - CDframetomsf(start, &m, &s, &f); - CDseek(icd, m, s, f); - cdstopframe = end; - playing = PLAYING; - signal(SIGALRM, alarmsignal); - setitimer(ITIMER_REAL, &audiotimer, NULL); -#else - int m, s, f; - CDframetomsf(start, &m, &s, &f); - CDplayabs(d->daux, m, s, f, 1); -#endif - return 0; -} /* gen_play() */ - -/*---------------* - * Pause the CD. - *---------------*/ -int -gen_pause( struct wm_drive *d ) -{ -#ifdef CDDA - playing = WM_CDM_PAUSED; -#else - CDSTATUS s; - if( CDgetstatus(d->daux, &s)==0 ) - return -1; - if(s.state == CD_PLAYING) - CDtogglepause(d->daux); -#endif - return 0; -} /* gen_pause() */ - -/*-------------------------------------------------* - * Resume playing the CD (assuming it was paused.) - *-------------------------------------------------*/ -int -gen_resume( struct wm_drive *d ) -{ -#ifdef CDDA - playing = WM_CDM_PLAYING; - signal(SIGALRM, alarmsignal); - setitimer(ITIMER_REAL, &audiotimer, NULL); -#else - CDSTATUS s; - if( CDgetstatus(d->daux, &s)==0 ) - return -1; - if(s.state == CD_PAUSED) - CDtogglepause(d->daux); -#endif - return 0; -} /* gen_resume() */ - -/*--------------* - * Stop the CD. - *--------------*/ -int -gen_stop( struct wm_drive *d ) -{ -#ifdef CDDA - playing = WM_CDM_STOPPED; -#else - CDstop(d->daux); -#endif - return 0; -} /* gen_stop() */ - -/*----------------------------------------* - * Eject the current CD, if there is one. - *----------------------------------------*/ -int -gen_eject( struct wm_drive *d ) -{ -#ifdef CDDA - playing = WM_CDM_STOPPED; -#endif - CDeject(d->daux); - return 0; -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - * - * Please edit and send changes to - * milliByte@Deathsdoor.com - *----------------------------------------*/ - -int -gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - -/*---------------------------------------------------------------------* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - *---------------------------------------------------------------------*/ -int -gen_set_volume( struct wm_drive *d, int left, int right ) -{ - long Param[4]; - Param[0] = AL_LEFT_SPEAKER_GAIN; Param[1] = left*255/100; - Param[2] = AL_RIGHT_SPEAKER_GAIN; Param[3] = right*255/100; - ALsetparams(AL_DEFAULT_DEVICE, Param, 4); - return 0; -} /* gen_set_volume() */ - -/*---------------------------------------------------------------------* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - *---------------------------------------------------------------------*/ -int -gen_get_volume( struct wm_drive *d, int *left, int *right ) -{ - long Param[4]; - Param[0] = AL_LEFT_SPEAKER_GAIN; Param[1] = 0; - Param[2] = AL_RIGHT_SPEAKER_GAIN; Param[3] = 0; - ALgetparams(AL_DEFAULT_DEVICE, Param, 4); - *left = Param[1] * 100 / 255; - *right = Param[3] * 100 / 255; - return 0; -} /* gen_get_volume() */ - -#endif - diff --git a/kcompactdisc/wmlib/plat_linux.c b/kcompactdisc/wmlib/plat_linux.c deleted file mode 100644 index 2a7a178a..00000000 --- a/kcompactdisc/wmlib/plat_linux.c +++ /dev/null @@ -1,756 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Linux-specific drive control routines. Very similar to the Sun module. - */ - -#if defined(__linux__) - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cdtext.h" -#include "include/wm_cdda.h" -#include "include/wm_struct.h" -#include "include/wm_platform.h" -#include "include/wm_cdrom.h" -#include "include/wm_scsi.h" -#include "include/wm_helpers.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/* Try to get around bug #29274 */ -#include -#if 0 -/* this breaks the build on ia64 and s390 for example. - sys/types.h is already included and should provide __u64. - please tell where we really need this and let's try to find - a working #if case for everyone ... adrian@suse.de */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,50)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) -#undef __GNUC__ -typedef unsigned long long __u64; -#endif -#endif - -#if defined(BSD_MOUNTTEST) - #include -#else - /* - * this is for glibc 2.x which defines ust structure in - * ustat.h not stat.h - */ - #ifdef __GLIBC__ - #include - #endif -#endif - - -#include -#include - -#ifndef __GNUC__ -#define __GNUC__ 1 -#endif -/* needed for vanilla kernel headers, which do provide __u64 only - for ansi */ -#undef __STRICT_ANSI__ -/* needed for non-ansi kernel headers */ -#define asm __asm__ -#define inline __inline__ -#include -#include -#undef asm -#undef inline - -#ifdef OSS_SUPPORT -#include -#define CD_CHANNEL SOUND_MIXER_CD -#endif - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -#ifdef LINUX_SCSI_PASSTHROUGH -/* this is from */ -# define SCSI_IOCTL_SEND_COMMAND 1 -#endif - -/*-------------------------------------------------------* - * - * - * CD-ROM drive functions. - * - * - *-------------------------------------------------------*/ -int gen_init(struct wm_drive *d) -{ - return 0; -} - -int gen_open(struct wm_drive *d) -{ - if(d->fd > -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "plat_open(): [device is open (fd=%d)]\n", - d->fd); - return 0; - } - - d->fd = open(d->cd_device, O_RDONLY | O_NONBLOCK); - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "plat_open(): device=%s fd=%d\n", - d->cd_device, d->fd); - - if(d->fd < 0) - return -errno; - - return 0; -} - -int gen_close(struct wm_drive *d) -{ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "linux_close(): closing the device\n"); - - close(d->fd); - d->fd = -1; - - return 0; -} - -/*--------------------------------------------------------------------------* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - *--------------------------------------------------------------------------*/ -int gen_get_drive_status(struct wm_drive *d, int oldmode, int *mode, int *pos, int *track, int *ind) -{ - struct cdrom_subchnl sc; - int ret; - -#ifdef SBPCD_HACK - static int prevpos = 0; -#endif - - /* Is the device open? */ - if (d->fd > -1) { - ret = d->proto.open(d); - if(ret < 0) /* error */ - return ret; - - if(ret == 1) { - /* retry */ - *mode = WM_CDM_UNKNOWN; - return 0; - } - } - - /* Try to get rid of the door locking */ - /* Don't care about return value. If it */ - /* works - fine. If not - ... */ - ioctl(d->fd, CDROM_LOCKDOOR, 0); - - *mode = WM_CDM_UNKNOWN; - - sc.cdsc_format = CDROM_MSF; - - if(!ioctl(d->fd, CDROMSUBCHNL, &sc)) { - switch (sc.cdsc_audiostatus) { - case CDROM_AUDIO_PLAY: - *mode = WM_CDM_PLAYING; - *track = sc.cdsc_trk; - *ind = sc.cdsc_ind; - *pos = sc.cdsc_absaddr.msf.minute * 60 * 75 + - sc.cdsc_absaddr.msf.second * 75 + - sc.cdsc_absaddr.msf.frame; -#ifdef SBPCD_HACK - if( *pos < prevpos ) { - if( (prevpos - *pos) < 75 ) { - *mode = WM_CDM_TRACK_DONE; - } - } - - prevpos = *pos; -#endif - break; - - case CDROM_AUDIO_PAUSED: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) { - *mode = WM_CDM_PAUSED; - *track = sc.cdsc_trk; - *ind = sc.cdsc_ind; - *pos = sc.cdsc_absaddr.msf.minute * 60 * 75 + - sc.cdsc_absaddr.msf.second * 75 + - sc.cdsc_absaddr.msf.frame; - } else - *mode = WM_CDM_STOPPED; - break; - - case CDROM_AUDIO_NO_STATUS: - *mode = WM_CDM_STOPPED; - break; - - case CDROM_AUDIO_COMPLETED: - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - break; - - case CDROM_AUDIO_INVALID: /**/ - default: - *mode = WM_CDM_UNKNOWN; - break; - } - } - - if(WM_CDS_NO_DISC(*mode)) { - /* verify status of drive */ - ret = ioctl(d->fd, CDROM_DRIVE_STATUS, 0/* slot */); - if(ret == CDS_DISC_OK) - ret = ioctl(d->fd, CDROM_DISC_STATUS, 0); - - switch(ret) { - case CDS_NO_DISC: - *mode = WM_CDM_NO_DISC; - break; - case CDS_TRAY_OPEN: - *mode = WM_CDM_EJECTED; - break; - case CDS_AUDIO: - case CDS_MIXED: - *mode = WM_CDM_STOPPED; - break; - case CDS_DRIVE_NOT_READY: - case CDS_NO_INFO: - case CDS_DATA_1: - case CDS_DATA_2: - case CDS_XA_2_1: - case CDS_XA_2_2: - default: - *mode = WM_CDM_UNKNOWN; - } - } - - return 0; -} - -/*-------------------------------------* - * Get the number of tracks on the CD. - *-------------------------------------*/ -int gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - struct cdrom_tochdr hdr; - - if(ioctl(d->fd, CDROMREADTOCHDR, &hdr)) - return -1; - - *tracks = hdr.cdth_trk1; - return 0; -} - -/*---------------------------------------------------------* - * Get the start time and mode (data or audio) of a track. - *---------------------------------------------------------*/ -int gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - struct cdrom_tocentry entry; - - entry.cdte_track = track; - entry.cdte_format = CDROM_MSF; - - if(ioctl(d->fd, CDROMREADTOCENTRY, &entry)) - return -1; - - *startframe = entry.cdte_addr.msf.minute * 60 * 75 + - entry.cdte_addr.msf.second * 75 + - entry.cdte_addr.msf.frame; - *data = entry.cdte_ctrl & CDROM_DATA_TRACK ? 1 : 0; - - return 0; -} - -/*-------------------------------------* - * Get the number of frames on the CD. - *-------------------------------------*/ -int gen_get_cdlen(struct wm_drive *d, int *frames) -{ - int tmp; - - return d->proto.get_trackinfo(d, CDROM_LEADOUT, &tmp, frames); -} - -/*------------------------------------------------------------* - * Play the CD from one position to another (both in frames.) - *------------------------------------------------------------*/ -int gen_play(struct wm_drive *d, int start, int end) -{ - struct cdrom_msf msf; - - msf.cdmsf_min0 = start / (60*75); - msf.cdmsf_sec0 = (start % (60*75)) / 75; - msf.cdmsf_frame0 = start % 75; - msf.cdmsf_min1 = end / (60*75); - msf.cdmsf_sec1 = (end % (60*75)) / 75; - msf.cdmsf_frame1 = end % 75; - - if(ioctl(d->fd, CDROMPLAYMSF, &msf)) { - if(ioctl(d->fd, CDROMSTART)) - return -1; - if(ioctl(d->fd, CDROMPLAYMSF, &msf)) - return -2; - } - - return 0; -} - -/*---------------* - * Pause the CD. - *---------------*/ -int gen_pause(struct wm_drive *d) -{ - return ioctl(d->fd, CDROMPAUSE); -} - -/*-------------------------------------------------* - * Resume playing the CD (assuming it was paused.) - *-------------------------------------------------*/ -int gen_resume(struct wm_drive *d) -{ - return ioctl(d->fd, CDROMRESUME); -} - -/*--------------* - * Stop the CD. - *--------------*/ -int gen_stop(struct wm_drive *d) -{ - return ioctl(d->fd, CDROMSTOP); -} - -/*----------------------------------------* - * Eject the current CD, if there is one. - *----------------------------------------*/ -int gen_eject(struct wm_drive *d) -{ - struct stat stbuf; -#if !defined(BSD_MOUNTTEST) - struct ustat ust; -#else - struct mntent *mnt; - FILE *fp; -#endif - - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "ejecting?\n"); - - if(fstat(d->fd, &stbuf) != 0) { - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, "that weird fstat() thingy\n"); - return -2; - } - - /* Is this a mounted filesystem? */ -#if !defined(BSD_MOUNTTEST) - if (ustat(stbuf.st_rdev, &ust) == 0) - return -3; -#else - /* - * This is the same test as in the WorkBone interface. - * I should eliminate it there, because there is no need - * for it in the UI - */ - /* check if drive is mounted (from Mark Buckaway's cdplayer code) */ - /* Changed it again (look at XPLAYCD from ???? */ - /* It's better to check the device name rather than one device is */ - /* mounted as iso9660. That prevents "no playing" if you have more*/ - /* than one CD-ROM, and one of them is mounted, but it's not the */ - /* audio CD -dirk */ - if((fp = setmntent (MOUNTED, "r")) == NULL) { - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, "Could not open %s: %s\n", - MOUNTED, strerror (errno)); - return -3; - } - - while((mnt = getmntent (fp)) != NULL) { - if(strcmp (mnt->mnt_fsname, d->cd_device) == 0) { - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "CDROM already mounted (according to mtab). Operation aborted.\n"); - endmntent (fp); - return -3; - } - } - endmntent (fp); -#endif /* BSD_MOUNTTEST */ - - ioctl(d->fd, CDROM_LOCKDOOR, 0); - - if(ioctl(d->fd, CDROMEJECT)) { - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, "eject failed (%s).\n", strerror(errno)); - return -1; - } - - /*------------------ - * Things in "foobar_one" are left over from 1.4b3 - * I put them here for further observation. In 1.4b3, however, - * that workaround didn't help at least for /dev/sbpcd - * (The tray closed just after ejecting because re-opening the - * device causes the tray to close) - *------------------*/ -#ifdef foobar_one - extern int intermittent_dev - /* - * Some drives (drivers?) won't recognize a new CD if we leave the - * device open. - */ - if(intermittent_dev) - d->proto.close(d); -#endif - - return 0; -} - -int gen_closetray(struct wm_drive *d) -{ -#ifdef CDROMCLOSETRAY - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, "CDROMCLOSETRAY closing tray...\n"); - return ioctl(d->fd, CDROMCLOSETRAY); -#else - return -1; -#endif /* CDROMCLOSETRAY */ -} - -static int min_volume = 0, max_volume = 255; -/*------------------------------------------------------------------------* - * scale_volume(vol, max) - * - * Return a volume value suitable for passing to the CD-ROM drive. "vol" - * is a volume slider setting; "max" is the slider's maximum value. - * This is not used if sound card support is enabled. - * - *------------------------------------------------------------------------*/ -static int scale_volume(int vol, int max) -{ -#ifdef CURVED_VOLUME - return ((max * max - (max - vol) * (max - vol)) * - track_info_status(max_volume - min_volume) / (max * max) + min_volume); -#else - return ((vol * (max_volume - min_volume)) / max + min_volume); -#endif -} - -static int unscale_volume(int vol, int max) -{ -#ifdef CURVED_VOLUME - /* FIXME do it simpler */ - int tmp = (((max_volume - min_volume - vol) * max * max) - (vol + min_volume)); - return max - sqrt((tmp/(max_volume - min_volume))); -#else - return (((vol - min_volume) * max) / (max_volume - min_volume)); -#endif -} - -/*---------------------------------------------------------------------* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - *---------------------------------------------------------------------*/ -int gen_set_volume(struct wm_drive *d, int left, int right) -{ - struct cdrom_volctrl v; - - v.channel0 = v.channel2 = left < 0 ? 0 : left > 255 ? 255 : left; - v.channel1 = v.channel3 = right < 0 ? 0 : right > 255 ? 255 : right; - - return (ioctl(d->fd, CDROMVOLCTRL, &v)); -} - -/*---------------------------------------------------------------------* - * Read the volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - *---------------------------------------------------------------------*/ -int gen_get_volume(struct wm_drive *d, int *left, int *right) -{ - struct cdrom_volctrl v; - -#if defined(CDROMVOLREAD) - if(!ioctl(d->fd, CDROMVOLREAD, &v)) { - *left = (v.channel0 + v.channel2)/2; - *right = (v.channel1 + v.channel3)/2; - } else -#endif - /* Suns, HPs, Linux, NEWS can't read the volume; oh well */ - *left = *right = -1; - - return 0; -} - -int gen_scale_volume(int *left, int *right) -{ - /* Adjust the volume to make up for the CD-ROM drive's weirdness. */ - *left = scale_volume(*left, 100); - *right = scale_volume(*right, 100); - - return 0; -} - -int gen_unscale_volume(int *left, int *right) -{ - *left = unscale_volume(*left, 100); - *right = unscale_volume(*right, 100); - - return 0; -} - -/*---------------------------------------------* - * Send an arbitrary SCSI command to a device. - *---------------------------------------------*/ -int gen_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen, - void *retbuf, int retbuflen, int getreply) -{ - int ret; -#ifdef LINUX_SCSI_PASSTHROUGH - - char *cmd; - int cmdsize; - - cmdsize = 2 * sizeof(int); - if(retbuf) { - if (getreply) - cmdsize += max(cdblen, retbuflen); - else - cmdsize += (cdblen + retbuflen); - } else { - cmdsize += cdblen; - } - - cmd = malloc(cmdsize); - if(cmd == NULL) { - return -ENOMEM; - } - ((int*)cmd)[0] = cdblen + ((retbuf && !getreply) ? retbuflen : 0); - ((int*)cmd)[1] = ((retbuf && getreply) ? retbuflen : 0); - - memcpy(cmd + 2*sizeof(int), cdb, cdblen); - if(retbuf && !getreply) - memcpy(cmd + 2*sizeof(int) + cdblen, retbuf, retbuflen); - - if(ioctl(d->fd, SCSI_IOCTL_SEND_COMMAND, cmd)) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "%s: ioctl(SCSI_IOCTL_SEND_COMMAND) failure\n", __FILE__); - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "command buffer is:\n"); - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "%02x %02x %02x %02x %02x %02x\n", - cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5]); - free(cmd); - return -1; - } - - if(retbuf && getreply) - memcpy(retbuf, cmd + 2*sizeof(int), retbuflen); - - free(cmd); - return 0; - -#else /* Linux SCSI passthrough*/ -/*----------------------------------------* - * send packet over cdrom interface - * kernel >= 2.2.16 - *----------------------------------------*/ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,2,15)) - - struct cdrom_generic_command cdc; - struct request_sense sense; - int capability; - - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wm_scsi over CDROM_SEND_PACKET entered\n"); - - capability = ioctl(d->fd, CDROM_GET_CAPABILITY); - - if(!(capability & CDC_GENERIC_PACKET)) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, - "your CDROM or/and kernel does not support CDC_GENERIC_PACKET ...\n"); - return -1; - } - - memset(&cdc, 0, sizeof(struct cdrom_generic_command)); - memset(&sense, 0, sizeof(struct request_sense)); - - memcpy(cdc.cmd, cdb, cdblen); - - cdc.buffer = retbuf; - cdc.buflen = retbuflen; - cdc.stat = 0; - cdc.sense = &sense; - cdc.data_direction = getreply?CGC_DATA_READ:CGC_DATA_WRITE; - - /* sendpacket_over_cdrom_interface() */ - if((ret = ioctl(d->fd, CDROM_SEND_PACKET, &cdc))) - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "ERROR: CDROM_SEND_PACKET %s\n", strerror(errno)); - return ret; -#endif /* CDROM_SEND_PACKET */ - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "ERROR: this binary was compiled without CDROM GENERIC PACKET SUPPORT. kernel version < 2.2.16?\n"); - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "ERROR: if you have a SCSI CDROM, rebuild it with a #define LINUX_SCSI_PASSTHROUGH\n"); - return -1; -#endif -} - -#if 0 -#define CDROM_LBA 0x01 /* "logical block": first frame is #0 */ -#define CDROMREADAUDIO 0x530e /* (struct cdrom_read_audio) */ -#define CD_MSF_OFFSET 150 /* MSF numbering offset of first frame */ - -/* This struct is used by the CDROMREADAUDIO ioctl */ -struct cdrom_read_audio -{ - union { - struct { - unsigned char minute; - unsigned char second; - unsigned char frame; - } msf; - signed int lba; - } addr; /* frame address */ - unsigned char addr_format; /* CDROM_LBA or CDROM_MSF */ - signed int nframes; /* number of 2352-byte-frames to read at once */ - unsigned char *buf; /* frame buffer (size: nframes*2352 bytes) */ -}; - -#define CDDABLKSIZE 2352 - -#endif - -int gen_cdda_init(struct wm_drive *d) -{ - return 0; -} - -/* - * Initialize the CDDA data buffer and open the appropriate device. - * - */ -int gen_cdda_open(struct wm_drive *d) -{ - int i; - struct cdrom_read_audio cdda; - - if (d->fd > -1) - return -1; - - for (i = 0; i < d->numblocks; i++) { - d->blocks[i].buflen = d->frames_at_once * CD_FRAMESIZE_RAW; - d->blocks[i].buf = malloc(d->blocks[i].buflen); - if (!d->blocks[i].buf) { - ERRORLOG("plat_cdda_open: ENOMEM\n"); - return -ENOMEM; - } - } - - cdda.addr_format = CDROM_LBA; - cdda.addr.lba = 200; - cdda.nframes = 1; - cdda.buf = (unsigned char *)d->blocks[0].buf; - - d->status = WM_CDM_STOPPED; - if((ioctl(d->fd, CDROMREADAUDIO, &cdda) < 0)) { - if (errno == ENXIO) { - /* CD ejected! */ - d->status = WM_CDM_EJECTED; - } else { - /* Sometimes it fails once, dunno why */ - d->status = WM_CDM_CDDAERROR; - } - } else { - d->status = WM_CDM_UNKNOWN; - } - - - return 0; -} - -/* - * Read some blocks from the CD. Stop if we hit the end of the current region. - * - * Returns number of bytes read, -1 on error, 0 if stopped for a benign reason. - */ -int gen_cdda_read(struct wm_drive *d, struct wm_cdda_block *block) -{ - struct cdrom_read_audio cdda; - - if (d->fd < 0) - return -1; - - /* Hit the end of the CD, probably. */ - if (d->current_position >= d->ending_position) { - block->status = WM_CDM_TRACK_DONE; - return 0; - } - - cdda.addr_format = CDROM_LBA; - cdda.addr.lba = d->current_position - CD_MSF_OFFSET; - if (d->ending_position && d->current_position + d->frames_at_once > d->ending_position) - cdda.nframes = d->ending_position - d->current_position; - else - cdda.nframes = d->frames_at_once; - - cdda.buf = (unsigned char*)block->buf; - - if (ioctl(d->fd, CDROMREADAUDIO, &cdda) < 0) { - if (errno == ENXIO) { - /* CD ejected! */ - block->status = WM_CDM_EJECTED; - return 0; - } else { - /* Sometimes it fails once, dunno why */ - block->status = WM_CDM_CDDAERROR; - return 0; - } - } - - block->track = -1; - block->index = 0; - block->frame = d->current_position; - block->status = WM_CDM_PLAYING; - block->buflen = cdda.nframes * CD_FRAMESIZE_RAW; - - d->current_position = d->current_position + cdda.nframes; - - return block->buflen; -} - -/* - * Close the CD-ROM device in preparation for exiting. - */ -int gen_cdda_close(struct wm_drive *d) -{ - int i; - - if (d->fd < 0) - return -1; - - for (i = 0; i < d->numblocks; i++) { - free(d->blocks[i].buf); - d->blocks[i].buf = 0; - d->blocks[i].buflen = 0; - } - - return 0; -} - -#endif /* __linux__ */ diff --git a/kcompactdisc/wmlib/plat_news.c b/kcompactdisc/wmlib/plat_news.c deleted file mode 100644 index e9227c86..00000000 --- a/kcompactdisc/wmlib/plat_news.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Sony NEWS-specific drive control routines. - */ - -#if defined( __sony_news) || defined(sony_news) - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -void *malloc(); -char *strchr(); - -extern int intermittent_dev; - -int min_volume = 128; -int max_volume = 255; - -/* - * Initialize the drive. A no-op for the generic driver. - */ -int -gen_init( struct wm_drive *d ) -{ - return 0; -} /* gen_init() */ - -/* - * Open the CD device and figure out what kind of drive is attached. - */ -int -gen_open( struct wm_drive *d ) -{ - if (d->fd > -1) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - intermittent_dev = 1; - - if ((d->fd = CD_Open(d->cd_device, 0)) < 0) { - /* Solaris 2.2 volume manager moves links around */ - if (errno == ENOENT && intermittent_dev) - return 0; - - if (errno == EACCES) - return -EACCES; - else if (errno != EIO) /* defined at top */ - return -6; - - /* No CD in drive. */ - return 1; - } - - return 0; -} /* gen_open() */ - -/* - * Pass SCSI commands to the device. - */ -int -gen_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen, - unsigned char *buf, int buflen, int getreply) -{ - /* NEWS can't do SCSI passthrough... or can it? */ - return -1; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - int ret = 0; - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device.\n"); - ret = CD_Close(d->fd); - d->fd = -1; - wm_susleep(3000000); - } - return ret; -} - -/* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - */ -int -gen_get_drive_status( struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *index) -{ - struct CD_Status sc; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - /* Is the device open? */ - if (d->fd < 0) { - switch (d->proto.open(d)) { - case -1: /* error */ - return -1; - - case 1: /* retry */ - return 0; - } - } - - /* Disc is ejected. Close the device. */ - if (CD_GetStatus(d->fd, &sc)) { - gen_close(d); - return 0; - } - - switch (sc.status) { - case CDSTAT_PLAY: - *mode = WM_CDM_PLAYING; - break; - - case CDSTAT_PAUSE: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) - *mode = WM_CDM_PAUSED; - else - *mode = WM_CDM_STOPPED; - break; - - case CDSTAT_STOP: - if (oldmode == WM_CDM_PLAYING) { - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - break; - } - /* fall through */ - - default: - *mode = WM_CDM_STOPPED; - break; - } - - switch(*mode) { - case WM_CDM_PLAYING: - case WM_CDM_PAUSED: - *track = sc.tno; - *index = sc.index; - *pos = sc.baddr; - break; - } - - return 0; -} /* gen_get_drive_status() */ - -/* - * Get the number of tracks on the CD. - */ -int -gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - struct CD_Capacity cc; - - if (CD_GetCapacity(d->fd, &cc)) - return -1; - - *tracks = cc.etrack - 1; - return 0; -} /* gen_get_trackcount() */ - -/* - * Get the start time and mode (data or audio) of a track. - */ -int -gen_get_trackinfo( struct wm_drive *d, int track, int *data, int *startframe ) -{ - struct CD_TOCinfo hdr; - struct CD_TOCdata ent; - - hdr.strack = track; - hdr.ntrack = 1; - hdr.data = &ent; - if (CD_ReadTOC(d->fd, &hdr)) - return (-1); - - *data = (ent.control & 4) ? 1 : 0; - *startframe = ent.baddr; - - return 0; -} /* gen_get_trackinfo */ - -/* - * Get the number of frames on the CD. - */ -int -gen_get_cdlen( struct wm_drive *d, int *frames ) -{ - int tmp; - - if ((d->get_trackcount)(d, &tmp)) - return -1; - - return gen_get_trackinfo(d, tmp + 1, &tmp, frames); -} /* gen_get_cdlen() */ - - -/* - * Play the CD from one position to another (both in frames.) - */ -int -gen_play( struct wm_drive *d, int start, int end ) -{ - struct CD_PlayAddr msf; - - msf.addrmode = CD_MSF; - msf.addr.msf.startmsf.min = start / (60*75); - msf.addr.msf.startmsf.sec = (start % (60*75)) / 75; - msf.addr.msf.startmsf.frame = start % 75; - msf.addr.msf.endmsf.min = end / (60*75); - msf.addr.msf.endmsf.sec = (end % (60*75)) / 75; - msf.addr.msf.endmsf.frame = end % 75; - - if (CD_Play(d->fd, &msf)) { - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "wm_cd_play_chunk(%d,%d)\n",start,end); - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "msf = %d:%d:%d %d:%d:%d\n", - msf.addr.msf.startmsf.min, - msf.addr.msf.startmsf.sec, - msf.addr.msf.startmsf.frame, - msf.addr.msf.endmsf.min, - msf.addr.msf.endmsf.sec, - msf.addr.msf.endmsf.frame); - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "CD_Play"); - return -1; - } - - return 0; -} /* gen_play() */ - -/* - * Pause the CD. - */ -int -gen_pause( struct wm_drive *d ) -{ - CD_Pause(d->fd); - return 0; -} /* gen_pause() */ - -/* - * Resume playing the CD (assuming it was paused.) - */ -int -gen_resume( struct wm_drive *d ) -{ - CD_Restart(d->fd); - return 0; -} /* gen_resume() */ - -/* - * Stop the CD. - */ -int -gen_stop( struct wm_drive *d ) -{ - CD_Stop(d->fd); - return 0; -} /* gen_stop() */ - -/* - * Eject the current CD, if there is one. - */ -int -gen_eject( struct wm_drive *d ) -{ - struct stat stbuf; - struct ustat ust; - - if (fstat(d->fd, &stbuf) != 0) - return -2; - - /* Is this a mounted filesystem? */ - if (ustat(stbuf.st_rdev, &ust) == 0) - return -3; - - if (CD_AutoEject(d->fd)) - return -1); - - /* Close the device if it needs to vanish. */ - if (intermittent_dev) - gen_close(d); - - return 0; -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - * - * Please edit and send changes to - * milliByte@DeathsDoor.com - *----------------------------------------*/ -int -gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - - -/* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - */ -int -gen_set_volume( struct wm_drive *d, int left, int right) -{ - /* NEWS can't adjust volume! */ - return 0; -} - -/* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - */ -int -gen_get_volume( struct wm_drive *d, omt *left, int *right) -{ - /* Suns, HPs, Linux, NEWS can't read the volume; oh well */ - *left = *right = -1; - return 0; -} /* gen_get_volume() */ - -#endif diff --git a/kcompactdisc/wmlib/plat_openbsd.c b/kcompactdisc/wmlib/plat_openbsd.c deleted file mode 100644 index f6c4caf4..00000000 --- a/kcompactdisc/wmlib/plat_openbsd.c +++ /dev/null @@ -1,480 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * OpenBSD-specific drive control routines. (Based on plat_freebsd.c) - * - * Michael Shalayeff, 7/24/96 - * Todd Pfaff, 3/20/94 - * - */ - -#if defined(__OpenBSD__) || defined(__OpenBSD) - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" -#include "include/wm_cdrom.h" -#include "include/wm_helpers.h" - -/* this is for glibc 2.x which defines the ust structure in ustat.h not stat.h */ -#ifdef __GLIBC__ -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_struct.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -void *malloc(); - -int min_volume = 10; -int max_volume = 255; - -const char* -find_cdrom() -{ - if (access("/dev/rcd0c", F_OK) == 0) { - return "/dev/rcd0c"; - } else if (access("/dev/rcd1c", F_OK) == 0) { - return "/dev/rcd1c"; - } else if (access("/dev/acd0c", F_OK) == 0) { - return "/dev/acd0c"; - } else { - fprintf(stderr, "Could not find a CD device!\n"); - return NULL; - } -} /* find_cdrom() */ - -/* - * Initialize the drive. A no-op for the generic driver. - */ -int -gen_init(struct wm_drive *d) -{ - return (0); -} /* gen_init() */ - - -/* - * Open the CD device and figure out what kind of drive is attached. - */ -int -gen_open(struct wm_drive *d) -{ - if (d->fd >= 0) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - d->fd = open(d->cd_device, O_RDONLY); - if (d->fd < 0) { - if (errno == EIO) /* No CD in drive. */ - return 1; - else - return -errno; - } - - return 0; -} /* gen_open() */ - -/* - * Send an arbitrary SCSI command to a device. - * - */ -int -gen_scsi(struct wm_drive *d, unsigned char *cdb, - int cdblen, void *retbuf, int retbuflen, int getreply) -{ - return -1; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd > -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - } - d->fd = -1; - return 0; -} - -/* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - */ -int -gen_get_drive_status(struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *index) -{ - struct ioc_read_subchannel sc; - struct cd_sub_channel_info scd; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - sc.address_format = CD_MSF_FORMAT; - sc.data_format = CD_CURRENT_POSITION; - sc.track = 0; - sc.data_len = sizeof(scd); - sc.data = (struct cd_sub_channel_info *)&scd; - - /* Is the device open? */ - if (d->fd < 0) { - switch (d->proto.open(d)) { - case -1: /* error */ - return -1; - case 1: /* retry */ - return 0; - } - } - - if (ioctl(d->fd, CDIOCREADSUBCHANNEL, &sc)) { - /* we need to release the device so the kernel will notice - reloaded media */ - d->proto.close(d); - return 0; /* ejected */ - } - - switch (scd.header.audio_status) { - case CD_AS_PLAY_IN_PROGRESS: - *mode = WM_CDM_PLAYING; - break; - - case CD_AS_PLAY_PAUSED: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) - *mode = WM_CDM_PAUSED; - else - *mode = WM_CDM_STOPPED; - break; - - case CD_AS_PLAY_COMPLETED: - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - break; - - case CD_AS_NO_STATUS: - case 0: - *mode = WM_CDM_STOPPED; - break; - } - - switch(*mode) { - case WM_CDM_PLAYING: - case WM_CDM_PAUSED: - *pos = scd.what.position.absaddr.msf.minute * 60 * 75 + - scd.what.position.absaddr.msf.second * 75 + - scd.what.position.absaddr.msf.frame; - *track = scd.what.position.track_number; - *index = scd.what.position.index_number; - break; - } - - return 0; -} /* gen_get_drive_status() */ - -/* - * Get the number of tracks on the CD. - */ -int -gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - struct ioc_toc_header hdr; - - if (ioctl(d->fd, CDIOREADTOCHEADER, &hdr) == -1) - return (-1); - - *tracks = hdr.ending_track - hdr.starting_track + 1; - return (0); -} /* gen_get_trackcount() */ - -/* - * Get the start time and mode (data or audio) of a track. - * - * XXX - this should get cached, but that means keeping track of ejects. - */ -int -gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - struct ioc_read_toc_entry toc; - struct cd_toc_entry toc_buffer; - - bzero((char *)&toc_buffer, sizeof(toc_buffer)); - toc.address_format = CD_MSF_FORMAT; - toc.starting_track = track; - toc.data_len = sizeof(toc_buffer); - toc.data = &toc_buffer; - - if (ioctl(d->fd, CDIOREADTOCENTRYS, &toc)) - return (-1); - - *data = ((toc_buffer.control & 0x4) != 0); - - *startframe = toc_buffer.addr.msf.minute*60*75 + - toc_buffer.addr.msf.second * 75 + - toc_buffer.addr.msf.frame; - - return (0); -} /* gen_get_trackinfo() */ - -/* - * Get the number of frames on the CD. - */ -int -gen_get_cdlen(struct wm_drive *d, int *frames) -{ - int tmp; - struct ioc_toc_header hdr; - int status; - -#define LEADOUT 0xaa /* see scsi.c. what a hack! */ - return gen_get_trackinfo(d, LEADOUT, &tmp, frames); -} /* gen_get_cdlen() */ - -/* - * Play the CD from one position to another (both in frames.) - */ -int -gen_play(struct wm_drive *d, int start, int end) -{ - struct ioc_play_msf msf; - - msf.start_m = start / (60*75); - msf.start_s = (start % (60*75)) / 75; - msf.start_f = start % 75; - msf.end_m = end / (60*75); - msf.end_s = (end % (60*75)) / 75; - msf.end_f = end % 75; - - if (ioctl(d->fd, CDIOCSTART)) - return (-1); - - if (ioctl(d->fd, CDIOCPLAYMSF, &msf)) - return (-2); - - return (0); -} /* gen_play() */ - -/* - * Pause the CD. - */ -int -gen_pause(struct wm_drive *d) -{ - return (ioctl(d->fd, CDIOCPAUSE)); -} /* gen_pause() */ - -/* - * Resume playing the CD (assuming it was paused.) - */ -int -gen_resume(struct wm_drive *d) -{ - return (ioctl(d->fd, CDIOCRESUME)); -} /* gen_resume() */ - -/* - * Stop the CD. - */ -int -gen_stop(struct wm_drive *d) -{ - return (ioctl(d->fd, CDIOCSTOP)); -} /* gen_stop() */ - -/* - * Eject the current CD, if there is one. - */ -int -gen_eject(struct wm_drive *d) -{ - /* On some systems, we can check to see if the CD is mounted. */ - struct stat stbuf; - struct statfs buf; - int rval; - - if (fstat(d->fd, &stbuf) != 0) - return (-2); - - /* Is this a mounted filesystem? */ - if (fstatfs(stbuf.st_rdev, &buf) == 0) - return (-3); - - rval = ioctl(d->fd, CDIOCALLOW); - if (rval == 0) - rval = ioctl(d->fd, CDIOCEJECT); - if (rval == 0) - rval = ioctl(d->fd, CDIOCPREVENT); - if (rval == 0) - rval = close(d->fd); - if (rval == 0) - d->fd = -1; - return rval; -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - * - * Please edit and send changes to - * milliByte@DeathsDoor.com - *----------------------------------------*/ - -int -gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - -/* - * scale_volume(vol, max) - * - * Return a volume value suitable for passing to the CD-ROM drive. "vol" - * is a volume slider setting; "max" is the slider's maximum value. - * - * On Sun and DEC CD-ROM drives, the amount of sound coming out the jack - * increases much faster toward the top end of the volume scale than it - * does at the bottom. To make up for this, we make the volume scale look - * sort of logarithmic (actually an upside-down inverse square curve) so - * that the volume value passed to the drive changes less and less as you - * approach the maximum slider setting. The actual formula looks like - * - * (max^2 - (max - vol)^2) * (max_volume - min_volume) - * v = --------------------------------------------------- + min_volume - * max^2 - * - * If your system's volume settings aren't broken in this way, something - * like the following should work: - * - * return ((vol * (max_volume - min_volume)) / max + min_volume); - */ -static int -scale_volume(int vol, int max) -{ - return ((vol * (max_volume - min_volume)) / max + min_volume); -} /* scale_volume() */ - -/* - * unscale_volume(cd_vol, max) - * - * Given a value between min_volume and max_volume, return the volume slider - * value needed to achieve that value. - * - * Rather than perform floating-point calculations to reverse the above - * formula, we simply do a binary search of scale_volume()'s return values. - */ -static int -unscale_volume(int cd_vol, int max) -{ - int vol = 0, top = max, bot = 0, scaled; - - while (bot <= top) - { - vol = (top + bot) / 2; - scaled = scale_volume(vol, max); - if (cd_vol == scaled) - break; - if (cd_vol < scaled) - top = vol - 1; - else - bot = vol + 1; - } - - if (vol < 0) - vol = 0; - else if (vol > max) - vol = max; - - return (vol); -} /* unscale_volume() */ - -/* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - */ -int -gen_set_volume(struct wm_drive *d, int left, int right) -{ - struct ioc_vol vol; - - if (left < 0) /* don't laugh, I saw this happen once! */ - left = 0; - if (right < 0) - right = 0; - left = scale_volume(left, 100); - right = scale_volume(right, 100); - - bzero((char *)&vol, sizeof(vol)); - - vol.vol[LEFT_PORT] = left; - vol.vol[RIGHT_PORT] = right; - - if (ioctl(d->fd, CDIOCSETVOL, &vol)) - return (-1); - - return (0); -} /* gen_set_volume() */ - - -/* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - */ -int -gen_get_volume(struct wm_drive *d, int *left, int *right) -{ - struct ioc_vol vol; - - if (d->fd >= 0) - { - bzero((char *)&vol, sizeof(vol)); - - if (ioctl(d->fd, CDIOCGETVOL, &vol)) - *left = *right = -1; - else - { - *left = unscale_volume(vol.vol[LEFT_PORT], 100); - *right = unscale_volume(vol.vol[RIGHT_PORT], 100); - } - } - else - *left = *right = -1; - - return (0); -} /* gen_get_volume() */ - -#endif diff --git a/kcompactdisc/wmlib/plat_osf1.c b/kcompactdisc/wmlib/plat_osf1.c deleted file mode 100644 index 63efb912..00000000 --- a/kcompactdisc/wmlib/plat_osf1.c +++ /dev/null @@ -1,610 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * OSF drive control routines. - */ - - -#if defined(__osf__) || defined(__osf) - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -/* #include -#include */ -#include -#include - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_helpers.h" -#include "include/wm_cdtext.h" - - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -/* - * This structure will be filled with the TOC header and all entries. - * Ultrix doesn't seem to allow getting single TOC entries. - * - Chris Ross (cross@eng.umd.edu) - */ -struct cd_toc_header_and_entries -{ - struct cd_toc_header cdth; - struct cd_toc_entry cdte[CDROM_MAX_TRACK+1]; -}; - -void *malloc(); -char *strchr(); - -int min_volume = 128; -int max_volume = 255; -static char* osf_cd_device = NULL; - -/* - * fgetline() - * - * Simulate fgets, but joining continued lines in the output of uerf. - * - * platform specific internal function - * - */ - -#define BUF_SIZE 85 /* Max length of a (real) line */ - -char * -fgetline( FILE *fp ) -{ - static char *retval = NULL; - static char holdbuf[BUF_SIZE + 1]; - char tmp[BUF_SIZE + 1]; - char *stmp; - - if (!retval) - { - retval = malloc(BUF_SIZE * 3); /* 3 lines can be joined */ - if (!retval) - return(NULL); - else - *retval = '\0'; - } - - if (*holdbuf) - { - strcpy(retval, holdbuf); - retval[strlen(retval)-1] = '\0'; - memset(holdbuf, 0, BUF_SIZE+1); - } - - while (fgets(tmp, BUF_SIZE, fp)) - { - stmp = tmp + strspn(tmp, " \t"); - if (*stmp == '_') { /* Continuation line */ - retval[strlen(retval)-1] = '\0'; /* Trim off C/R */ - strcat(retval, stmp+1); - } else { - if (*retval) - { - strcpy(holdbuf, tmp); - holdbuf[strlen(holdbuf)-1] = -1; - return retval; - } else { /* First line read, keep reading */ - strcat(retval, stmp); - retval[strlen(retval)-1] = '\0'; - } - } - } - return NULL; -} /* fgetline() */ - - -/* - * find_cdrom - * - * Determine the name of the CD-ROM device. - * - * Read through the boot records (via a call to uerf) and find the SCSI - * address of the CD-ROM. - */ -const char* -find_cdrom() -{ - char *data; - FILE *uerf; - int fds[2]; - int pid; - extern char *getenv(); - const char *device = NULL; - - pipe(fds); - - device = getenv("CDROM"); - /* - ** the path of the device has to start w/ /dev - ** otherwise we are vulnerable to race conditions - ** Thomas Biege - */ - if ( device == NULL || - strncmp("/dev/", device, 5) || - strstr(device, "/../") - ) - return NULL; - - if ((pid = fork()) == 0) - { - close(fds[0]); - dup2(fds[1], 1); - execl("/etc/uerf", "uerf", "-R", "-r", "300", (void *)0); - execl("/usr/sbin/uerf", "uerf", "-R", "-r", "300", (void *)0); - return NULL; /* _exit(1); */ - } else if (pid < 0) { - perror("fork"); - return NULL; - } - - close(fds[1]); - uerf = fdopen(fds[0], "r"); - - while (data = fgetline(uerf)) - if (strstr(data, "RRD42")) - { - char *device_p; - - osf_cd_device = (char *)malloc(sizeof("/dev/rrz##c")); - strcpy(osf_cd_device, "/dev/r"); - device_p = strstr(data, "rz"); - device_p[(int)(strchr(device_p, ' ') - device_p)] = '\0'; - strcat(osf_cd_device, device_p); - strcat(osf_cd_device, "c"); - device = osf_cd_device; - break; - } - - fclose(uerf); - - if (device == NULL) - { - fprintf(stderr, - "No cdrom (RRD42) is installed on this system\n"); - return NULL; - } - - kill(pid, 15); - (void)wait((int *)NULL); - return device; -} /* find_cdrom() */ - -/* - * Initialize the drive. A no-op for the generic driver. - */ -int -gen_init( struct wm_drive *d ) -{ - return 0; -} /* gen_init() */ - -/* - * Open the CD device and figure out what kind of drive is attached. - */ -int -gen_open( struct wm_drive *d ) -{ - if (d->fd >= 0) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - d->fd = open(d->cd_device, O_RDWR); - if (d->fd < 0) { - if (errno == EACCES) - return -EACCES; - else if (errno != EINTR) - return -6; - - /* No CD in drive. */ - return 1; - } - - return 0; -} /* gen_open() */ - -/* - * Send an arbitrary SCSI command to a device. - */ -int -gen_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen, - void *retbuf, int retbuflen, int getreply) -{ - /* OSF1 doesn't have a SCSI passthrough interface, does it? */ - return -1; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd > -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - */ -int -gen_get_drive_status(struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *index) -{ - struct cd_sub_channel sc; - struct cd_subc_channel_data scd; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - sc.sch_address_format = CDROM_MSF_FORMAT; - sc.sch_data_format = CDROM_CURRENT_POSITION; - sc.sch_track_number = 0; - sc.sch_alloc_length = sizeof(scd); - sc.sch_buffer = (caddr_t)&scd; - - /* Is the device open? */ - if (d->fd < 0) { - switch (d->proto.open(d)) { - case -1: /* error */ - return -1; - - case 1: /* retry */ - return 0; - } - } - - if (ioctl(d->fd, CDROM_READ_SUBCHANNEL, &sc)) - return 0; /* ejected */ - - switch (scd.scd_header.sh_audio_status) { - case AS_PLAY_IN_PROGRESS: - *mode = WM_CDM_PLAYING; - dopos: - *pos = scd.scd_position_data.scp_absaddr.msf.m_units * 60 * 75 + - scd.scd_position_data.scp_absaddr.msf.s_units * 75 + - scd.scd_position_data.scp_absaddr.msf.f_units; - *track = scd.scd_position_data.scp_track_number; - *index = scd.scd_position_data.scp_index_number; - break; - - case AS_PLAY_PAUSED: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) - { - *mode = WM_CDM_PAUSED; - goto dopos; - } - else - *mode = WM_CDM_STOPPED; - break; - - case AS_PLAY_COMPLETED: - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - break; - - case AS_NO_STATUS: - *mode = WM_CDM_STOPPED; - break; - default: - abort(); - } - - return (0); -} /* gen_get_drive_status() */ - -/* - * Play the CD from one position to another (both in frames.) - */ -int -gen_play( struct wm_drive *d, int start, int end ) -{ - struct cd_play_audio_msf msf; - - msf.msf_starting_M_unit = start / (60*75); - msf.msf_starting_S_unit = (start % (60*75)) / 75; - msf.msf_starting_F_unit = start % 75; - msf.msf_ending_M_unit = end / (60*75); - msf.msf_ending_S_unit = (end % (60*75)) / 75; - msf.msf_ending_F_unit = end % 75; - - if (ioctl(d->fd, SCSI_START_UNIT)) - return (-1); - if (ioctl(d->fd, CDROM_PLAY_AUDIO_MSF, &msf)) - return (-2); - - return (0); -} /* gen_play() */ - -/* - * Pause the CD. - */ -int -gen_pause( struct wm_drive *d ) -{ - return (ioctl(d->fd, CDROM_PAUSE_PLAY, 0)); -} /* gen_pause() */ - -/* - * Resume playing the CD (assuming it was paused.) - */ -int -gen_resume( struct wm_drive *d ) -{ - return (ioctl(d->fd, CDROM_RESUME_PLAY, 0)); -} /* gen_resume() */ - -/* - * Stop the CD. - */ -int -gen_stop( struct wm_drive *d ) -{ - return (ioctl(d->fd, SCSI_STOP_UNIT, 0)); -} /* gen_stop() */ - -/* - * Eject the current CD, if there is one. - */ -int -gen_eject(struct wm_drive *d) -{ - /* On some systems, we can check to see if the CD is mounted. */ - struct stat stbuf; - struct ustat ust; - - if (fstat(d->fd, &stbuf) != 0) - return (-2); - - /* Is this a mounted filesystem? */ - if (ustat(stbuf.st_rdev, &ust) == 0) - return (-3); - - return (ioctl(d->fd, CDROM_EJECT_CADDY, 0)); -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - * - * Please edit and send changes to - * milliByte@DeathsDoor.com - *----------------------------------------*/ - -int -gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - -/* - * Get the number of tracks on the CD. - */ -int -gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - struct cd_toc_header hdr; - - if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr)) - return (-1); - - *tracks = hdr.th_ending_track; - - return (0); -} /* gen_get_trackcount() */ - -/* - * Get the start time and mode (data or audio) of a track. - * - * XXX - this should get cached, but that means keeping track of ejects. - */ -int -gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - struct cd_toc toc; - struct cd_toc_header hdr; - struct cd_toc_header_and_entries toc_buffer; - - if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr)) - return (-1); - - bzero((char *)&toc_buffer, sizeof(toc_buffer)); - toc.toc_address_format = CDROM_MSF_FORMAT; - toc.toc_starting_track = 0; - toc.toc_alloc_length = (u_short)(((hdr.th_data_len1 << 8) + - hdr.th_data_len0) & 0xfff) + 2; - toc.toc_buffer = (caddr_t)&toc_buffer; - - if (ioctl(d->fd, CDROM_TOC_ENTRYS, &toc)) - return (-1); - - if (track == 0) - track = hdr.th_ending_track + 1; - - *data = (toc_buffer.cdte[track-1].te_control & CDROM_DATA_TRACK) ? 1:0; - *startframe = toc_buffer.cdte[track - 1].te_absaddr.msf.m_units*60*75 + - toc_buffer.cdte[track - 1].te_absaddr.msf.s_units * 75 + - toc_buffer.cdte[track - 1].te_absaddr.msf.f_units; - - return (0); -} /* gen_get_trackinfo() */ - -/* - * Get the number of frames on the CD. - */ -int -gen_get_cdlen( struct wm_drive *d, int *frames ) -{ - int tmp; - - return (gen_get_trackinfo(d, 0, &tmp, frames)); -} /* gen_get_cdlen() */ - -/* - * scale_volume(vol, max) - * - * Return a volume value suitable for passing to the CD-ROM drive. "vol" - * is a volume slider setting; "max" is the slider's maximum value. - * - * On Sun and DEC CD-ROM drives, the amount of sound coming out the jack - * increases much faster toward the top end of the volume scale than it - * does at the bottom. To make up for this, we make the volume scale look - * sort of logarithmic (actually an upside-down inverse square curve) so - * that the volume value passed to the drive changes less and less as you - * approach the maximum slider setting. The actual formula looks like - * - * (max^2 - (max - vol)^2) * (max_volume - min_volume) - * v = --------------------------------------------------- + min_volume - * max^2 - * - * If your system's volume settings aren't broken in this way, something - * like the following should work: - * - * return ((vol * (max_volume - min_volume)) / max + min_volume); - */ -scale_volume(int vol, int max) -{ - return ((max * max - (max - vol) * (max - vol)) * - (max_volume - min_volume) / (max * max) + min_volume); -} /* scale_volume() */ - -/* - * unscale_volume(cd_vol, max) - * - * Given a value between min_volume and max_volume, return the volume slider - * value needed to achieve that value. - * - * Rather than perform floating-point calculations to reverse the above - * formula, we simply do a binary search of scale_volume()'s return values. - */ -static int -unscale_volume( int cd_vol, int max ) -{ - int vol = 0, top = max, bot = 0, scaled; - - while (bot <= top) - { - vol = (top + bot) / 2; - scaled = scale_volume(vol, max); - if (cd_vol == scaled) - break; - if (cd_vol < scaled) - top = vol - 1; - else - bot = vol + 1; - } - - if (vol < 0) - vol = 0; - else if (vol > max) - vol = max; - - return (vol); -} /* unscale_volume() */ - -/* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - */ -int -gen_set_volume(struct wm_drive *d, int left, int right) -{ - struct cd_playback pb; - struct cd_playback_status ps; - struct cd_playback_control pc; - - left = scale_volume(left, 100); - right = scale_volume(right, 100); - - bzero((char *)&pb, sizeof(pb)); - bzero((char *)&ps, sizeof(ps)); - bzero((char *)&pc, sizeof(pc)); - - pb.pb_alloc_length = sizeof(ps); - pb.pb_buffer = (caddr_t)&ps; - - if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb)) - return (-1); - - pc.pc_chan0_select = ps.ps_chan0_select; - pc.pc_chan0_volume = (left < CDROM_MIN_VOLUME) ? - CDROM_MIN_VOLUME : (left > CDROM_MAX_VOLUME) ? - CDROM_MAX_VOLUME : left; - pc.pc_chan1_select = ps.ps_chan1_select; - pc.pc_chan1_volume = (right < CDROM_MIN_VOLUME) ? - CDROM_MIN_VOLUME : (right > CDROM_MAX_VOLUME) ? - CDROM_MAX_VOLUME : right; - - pb.pb_alloc_length = sizeof(pc); - pb.pb_buffer = (caddr_t)&pc; - - if (ioctl(d->fd, CDROM_PLAYBACK_CONTROL, &pb)) - return (-1); - - return (0); -} /* gen_set_volume() */ - - -/* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - */ -int -gen_get_volume( struct wm_drive *d, int *left, int *right ) -{ - struct cd_playback pb; - struct cd_playback_status ps; - - bzero((char *)&pb, sizeof(pb)); - bzero((char *)&ps, sizeof(ps)); - - pb.pb_alloc_length = sizeof(ps); - pb.pb_buffer = (caddr_t)&ps; - - if (d->fd >= 0) - { - if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb)) - *left = *right = -1; - else - { - *left = unscale_volume(ps.ps_chan0_volume, 100); - *right = unscale_volume(ps.ps_chan1_volume, 100); - } - } - else - *left = *right = -1; - - return (0); -} /* gen_get_volume() */ - -#endif diff --git a/kcompactdisc/wmlib/plat_scor5.c b/kcompactdisc/wmlib/plat_scor5.c deleted file mode 100644 index 206dc471..00000000 --- a/kcompactdisc/wmlib/plat_scor5.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * SCO Openserver R5 specific. Derived from the KSCD plat_scor5.c - * - */ - -#if defined(M_UNIX) || defined(__M_UNIX) - -#include "include/wm_config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_struct.h" -#include "include/gen_scsi.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -#define SENSE_SZ EXTD_SENSE_LEN - -void *malloc(); -char *strchr(); - -int min_volume = 0; -int max_volume = 255; - -/* - * platformspecific internal function - */ -static int -create_cdrom_node(char *dev_name) -{ - char pass_through[100]; - int file_des; - struct stat sbuf; - int err; - int ccode; - - - strncpy(pass_through, dev_name, sizeof(pass_through)-2); - pass_through[sizeof(pass_through) - 2] = '\0'; - strcat(pass_through, "p" ); - - if (setreuid(-1,0) < 0) - { - perror("setregid/setreuid/access"); - return -1; - } - - ccode = access(pass_through, F_OK); - - if (ccode < 0) - { - - if (stat(dev_name, &sbuf) < 0) - { - perror("Call to get pass-through device number failed"); - return -1; - } - - if (mknod(pass_through, (S_IFCHR | S_IREAD | S_IWRITE), - sbuf.st_rdev) < 0) - { - perror("Unable to make pass-through node"); - return -1; - } - - if (chown(pass_through, 0 , 0) < 0) - { - perror("chown"); - return -1; - } - - if (chmod(pass_through, 0660 ) < 0) - { - perror("chmod"); - return -1; - } - } - - file_des = open( pass_through, O_RDONLY); - err = errno; - - /* - if ( (setreuid(-1,getuid()) < 0) || (setregid(-1,getgid()) < 0) ) - { - perror("setreuid/setregid"); - exit(1); - } - - */ - - errno = err; - return file_des; -} /* create_cdrom_node() */ - - -/* - * Initialize the drive. A no-op for the generic driver. - */ -int -gen_init(struct wm_drive *d) -{ - return (0); -} /* gen_init() */ - -/* - * Open the CD and figure out which kind of drive is attached. - */ -int -gen_open(struct wm_drive *d) -{ - if (d->fd > -1) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - d->fd = create_cdrom_node(d->cd_device); /* this will do open */ - if (d->fd < 0) { - if (errno == EACCES) { - } else if (errno != EINTR) { - perror(d->cd_device); - return -6; - } - - /* cannot access CDROM device */ - return -1; - } - - return 0; -} /* gen_open */ - -/* - * Send a SCSI command out the bus. - */ -int -gen_scsi(struct wm_drive *d, unsigned char *xcdb, int cdblen, - char *retbuf, int retbuflen, int getreply) -{ - int ccode; - int file_des = d->fd; - unsigned char sense_buffer[ SENSE_SZ ]; - - /* getreply == 1 is read, == 0 is write */ - - struct scsicmd2 sb; /* Use command with automatic sense */ - - if (cdblen > SCSICMDLEN) - { - fprintf(stderr,"Cannot handle longer commands than %d bytes.\n", SCSICMDLEN); - exit(-1); - } - - /* Get the command */ - memcpy(sb.cmd.cdb, xcdb, cdblen); - sb.cmd.cdb_len = cdblen; - - /* Point to data buffer */ - sb.cmd.data_ptr = retbuf; - sb.cmd.data_len = retbuflen; - - /* Is this write or read ? */ - sb.cmd.is_write = (getreply==1) ? 0 : 1; - - /* Zero out return status fields */ - sb.cmd.host_sts = 0; - sb.cmd.target_sts = 0; - - /* Set up for possible sense info */ - - sb.sense_ptr = sense_buffer; - sb.sense_len = sizeof(sense_buffer); - - ccode = ioctl(file_des, SCSIUSERCMD2, &sb); - - if ( sb.cmd.target_sts != 02 ) - return ccode; - - return 0; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -void -keep_cd_open() { } - -/* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - */ -int -gen_get_drive_status(wm_drive *d, int oldmode, int *mode, - int *pos, int *track, int *index) -{ - return (wm_scsi2_get_drive_status(d, oldmode, mode, pos, track, index)); -} /* gen_get_drive_status() */ - -/* - * Get the number of tracks on the CD. - */ -int -gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - return (wm_scsi2_get_trackcount(d, tracks)); -} /* gen_get_trackcount() */ - - -/* - * Get the start time and mode (data or audio) of a track. - */ -int -gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - return (wm_scsi2_get_trackinfo(d, track, data, startframe)); -} /* gen_get_trackinfo() */ - -/* - * Get the number of frames on the CD. - */ -int -gen_get_cdlen(struct wm_drive *d, int *frames) -{ - return (wm_scsi2_get_cdlen(d, frames)); -} /* gen_get_cdlen() */ - - -/* - * Play the CD from one position to another (both in frames.) - */ -int -gen_play(struct wm_drive *d, int start, int end) -{ - return (wm_scsi2_play(d, start, end)); -} /* gen_play() */ - -/* - * Pause the CD. - */ -int -gen_pause( struct wm_drive *d ) -{ - return (wm_scsi2_pause(d)); -} /* gen_pause() */ - -/* - * Resume playing the CD (assuming it was paused.) - */ -int -gen_resume( struct wm_drive *d ) -{ - return (wm_scsi2_resume(d)); -} /* gen_resume() */ - -/* - * Stop the CD. - */ -int -gen_stop(struct wm_drive *d) -{ - return (wm_scsi2_stop(d)); -} /* gen_stop() */ - -/* - * Eject the current CD, if there is one. - */ -int -gen_eject(struct wm_drive *d) -{ - int stat; - - stat = wm_scsi2_eject(d); - wm_susleep(1000); - return (stat); -} /* gen_eject() */ - - -int -gen_closetray(struct wm_drive *d) -{ - return(wm_scsi2_closetray(d)); -} /* gen_closetray() */ - - -/* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - */ -int -gen_set_volume(struct wm_drive *d, int left, int right) -{ - return (wm_scsi2_set_volume(d, left, right)); -} /* gen_set_volume() */ - -/* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - */ -int -gen_get_volume(struct wm_drive *d, int *left, int *right) -{ - return (wm_scsi2_get_volume(d, left, right)); -} /* gen_get_volume() */ - -#endif /* M_UNIX */ - - - - diff --git a/kcompactdisc/wmlib/plat_sun.c b/kcompactdisc/wmlib/plat_sun.c deleted file mode 100644 index 22a1ff22..00000000 --- a/kcompactdisc/wmlib/plat_sun.c +++ /dev/null @@ -1,999 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Sun-specific drive control routines. - */ - -#if defined(sun) || defined(__sun) - -#include "include/wm_config.h" -#include "include/wm_helpers.h" -#include "include/wm_cdrom.h" -#include "include/wm_cdtext.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#ifdef solbourne -# include -# include -# include -# include -#else /* A real Sun */ -# ifdef SYSV -# include -# include -# include -# include -# include -# include "include/wm_cdda.h" -# else -# include -# include -# include -# include -# include -# endif -#endif - -#include "include/wm_struct.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -int min_volume = 0; -int max_volume = 255; - -static const char *sun_cd_device = NULL; -extern int intermittent_dev; - -int current_end; - -#if defined(SYSV) && defined(SIGTHAW) -#ifdef __GNUC__ -void sigthawinit(void) __attribute__ ((constructor)); -#else -#pragma init(sigthawinit) -#endif /* GNUC */ - -static int last_left, last_right; -static struct wm_drive *thecd = NULL; - -/* - * Handling for Sun's Suspend functionality - */ -static void -thawme(int sig) -{ -// Just leave this line in as a reminder for a missing -// functionality in the GUI. -// change_mode(NULL, WM_CDM_STOPPED, NULL); - codec_init(); - if( thecd ) - gen_set_volume(thecd, last_left, last_right); -} /* thawme() */ - -void -sigthawinit( void ) -{ - struct sigaction sa; - - sa.sa_handler = thawme; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - - sigaction(SIGTHAW, &sa, NULL); -} /* sigthawinit() */ - -#endif /* SYSV && SIGTHAW */ - -/* - * find_cdrom - * - * Determine the name of the CD-ROM device. - * - * Use the first of /vol/dev/aliases/cdrom0, /dev/rdsk/c0t6d0s2, and /dev/rsr0 - * that exists. (Check for /vol/dev/aliases, not cdrom0, since it won't be - * there if there's no CD in the drive.) This is done so a single SunOS 4.x - * binary can be used on any 4.x or higher Sun system. - */ -const char* -find_cdrom() -{ - if (access("/vol/dev/aliases", X_OK) == 0) - { - /* Volume manager. Device might not be there. */ - intermittent_dev = 1; - - /* If vold is running us, it'll tell us the device name. */ - sun_cd_device = getenv("VOLUME_DEVICE"); - /* - ** the path of the device has to include /dev - ** otherwise we are vulnerable to race conditions - ** Thomas Biege - */ - if (sun_cd_device == NULL || - strncmp("/vol/dev/", sun_cd_device, 9) || - strstr(sun_cd_device, "/../") ) - return "/vol/dev/aliases/cdrom0"; - else - return sun_cd_device; - } - else if (access("/dev/rdsk/c0t6d0s2", F_OK) == 0) - { - /* Solaris 2.x w/o volume manager. */ - return "/dev/rdsk/c0t6d0s2"; - } - else if (access("/dev/rcd0", F_OK) == 0) - { - return "/dev/rcd0"; - } - else if (access("/dev/rsr0", F_OK) == 0) - return "/dev/rsr0"; - else - { - fprintf(stderr, "Could not find a CD device!\n"); - return NULL; - } -} /* find_cdrom() */ - -/* - * Initialize the drive. A no-op for the generic driver. - */ -int -gen_init( struct wm_drive *d ) -{ - codec_init(); - return 0; -} /* gen_init() */ - - -/* - * Open the CD device and figure out what kind of drive is attached. - */ -int -gen_open( struct wm_drive *d ) -{ - static int warned = 0; - - if (d->fd >= 0) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - - d->fd = open(d->cd_device, 0); - if (d->fd < 0) { - /* Solaris 2.2 volume manager moves links around */ - if (errno == ENOENT && intermittent_dev) - return 1; - - if (errno == EACCES) { - if (!warned) { - /* char realname[MAXPATHLEN]; - if (realpath(cd_device, realname) == NULL) { - perror("realpath"); - return 1; - } */ - return -EACCES; - } - } else if (errno != ENXIO) { - return -6; - } - - /* No CD in drive. */ - return 1; - } - - thecd = d; - - return 0; -} - -/* - * Send an arbitrary SCSI command out the bus and optionally wait for - * a reply if "retbuf" isn't NULL. - */ -int -gen_scsi( struct wm_drive *d, - unsigned char *cdb, - int cdblen, void *retbuf, - int retbuflen, int getreply ) -{ -#ifndef solbourne - char x; - struct uscsi_cmd cmd; - - memset(&cmd, 0, sizeof(cmd)); - cmd.uscsi_cdb = (void *) cdb; - cmd.uscsi_cdblen = cdblen; - cmd.uscsi_bufaddr = retbuf ? retbuf : (void *)&x; - cmd.uscsi_buflen = retbuf ? retbuflen : 0; - cmd.uscsi_flags = USCSI_ISOLATE | USCSI_SILENT; - if (getreply) - cmd.uscsi_flags |= USCSI_READ; - - if (ioctl(d->fd, USCSICMD, &cmd)) - return -1; - - if (cmd.uscsi_status) - return -1; - - return 0; -#else - return -1; -#endif -} - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/* Alarm signal handler. */ -static void do_nothing( int x ) { x++; } - -/* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - */ -int -gen_get_drive_status( struct wm_drive *d, - int oldmode, - int *mode, - int *pos, int *track, int *index ) -{ - struct cdrom_subchnl sc; - struct itimerval old_timer, new_timer; - struct sigaction old_sig, new_sig; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - /* Is the device open? */ - if (d->fd < 0) { - switch (d->proto.open(d)) { - case -1: /* error */ - return -1; - - case 1: /* retry */ - return 0; - } - } - - /* - * Solaris 2.2 hangs on this ioctl if someone else ejects the CD. - * So we schedule a signal to break out of the hang if the call - * takes an unreasonable amount of time. The signal handler and - * timer are restored immediately to avoid interfering with XView. - */ - if (intermittent_dev) { - /* - * First clear out the timer so XView's signal doesn't happen - * while we're diddling with the signal handler. - */ - timerclear(&new_timer.it_interval); - timerclear(&new_timer.it_value); - setitimer(ITIMER_REAL, &new_timer, &old_timer); - - /* - * Now install the no-op signal handler. - */ - new_sig.sa_handler = do_nothing; - memset(&new_sig.sa_mask, 0, sizeof(new_sig.sa_mask)); - new_sig.sa_flags = 0; - if (sigaction(SIGALRM, &new_sig, &old_sig)) - perror("sigaction"); - - /* - * And finally, set the timer. - */ - new_timer.it_value.tv_sec = 2; - setitimer(ITIMER_REAL, &new_timer, NULL); - } - - sc.cdsc_format = CDROM_MSF; - - if (ioctl(d->fd, CDROMSUBCHNL, &sc)) { - if (intermittent_dev) { - sigaction(SIGALRM, &old_sig, NULL); - setitimer(ITIMER_REAL, &old_timer, NULL); - - /* If the device can disappear, let it do so. */ - d->proto.close(d); - } - - return 0; - } - - if (intermittent_dev) { - sigaction(SIGALRM, &old_sig, NULL); - setitimer(ITIMER_REAL, &old_timer, NULL); - } - - switch (sc.cdsc_audiostatus) { - case CDROM_AUDIO_PLAY: - *mode = WM_CDM_PLAYING; - *track = sc.cdsc_trk; - *index = sc.cdsc_ind; - *pos = sc.cdsc_absaddr.msf.minute * 60 * 75 + - sc.cdsc_absaddr.msf.second * 75 + - sc.cdsc_absaddr.msf.frame; - break; - - case CDROM_AUDIO_PAUSED: - case CDROM_AUDIO_INVALID: - case CDROM_AUDIO_NO_STATUS: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) - { - *mode = WM_CDM_PAUSED; - *track = sc.cdsc_trk; - *index = sc.cdsc_ind; - *pos = sc.cdsc_absaddr.msf.minute * 60 * 75 + - sc.cdsc_absaddr.msf.second * 75 + - sc.cdsc_absaddr.msf.frame; - } - else - *mode = WM_CDM_STOPPED; - break; - - /* CD ejected manually during play. */ - case CDROM_AUDIO_ERROR: - break; - - case CDROM_AUDIO_COMPLETED: - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - break; - - default: - *mode = WM_CDM_UNKNOWN; - break; - } - - return 0; -} /* gen_get_drive_status() */ - -/* - * Get the number of tracks on the CD. - */ -int -gen_get_trackcount( struct wm_drive *d, int *tracks ) -{ - struct cdrom_tochdr hdr; - - if (ioctl(d->fd, CDROMREADTOCHDR, &hdr)) - return -1; - - *tracks = hdr.cdth_trk1; - return 0; -} /* gen_get_trackcount() */ - -/* - * Get the start time and mode (data or audio) of a track. - */ -int -gen_get_trackinfo( struct wm_drive *d, int track, int *data, int *startframe) -{ - struct cdrom_tocentry entry; - - entry.cdte_track = track; - entry.cdte_format = CDROM_MSF; - - if (ioctl(d->fd, CDROMREADTOCENTRY, &entry)) - return -1; - - *startframe = entry.cdte_addr.msf.minute * 60 * 75 + - entry.cdte_addr.msf.second * 75 + - entry.cdte_addr.msf.frame; - *data = entry.cdte_ctrl & CDROM_DATA_TRACK ? 1 : 0; - - return 0; -} /* gen_get_trackinfo() */ - -/* - * Get the number of frames on the CD. - */ -int -gen_get_cdlen(struct wm_drive *d, int *frames ) -{ - int tmp; - - return (gen_get_trackinfo(d, CDROM_LEADOUT, &tmp, frames)); -} /* gen_get_cdlen() */ - -/* - * Play the CD from one position to another. - * - * d Drive structure. - * start Frame to start playing at. - * end End of this chunk. - */ -int -gen_play( struct wm_drive *d, int start, int end) -{ - struct cdrom_msf msf; - unsigned char cmdbuf[10]; - - current_end = end; - - msf.cdmsf_min0 = start / (60*75); - msf.cdmsf_sec0 = (start % (60*75)) / 75; - msf.cdmsf_frame0 = start % 75; - msf.cdmsf_min1 = end / (60*75); - msf.cdmsf_sec1 = (end % (60*75)) / 75; - msf.cdmsf_frame1 = end % 75; - - codec_start(); - if (ioctl(d->fd, CDROMSTART)) - return -1; - if (ioctl(d->fd, CDROMPLAYMSF, &msf)) - return -2; - - return 0; -} /* gen_play() */ - -/* - * Pause the CD. - */ -int -gen_pause( struct wm_drive *d ) -{ - codec_stop(); - return (ioctl(d->fd, CDROMPAUSE)); -} /* gen_pause() */ - -/* - * Resume playing the CD (assuming it was paused.) - */ -int -gen_resume( struct wm_drive *d ) -{ - codec_start(); - return (ioctl(d->fd, CDROMRESUME)); -} /* gen_resume() */ - -/* - * Stop the CD. - */ -int -gen_stop( struct wm_drive *d ) -{ - codec_stop(); - return (ioctl(d->fd, CDROMSTOP)); -} /* gen_stop() */ - -/* - * Eject the current CD, if there is one. - */ -int -gen_eject( struct wm_drive *d )cddax -{ - struct stat stbuf; - struct statvfs ust; - - if (fstat(d->fd, &stbuf) != 0) - return -2; - - /* Is this a mounted filesystem? */ - if (statvfs(stbuf.st_rdev, &ust) == 0) - return -3; - - if (ioctl(d->fd, CDROMEJECT)) - return -1; - - /* Close the device if it needs to vanish. */ - if (intermittent_dev) { - d->proto.close(d); - /* Also remember to tell the cddaslave since volume - manager switches links around on us */ - if (d->cdda_slave > -1) { - write(d->cdda_slave, "E", 1); - } - } - - return 0; -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - * - * Please edit and send changes to - * milliByte@DeathsDoor.com - *----------------------------------------*/ - -int -gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - -/* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - */ -int -gen_set_volume( struct wm_drive *d, int left, int right ) -{ - struct cdrom_volctrl v; - -#if defined(SIGTHAW) && defined(SYSV) - last_left = left; - last_right = right; - thecd = d; -#endif - - CDDARETURN(d) cdda_set_volume(d, left, right); - - left = (left * (max_volume - min_volume)) / 100 + min_volume; - right = (right * (max_volume - min_volume)) / 100 + min_volume; - - v.channel0 = left < 0 ? 0 : left > 255 ? 255 : left; - v.channel1 = right < 0 ? 0 : right > 255 ? 255 : right; - - return (ioctl(d->fd, CDROMVOLCTRL, &v)); -} /* gen_set_volume() */ - -/* - * Read the volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - */ -int -gen_get_volume( struct wm_drive *d, int *left, int *right ) -{ - CDDARETURN(d) cdda_get_volume(d, left, right); - - *left = *right = -1; - - return (wm_scsi2_get_volume(d, left, right)); -} /* gen_get_volume() */ - -#define CDDABLKSIZE 2368 -#define SAMPLES_PER_BLK 588 - -/* - * This is the fastest way to convert from BCD to 8-bit. - */ -static unsigned char unbcd[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,0,0,0,0,0, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0,0,0,0,0,0, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0,0,0,0,0,0, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0,0,0,0,0,0, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 0,0,0,0,0,0, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0,0,0,0,0,0, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0,0,0,0,0,0, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0,0,0,0,0,0, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 0,0,0,0,0,0, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -}; -/* - * Try to initialize the CDDA slave. Returns 0 on success. - */ -int -gen_cdda_init( struct wm_drive *d ) -{ - enable_cdda_controls(1); - return 0; -} - -/* - * Initialize the CDDA data buffer and open the appropriate device. - * - */ -int gen_cdda_open(struct wm_drive *d) -{ - int i; - struct cdrom_cdda cdda; - - if (d->fd < 0) - return -1; - - for (i = 0; i < d->numblocks; ++i) { - d->blocks[i].buflen = d->frames_at_once * CDDABLKSIZE; - d->blocks[i].buf = malloc(d->blocks[i].buflen); - if (!d->blocks[i].buf) { - ERRORLOG("plat_cdda_open: ENOMEM\n"); - return -ENOMEM; - } - } - - cdda.cdda_addr = 200; - cdda.cdda_length = 1; - cdda.cdda_data = d->blocks[0].buf; - cdda.cdda_subcode = CDROM_DA_SUBQ; - - d->status = WM_CDM_STOPPED; - if((ioctl(d->fd, CDROMCDDA, &cdda) < 0)) { - return -1; - } - - return 0; -} - -/* - * Normalize a bunch of CDDA data. Basically this means ripping out the - * Q subchannel data and doing byte-swapping, since the CD audio is in - * littleendian format. - * - * Scanning is handled here too. - * - * XXX - do byte swapping on Intel boxes? - */ -long -sun_normalize(struct cdda_block *block) -{ - int i, nextq; - long buflen = block->buflen; - int blocks = buflen / CDDABLKSIZE; - unsigned char *rawbuf = block->buf; - unsigned char *dest = rawbuf; - unsigned char tmp; - long *buf32 = (long *)rawbuf, tmp32; - -/* - * this was #ifndef LITTLEENDIAN - * in wmcdda it was called LITTLE_ENDIAN. Was this a flaw? - */ -#if WM_BIG_ENDIAN - if (blocks--) { - for (i = 0; i < SAMPLES_PER_BLK * 2; ++i) { - /* Only need to use temp buffer on first block. */ - tmp = *rawbuf++; - *dest++ = *rawbuf++; - *dest++ = tmp; - } - } -#endif - - while (blocks--) { - /* Skip over Q data. */ - rawbuf += 16; - - for (i = 0; i < SAMPLES_PER_BLK * 2; i++) { -#if WM_LITTLE_ENDIAN - *dest++ = *rawbuf++; - *dest++ = *rawbuf++; -#else - *dest++ = rawbuf[1]; - *dest++ = rawbuf[0]; - rawbuf += 2; -#endif - } - } - - buflen -= ((buflen / CDDABLKSIZE) * 16); - - return buflen; -} - -/* - * Read some blocks from the CD. Stop if we hit the end of the current region. - * - * Returns number of bytes read, -1 on error, 0 if stopped for a benign reason. - */ -int gen_cdda_read(struct wm_drive *d, struct wm_cdda_block *block) -{ - struct cdrom_cdda cdda; - int blk; - unsigned char *q; - unsigned char* rawbuf = block->buf; - - if (d->fd < 0) - return -1; - - /* Hit the end of the CD, probably. */ - if ((direction > 0 && d->current_position >= d->ending_position) || - (direction < 0 && d->current_position < d->starting_position)) { - block->status = WM_CDM_TRACK_DONE; - return 0; - } - - cdda.cdda_addr = d->current_position - 150; - if (d->ending_position && d->current_position + d->frames_at_once > d->ending_position) - cdda.cdda_length = d->ending_position - d->current_position; - else - cdda.cdda_length = d->frames_at_once; - cdda.cdda_data = (unsigned char*)block->buf; - cdda.cdda_subcode = CDROM_DA_SUBQ; - - if (ioctl(d->fd, CDROMCDDA, &cdda) < 0) { - if (errno == ENXIO) { /* CD ejected! */ - block->status = WM_CDM_EJECTED; - return -1; - } - - /* Sometimes it fails once, dunno why */ - if (ioctl(d->fd, CDROMCDDA, &cdda) < 0) { - if (ioctl(d->fd, CDROMCDDA, &cdda) < 0) { - if (ioctl(d->fd, CDROMCDDA, &cdda) < 0) { - perror("CDROMCDDA"); - block->status = WM_CDM_CDDAERROR; - return -1; - } - } - } - } - - d->current_position = d->current_position + cdda.cdda_length * direction; - -#if 0 - /* - * New valid Q-subchannel information? Update the block - * status. - */ - for (blk = 0; blk < d->numblocks; ++blk) { - q = &rawbuf[blk * CDDABLKSIZE + SAMPLES_PER_BLK * 4]; - if (*q == 1) { - block->track = unbcd[q[1]]; - block->index = unbcd[q[2]]; - /*block->minute = unbcd[q[7]]; - block->second = unbcd[q[8]];*/ - block->frame = unbcd[q[9]]; - block->status = WM_CDM_PLAYING; - block->buflen = cdda.cdda_length; - } - } -#endif - return sun_normalize(block); -} - -/* - * Close the CD-ROM device in preparation for exiting. - */ -int gen_cdda_close(struct wm_drive *d) -{ - int i; - - if (d->fd < 0) - return -1; - - for (i = 0; i < d->numblocks; i++) { - free(d->blocks[i].buf); - d->blocks[i].buf = 0; - d->blocks[i].buflen = 0; - } - - return 0; -} - -/* - * The following code activates the internal CD audio passthrough on - * SPARCstation 5 systems (and possibly others.) - * - * Thanks to , Roger Oscarsson - * and Steve McKinty <> - * - * Most CD drives have a headphone socket on the front, but it - * is often more convenient to route the audio though the - * built-in audio device. That way the user can leave their - * headphones plugged-in to the base system, for use with - * other audio stuff like ShowMeTV - */ - -#ifdef CODEC /* { */ -#ifdef SYSV /* { */ - -# include -# include -# include - -#else /* } { */ - -# include -# define AUDIO_DEV_SS5STYLE 5 -typedef int audio_device_t; - -#endif /* } */ -#endif /* } */ - -/* - * Don't do anything with /dev/audio if we can't set it to high quality. - * Also, don't do anything real if it's not Solaris. - */ -#if !defined(AUDIO_ENCODING_LINEAR) || !defined(CODEC) || !defined(SYSV) /* { */ -codec_init() { return 0; } -codec_start() { return 0; } -codec_stop() { return 0; } -#else - -#ifndef AUDIO_INTERNAL_CD_IN -#define AUDIO_INTERNAL_CD_IN 0x4 -#endif - -static char* devname = 0; -static char* ctlname = 0; -static int ctl_fd = -1; -static int port = AUDIO_LINE_IN; -int internal_audio = 1; - -codec_init( void ) -{ - register int i; - char* ctlname; - audio_info_t foo; - audio_device_t aud_dev; - - if (internal_audio == 0) - { - ctl_fd = -1; - return 0; - } - - if (!(devname = getenv("AUDIODEV"))) devname = "/dev/audio"; - ctlname = strcat(strcpy(malloc(strlen(devname) + 4), devname), "ctl"); - if ((ctl_fd = open(ctlname, O_WRONLY, 0)) < 0) - { - perror(ctlname); - return -1; - } - if (ioctl(ctl_fd, AUDIO_GETDEV, &aud_dev) < 0) - { - close(ctl_fd); - ctl_fd = -1; - return -1; - } - /* - * Instead of filtering the "OLD_SUN_AUDIO", try to find the new ones. - * Not sure if this is all correct. - */ -#ifdef SYSV - if (strcmp(aud_dev.name, "SUNW,CS4231") && - strcmp(aud_dev.name, "SUNW,sb16") && - strcmp(aud_dev.name, "SUNW,sbpro")) -#else - if (aud_dev != AUDIO_DEV_SS5STYLE) -#endif - { - close(ctl_fd); - ctl_fd = -1; - return 0; /* but it's okay */ - } - - /* - * Does the chosen device have an internal CD port? - * If so, use it. If not then try and use the - * Line In port. - */ - if (ioctl(ctl_fd, AUDIO_GETINFO, &foo) < 0) - { - perror("AUDIO_GETINFO"); - close(ctl_fd); - ctl_fd = -1; - return -1; - } - if (foo.record.avail_ports & AUDIO_INTERNAL_CD_IN) - port = AUDIO_INTERNAL_CD_IN; - else - port = AUDIO_LINE_IN; - - /* - * now set it up to use it. See audio(7I) - */ - - AUDIO_INITINFO(&foo); - foo.record.port = port; - foo.record.balance = foo.play.balance = AUDIO_MID_BALANCE; - - if (d->cdda_slave > -1) - foo.monitor_gain = 0; - else - foo.monitor_gain = AUDIO_MAX_GAIN; - /* - * These next ones are tricky. The voulme will depend on the CD drive - * volume (set by the knob on the drive and/or by workman's volume - * control), the audio device record gain and the audio device - * play gain. For simplicity we set the latter two to something - * reasonable, but we don't force them to be reset if the user - * wants to change them. - */ - foo.record.gain = (AUDIO_MAX_GAIN * 80) / 100; - foo.play.gain = (AUDIO_MAX_GAIN * 40) / 100; - - ioctl(ctl_fd, AUDIO_SETINFO, &foo); - return 0; -} - -static int -kick_codec( void ) -{ - audio_info_t foo; - int dev_fd; - int retval = 0; - - /* - * Open the audio device, not the control device. This - * will fail if someone else has taken it. - */ - - if ((dev_fd = open(devname, O_WRONLY|O_NDELAY, 0)) < 0) - { - perror(devname); - return -1; - } - - AUDIO_INITINFO(&foo); - foo.record.port = port; - foo.monitor_gain = AUDIO_MAX_GAIN; - - /* These can only be set on the real device */ - foo.play.sample_rate = 44100; - foo.play.channels = 2; - foo.play.precision = 16; - foo.play.encoding = AUDIO_ENCODING_LINEAR; - - if ((retval = ioctl(dev_fd, AUDIO_SETINFO, &foo)) < 0) - perror(devname); - - close(dev_fd); - return retval; -} /* kick_codec() */ - -codec_start( void ) -{ - audio_info_t foo; - - if (ctl_fd < 0) - return 0; - - if (ioctl(ctl_fd, AUDIO_GETINFO, &foo) < 0) - return -1; - - if (foo.play.channels != 2) return kick_codec(); - if (foo.play.encoding != AUDIO_ENCODING_LINEAR) return kick_codec(); - if (foo.play.precision != 16) return kick_codec(); - if (foo.play.sample_rate != 44100) return kick_codec(); - - if (foo.record.channels != 2) return kick_codec(); - if (foo.record.encoding != AUDIO_ENCODING_LINEAR) return kick_codec(); - if (foo.record.precision != 16) return kick_codec(); - if (foo.record.sample_rate != 44100) return kick_codec(); - - if (foo.monitor_gain != AUDIO_MAX_GAIN) return kick_codec(); - if (foo.record.port != port) return kick_codec(); - - return 0; -} /* codec_start() */ - -codec_stop( void ) { return 0; } - -#endif /* CODEC } */ - -#endif /* sun */ diff --git a/kcompactdisc/wmlib/plat_sun_cdda.c b/kcompactdisc/wmlib/plat_sun_cdda.c deleted file mode 100644 index 4f34d6ad..00000000 --- a/kcompactdisc/wmlib/plat_sun_cdda.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Sun (really Solaris) CDDA functions. - */ - -#include "include/wm_cdda.h" - -#if defined(sun) || defined(__sun__) && defined(SYSV) - - -#include "include/wm_struct.h" -#include "include/wm_cdda.h" -/* types.h and cdio.h are included by wm_cdda.h */ - -#include -#include -#include -#include -#include - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -#define CDDABLKSIZE 2368 -#define SAMPLES_PER_BLK 588 - -/* Address of next block to read. */ -int current_position = 0; - -/* Address of first and last blocks to read. */ -int starting_position = 0; -int ending_position = 0; - -/* Playback direction. */ -int direction = 1; - -/* Number of blocks to read at once; initialize to the maximum. */ -/* (was 30. Set to 15 for INTeL. Maybe config option? */ -int numblocks = 15; - -/* - * This is the fastest way to convert from BCD to 8-bit. - */ -unsigned char unbcd[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,0,0,0,0,0, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0,0,0,0,0,0, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0,0,0,0,0,0, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0,0,0,0,0,0, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 0,0,0,0,0,0, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0,0,0,0,0,0, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0,0,0,0,0,0, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0,0,0,0,0,0, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 0,0,0,0,0,0, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -}; - -static long wmcdda_normalize(struct cdda_block *block); - -/* - * Initialize the CDDA data buffer and open the appropriate device. - * - * NOTE: We allocate twice as much space as we need to actually read a block; - * this lets us do audio manipulations without bothering to malloc a second - * buffer. - * - * Also, test to see if we can actually *do* CDDA on this drive; if not, we - * need to exit right away so the UI doesn't show the user any CDDA controls. - */ -int -wmcdda_init(struct cdda_device* pdev, struct cdda_block *block) -{ - struct cdrom_cdda cdda; - int i; - - if (pdev->fd > -1) - return -1; - - for (i = 0; i < pdev->numblocks; i++) { - /* in Linux const */ - pdev->blocks[i].buflen = pdev->frames_at_once * CDDABLKSIZE; - pdev->blocks[i].buf = malloc(pdev->blocks[i].buflen); - if (!pdev->blocks[i].buf) - return -ENOMEM; - } - - pdev->fd = open(pdev->devname, 0); - if (pdev->fd == -1) - pdev->fd = open("/dev/rdsk/c0t6d0s2", 0); - - if (pdev->fd > -1) - { - cdda.cdda_addr = 200; - cdda.cdda_length = 1; - cdda.cdda_data = pdev->blocks[0].buf; - cdda.cdda_subcode = CDROM_DA_SUBQ; - - if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0) - { - block->status = WM_CDM_STOPPED; - return -1; - } else { - block->status = WM_CDM_STOPPED; - return 0; - } - } else { - block->status = WM_CDM_EJECTED; - return -1; - } -} - -/* - * Close the CD-ROM device in preparation for exiting. - */ -int -wmcdda_close(struct cdda_device* pdev) -{ - int i; - - if(-1 == pdev->fd) - return -1; - - close(pdev->fd); - pdev->fd = -1; - - for (i = 0; i < pdev->numblocks; i++) { - free(pdev->blocks[i].buf); - pdev->blocks[i].buf = 0; - pdev->blocks[i].buflen = 0; - } - - return 0; -} - -/* - * Set up for playing the CD. Actually this doesn't play a thing, just sets a - * couple variables so we'll know what to do when we're called. - */ -int -wmcdda_setup(int start, int end) -{ - current_position = start - 150; - ending_position = end - 150; - - /* - * Special case: don't start at the "end" of a track if we're - * playing backwards! - */ - if (direction == -1) - current_position = ending_position - numblocks; - return 0; -} - -/* - * Read some blocks from the CD. Stop if we hit the end of the current region. - * - * Returns number of bytes read, -1 on error, 0 if stopped for a benign reason. - */ -long -wmcdda_read(struct cdda_device* pdev, struct cdda_block *block) -{ - struct cdrom_cdda cdda; - int blk; - unsigned char *q; - extern int speed; - unsigned char* rawbuf = block->buf; - - if(pdev->fd < 0 && (wmcdda_init(pdev, block) < 0)) { - return -1; - } - - /* - * Hit the end of the CD, probably. - */ - if ((direction > 0 && current_position >= ending_position) || - (direction < 0 && current_position < starting_position)) - { - block->status = WM_CDM_TRACK_DONE; - return (0); - } - - cdda.cdda_addr = current_position; - if (ending_position && current_position + pdev->frames_at_once > ending_position) - cdda.cdda_length = ending_position - current_position; - else - cdda.cdda_length = pdev->frames_at_once; - cdda.cdda_data = (unsigned char*)block->buf; - cdda.cdda_subcode = CDROM_DA_SUBQ; - - if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0) - { - if (errno == ENXIO) /* CD ejected! */ - { - block->status = WM_CDM_EJECTED; - return (-1); - } - - /* Sometimes it fails once, dunno why */ - if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0) - { - if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0) - { - if (ioctl(pdev->fd, CDROMCDDA, &cdda) < 0) - { - perror("CDROMCDDA"); - block->status = WM_CDM_CDDAERROR; - return (-1); - } - } - } - } - - if (speed > 148) - { - /* - * We want speed=148 to advance by cdda_length, but - * speed=256 to advance cdda_length * 4. - */ - current_position = current_position + - (cdda.cdda_length * direction * (speed - 112)) / 36; - } - else - current_position = current_position + cdda.cdda_length * direction; - - for (blk = 0; blk < numblocks; blk++) - { - /* - * New valid Q-subchannel information? Update the block - * status. - */ - q = &rawbuf[blk * CDDABLKSIZE + SAMPLES_PER_BLK * 4]; - if (*q == 1) - { - block->track = unbcd[q[1]]; - block->index = unbcd[q[2]]; - /*block->minute = unbcd[q[7]]; - block->second = unbcd[q[8]];*/ - block->frame = unbcd[q[9]]; - block->status = WM_CDM_PLAYING; - block->buflen = cdda.cdda_length; - } - } - - return wmcdda_normalize(block); -} - -/* - * Normalize a bunch of CDDA data. Basically this means ripping out the - * Q subchannel data and doing byte-swapping, since the CD audio is in - * littleendian format. - * - * Scanning is handled here too. - * - * XXX - do byte swapping on Intel boxes? - */ -long -wmcdda_normalize(struct cdda_block *block) -{ - int i, nextq; - long buflen = block->buflen; - int blocks = buflen / CDDABLKSIZE; - unsigned char *rawbuf = block->buf; - unsigned char *dest = rawbuf; - unsigned char tmp; - long *buf32 = (long *)rawbuf, tmp32; - -/* - * this was #ifndef LITTLEENDIAN - * in wmcdda it was called LITTLE_ENDIAN. Was this a flaw? - */ -#if WM_BIG_ENDIAN - if (blocks--) - for (i = 0; i < SAMPLES_PER_BLK * 2; i++) - { - /* Only need to use temp buffer on first block. */ - tmp = *rawbuf++; - *dest++ = *rawbuf++; - *dest++ = tmp; - } -#endif - - while (blocks--) - { - /* Skip over Q data. */ - rawbuf += 16; - - for (i = 0; i < SAMPLES_PER_BLK * 2; i++) - { -#if WM_LITTLE_ENDIAN - *dest++ = *rawbuf++; - *dest++ = *rawbuf++; -#else - *dest++ = rawbuf[1]; - *dest++ = rawbuf[0]; - rawbuf += 2; -#endif - } - } - - buflen -= ((buflen / CDDABLKSIZE) * 16); - - /* - * Reverse the data here if we're playing backwards. - * XXX - ideally this should be done above. - */ - if (direction < 0) - { - buflen /= 4; /* we can move 32 bits at a time. */ - - for (i = 0; i < buflen / 2; i++) - { - tmp32 = buf32[i]; - buf32[i] = buf32[buflen - i - 1]; - buf32[buflen - i - 1] = tmp32; - } - - buflen *= 4; - } - - return (buflen); -} - -/* - * Set the playback direction. - */ -void -wmcdda_direction(int newdir) -{ - if (newdir == 0) - { - numblocks = 20; - direction = 1; - } - else - { - numblocks = 30; - direction = -1; - } -} - -/* - * Do system-specific stuff to get ready to play at a particular speed. - */ -void -wmcdda_speed(int speed) -{ - if (speed > 128) - numblocks = 12; - else - numblocks = direction > 0 ? 20 : 30; -} - -#endif /* } */ diff --git a/kcompactdisc/wmlib/plat_svr4.c b/kcompactdisc/wmlib/plat_svr4.c deleted file mode 100644 index 56d7f41e..00000000 --- a/kcompactdisc/wmlib/plat_svr4.c +++ /dev/null @@ -1,406 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * SVR4 specific. Much of this is similar to plat_hpux.c. - */ - -#if (defined(SVR4) || defined(__SVR4)) && !defined(sun) && !defined(__sun) && !defined(sony_news) && !defined(__sony_news) - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - - -void *malloc(); -char *strchr(); - -int min_volume = 0; -int max_volume = 255; - -static int -create_cdrom_node(char *dev_name) -{ - char pass_through[100]; - int file_des; - dev_t pass_thru_device; - int err; - int ccode; - - - strncpy(pass_through, dev_name, sizeof(pass_through) - 2); - pass_through[sizeof(pass_through) - 2] = '\0'; - strcat(pass_through, "p" ); - - if (setreuid(-1,0) < 0) - { - perror("setregid/setreuid/access"); - return -1; - } - - ccode = access(pass_through, F_OK); - - if (ccode < 0) - { - if ((file_des = open(dev_name, O_RDONLY)) < 0) - { - perror("open cdrom devices failed"); - return -1; - } - - if (ioctl(file_des, B_GETDEV, &pass_thru_device) < 0) - { - perror("Call to get pass-through device number failed"); - return -1; - } - - (void)close(file_des); - - if (mknod(pass_through, (S_IFCHR | S_IREAD | S_IWRITE), - pass_thru_device) < 0) - { - perror("Unable to make pass-through node"); - return -1; - } - - if (chown(pass_through, 0 , 0) < 0) - { - perror("chown"); - return -1; - } - - if (chmod(pass_through, 0660 ) < 0) - { - perror("chmod"); - return -1; - } - } - - file_des = open( pass_through, O_RDWR); - err = errno; - - if ( (setreuid(-1,getuid()) < 0) || (setregid(-1,getgid()) < 0) ) - { - perror("setreuid/setregid"); - return -1; - } - errno = err; - return file_des; -} /* create_cdrom_node() */ - -const char* -find_cdrom() -{ - /* - ** the path of the device has to start w/ /dev - ** otherwise we are vulnerable to race conditions - ** Thomas Biege - */ - const char* device = NULL; - - device = getenv("CDROM"); - if ( (device != NULL) && - !(strncmp("/dev/", device, 5) || - strstr(_device, "/../") )) - return device; - - if (access("/dev/cdrom/cdrom1", F_OK) == 0) - { - return "/dev/cdrom/cdrom1"; - } - else if (access("/dev/cdrom/cdrom2", F_OK) == 0) - { - return "/dev/cdrom/cdrom2"; - } - else - { - fprintf(stderr, "Could not find a CD device!\n"); - return NULL; - } -} /* find_cdrom() */ - -/* - * Initialize the drive. A no-op for the generic driver. - */ -int -gen_init(struct wm_drive *d) -{ - return 0; -} /* gen_init() */ - -/* - * Open the CD and figure out which kind of drive is attached. - */ -int -gen_open(struct wm_drive *d) -{ - if (d->fd >= 0) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - d->fd = create_cdrom_node(d->cd_device); /* this will do open */ - if (d->fd < 0) { - if (errno == EACCES) - else if (errno != EINTR) - return -6; - - /* No CD in drive. (Is this true also for svr4 ? XXX ) */ - return 1; - } - - return 0; -} /* gen_open() */ - -/* - * Send a SCSI command out the bus. - */ -int -gen_scsi( struct wm_drive *d, unsigned char *xcdb, int cdblen, - char *retbuf, int retbuflen, int getreply) -{ - int ccode; - int file_des = d->fd; - int i,j; - unsigned char sense_buffer[ SENSE_SZ ]; - int errno_save; - - /* getreply == 1 is read, == 0 is write */ - - struct sb sb; - struct scs scs; - - sb.sb_type = ISCB_TYPE; - - sb.SCB.sc_comp_code = SDI_PROGRES; - sb.SCB.sc_int = NULL; - sb.SCB.sc_wd = 0; - sb.SCB.sc_dev.sa_major = 0; - sb.SCB.sc_dev.sa_minor = 0; - sb.SCB.sc_dev.sa_lun = 0; - sb.SCB.sc_dev.sa_exlun = 0; - sb.SCB.sc_status = 0; - sb.SCB.sc_link = (struct sb *) NULL; - sb.SCB.sc_resid = 0; - - sb.SCB.sc_cmdpt = (void *)xcdb; - sb.SCB.sc_cmdsz = cdblen; - - sb.SCB.sc_datapt = retbuf ; - sb.SCB.sc_datasz = retbuflen ; - - if (getreply == 1) - sb.SCB.sc_mode = SCB_READ; - else - sb.SCB.sc_mode = SCB_WRITE; - - sb.SCB.sc_time = 500; - - ccode = ioctl(file_des, SDI_SEND, &sb); - - if ( (sb.SCB.sc_comp_code != 0xd000000e ) || - ( sb.SCB.sc_status != 02) ) - return ccode; - - errno_save = errno; - - sb.SCB.sc_comp_code = SDI_PROGRES; - sb.SCB.sc_int = NULL; - sb.SCB.sc_wd = 0; - sb.SCB.sc_dev.sa_major = 0; - sb.SCB.sc_dev.sa_minor = 0; - sb.SCB.sc_dev.sa_lun = 0; - sb.SCB.sc_dev.sa_exlun = 0; - sb.SCB.sc_status = 0; - sb.SCB.sc_link = (struct sb *) NULL; - sb.SCB.sc_resid = 0; - - scs.ss_op = SS_REQSEN; - scs.ss_lun = 0; - scs.ss_addr1 = 0; - scs.ss_addr = 0; - scs.ss_len = SENSE_SZ; - scs.ss_cont = 0; - - sb.SCB.sc_cmdpt = SCS_AD(&scs); - sb.SCB.sc_cmdsz = SCS_SZ; - sb.SCB.sc_datapt = sense_buffer; - sb.SCB.sc_datasz = 18; - sb.SCB.sc_mode = SCB_READ; - sb.SCB.sc_time = 5000; - - if (ioctl(file_des, SDI_SEND, &sb) < 0) - { - fprintf(stderr,"Cannot read sense.\n"); - exit(-1); - } - - errno=errno_save; - return -1; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - */ -int -gen_get_drive_status(struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *index) -{ - return wm_scsi2_get_drive_status(d, oldmode, mode, pos, track, index); -} /* gen_get_drive_status() */ - -/* - * Get the number of tracks on the CD. - */ -int -gen_get_trackcount(struct wm_drive *d, int *tracks) -{ - return wm_scsi2_get_trackcount(d, tracks); -} /* gen_get_trackcount() */ - -/* - * Get the start time and mode (data or audio) of a track. - */ -int -gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - return wm_scsi2_get_trackinfo(d, track, data, startframe); -} /* gen_get_trackinfo() */ - -/* - * Get the number of frames on the CD. - */ -int -gen_get_cdlen(struct wm_drive *d, int *frames) -{ - int tmp; - - return wm_scsi2_get_cdlen(d, frames); -} /* gen_get_cdlen() */ - -/* - * Play the CD from one position to another (both in frames.) - */ -int -gen_play(struct wm_drive *d, int start, int end) -{ - return wm_scsi2_play(d, start, end); -} /* gen_play() */ - -/* - * Pause the CD. - */ -int -gen_pause(struct wm_drive *d) -{ - return wm_scsi2_pause(d); -} /* gen_pause() */ - -/* - * Resume playing the CD (assuming it was paused.) - */ -int -gen_resume(struct wm_drive *d) -{ - return wm_scsi2_resume(d); -} /* gen_resume() */ - -/* - * Stop the CD. - */ -int -gen_stop(struct wm_drive *d) -{ - return wm_scsi2_stop(d); -} /* gen_stop() */ - - -/* - * Eject the current CD, if there is one. - */ -int -gen_eject(struct wm_drive *d) -{ - return wm_scsi2_eject(d); -} /* gen_eject() */ - -/* - * Close the tray. - * please review scsi.c / wm_scsi2_closetray() - * and send changes to milliByte@DeathsDoor.com - */ -int -gen_closetray( struct wm_drive *d ) -{ - return wm_scsi2_closetray(d); -} /* gen_closetray() */ - - -/* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - */ -int -gen_set_volume(struct wm_drive *d, int left, int right) -{ - return wm_scsi2_set_volume(d, left, right); -} /* gen_set_volume() */ - -/* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - */ -int -gen_get_volume(struct wm_drive *d, int *left, int *right) -{ - return wm_scsi2_get_volume(d, left, right); -} /* gen_get_volume() */ - -#endif diff --git a/kcompactdisc/wmlib/plat_template.c b/kcompactdisc/wmlib/plat_template.c deleted file mode 100644 index d4bd9eb6..00000000 --- a/kcompactdisc/wmlib/plat_template.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * This file surely contains nonsense. It's the porter's part to fill - * the gaps and assure that the resulting code makes sense. - * - */ - -#if [TEMPLATESYSTEM] - - -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_cdtext.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -/* - * gen_init(); - * - */ -int -gen_init(struct wm_drive *d) -{ - return (0); -} /* gen_init() */ - -/* - * gen_open() - * - */ -int -gen_open(struct wm_drive *d) -{ - if( ! d ) - { - errno = EFAULT; - return -1; - } - - if(d->fd > -1) /* device already open? */ - { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - - return (0); -} /* gen_open() */ - -/* - * gen_scsi() - * - */ -int -gen_scsi(struct wm_drive *d, - uchar_t *cdb, int cdblen,void *retbuf,int retbuflen,int getreply) -{ - return -1; -} /* gen_scsi() */ - -/* - * close the CD device - */ - -int -gen_close(struct wm_drive *d) -{ - if(d->fd != -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} /* gen_close() */ - -/* - * gen_get_drive_status() - * - */ -int -gen_get_drive_status(struct wm_drive *d, - int oldmode, - int *mode, - int *pos, - int *track, - int *index) -{ - return (0); -} /* gen_get_drive_status() */ - -/* - * gen_get_trackcount() - * - */ -int -gen_get_trackcount(struct wm_drive *d,int *tracks) -{ - return (0); -} /* gen_get_trackcount() */ - -/* - * gen_get_trackinfo() - * - */ -int -gen_get_trackinfo(struct wm_drive *d,int track,int *data,int *startframe) -{ - return (0); -} /* gen_get_trackinfo() */ - -/* - * gen_get_cdlen() - * - */ -int -gen_get_cdlen(struct wm_drive *d,int *frames) -{ - return (0); -} /* gen_get_cdlen() */ - -/* - * gen_play() - * - */ -int -gen_play(struct wm_drive *d,int start,int end) -{ - return (0); -} /* gen_play() */ - -/* - * gen_pause() - * - */ -int -gen_pause(struct wm_drive *d) -{ - return ioctl( 0 ); -} /* gen_pause() */ - -/* - * gen_resume - * - */ -int -gen_resume(struct wm_drive *d) -{ - return (0); -} /* gen_resume() */ - -/* - * gen_stop() - * - */ -int -gen_stop(struct wm_drive *d) -{ - return (0); -} /* gen_stop() */ - -/* - * gen_eject() - * - */ -int -gen_eject(struct wm_drive *d) -{ - return (0); -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - *----------------------------------------*/ -int gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - -int -scale_volume(int vol,int max) -{ - return ((vol * (max_volume - min_volume)) / max + min_volume); -} /* scale_volume() */ - -int -unscale_volume(int vol,int max) -{ - int n; - n = ( vol - min_volume ) * max_volume / (max - min_volume); - return (n <0)?0:n; -} /* unscale_volume() */ - -/* - * gen_set_volume() - * - */ -int -gen_set_volume(struct wm_drive *d,int left,int right) -{ - return (0); -} /* gen_set_volume() */ - -/* - * gen_get_volume() - * - */ -int -gen_get_volume(struct wm_drive *d,int *left,int *right) -{ - return (0); -} /* gen_get_volume() */ - -#endif /* TEMPLATESYSTEM */ diff --git a/kcompactdisc/wmlib/plat_ultrix.c b/kcompactdisc/wmlib/plat_ultrix.c deleted file mode 100644 index 51c791b6..00000000 --- a/kcompactdisc/wmlib/plat_ultrix.c +++ /dev/null @@ -1,587 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * ULTRIX 4.2 drive control routines. - */ - -#if defined(ultrix) || defined(__ultrix) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/wm_config.h" -#include "include/wm_cdtext.h" -#include "include/wm_struct.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM - -/* - * This structure will be filled with the TOC header and all entries. - * Ultrix doesn't seem to allow getting single TOC entries. - * - Chris Ross (cross@eng.umd.edu) - */ -struct cd_toc_header_and_entries -{ - struct cd_toc_header cdth; - struct cd_toc_entry cdte[CDROM_MAX_TRACK+1]; -}; - -void *malloc(); -char *strchr(); - -int min_volume = 128; -int max_volume = 255; - -char * ultrix_cd_device = NULL; -/* - * fgetline() - * - * Simulate fgets, but joining continued lines in the output of uerf. - */ - -#define BUF_SIZE 85 /* Max length of a (real) line */ - -char * -fgetline( FILE *fp ) -{ - static char *retval = NULL; - static char holdbuf[BUF_SIZE + 1]; - char tmp[BUF_SIZE + 1]; - char *stmp; - - if (!retval) { - retval = malloc(BUF_SIZE * 3); /* 3 lines can be joined */ - if (!retval) - return(NULL); - else - *retval = '\0'; - } - - if (*holdbuf) { - strcpy(retval, holdbuf); - retval[strlen(retval)-1] = '\0'; - memset(holdbuf, 0, BUF_SIZE+1); - } - - while (fgets(tmp, BUF_SIZE, fp)) { - stmp = tmp + strspn(tmp, " \t"); - if (*stmp == '_') { /* Continuation line */ - retval[strlen(retval)-1] = '\0'; /* Trim off C/R */ - strcat(retval, stmp+1); - } else { - if (*retval) { - strcpy(holdbuf, tmp); - holdbuf[strlen(holdbuf)-1] = -1; - return retval; - } else { /* First line read, keep reading */ - strcat(retval, stmp); - retval[strlen(retval)-1] = '\0'; - } - } - } - - return NULL; -} /* fgetline() */ - -/* - * find_cdrom - * - * Determine the name of the CD-ROM device. - * - * Read through the boot records (via a call to uerf) and find the SCSI - * address of the CD-ROM. If the "CDROM" environment variable is set, - * use that instead. - */ -const char* -find_cdrom() -{ - char *data; - FILE *uerf; - int fds[2]; - int pid; - const char* device = NULL; - - device = getenv("CDROM"); - - if (device != NULL) { - if(strncmp("/dev/", device, 5) || strstr(device, "/../")) - return NULL; - } - - pipe(fds); - - if ((pid = fork()) == 0) { - close(fds[0]); - dup2(fds[1], 1); - execl("/etc/uerf", "uerf", "-R", "-r", "300", (void *)0); - execl("/usr/sbin/uerf", "uerf", "-R", "-r", "300", (void *)0); - return NULL; /* _exit(1); */ - } else if (pid < 0) { - perror("fork"); - return NULL; /* exit(1); */ - } - - close(fds[1]); - uerf = fdopen(fds[0], "r"); - - while (data = fgetline(uerf)) { - if (strstr(data, "RRD42")) { - char *device_p; - - ultrix_cd_device = (char *)malloc(sizeof("/dev/rrz##c")); - strcpy(ultrix_cd_device, "/dev/r"); - device_p = strstr(data, "rz"); - device_p[(int)(strchr(device_p, ' ') - device_p)] = '\0'; - strcat(ultrix_cd_device, device_p); - strcat(ultrix_cd_device, "c"); - device = ultrix_cd_device; - break; - } - } - - fclose(uerf); - - if (device == NULL) { - fprintf(stderr, "No cdrom (RRD42) is installed on this system\n"); - return NULL; /* exit(1); */ - } - - kill(pid, 15); - (void)wait((int *)NULL); - return device; -} /* find_cdrom() */ - -/* - * initialize the drive. a no-op for the generic driver. - */ -int -gen_init( struct wm_drive *d ) -{ - return 0; -} /* gen_init() */ - - -/* - * Open the CD device and figure out what kind of drive is attached. - */ -int -gen_open( struct wm_drive *d ) -{ - if (d->fd >= 0) { /* Device already open? */ - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); - return 0; - } - - d->fd = open(d->cd_device, 0); - if (d->fd < 0) { - if (errno == EACCES) - return -EACCES; - else if (errno != EINTR) - return -6; - - /* No CD in drive. */ - return 1; - } - - return 0; -} /* gen_open() */ - -/* - * Send an arbitrary SCSI command to a device. - */ -int -gen_scsi( struct wm_drive *d, unsigned char *cdb, int cdblen, - void *retbuf, int retbuflen, int getreply ) -{ - /* ULTRIX doesn't have a SCSI passthrough interface, does it? */ - return -1; -} /* gen_scsi() */ - -int -gen_close( struct wm_drive *d ) -{ - if(d->fd > -1) { - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); - close(d->fd); - d->fd = -1; - } - return 0; -} - -/* - * Get the current status of the drive: the current play mode, the absolute - * position from start of disc (in frames), and the current track and index - * numbers if the CD is playing or paused. - */ -int -gen_get_drive_status( struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *index) -{ - struct cd_sub_channel sc; - struct cd_subc_channel_data scd; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - sc.sch_address_format = CDROM_MSF_FORMAT; - sc.sch_data_format = CDROM_CURRENT_POSITION; - sc.sch_track_number = 0; - sc.sch_alloc_length = sizeof(scd); - sc.sch_buffer = (caddr_t)&scd; - - /* Is the device open? */ - if (d->fd < 0) { - switch (d->proto.open(d)) { - case -1: /* error */ - return -1; - - case 1: /* retry */ - return 0; - } - } - - if (ioctl(d->fd, CDROM_READ_SUBCHANNEL, &sc)) - return 0; /* ejected */ - - switch (scd.scd_header.sh_audio_status) { - case AS_PLAY_IN_PROGRESS: - *mode = WM_CDM_PLAYING; - break; - - case AS_PLAY_PAUSED: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) - *mode = WM_CDM_PAUSED; - else - *mode = WM_CDM_STOPPED; - break; - - case AS_PLAY_COMPLETED: - *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */ - break; - - case AS_NO_STATUS: - *mode = WM_CDM_STOPPED; - break; - } - - switch(*mode) { - case WM_CDM_PLAYING: - case WM_CDM_PAUSED: - *pos = scd.scd_position_data.scp_absaddr.msf.m_units * 60 * 75 + - scd.scd_position_data.scp_absaddr.msf.s_units * 75 + - scd.scd_position_data.scp_absaddr.msf.f_units; - *track = scd.scd_position_data.scp_track_number; - *index = scd.scd_position_data.scp_index_number; - break; - } - - return 0; -} /* gen_get_drive_status() */ - -/* - * Get the number of tracks on the CD. - */ -int -gen_get_trackcount( struct wm_drive *d, int *tracks ) -{ - struct cd_toc_header hdr; - - if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr)) - return (-1); - - *tracks = hdr.th_ending_track; - - return 0; -} /* gen_get_trackcount() */ - -/* - * Get the start time and mode (data or audio) of a track. - * - * XXX - this should get cached, but that means keeping track of ejects. - */ -int -gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe) -{ - struct cd_toc toc; - struct cd_toc_header hdr; - struct cd_toc_header_and_entries toc_buffer; - - if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr)) - return (-1); - - bzero((char *)&toc_buffer, sizeof(toc_buffer)); - toc.toc_address_format = CDROM_MSF_FORMAT; - toc.toc_starting_track = 0; - toc.toc_alloc_length = (u_short)(((hdr.th_data_len1 << 8) + - hdr.th_data_len0) & 0xfff) + 2; - toc.toc_buffer = (caddr_t)&toc_buffer; - - if (ioctl(d->fd, CDROM_TOC_ENTRYS, &toc)) - return (-1); - - if (track == 0) - track = hdr.th_ending_track + 1; - - *data = (toc_buffer.cdte[track-1].te_control & CDROM_DATA_TRACK) ? 1:0; - *startframe = toc_buffer.cdte[track - 1].te_absaddr.msf.m_units*60*75 + - toc_buffer.cdte[track - 1].te_absaddr.msf.s_units * 75 + - toc_buffer.cdte[track - 1].te_absaddr.msf.f_units; - - return 0; -} /* gen_get_trackinfo() */ - -/* - * Get the number of frames on the CD. - */ -int -gen_get_cdlen(struct wm_drive *d, int *frames) -{ - int tmp; - return gen_get_trackinfo(d, 0, &tmp, frames); -} /* gen_get_cdlen() */ - -/* - * Play the CD from one position to another (both in frames.) - */ -int -gen_play( struct wm_drive *d, int start, int end ) -{ - struct cd_play_audio_msf msf; - - msf.msf_starting_M_unit = start / (60*75); - msf.msf_starting_S_unit = (start % (60*75)) / 75; - msf.msf_starting_F_unit = start % 75; - msf.msf_ending_M_unit = end / (60*75); - msf.msf_ending_S_unit = (end % (60*75)) / 75; - msf.msf_ending_F_unit = end % 75; - - if (ioctl(d->fd, SCSI_START_UNIT)) - return -1; - - if (ioctl(d->fd, CDROM_PLAY_MSF, &msf)) - return -2; - - return 0; -} /* gen_play() */ - -/* - * Pause the CD. - */ -int -gen_pause( struct wm_drive *d ) -{ - return ioctl(d->fd, CDROM_PAUSE_PLAY); -} /* gen_pause() */ - -/* - * Resume playing the CD (assuming it was paused.) - */ -int -gen_resume( struct wm_drive *d ) -{ - return ioctl(d->fd, CDROM_RESUME_PLAY); -} /* gen_resume() */ - -/* - * Stop the CD. - */ -int -gen_stop( struct wm_drive *d ) -{ - return ioctl(d->fd, SCSI_STOP_UNIT); -} /* gen_stop() */ - -/* - * Eject the current CD, if there is one. - */ -int -gen_eject(struct wm_drive *d) -{ - /* On some systems, we can check to see if the CD is mounted. */ - struct stat stbuf; - struct ustat ust; - - if (fstat(d->fd, &stbuf) != 0) - return -2; - - /* Is this a mounted filesystem? */ - if (ustat(stbuf.st_rdev, &ust) == 0) - return -3; - - return ioctl(d->fd, CDROM_EJECT_CADDY); -} /* gen_eject() */ - -/*----------------------------------------* - * Close the CD tray - * - * Please edit and send changes to - * milliByte@DeathsDoor.com - *----------------------------------------*/ - -int -gen_closetray(struct wm_drive *d) -{ - return -1; -} /* gen_closetray() */ - - -/* - * scale_volume(vol, max) - * - * Return a volume value suitable for passing to the CD-ROM drive. "vol" - * is a volume slider setting; "max" is the slider's maximum value. - * - * On Sun and DEC CD-ROM drives, the amount of sound coming out the jack - * increases much faster toward the top end of the volume scale than it - * does at the bottom. To make up for this, we make the volume scale look - * sort of logarithmic (actually an upside-down inverse square curve) so - * that the volume value passed to the drive changes less and less as you - * approach the maximum slider setting. The actual formula looks like - * - * (max^2 - (max - vol)^2) * (max_volume - min_volume) - * v = --------------------------------------------------- + min_volume - * max^2 - * - * If your system's volume settings aren't broken in this way, something - * like the following should work: - * - * return ((vol * (max_volume - min_volume)) / max + min_volume); - */ -scale_volume( int vol, int max ) -{ - return ((max * max - (max - vol) * (max - vol)) * - (max_volume - min_volume) / (max * max) + min_volume); -} /* scale_volume() */ - - -/* - * unscale_volume(cd_vol, max) - * - * Given a value between min_volume and max_volume, return the volume slider - * value needed to achieve that value. - * - * Rather than perform floating-point calculations to reverse the above - * formula, we simply do a binary search of scale_volume()'s return values. - */ -static int -unscale_volume( int cd_vol, int max ) -{ - int vol = 0, top = max, bot = 0, scaled; - - while (bot <= top) { - vol = (top + bot) / 2; - scaled = scale_volume(vol, max); - if (cd_vol == scaled) - break; - if (cd_vol < scaled) - top = vol - 1; - else - bot = vol + 1; - } - - if (vol < 0) - vol = 0; - else if (vol > max) - vol = max; - - return vol; -} /* unscale_volume() */ - -/* - * Set the volume level for the left and right channels. Their values - * range from 0 to 100. - */ -int -gen_set_volume( struct wm_drive *d, int left, int right ) -{ - struct cd_playback pb; - struct cd_playback_status ps; - struct cd_playback_control pc; - - left = scale_volume(left, 100); - right = scale_volume(right, 100); - - bzero((char *)&pb, sizeof(pb)); - bzero((char *)&ps, sizeof(ps)); - bzero((char *)&pc, sizeof(pc)); - - pb.pb_alloc_length = sizeof(ps); - pb.pb_buffer = (caddr_t)&ps; - - if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb)) - return -1; - - pc.pc_chan0_select = ps.ps_chan0_select; - pc.pc_chan0_volume = (left < CDROM_MIN_VOLUME) ? - CDROM_MIN_VOLUME : (left > CDROM_MAX_VOLUME) ? - CDROM_MAX_VOLUME : left; - pc.pc_chan1_select = ps.ps_chan1_select; - pc.pc_chan1_volume = (right < CDROM_MIN_VOLUME) ? - CDROM_MIN_VOLUME : (right > CDROM_MAX_VOLUME) ? - CDROM_MAX_VOLUME : right; - - pb.pb_alloc_length = sizeof(pc); - pb.pb_buffer = (caddr_t)&pc; - - if (ioctl(d->fd, CDROM_PLAYBACK_CONTROL, &pb)) - return -1; - - return 0; -} /* gen_set_volume() */ - -/* - * Read the initial volume from the drive, if available. Each channel - * ranges from 0 to 100, with -1 indicating data not available. - */ -int -gen_get_volume(struct wm_drive *d, int *left, int *right) -{ - struct cd_playback pb; - struct cd_playback_status ps; - - bzero((char *)&pb, sizeof(pb)); - bzero((char *)&ps, sizeof(ps)); - - pb.pb_alloc_length = sizeof(ps); - pb.pb_buffer = (caddr_t)&ps; - - if (d->fd >= 0) { - if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb)) - *left = *right = -1; - else { - *left = unscale_volume(ps.ps_chan0_volume, 100); - *right = unscale_volume(ps.ps_chan1_volume, 100); - } - } else - *left = *right = -1; - - return 0; -} /* gen_get_volume() */ - -#endif diff --git a/kcompactdisc/wmlib/scsi.c b/kcompactdisc/wmlib/scsi.c deleted file mode 100644 index 91595ee8..00000000 --- a/kcompactdisc/wmlib/scsi.c +++ /dev/null @@ -1,645 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Frontend functions for sending raw SCSI commands to the CD-ROM drive. - * These depend on wm_scsi(), which should be defined in each platform - * module. - */ - -#include -#include -#include -#include "include/wm_config.h" -#include "include/wm_struct.h" -#include "include/wm_scsi.h" -#include "include/wm_platform.h" -#include "include/wm_helpers.h" -#include "include/wm_cdrom.h" -#include "include/wm_cdtext.h" - -#define SCMD_INQUIRY 0x12 -#define SCMD_MODE_SELECT 0x15 -#define SCMD_MODE_SENSE 0x1a -#define SCMD_START_STOP 0x1b -#define SCMD_PREVENT 0x1e -#define SCMD_READ_SUBCHANNEL 0x42 -#define SCMD_READ_TOC 0x43 -#define SCMD_PLAY_AUDIO_MSF 0x47 -#define SCMD_PAUSE_RESUME 0x4b -#define SCMD_SET_CD_SPEED 0xbb - -#define SUBQ_STATUS_INVALID 0x00 -#define SUBQ_STATUS_PLAY 0x11 -#define SUBQ_STATUS_PAUSE 0x12 -#define SUBQ_STATUS_DONE 0x13 -#define SUBQ_STATUS_ERROR 0x14 -#define SUBQ_STATUS_NONE 0x15 -#define SUBQ_STATUS_NO_DISC 0x17 /* Illegal, but Toshiba returns it. */ -#define SUBQ_ILLEGAL 0xff - -#define PAGE_AUDIO 0x0e -#define LEADOUT 0xaa - -#define WM_MSG_CLASS WM_MSG_CLASS_SCSI - -/* local prototypes */ -int wm_scsi_mode_select( struct wm_drive *d, unsigned char *buf, unsigned char len ); -int wm_scsi2_pause_resume(struct wm_drive *d, int resume); -int wm_scsi2_prevent(struct wm_drive *d, int prevent); -int wm_scsi2_play(struct wm_drive *d, int sframe, int eframe); -int wm_scsi2_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe); -int wm_scsi2_get_cdlen(struct wm_drive *d, int frames); -int wm_scsi2_get_drive_status(struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *ind); -int wm_scsi2_get_trackcount(struct wm_drive *d, int *tracks); -int wm_scsi2_pause(struct wm_drive *d); -int wm_scsi2_resume(struct wm_drive *d); -int wm_scsi2_stop(struct wm_drive *d); -int wm_scsi2_eject(struct wm_drive *d); -int wm_scsi2_closetray(struct wm_drive *d); -int wm_scsi2_get_volume(struct wm_drive *d, int *left, int *right); -int wm_scsi2_set_volume(struct wm_drive *d, int left, int right); -/* local prototypes END */ - -/* - * Send a SCSI command over the bus, with all the CDB bytes specified - * as unsigned char parameters. This doesn't use varargs because some - * systems have stdargs instead and the number of bytes in a CDB is - * limited to 12 anyway. - * - * d Drive structure - * buf Buffer for data, both sending and receiving - * len Size of buffer - * dir TRUE if the command expects data to be returned in the buffer. - * a0- CDB bytes. Either 6, 10, or 12 of them, depending on the command. - */ -/*VARARGS4*/ -int -sendscsi( struct wm_drive *d, void *buf, - unsigned int len, int dir, - unsigned char a0, unsigned char a1, - unsigned char a2, unsigned char a3, - unsigned char a4, unsigned char a5, - unsigned char a6, unsigned char a7, - unsigned char a8, unsigned char a9, - unsigned char a10, unsigned char a11 ) -{ - int cdblen = 0; - unsigned char cdb[12]; - - cdb[0] = a0; - cdb[1] = a1; - cdb[2] = a2; - cdb[3] = a3; - cdb[4] = a4; - cdb[5] = a5; - - switch ((a0 >> 5) & 7) { - case 0: - cdblen = 6; - break; - - case 5: - cdb[10] = a10; - cdb[11] = a11; - cdblen = 12; - - case 1: - case 2: - case 6: /* assume 10-byte vendor-specific codes for now */ - cdb[6] = a6; - cdb[7] = a7; - cdb[8] = a8; - cdb[9] = a9; - if (! cdblen) - cdblen = 10; - break; - } - - if(d->proto.scsi) - return d->proto.scsi(d, cdb, cdblen, buf, len, dir); - return -1; -} - -/* - * Send a MODE SENSE command and return the results (minus header cruft) - * in a user buffer. - * - * d Drive structure - * page Number of page to query (plus page control bits, if any) - * buf Result buffer - */ -int -wm_scsi_mode_sense( struct wm_drive *d, unsigned char page, unsigned char *buf ) -{ - unsigned char pagebuf[255]; - int status, i, len, offset; - - status = sendscsi(d, pagebuf, sizeof(pagebuf), 1, SCMD_MODE_SENSE, 0, - page, 0, sizeof(pagebuf), 0,0,0,0,0,0,0); - if (status < 0) - return (status); - - /* - * The first byte of the returned data is the transfer length. Then - * two more bytes and the length of whatever header blocks are in - * front of the page we want. - */ - len = pagebuf[0] - pagebuf[3] - 3; - offset = pagebuf[3] + 4; - for (i = 0; i < len; i++) - buf[i] = pagebuf[offset + i]; - - return (0); -} - -/* - * Send a MODE SELECT command. - * - * d Drive structure - * buf Page buffer (no need to put on block descriptors) - * len Size of page - */ -int -wm_scsi_mode_select( struct wm_drive *d, unsigned char *buf, unsigned char len ) -{ - unsigned char pagebuf[255]; - int i; - - pagebuf[0] = pagebuf[1] = pagebuf[2] = pagebuf[3] = 0; - for (i = 0; i < (int) len; i++) - pagebuf[i + 4] = buf[i]; - - return sendscsi(d, pagebuf, len + 4, 0, SCMD_MODE_SELECT, 0x10, 0, - 0, len + 4, 0,0,0,0,0,0,0); -} - -/* - * Send an INQUIRY command to get the drive type. - * - * d Drive structure - * vendor Buffer for vendor name (8 bytes + null) - * model Buffer for model name (16 bytes + null) - * rev Buffer for revision level (4 bytes + null) - * - * The above string lengths apply to the SCSI INQUIRY command. The - * actual WorkMan drive structure reserves 31 bytes + NULL per entry. - * - * If the model name begins with "CD-ROM" and zero or more spaces, that will - * all be stripped off since it's just extra junk to WorkMan. - */ -int -wm_scsi_get_drive_type(struct wm_drive *d) -{ -/* removed unsigned*/ - char *s, *t, buf[36]; - - memset(buf, 0, 36); - - wm_lib_message(WM_MSG_CLASS_SCSI | WM_MSG_LEVEL_INFO, "Sending SCSI inquiry command...\n"); - if(sendscsi(d, buf, 36, 1, SCMD_INQUIRY, 0, 0, 0, 36, 0,0,0,0,0,0,0)) { - sprintf(d->vendor, WM_STR_GENVENDOR); - sprintf(d->model, WM_STR_GENMODEL); - sprintf(d->revision, WM_STR_GENREV); - wm_lib_message(WM_MSG_CLASS_SCSI | WM_MSG_LEVEL_ERROR, - "SCSI Inquiry command not supported in this context\n"); - return -1; - } - - wm_lib_message(WM_MSG_CLASS_SCSI | WM_MSG_LEVEL_DEBUG, "sent.\n"); - - memcpy(d->vendor, buf + 8, 8); - d->vendor[8] = '\0'; - memcpy(d->model, buf + 16, 16); - d->model[16] = '\0'; - memcpy(d->revision, buf + 32, 4); - d->revision[4] = '\0'; - wm_lib_message(WM_MSG_CLASS_SCSI | WM_MSG_LEVEL_VERB, "SCSI Inquiry result: [%s|%s|%s]\n", - d->vendor, d->model, d->revision); - - /* Remove "CD-ROM " from the model. */ - if (! strncmp(d->model, "CD-ROM", 6)) { - s = d->model + 6; - t = d->model; - while (*s == ' ' || *s == '\t') - s++; - while( (*t++ = *s++) ) - ; - } - - wm_lib_message(WM_MSG_CLASS_SCSI | WM_MSG_LEVEL_INFO, "scsi: Cooked data: %s %s rev. %s\n", - d->vendor, d->model,d->revision); - - return 0; -} /* wm_scsi_get_drive_type() */ - -/* - * Send a SCSI-2 PAUSE/RESUME command. "resume" is 1 to resume, 0 to pause. - */ -int -wm_scsi2_pause_resume(struct wm_drive *d, int resume) -{ - return sendscsi(d, NULL, 0, 0, SCMD_PAUSE_RESUME, 0, 0, 0, 0, 0, 0, - 0, resume ? 1 : 0, 0,0,0); -} - -/* - * Send a SCSI-2 "prevent media removal" command. "prevent" is 1 to lock - * caddy in. - */ -int -wm_scsi2_prevent(struct wm_drive *d, int prevent) -{ - return sendscsi(d, NULL, 0, 0, SCMD_PREVENT, 0, 0, 0, 0, 0, 0, - 0, prevent ? 1 : 0, 0,0,0); -} - -/* - * Send a SCSI-2 PLAY AUDIO MSF command. Pass the starting and ending - * frame numbers. - */ -int -wm_scsi2_play(struct wm_drive *d, int sframe, int eframe) -{ - return sendscsi(d, NULL, 0, 0, SCMD_PLAY_AUDIO_MSF, 0, 0, - sframe / (60 * 75), (sframe / 75) % 60, sframe % 75, - eframe / (60 * 75), (eframe / 75) % 60, eframe % 75, - 0,0,0); -} - -/* - * Send a SCSI-2 READ TOC command to get the data for a particular track. - * Fill in track information from the returned data. - */ -int -wm_scsi2_get_trackinfo(struct wm_drive *d, int track, - int *data, int *startframe) -{ - unsigned char buf[12]; /* one track's worth of info */ - - if (sendscsi(d, buf, sizeof(buf), 1, SCMD_READ_TOC, 2, - 0, 0, 0, 0, track, sizeof(buf) / 256, - sizeof(buf) % 256, 0,0,0)) - return (-1); - - *data = buf[5] & 4 ? 1 : 0; - *startframe = buf[9] * 60 * 75 + buf[10] * 75 + buf[11]; - - return 0; -} - -/* - * Get the starting frame for the leadout area (which should be the same as - * the length of the disc as far as WorkMan is concerned). - */ -int -wm_scsi2_get_cdlen(struct wm_drive *d, int frames) -{ - int tmp; - return wm_scsi2_get_trackinfo(d, LEADOUT, &tmp, &frames); -} - -/* - * Get the current status of the drive by sending the appropriate SCSI-2 - * READ SUB-CHANNEL command. - */ -int -wm_scsi2_get_drive_status(struct wm_drive *d, int oldmode, - int *mode, int *pos, int *track, int *ind) -{ - unsigned char buf[48]; - - /* If we can't get status, the CD is ejected, so default to that. */ - *mode = WM_CDM_EJECTED; - - /* If we can't read status, the CD has been ejected. */ - buf[1] = SUBQ_ILLEGAL; - if (sendscsi(d, buf, sizeof(buf), 1, SCMD_READ_SUBCHANNEL, 2, 64, 1, - 0, 0, 0, sizeof(buf) / 256, sizeof(buf) % 256, 0,0,0)) - return 0; - - switch (buf[1]) { - case SUBQ_STATUS_PLAY: - *mode = WM_CDM_PLAYING; - *track = buf[6]; - *ind = buf[7]; - *pos = buf[9] * 60 * 75 + buf[10] * 75 + buf[11]; - break; - - case SUBQ_STATUS_PAUSE: - if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED) { - *mode = WM_CDM_PAUSED; - *track = buf[6]; - *ind = buf[7]; - *pos = buf[9] * 60 * 75 + - buf[10] * 75 + - buf[11]; - } else - *mode = WM_CDM_STOPPED; - break; - - /* - * SUBQ_STATUS_DONE is sometimes returned when the CD is idle, - * even though the spec says it should only be returned when an - * audio play operation finishes. - */ - case SUBQ_STATUS_DONE: - case SUBQ_STATUS_NONE: - case SUBQ_STATUS_INVALID: - if (oldmode == WM_CDM_PLAYING) - *mode = WM_CDM_TRACK_DONE; - else - *mode = WM_CDM_STOPPED; - break; - - /* - * This usually means there's no disc in the drive. - */ - case SUBQ_STATUS_NO_DISC: - break; - - /* - * This usually means the user ejected the CD manually. - */ - case SUBQ_STATUS_ERROR: - break; - - case SUBQ_ILLEGAL: /* call didn't really succeed */ - break; - - default: - *mode = WM_CDM_UNKNOWN; - break; - } - - return 0; -} - -/* - * Get the number of tracks on the CD using the SCSI-2 READ TOC command. - */ -int -wm_scsi2_get_trackcount(struct wm_drive *d, int *tracks) -{ - unsigned char buf[4]; - - if (sendscsi(d, buf, sizeof(buf), 1, SCMD_READ_TOC, 0, - 0, 0, 0, 0, 0, sizeof(buf) / 256, - sizeof(buf) % 256, 0,0,0)) - return -1; - - *tracks = buf[3] - buf[2] + 1; - return 0; -} - -/* - * Pause the CD. - */ -int -wm_scsi2_pause(struct wm_drive *d) -{ - return wm_scsi2_pause_resume(d, 0); -} - -/* - * Resume playing after a pause. - */ -int -wm_scsi2_resume(struct wm_drive *d) -{ - return wm_scsi2_pause_resume(d, 1); -} - -/* - * Stop playing the CD by sending a START STOP UNIT command. - */ -int -wm_scsi2_stop(struct wm_drive *d) -{ - return sendscsi(d, NULL, 0, 0, SCMD_START_STOP, 0, 0,0,0,0,0,0,0,0,0,0); -} - -/* - * Eject the CD by sending a START STOP UNIT command. - */ -int -wm_scsi2_eject(struct wm_drive *d) -{ - /* Unlock the disc (possibly unnecessary). */ - if (wm_scsi2_prevent(d, 0)) - return -1; - wm_lib_message(WM_MSG_CLASS_SCSI | WM_MSG_LEVEL_VERB, "Issuing START_STOP for ejecting...\n"); - return sendscsi(d, NULL, 0, 0, SCMD_START_STOP, 2, 0,0,0,0,0,0,0,0,0,0); -} - -/* - * Something like a dummy. The SCSI-2 specs are too hard for me to - * understand here... - * - * If you have the correct command handy, please send the code to - * milliByte@DeathsDoor.com - */ -int -wm_scsi2_closetray(struct wm_drive *d) -{ - wm_lib_message(WM_MSG_CLASS_SCSI | WM_MSG_LEVEL_VERB, "Issuing START_STOP for closing...\n"); - return sendscsi(d, NULL, 0,0, SCMD_START_STOP, 2, 0,0,0,0,0,0,0,0,0,0); -} - -/* - * Get the volume by doing a MODE SENSE command. - */ -int -wm_scsi2_get_volume(struct wm_drive *d, int *left, int *right) -{ - unsigned char mode[16]; - - *left = *right = -1; - - /* Get the current audio parameters first. */ - if (wm_scsi_mode_sense(d, PAGE_AUDIO, mode)) - return (-1); - - *left = ((int) mode[9] * 100) / 255; - *right = ((int) mode[11] * 100) / 255; - - return 0; -} - -/* - * Set the volume by doing a MODE SELECT command. - */ -int -wm_scsi2_set_volume(struct wm_drive *d, int left, int right) -{ - unsigned char mode[16]; - - /* Get the current audio parameters first. */ - if (wm_scsi_mode_sense(d, PAGE_AUDIO, mode)) - return -1; - - /* Tweak the volume part of the parameters. */ - mode[9] = (left * 255) / 100; - mode[11] = (right * 255) / 100; - - /* And send them back to the drive. */ - return wm_scsi_mode_select(d, mode, sizeof(mode)); -} - -/*------------------------------------------------------------------------* - * wm_scsi_get_cdtext(drive, buffer, length) - * - * Return a buffer with cdtext-stream. buffer mus be allocated and filled - * - * - *------------------------------------------------------------------------*/ - -int -wm_scsi_get_cdtext(struct wm_drive *d, unsigned char **pp_buffer, int *p_buffer_length) -{ - int ret; - unsigned char temp[8]; - unsigned char *dynamic_temp; - int cdtext_possible; - unsigned short cdtext_data_length; - unsigned long feature_list_length; -#define IGNORE_FEATURE_LIST -#ifndef IGNORE_FEATURE_LIST - struct feature_list_header *pHeader; - struct feature_descriptor_cdread *pDescriptor; -#endif /* IGNORE_FEATURE_LIST */ - - dynamic_temp = NULL; - cdtext_possible = 0; - wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wm_scsi_get_cdtext entered\n"); - - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, "CDTEXT INFO: use GET_FEATURY_LIST(0x46)...\n"); - ret = sendscsi(d, temp, 8, 1, 0x46, 0x02, 0x00, 0x1E, 0, 0, 0, 0, 8, 0, 0, 0); - - if(ret) { - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT ERROR: GET_FEATURY_LIST(0x46) not implemented or broken. ret = %i!\n", ret); -#ifndef IGNORE_FEATURE_LIST - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT ERROR: Try #define IGNORE_FEATURE_LIST in libwm/scsi.c\n"); -#else - cdtext_possible = 1; - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT INFO: GET_FEATURY_LIST(0x46) ignored. It is OK, because many CDROMS do not implement this feature\n"); -#endif /* IGNORE_FEATURE_LIST */ - } else { - feature_list_length = temp[0]*0xFFFFFF + temp[1]*0xFFFF + temp[2]*0xFF + temp[3] + 4; - - dynamic_temp = malloc(feature_list_length); - - if(!dynamic_temp) - return -1; - - memset(dynamic_temp, 0, feature_list_length); - ret = sendscsi(d, dynamic_temp, feature_list_length, 1, - 0x46, 0x02, 0x00, 0x1E, 0, 0, 0, (feature_list_length>>8) & 0xFF, - feature_list_length & 0xFF, 0, 0, 0); - -#ifndef IGNORE_FEATURE_LIST - if(!ret) { - pHeader = (struct feature_list_header*)dynamic_temp; -/* printf("length = %i, profile = 0x%02X%02X\n", pHeader->lenght_lsb, pHeader->profile_msb, pHeader->profile_lsb);*/ - pDescriptor = (struct feature_descriptor_cdread*) - (dynamic_temp + sizeof(struct feature_list_header)); -/* printf("code = 0x%02X%02X, settings = 0x%02X, add_length = %i, add_settings = 0x%02X \n", - pDescriptor->feature_code_msb, pDescriptor->feature_code_lsb, pDescriptor->settings, - pDescriptor->add_lenght, pDescriptor->add_settings);*/ - - cdtext_possible = pDescriptor->add_settings & 0x01; - } else { - cdtext_possible = 0; - } -#else - cdtext_possible = 1; -#endif /* IGNORE_FEATURE_LIST */ - - free (dynamic_temp); - dynamic_temp = 0; - } - - if(!cdtext_possible) { - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT INFO: GET_FEATURY_LIST(0x46) says, CDTEXT is not present!\n"); - return EXIT_SUCCESS; - } - - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, "CDTEXT INFO: try to read, how long CDTEXT is?\n"); - ret = sendscsi(d, temp, 4, 1, SCMD_READ_TOC, 0x00, 0x05, 0, 0, 0, 0, 0, 4, 0, 0, 0); - - if(ret) { - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT ERROR: READ_TOC(0x43) with format code 0x05 not implemented or broken. ret = %i!\n", ret); - } else { - cdtext_data_length = temp[0]*0xFF + temp[1] + 4 + 1; /* divide by 18 + 4 ? */ - /* cdtext_data_length%18 == 0;? */ - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT INFO: CDTEXT is %i byte(s) long\n", cdtext_data_length); - /* cdc_buffer[2]; cdc_buffer[3]; reserwed */ - dynamic_temp = malloc(cdtext_data_length); - if(!dynamic_temp) - return -1; - - memset(dynamic_temp, 0, cdtext_data_length); - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, "CDTEXT INFO: try to read CDTEXT\n"); - ret = sendscsi(d, dynamic_temp, cdtext_data_length, 1, - SCMD_READ_TOC, 0x00, 0x05, 0, 0, 0, 0, (cdtext_data_length>>8) & 0xFF, - cdtext_data_length & 0xFF, 0, 0, 0); - - if(ret) { - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT ERROR: READ_TOC(0x43) with format code 0x05 not implemented or broken. ret = %i!\n", ret); - } else { - cdtext_data_length = temp[0]*0xFF + temp[1] + 4 + 1; /* divide by 18 + 4 ? */ - wm_lib_message(WM_MSG_LEVEL_INFO|WM_MSG_CLASS, - "CDTEXT INFO: read %i byte(s) of CDTEXT\n", cdtext_data_length); - - /* send cdtext only 18 bytes packs * ? */ - *(p_buffer_length) = cdtext_data_length - 4; - *pp_buffer = malloc(*p_buffer_length); - if(!(*pp_buffer)) { - return -1; - } - memcpy(*pp_buffer, dynamic_temp + 4, *p_buffer_length); - } - free(dynamic_temp); - dynamic_temp = 0; - } - - return ret; -} /* wm_scsi_get_cdtext() */ - -int -wm_scsi_set_speed(struct wm_drive *d, int read_speed) -{ - int ret; - - ret = sendscsi(d, NULL, 0, 0, - SCMD_SET_CD_SPEED, 0x00, (read_speed>>8) & 0xFF, read_speed & 0xFF, 0xFF, 0xFF, - 0, 0, 0, 0, 0, 0); - wm_lib_message(WM_MSG_LEVEL_ERROR|WM_MSG_CLASS, - "wm_scsi_set_speed returns %i\n", ret); - return ret; -} /* wm_scsi_set_speed() */ diff --git a/kcompactdisc/wmlib/wm_helpers.c b/kcompactdisc/wmlib/wm_helpers.c deleted file mode 100644 index 5179920b..00000000 --- a/kcompactdisc/wmlib/wm_helpers.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * This file is part of WorkMan, the civilized CD player library - * Copyright (C) 1991-1997 by Steven Grimm - * Copyright (C) by Dirk Försterling - * Copyright (C) 2004-2006 Alexander Kern - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Some helpful functions... - * - */ - -#include -#include -#include -#include -#include -#include -#include "include/workman_defs.h" -#include "include/wm_config.h" -#include "include/wm_helpers.h" -#include "include/wm_struct.h" - -#define WM_MSG_CLASS WM_MSG_CLASS_MISC - -int wm_lib_verbosity = WM_MSG_LEVEL_ERROR | WM_MSG_CLASS_ALL; - -/* - * Some seleced functions of version reporting follow... - */ - -int wm_libver_major( void ){return WM_LIBVER_MAJOR;} -int wm_libver_minor( void ){return WM_LIBVER_MINOR;} -int wm_libver_pl( void ){return WM_LIBVER_PL;} - -char *wm_libver_name( void ) -{ - char *s = NULL; - - wm_strmcat(&s, WM_LIBVER_NAME); - return s; -} /* wm_libver_name() */ - -char *wm_libver_number( void ) -{ - char *s = NULL; - - s = malloc(10); - /* this is not used very often, so don't care about speed...*/ - sprintf(s, "%d.%d.%d", wm_libver_major(), wm_libver_minor(), wm_libver_pl()); - return s; -} /* wm_libver_number() */ - -char *wm_libver_date( void ) -{ - char *s = NULL; - wm_strmcat(&s, __DATE__); - return s; -} /* wm_libver_date() */ - -char *wm_libver_string( void ) -{ - char *s = NULL; - - wm_strmcat( &s, wm_libver_name() ); - wm_strmcat( &s, " " ); - wm_strmcat( &s, wm_libver_number() ); - return s; -} /* wm_libver_string() */ - - -/* - * - * Now for some memory management... - * - */ - -/* Free some memory and set a pointer to null. */ -void freeup( char **x ) -{ - if (*x != NULL) - { - free(*x); - *x = NULL; - } -} /* freeup() */ - -/* Copy into a malloced string. */ -void -wm_strmcpy( char **t, const char *s ) -{ - wm_lib_message(WM_MSG_CLASS_MISC | WM_MSG_LEVEL_DEBUG, "wm_strmcpy(%s, '%s')\n", *t, s); - if (*t != NULL) - { - wm_lib_message(WM_MSG_CLASS_MISC | WM_MSG_LEVEL_DEBUG, "wm_strmcpy freeing pointer %p\n", *t); - free(*t); - } - - *t = malloc(strlen(s) + 1); - if (*t == NULL) - { - perror("wm_strmcpy"); - exit(1); - } - - wm_lib_message(WM_MSG_CLASS_MISC | WM_MSG_LEVEL_DEBUG, "wm_strmcpy finally copying (%p, '%s')\n", *t, s); - strncpy(*t, s, strlen(s)); -} /* wm_strmcpy() */ - -/* Add to a malloced string. */ -void -wm_strmcat( char **t, const char *s) -{ - int len = strlen(s) + 1; - - wm_lib_message(WM_MSG_CLASS_MISC | WM_MSG_LEVEL_DEBUG, "wm_strmcat(%s, %s)\n", *t, s); - - if (*s == '\0') - return; - - if (*t != NULL) - { - len += strlen(*t); - *t = realloc(*t, len); - if (*t == NULL) - { - perror("wm_strmcat"); - exit(1); - } - strcat(*t, s); - } - else - wm_strmcpy(t, s); -} /* wm_strmcat() */ - -/* Duplicate a string. Some systems have this in libc, but not all. */ -char * -wm_strdup( char *s ) -{ - char *new; - - new = malloc(strlen(s) + 1); - if (new) - strcpy(new, s); - return (new); -} /* wm_strdup() */ - - -/* - * set and get verbosity level. - */ -void wm_lib_set_verbosity( int level ) -{ - int l = level & WM_MSG_LEVEL_ALL; - int c = level & WM_MSG_CLASS_ALL; - if( WM_MSG_LEVEL_NONE <= l && l <= WM_MSG_LEVEL_DEBUG ) - { - wm_lib_verbosity = l | c; - wm_lib_message(WM_MSG_CLASS_MISC | WM_MSG_LEVEL_DEBUG, "Verbosity set to 0x%x|0x%x\n", l, c); - } -} /* wm_lib_set_verbosity */ - -int wm_lib_get_verbosity( void ) -{ - return wm_lib_verbosity; -} - -/* - * wm_lib_message(). - * - * any message that falls into allowed classes and has at least - * verbosity level wm_lib_verbosity & 0xf will be printed. - * - * Usage: - * - * wm_lib_message( WM_MSG_LEVEL | WM_MSG_CLASS, "format", contents); - * - * To simplify the usage, you may simply use WM_MSG_CLASS. It should be - * defined in each module to reflect the correct message class. - * - */ -void wm_lib_message( unsigned int level, const char *fmt, ... ) -{ - va_list ap; - - unsigned int l, c, vl, vc; - /* verbosity level */ - vl = wm_lib_verbosity & WM_MSG_LEVEL_ALL; - /* allowed classes */ - vc = wm_lib_verbosity & WM_MSG_CLASS_ALL; - - l = level & WM_MSG_LEVEL_ALL; - c = level & WM_MSG_CLASS_ALL; - - /* - * print it only if level and class are allowed. - */ - if( (l <= vl) && (vc & c) ) - { - fprintf(stderr, "libWorkMan: "); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - } -} /* wm_lib_message() */ - -/* - * Simulate usleep() using select(). - */ -int -wm_susleep( int usec ) -{ - struct timeval tv; - - timerclear(&tv); - tv.tv_sec = usec / 1000000; - tv.tv_usec = usec % 1000000; - return (select(0, NULL, NULL, NULL, &tv)); -} /* wm_susleep() */ - - diff --git a/kcompactdisc/wmlib_interface.cpp b/kcompactdisc/wmlib_interface.cpp deleted file mode 100644 index b092cd90..00000000 --- a/kcompactdisc/wmlib_interface.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/* - * KCompactDisc - A CD drive interface for the KDE Project. - * - * Copyright (C) 2007 Alexander Kern - * - * 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, 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 "wmlib_interface.h" - -#include -#include - -extern "C" -{ - // We don't have libWorkMan installed already, so get everything - // from within our own directory - #include "wmlib/include/wm_cdrom.h" - #include "wmlib/include/wm_cdtext.h" - #include "wmlib/include/wm_helpers.h" -} - -#define TRACK_VALID(track) ((track) && (track <= m_tracks)) - -KWMLibCompactDiscPrivate::KWMLibCompactDiscPrivate(KCompactDisc *p, - const QString &dev, const QString &audioSystem, const QString &audioDevice) : - KCompactDiscPrivate(p, dev), - m_handle(NULL), - m_audioSystem(audioSystem), - m_audioDevice(audioDevice) -{ - m_interface = m_audioSystem; -} - -KWMLibCompactDiscPrivate::~KWMLibCompactDiscPrivate() -{ - if (m_handle) { - wm_cd_destroy(m_handle); - } -} - -bool KWMLibCompactDiscPrivate::createInterface() -{ - QString devicePath; - - devicePath = KCompactDisc::cdromDeviceUrl(m_deviceName).path(); - - // Debug. - //wm_cd_set_verbosity(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS_ALL); - - int status = wm_cd_init( - devicePath.toAscii().data(), - m_audioSystem.toAscii().data(), - m_audioDevice.toAscii().data(), - NULL, - &m_handle); - - if(!WM_CDS_ERROR(status)) { - m_deviceVendor = QLatin1String(wm_drive_vendor(m_handle)); - m_deviceModel = QLatin1String(wm_drive_model(m_handle)); - m_deviceRevision = QLatin1String(wm_drive_revision(m_handle)); - - Q_Q(KCompactDisc); - emit q->discChanged(0); - - if (m_infoMode == KCompactDisc::Asynchronous) { - timerExpired(); - } else { - QTimer::singleShot(1000, this, SLOT(timerExpired())); - } - - return true; - } - m_handle = NULL; - return false; -} - -unsigned KWMLibCompactDiscPrivate::trackLength(unsigned track) -{ - return (unsigned)wm_cd_gettracklen(m_handle, track); -} - -bool KWMLibCompactDiscPrivate::isTrackAudio(unsigned track) -{ - return !wm_cd_gettrackdata(m_handle, track); -} - -void KWMLibCompactDiscPrivate::playTrackPosition(unsigned track, unsigned position) -{ - unsigned firstTrack, lastTrack; - - firstTrack = TRACK_VALID(track) ? track : 1; - lastTrack = firstTrack + 1; - lastTrack = TRACK_VALID(lastTrack) ? lastTrack : WM_ENDTRACK; - - kDebug() << "play track " << firstTrack << " position " - << position << endl; - - wm_cd_play(m_handle, firstTrack, position, lastTrack); -} - -void KWMLibCompactDiscPrivate::pause() -{ - wm_cd_pause(m_handle); -} - -void KWMLibCompactDiscPrivate::stop() -{ - wm_cd_stop(m_handle); -} - -void KWMLibCompactDiscPrivate::eject() -{ - wm_cd_eject(m_handle); -} - -void KWMLibCompactDiscPrivate::closetray() -{ - wm_cd_closetray(m_handle); -} - -/* WM_VOLUME_MUTE ... WM_VOLUME_MAXIMAL */ -/* WM_BALANCE_ALL_LEFTS .WM_BALANCE_SYMMETRED. WM_BALANCE_ALL_RIGHTS */ -#define RANGE2PERCENT(x, min, max) (((x) - (min)) * 100)/ ((max) - (min)) -#define PERCENT2RANGE(x, min, max) ((((x) * ((max) - (min))) / 100 ) + (min)) -void KWMLibCompactDiscPrivate::setVolume(unsigned volume) -{ - int vol, bal; - vol = PERCENT2RANGE(volume, WM_VOLUME_MUTE, WM_VOLUME_MAXIMAL); - bal = wm_cd_getbalance(m_handle); - wm_cd_volume(m_handle, vol, bal); -} - -void KWMLibCompactDiscPrivate::setBalance(unsigned balance) -{ - int vol, bal; - vol = wm_cd_getvolume(m_handle); - bal = PERCENT2RANGE(balance, WM_BALANCE_ALL_LEFTS, WM_BALANCE_ALL_RIGHTS); - wm_cd_volume(m_handle, vol, bal); -} - -unsigned KWMLibCompactDiscPrivate::volume() -{ - int vol = wm_cd_getvolume(m_handle); - unsigned volume = RANGE2PERCENT(vol, WM_VOLUME_MUTE, WM_VOLUME_MAXIMAL); - return volume; -} - -unsigned KWMLibCompactDiscPrivate::balance() -{ - int bal = wm_cd_getbalance(m_handle); - unsigned balance = RANGE2PERCENT(bal, WM_BALANCE_ALL_LEFTS, WM_BALANCE_ALL_RIGHTS); - - return balance; -} - -void KWMLibCompactDiscPrivate::queryMetadata() -{ - cdtext(); - //cddb(); -} - -KCompactDisc::DiscStatus KWMLibCompactDiscPrivate::discStatusTranslate(int status) -{ - switch (status) { - case WM_CDM_TRACK_DONE: - case WM_CDM_PLAYING: - case WM_CDM_FORWARD: - return KCompactDisc::Playing; - case WM_CDM_PAUSED: - return KCompactDisc::Paused; - case WM_CDM_STOPPED: - return KCompactDisc::Stopped; - case WM_CDM_EJECTED: - return KCompactDisc::Ejected; - case WM_CDM_NO_DISC: - case WM_CDM_UNKNOWN: - return KCompactDisc::NoDisc; - case WM_CDM_CDDAERROR: - case WM_CDM_LOADING: - case WM_CDM_BUFFERING: - return KCompactDisc::NotReady; - default: - return KCompactDisc::Error; - } -} - -void KWMLibCompactDiscPrivate::timerExpired() -{ - KCompactDisc::DiscStatus status; - unsigned track, i; - Q_Q(KCompactDisc); - - status = discStatusTranslate(wm_cd_status(m_handle)); - - if(m_status != status) { - if(skipStatusChange(status)) - goto timerExpiredExit; - - m_status = status; - - switch(m_status) { - case KCompactDisc::Ejected: - case KCompactDisc::NoDisc: - clearDiscInfo(); - break; - default: - if(m_tracks == 0) { - m_tracks = wm_cd_getcountoftracks(m_handle); - if(m_tracks > 0) { - kDebug() << "New disc with " << m_tracks << " tracks"; - m_discId = wm_cddb_discid(m_handle); - - for(i = 1; i <= m_tracks; i++) { - m_trackStartFrames.append(wm_cd_gettrackstart(m_handle, i)); - } - m_trackStartFrames.append(wm_cd_gettrackstart(m_handle, i)); - - m_discLength = FRAMES2SEC(m_trackStartFrames[m_tracks] - - m_trackStartFrames[0]); - - make_playlist(); - - m_trackArtists.append(i18n("Unknown Artist")); - m_trackTitles.append(i18n("Unknown Title")); - for(i = 1; i <= m_tracks; i++) { - m_trackArtists.append(i18n("Unknown Artist")); - m_trackTitles.append(ki18n("Track %1").subs(i, 2).toString()); - } - -kDebug() << "m_tracks " << m_tracks; -kDebug() << "m_trackStartFrames " << m_trackStartFrames; -kDebug() << "m_trackArtists " << m_trackArtists; -kDebug() << "m_trackTitles " << m_trackTitles; - - emit q->discChanged(m_tracks); - - if(m_autoMetadata) - queryMetadata(); - } - } - break; - } - } - - switch(m_status) { - case KCompactDisc::Playing: - m_trackPosition = wm_get_cur_pos_rel(m_handle); - m_discPosition = wm_get_cur_pos_abs(m_handle) - FRAMES2SEC(m_trackStartFrames[0]); - // Update the current playing position. - if(m_seek) { - kDebug() << "seek: " << m_seek << " trackPosition " << m_trackPosition; - if(abs((long)(m_trackExpectedPosition - m_trackPosition)) > m_seek) - m_seek = 0; - else - m_seek = abs((long)(m_trackExpectedPosition - m_trackPosition)); - } - - if(!m_seek) { - emit q->playoutPositionChanged(m_trackPosition); - //emit q->playoutDiscPositionChanged(m_discPosition); - } - - // Per-event processing. - track = wm_cd_getcurtrack(m_handle); - - if(m_track != track) { - m_track = track; - emit q->playoutTrackChanged(m_track); - } - break; - - case KCompactDisc::Stopped: - m_seek = 0; - m_track = 0; - break; - - default: - break; - } - -timerExpiredExit: - // Now that we have incurred any delays caused by the signals, we'll start the timer. - QTimer::singleShot(1000, this, SLOT(timerExpired())); -} - -void KWMLibCompactDiscPrivate::cdtext() -{ - struct cdtext_info *info; - unsigned i; - Q_Q(KCompactDisc); - - info = wm_cd_get_cdtext(m_handle); - - if(!info || !info->valid || (unsigned)info->count_of_entries != (m_tracks + 1)) { - kDebug() << "no or invalid CDTEXT"; - return; - } - - m_trackArtists[0] = QLatin1String( reinterpret_cast(info->blocks[0]->performer[0]) ); - m_trackTitles[0] = QLatin1String( reinterpret_cast(info->blocks[0]->name[0]) ); - - for(i = 1; i <= m_tracks; i++) { - m_trackArtists[i] = QLatin1String( reinterpret_cast(info->blocks[0]->performer[i]) ); - m_trackTitles[i] =QLatin1String( reinterpret_cast(info->blocks[0]->name[i]) ); - } - - kDebug() << "CDTEXT"; - kDebug() << "m_trackArtists " << m_trackArtists; - kDebug() << "m_trackTitles " << m_trackTitles; - - emit q->discInformation(KCompactDisc::Cdtext); -} - -#include "moc_wmlib_interface.cpp" diff --git a/kcompactdisc/wmlib_interface.h b/kcompactdisc/wmlib_interface.h deleted file mode 100644 index 01254539..00000000 --- a/kcompactdisc/wmlib_interface.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * KCompactDisc - A CD drive interface for the KDE Project. - * - * Copyright (C) 2007 Alexander Kern - * - * 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, 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 WMLIB_INTERFACE_H -#define WMLIB_INTERFACE_H - -#include "kcompactdisc_p.h" - -class KWMLibCompactDiscPrivate : public KCompactDiscPrivate -{ - Q_OBJECT - - public: - KWMLibCompactDiscPrivate(KCompactDisc *, const QString&, const QString &, const QString&); - virtual ~KWMLibCompactDiscPrivate(); - - virtual bool createInterface(); - - virtual unsigned trackLength(unsigned); - virtual bool isTrackAudio(unsigned); - virtual void playTrackPosition(unsigned, unsigned); - virtual void pause(); - virtual void stop(); - virtual void eject(); - virtual void closetray(); - - virtual void setVolume(unsigned); - virtual void setBalance(unsigned); - virtual unsigned volume(); - virtual unsigned balance(); - - virtual void queryMetadata(); - - - private: - KCompactDisc::DiscStatus discStatusTranslate(int); - void *m_handle; - QString m_audioSystem; - QString m_audioDevice; - - - private Q_SLOTS: - void timerExpired(); - void cdtext(); -}; - -#endif // WMLIB_INTERFACE_H diff --git a/kdecore/kdebug.areas b/kdecore/kdebug.areas index 12e39eb4..83e6f52e 100644 --- a/kdecore/kdebug.areas +++ b/kdecore/kdebug.areas @@ -37,8 +37,6 @@ 399 kimgio 410 kross (kdelibs) 500 kdeprint -600 phonon (KDE plugin) -601 phonon (kded module) 700 kutils (KSettings::Dialog) 701 kutils (KSettings::Dispatcher) 702 kutils (KPluginSelector) @@ -47,12 +45,12 @@ 711 kutils (KCModuleProxy) 712 kutils (KCModuleInfo) 713 kutils (KCModuleContainer) -750 kde3support (kspell) 800 kdewebkit 912 ksmartcard (kdelibs) 920 Solid (kdelibs) 921 Solid Networking 930 KUnitConversion +940 KMediaPlayer 1000 kparts diff --git a/kdecore/localization/klocale_kde.cpp b/kdecore/localization/klocale_kde.cpp index 5559dfb4..3e593160 100644 --- a/kdecore/localization/klocale_kde.cpp +++ b/kdecore/localization/klocale_kde.cpp @@ -314,7 +314,6 @@ void KLocalePrivate::initMainCatalogs() // catalogs from which each application can draw translations const int numberOfCatalogs = m_catalogNames.size(); - m_catalogNames.append(KCatalogName(QString::fromLatin1("libphonon"))); m_catalogNames.append(KCatalogName(QString::fromLatin1("kio4"))); m_catalogNames.append(KCatalogName(QString::fromLatin1("kdelibs4"))); m_catalogNames.append(KCatalogName(QString::fromLatin1("kdeqt"))); diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 65cf11c8..e6094b48 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -376,12 +376,12 @@ add_library(kdeui ${LIBRARY_TYPE} ${kdeui_LIB_SRCS}) target_link_libraries(kdeui PRIVATE ${KDE4_KDECORE_LIBS} - ${X11_LIBRARIES} ${QT_QTGUI_LIBRARY} ${QT_QTXML_LIBRARY} - ${KDEUI_EXTRA_LIBS} ${QT_QTNETWORK_LIBRARY} ${QT_QTSVG_LIBRARY} + ${X11_LIBRARIES} + ${KDEUI_EXTRA_LIBS} ) diff --git a/kdeui/kdepackages.h b/kdeui/kdepackages.h index 8dc9083d..14aeef39 100644 --- a/kdeui/kdepackages.h +++ b/kdeui/kdepackages.h @@ -279,6 +279,7 @@ const char * const packages[] = { "kdelibs/kwallet", "kdelibs/print-dialog", "kdelibs/qt", +"kdelibs/kmediaplayer", "kdelibs/shortcuts", "kdemultimedia", "kdemultimedia/mplayerthumbs", @@ -919,16 +920,6 @@ const char * const packages[] = { "Oxygen/win deco", "parley", "partitionmanager", -"Phonon", -"Phonon/avKode backend", -"Phonon/frontend", -"Phonon/GStreamer backend", -"Phonon/KDE platform plugin", -"Phonon/kded module for audio device listing", -"Phonon/NMM backend", -"Phonon/settings", -"Phonon/VLC backend", -"Phonon/Xine backend", "Planet KDE", "Planet KDE/feeds", "plasma", @@ -1022,7 +1013,6 @@ const char * const packages[] = { "systemsettings/kcm_mouse", "systemsettings/kcm_netpref", "systemsettings/kcm_notify", -"systemsettings/kcm_phonon", "systemsettings/kcm_proxy", "systemsettings/kcm_randr", "systemsettings/kcm_samba", diff --git a/kdeui/kernel/kclipboard.h b/kdeui/kernel/kclipboard.h index 01b554b7..51aeeadf 100644 --- a/kdeui/kernel/kclipboard.h +++ b/kdeui/kernel/kclipboard.h @@ -1,5 +1,5 @@ /* This file is part of the KDE libraries - Copyright (C) 2002 Carsten Pfeiffer + Copyright (C) 2016 Ivailo Monev This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/kdeui/tests/CMakeLists.txt b/kdeui/tests/CMakeLists.txt index e395bc7e..6833f6c5 100644 --- a/kdeui/tests/CMakeLists.txt +++ b/kdeui/tests/CMakeLists.txt @@ -164,12 +164,10 @@ target_link_libraries(kplottest ${KDE4_KDEUI_LIBS}) ## kcolorutilsdemo -SET(kcolorUtilsDemoSources +set(kcolorUtilsDemoSources kcolorutilsdemo.cpp kimageframe.cpp ../colors/kcolorspaces.cpp - kcolorutilsdemo.ui ) kde4_add_manual_test(kcolorutilsdemo ${kcolorUtilsDemoSources}) target_link_libraries(kcolorutilsdemo ${KDE4_KDEUI_LIBS}) - diff --git a/kdewidgets/CMakeLists.txt b/kdewidgets/CMakeLists.txt index b3cfdcf6..a6e751e1 100644 --- a/kdewidgets/CMakeLists.txt +++ b/kdewidgets/CMakeLists.txt @@ -6,7 +6,10 @@ endif() add_subdirectory(pics) -include_directories(${KDE4_KIO_INCLUDES}) +include_directories( + ${KDE4_KIO_INCLUDES} + ${CMAKE_SOURCE_DIR}/kutils/kmediaplayer +) ########### next target ############### @@ -34,7 +37,7 @@ if(QT_QTDESIGNER_FOUND) kde4_add_plugin(kdewidgets ${kdewidgets_SRCS}) - target_link_libraries(kdewidgets ${KDE4_KIO_LIBS}) + target_link_libraries(kdewidgets ${KDE4_KIO_LIBS} kmediaplayer) install( TARGETS kdewidgets diff --git a/kdewidgets/kde.widgets b/kdewidgets/kde.widgets index 85d9a336..40a94222 100644 --- a/kdewidgets/kde.widgets +++ b/kdewidgets/kde.widgets @@ -366,3 +366,9 @@ IncludeFile=sonnet/dictionarycombobox.h ToolTip=Dictionary Combobox WhatsThis=A combobox to select a dictionary for spellchecking Group=Sonnet (KDE) + +[KMediaWidget] +ToolTip=Multimedia files player (KDE) +WhatsThis=A widget holding media controls for playing media files +Group=Display (KDE) +ConstructorArgs=(parent) \ No newline at end of file diff --git a/khtml/CMakeLists.txt b/khtml/CMakeLists.txt index 5b8c4303..7810ea67 100644 --- a/khtml/CMakeLists.txt +++ b/khtml/CMakeLists.txt @@ -14,12 +14,13 @@ configure_file( ) include_directories( - ${KDE4_PHONON_INCLUDES} + ${KDE4_KDEUI_INCLUDES} ${KDE4_KPARTS_INCLUDES} ${CMAKE_BINARY_DIR}/kio/kssl ${KDE4_KJS_INCLUDES} ${CMAKE_SOURCE_DIR}/kimgio ${CMAKE_SOURCE_DIR}/kio/kssl + ${CMAKE_SOURCE_DIR}/kutils/kmediaplayer ${CMAKE_SOURCE_DIR}/interfaces ${CMAKE_SOURCE_DIR}/interfaces/kregexpeditor @@ -367,7 +368,6 @@ set(khtmlrender_STAT_SRCS ${CMAKE_SOURCE_DIR}/khtml/rendering/render_canvasimage.cpp ${CMAKE_SOURCE_DIR}/khtml/rendering/render_position.cpp ${CMAKE_SOURCE_DIR}/khtml/rendering/render_media.cpp - ${CMAKE_SOURCE_DIR}/khtml/rendering/media_controls.cpp ) set(khtmlcss_STAT_SRCS @@ -496,13 +496,14 @@ qt4_add_dbus_interface(khtml_LIB_SRCS add_library(khtml ${LIBRARY_TYPE} ${khtml_LIB_SRCS} $) target_link_libraries(khtml - ${KDE4_PHONON_LIBRARY} + ${KDE4_KDEUI_LIBRARY} ${KDE4_KPARTS_LIBS} ktexteditor kparts kio kdeui kdecore + kmediaplayer ${X11_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} diff --git a/khtml/html/HTMLMediaElement.cpp b/khtml/html/HTMLMediaElement.cpp index d02a780b..38842fb8 100644 --- a/khtml/html/HTMLMediaElement.cpp +++ b/khtml/html/HTMLMediaElement.cpp @@ -37,11 +37,11 @@ #include "css/cssproperties.h" #include "css/cssvalues.h" #include "css/csshelper.h" -#include -#include #include #include +#include + const double doubleMax = 999999999.8; // ### numeric_limits::max() const double doubleInf = 999999999.0; // ### numeric_limits::infinity() @@ -57,15 +57,13 @@ HTMLMediaElement::HTMLMediaElement(Document* doc) , m_loadedFirstFrame(false) , m_autoplaying(true) , m_autobuffer(true) - , m_volume(0.5f) - , m_muted(false) , m_paused(true) , m_seeking(false) , m_currentTimeDuringSeek(0) , m_previousProgress(0) , m_previousProgressTime(doubleMax) , m_sentStalledEvent(false) - , m_player(new MediaPlayer()) + , m_player(new KMediaWidget(NULL, KMediaWidget::FullscreenVideo)) { } @@ -182,13 +180,9 @@ void HTMLMediaElement::load(ExceptionCode&) void HTMLMediaElement::loadResource(String &url) { - KUrl kurl(url.string()); if (!m_player) return; - if (autoplay()) - m_player->play(kurl); - else - m_player->load(kurl); + m_player->open(url.string()); } void HTMLMediaElement::updateLoadState() @@ -206,16 +200,10 @@ String HTMLMediaElement::canPlayType(String type) { QString theType = type.string().simplified(); int paramsIdx = theType.indexOf(';'); - bool hasParams = (paramsIdx > 0 ); - // FIXME: Phonon doesn't provide the API to handle codec parameters yet - if (hasParams) + if (paramsIdx > 0) theType.truncate(paramsIdx); - if (theType == QLatin1String("audio/ogg") || theType == QLatin1String("video/ogg")) - theType = QLatin1String("application/ogg"); - if (Phonon::BackendCapabilities::isMimeTypeAvailable(theType)) + if (m_player->player()->isMimeSupported(theType)) return "probably"; - if (theType == QLatin1String("application/octet-stream") && hasParams) - return ""; return "maybe"; } @@ -247,7 +235,7 @@ float HTMLMediaElement::currentTime() const return 0; if (m_seeking) return m_currentTimeDuringSeek; - return m_player->currentTime(); + return m_player->player()->currentTime(); } void HTMLMediaElement::setCurrentTime(float time, ExceptionCode& ec) @@ -264,7 +252,7 @@ float HTMLMediaElement::startTime() const float HTMLMediaElement::duration() const { - return m_player ? m_player->totalTime() : 0; + return m_player ? m_player->player()->totalTime() : 0; } bool HTMLMediaElement::paused() const @@ -394,35 +382,31 @@ void HTMLMediaElement::setControls(bool b) float HTMLMediaElement::volume() const { - return m_volume; + if (!m_player) { + return 0; + } + return m_player->player()->volume(); } void HTMLMediaElement::setVolume(float vol, ExceptionCode& ec) { - if (vol < 0.0f || vol > 1.0f) { - ec = DOMException::INDEX_SIZE_ERR; - return; - } - - if (m_volume != vol) { - m_volume = vol; - updateVolume(); - // ### dispatchEventAsync(volumechangeEvent); - } + // that's a stub, KMediaWidget manages its state per-application + Q_UNUSED(vol); + Q_UNUSED(ec); } bool HTMLMediaElement::muted() const { - return m_muted; + if (m_player) { + return m_player->player()->mute(); + } + return false; } void HTMLMediaElement::setMuted(bool muted) { - if (m_muted != muted) { - m_muted = muted; - updateVolume(); - // ### dispatchEventAsync(volumechangeEvent); - } + // that's a stub, KMediaWidget manages its state per-application + Q_UNUSED(muted); } String HTMLMediaElement::pickMedia() @@ -502,18 +486,7 @@ bool HTMLMediaElement::endedPlayback() const #if 0 return networkState() >= LOADED_METADATA && currentTime() >= effectiveEnd() && currentLoop() == playCount() - 1; #endif - return m_player && m_player->mediaObject()->remainingTime() == 0; -} - -void HTMLMediaElement::updateVolume() -{ - if (!m_player) - return; - - m_player->setVolume(m_muted ? 0 : m_volume); - - if (renderer()) - renderer()->updateFromElement(); + return m_player && m_player->player()->remainingTime() == 0; } void HTMLMediaElement::updatePlayState() @@ -522,10 +495,7 @@ void HTMLMediaElement::updatePlayState() return; if (m_autoplaying) return; - if (m_paused && !m_player->isPaused()) - m_player->pause(); - if (!m_paused && !m_player->isPlaying()) - m_player->play(); + m_player->setPlay(); } } diff --git a/khtml/html/HTMLMediaElement.h b/khtml/html/HTMLMediaElement.h index baba984e..fef5165a 100644 --- a/khtml/html/HTMLMediaElement.h +++ b/khtml/html/HTMLMediaElement.h @@ -32,13 +32,13 @@ #include "ExceptionCode.h" #include #include +#include namespace khtml { class MediaError; class TimeRanges; class RenderMedia; -class MediaPlayer; class HTMLMediaElement : public HTMLElement { public: @@ -118,7 +118,6 @@ private: void loadResource(String& url); void updateLoadState(); - void updateVolume(); void updatePlayState(); bool endedPlayback() const; @@ -134,10 +133,7 @@ protected: bool m_loadedFirstFrame; bool m_autoplaying; bool m_autobuffer; - - float m_volume; - bool m_muted; - + bool m_paused; bool m_seeking; @@ -147,7 +143,7 @@ protected: double m_previousProgressTime; bool m_sentStalledEvent; - QPointer m_player; + QPointer m_player; }; } //namespace diff --git a/khtml/html/HTMLVideoElement.cpp b/khtml/html/HTMLVideoElement.cpp index 0d102f4c..35d7d718 100644 --- a/khtml/html/HTMLVideoElement.cpp +++ b/khtml/html/HTMLVideoElement.cpp @@ -44,20 +44,14 @@ int HTMLVideoElement::videoWidth() const { if (!m_player) return 0; - if (m_player->mediaObject()->hasVideo()) - return m_player->videoWidget()->sizeHint().width(); - else - return 0; + return m_player->sizeHint().width(); } int HTMLVideoElement::videoHeight() const { if (!m_player) return 0; - if (m_player->mediaObject()->hasVideo()) - return m_player->videoWidget()->sizeHint().height(); - else - return 0; + return m_player->sizeHint().height(); } int HTMLVideoElement::width() const diff --git a/khtml/html/HTMLVideoElement.h b/khtml/html/HTMLVideoElement.h index 603d13c8..9bbaa9f0 100644 --- a/khtml/html/HTMLVideoElement.h +++ b/khtml/html/HTMLVideoElement.h @@ -26,8 +26,7 @@ #ifndef HTMLVideoElement_h #define HTMLVideoElement_h -#include -#include +#include #include "HTMLMediaElement.h" namespace khtml { diff --git a/khtml/rendering/media_controls.cpp b/khtml/rendering/media_controls.cpp deleted file mode 100644 index d68a018a..00000000 --- a/khtml/rendering/media_controls.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2009 Michael Howell . - * Copyright (C) 2009 Germain Garand - * Parts copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "media_controls.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace khtml { - -MediaControls::MediaControls(MediaPlayer* mediaPlayer, QWidget* parent) : QWidget(parent) -{ - m_mediaPlayer = mediaPlayer; - Phonon::MediaObject* mediaObject = m_mediaPlayer->mediaObject(); - setLayout(new QHBoxLayout(this)); - m_play = new QPushButton(KIcon("media-playback-start"), i18n("Play"), this); - connect(m_play, SIGNAL(clicked()), mediaObject, SLOT(play())); - layout()->addWidget(m_play); - m_pause = new QPushButton(KIcon("media-playback-pause"), i18n("Pause"), this); - connect(m_pause, SIGNAL(clicked()), mediaObject, SLOT(pause())); - layout()->addWidget(m_pause); - layout()->addWidget(new Phonon::SeekSlider(mediaObject, this)); - KAction* fsac = new KToggleFullScreenAction(this); - fsac->setObjectName("KHTMLMediaPlayerFullScreenAction"); // needed for global shortcut activation. - m_fullscreen = new QToolButton(this); - m_fullscreen->setDefaultAction(fsac); - m_fullscreen->setCheckable(true); - connect(fsac, SIGNAL(toggled(bool)), this, SLOT(slotToggled(bool))); - layout()->addWidget(m_fullscreen); - - slotStateChanged(mediaObject->state()); - connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), SLOT(slotStateChanged(Phonon::State))); -} - -void MediaControls::slotToggled(bool t) -{ - if (t) { - m_mediaPlayer->videoWidget()->enterFullScreen(); - static_cast(m_fullscreen->defaultAction())->setGlobalShortcut(KShortcut(Qt::Key_Escape)); - } else { - m_mediaPlayer->videoWidget()->exitFullScreen(); - static_cast(m_fullscreen->defaultAction())->forgetGlobalShortcut(); - } -} - -void MediaControls::slotStateChanged(Phonon::State state) -{ - if (state == Phonon::PlayingState) { - m_play->hide(); - m_pause->show(); - } else { - m_pause->hide(); - m_play->show(); - } -} - -} - diff --git a/khtml/rendering/media_controls.h b/khtml/rendering/media_controls.h deleted file mode 100644 index cf2d4414..00000000 --- a/khtml/rendering/media_controls.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2009 Michael Howell . - * Parts copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef media_controls_h -#define media_controls_h - -#include -#include -#include -#include - -namespace khtml { - -class MediaPlayer; - -class MediaControls : public QWidget { -Q_OBJECT -public: - MediaControls(MediaPlayer* mediaPlayer, QWidget* parent = 0); - -private Q_SLOTS: - void slotStateChanged(Phonon::State state); - void slotToggled(bool); - -private: - QPushButton* m_play; - QPushButton* m_pause; - QToolButton* m_fullscreen; - MediaPlayer* m_mediaPlayer; -}; - -} //namespace - -#endif diff --git a/khtml/rendering/render_media.cpp b/khtml/rendering/render_media.cpp index 5a9680f9..e6d6f3bc 100644 --- a/khtml/rendering/render_media.cpp +++ b/khtml/rendering/render_media.cpp @@ -25,10 +25,8 @@ */ #include "render_media.h" -#include "media_controls.h" -#include -#include -#include +#include +#include const double doubleMax = 999999999.8; // ### numeric_limits::max() const double doubleInf = 999999999.0; // ### numeric_limits::infinity() @@ -45,12 +43,12 @@ RenderMedia::RenderMedia(HTMLMediaElement* element) : RenderWidget(element), m_p setQWidget(container); } -void RenderMedia::setPlayer(MediaPlayer* player) +void RenderMedia::setPlayer(KMediaWidget* player) { if (m_player == player) return; if (m_player) m_player->deleteLater(); m_player = player; - connect(player->mediaObject(), SIGNAL(metaDataChanged()), SLOT(slotMetaDataChanged())); + connect(player->player(), SIGNAL(loaded()), SLOT(slotMetaDataChanged())); player->setParent(widget()); widget()->layout()->addWidget(player); } @@ -61,15 +59,6 @@ void RenderMedia::layout() calcHeight(); RenderWidget::layout(); - - if (mediaElement()->controls() && widget()->layout()->count() == 1) { - MediaControls* toolbox = new MediaControls(player(), widget()); - widget()->layout()->addWidget(toolbox); - if ((!widget()->underMouse()) && mediaElement()->isVideo()) - toolbox->hide(); - else - toolbox->show(); - } } bool RenderMedia::eventFilter(QObject* o, QEvent* e) @@ -99,9 +88,9 @@ void RenderMedia::updateFromElement() void RenderMedia::slotMetaDataChanged() { if (mediaElement()->isVideo()) { - if (player()->videoWidget()->sizeHint().isValid()) { - setIntrinsicWidth(player()->videoWidget()->sizeHint().width()); - setIntrinsicHeight(player()->videoWidget()->sizeHint().height()); + if (player()->sizeHint().isValid()) { + setIntrinsicWidth(player()->sizeHint().width()); + setIntrinsicHeight(player()->sizeHint().height()); } } else { if (widget()->sizeHint().isValid()) { diff --git a/khtml/rendering/render_media.h b/khtml/rendering/render_media.h index 46b526c9..e78e4952 100644 --- a/khtml/rendering/render_media.h +++ b/khtml/rendering/render_media.h @@ -27,30 +27,21 @@ #ifndef render_media_h #define render_media_h -#include +#include #include #include namespace khtml { -class MediaPlayer : public Phonon::VideoPlayer { -Q_OBJECT -public: - inline MediaPlayer(Phonon::Category category, QWidget *parent = 0) : Phonon::VideoPlayer(category, parent) - { - } - inline explicit MediaPlayer(QWidget* parent = 0) : Phonon::VideoPlayer(parent) {}; -}; - class RenderMedia : public RenderWidget { Q_OBJECT public: virtual const char *renderName() const { return "RenderMedia"; } virtual bool isMedia() const { return true; } - void setPlayer(MediaPlayer* player); - MediaPlayer* player() { return m_player; } - const MediaPlayer* player() const { return m_player; } + void setPlayer(KMediaWidget* player); + KMediaWidget* player() { return m_player; } + const KMediaWidget* player() const { return m_player; } HTMLMediaElement* mediaElement() { return static_cast(RenderWidget::element()); } const HTMLMediaElement* mediaElement() const { return static_cast(RenderWidget::element()); } @@ -64,7 +55,7 @@ private: RenderMedia(HTMLMediaElement* element); void layout(); void updateFromElement(); - MediaPlayer* m_player; + KMediaWidget* m_player; friend class HTMLMediaElement; }; diff --git a/kio/CMakeLists.txt b/kio/CMakeLists.txt index f46ec12e..a1a57e17 100644 --- a/kio/CMakeLists.txt +++ b/kio/CMakeLists.txt @@ -7,6 +7,7 @@ endif() if(NOT STRIGI_FOUND) set(KIO_NO_STRIGI TRUE) endif() +set(KIO_NO_STRIGI TRUE) if(OPENSSL_FOUND) set(KSSL_HAVE_SSL 1) diff --git a/knotify/CMakeLists.txt b/knotify/CMakeLists.txt index c6161ef4..9253989c 100644 --- a/knotify/CMakeLists.txt +++ b/knotify/CMakeLists.txt @@ -1,7 +1,9 @@ project(knotify) -include_directories(${KDE4_KIO_INCLUDES}) -include_directories(BEFORE ${KDE4_PHONON_INCLUDES}) +include_directories( + ${KDE4_KIO_INCLUDES} + ${CMAKE_SOURCE_DIR}/kutils/kmediaplayer +) if(ENABLE_TESTING) add_subdirectory(tests) @@ -14,7 +16,6 @@ set(knotifyconfig_LIB_SRCS knotifyconfigelement.cpp knotifyeventlist.cpp knotifyconfigwidget.cpp - knotifyconfigactionswidgetbase.ui ) add_library(knotifyconfig ${LIBRARY_TYPE} ${knotifyconfig_LIB_SRCS}) @@ -22,9 +23,9 @@ add_library(knotifyconfig ${LIBRARY_TYPE} ${knotifyconfig_LIB_SRCS}) # Needs KIO for KUrlRequester target_link_libraries(knotifyconfig ${KDE4_KIO_LIBS} - ${KDE4_PHONON_LIBS} ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} + kmediaplayer ) set_target_properties(knotifyconfig PROPERTIES diff --git a/knotify/knotifyconfigactionswidget.cpp b/knotify/knotifyconfigactionswidget.cpp index 9bce5e5a..4a5ca900 100644 --- a/knotify/knotifyconfigactionswidget.cpp +++ b/knotify/knotifyconfigactionswidget.cpp @@ -20,8 +20,7 @@ #include #include - -#include +#include KNotifyConfigActionsWidget::KNotifyConfigActionsWidget( QWidget * parent ) : QWidget(parent) @@ -135,8 +134,8 @@ void KNotifyConfigActionsWidget::slotPlay( ) if ( search.isEmpty() )*/ soundURL = KUrl::fromPath( KStandardDirs::locate( "sound", soundString ) ); } - Phonon::MediaObject* media = Phonon::createPlayer( Phonon::NotificationCategory, soundURL ); - media->play(); + KAudioPlayer* media = new KAudioPlayer(this); + media->load(soundURL.url()); connect(media, SIGNAL(finished()), media, SLOT(deleteLater())); } diff --git a/kutils/CMakeLists.txt b/kutils/CMakeLists.txt index 26c0bde3..af0f188e 100644 --- a/kutils/CMakeLists.txt +++ b/kutils/CMakeLists.txt @@ -3,9 +3,10 @@ project(kutils) include_directories( ${KDE4_KDEUI_INCLUDES} ${KDE4_KPARTS_INCLUDES} - ${CMAKE_CURRENT_SOURCE_DIR} ) +add_subdirectory(kmediaplayer) + ########### kemoticons ################ add_subdirectory(kemoticons) diff --git a/kutils/kmediaplayer/CMakeLists.txt b/kutils/kmediaplayer/CMakeLists.txt new file mode 100644 index 00000000..f9d040ab --- /dev/null +++ b/kutils/kmediaplayer/CMakeLists.txt @@ -0,0 +1,41 @@ +include_directories( + ${MPV_INCLUDES} +) + +add_definitions( + -DMAKE_KMEDIAPLAYER_LIB + -DKDE_DEFAULT_DEBUG_AREA=940 +) + +set(kmediaplayer_LIB_SRCS + kmediaplayer.cpp + kmediawidget.cpp +) + +add_library(kmediaplayer ${LIBRARY_TYPE} ${kmediaplayer_LIB_SRCS}) + +target_link_libraries(kmediaplayer + ${MPV_LIBRARIES} + ${KDE4_KDECORE_LIBS} + ${KDE4_KDEUI_LIBS} +) + +set_target_properties(kmediaplayer PROPERTIES + VERSION ${KDE_NON_GENERIC_LIB_VERSION} + SOVERSION ${KDE_NON_GENERIC_LIB_SOVERSION} +) + +install( + FILES + kmediaplayer_export.h + kmediaplayer.h + kmediawidget.h + DESTINATION ${INCLUDE_INSTALL_DIR} + COMPONENT Devel +) + +install( + TARGETS kmediaplayer + EXPORT kdelibsLibraryTargets + ${INSTALL_TARGETS_DEFAULT_ARGS} +) diff --git a/kutils/kmediaplayer/kmediaplayer.cpp b/kutils/kmediaplayer/kmediaplayer.cpp new file mode 100644 index 00000000..1aa67a4d --- /dev/null +++ b/kutils/kmediaplayer/kmediaplayer.cpp @@ -0,0 +1,471 @@ +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#ifndef QT_KATIE +#include +#endif +#include "kmediaplayer.h" +#include +#include + +void KAbstractPlayer::load(QString path) +{ + command(QStringList() << "loadfile" << path); +} + +void KAbstractPlayer::play() + { setProperty("pause", false); }; + +void KAbstractPlayer::pause() +{ + setProperty("pause", true); +} + +void KAbstractPlayer::seek(float position) +{ + command(QVariantList() << "seek" << position << "absolute"); +} + +void KAbstractPlayer::seek(int position) +{ + command(QVariantList() << "seek" << position << "absolute"); +} + +void KAbstractPlayer::stop() +{ + command("stop"); +} + +float KAbstractPlayer::currentTime() +{ + return property("time-pos").toFloat(); +} + +float KAbstractPlayer::remainingTime() +{ + return property("time-remaining").toFloat(); +} + +float KAbstractPlayer::totalTime() +{ + return property("duration").toFloat(); +} + +float KAbstractPlayer::volume() +{ + return property("volume").toFloat(); +} + +bool KAbstractPlayer::mute() +{ + return property("mute").toBool(); +} + +QStringList KAbstractPlayer::protocols() +{ + static QStringList s_protocols; + if (s_protocols.isEmpty()) { + s_protocols << "file" << "ftp" << "sftp" << "http" << "https" << "mms" << "rtmp" << "rtsp" << "smb"; + } + return s_protocols; +} + +bool KAbstractPlayer::isPlaying() +{ + return (!property("pause").toBool() && !property("path").isNull()); +} + +bool KAbstractPlayer::isBuffering() +{ + return property("paused-for-cache").toBool(); +} + +bool KAbstractPlayer::isSeekable() +{ + return property("seekable").toBool() || property("partially-seekable").toBool(); +} + +bool KAbstractPlayer::isFullscreen() +{ + return property("fullscreen").toBool(); +} + +bool KAbstractPlayer::isProtocolSupported(QString protocol) +{ + return protocol.startsWith("file") || protocol.startsWith("ftp") + || protocol.startsWith("sftp") || protocol.startsWith("http") + || protocol.startsWith("https") || protocol.startsWith("mms") + || protocol.startsWith("rtmp") || protocol.startsWith("rtsp") + || protocol.startsWith("smb"); +} + +bool KAbstractPlayer::isPathSupported(QString path) +{ + KMimeType::Ptr mime = KMimeType::findByPath(path); + if ((mime && isMimeSupported(mime->name())) || isProtocolSupported(path)) { + return true; + } + return false; +} + +void KAbstractPlayer::setVolume(float volume) +{ + setProperty("volume", volume); +} + +void KAbstractPlayer::setVolume(int volume) +{ + setProperty("volume", volume); +} + + +void KAbstractPlayer::setMute(bool mute) +{ + setProperty("mute", mute); +} + +void KAbstractPlayer::setFullscreen(bool fullscreen) +{ + setProperty("fullscreen", fullscreen); +} + +/* + Since exposing mpv_handle is not desirable and sigals/slots cannot be virtual here are some + pre-processor definitions used to share the code as much as possible making modifications + easier +*/ +#define COMMON_CONSTRUCTOR \ + setlocale(LC_NUMERIC, "C"); \ + m_handle = mpv_create(); \ + if (m_handle) { \ + int rc = mpv_initialize(m_handle); \ + if (rc < 0) { \ + kWarning() << mpv_error_string(rc); \ + return; \ + } \ + mpv_observe_property(m_handle, 0, "time-pos", MPV_FORMAT_DOUBLE); \ + mpv_observe_property(m_handle, 0, "loadfile", MPV_FORMAT_NONE); \ + mpv_observe_property(m_handle, 0, "paused-for-cache", MPV_FORMAT_FLAG); \ + mpv_observe_property(m_handle, 0, "seekable", MPV_FORMAT_FLAG); \ + mpv_observe_property(m_handle, 0, "partially-seekable", MPV_FORMAT_FLAG); \ + mpv_request_log_messages(m_handle, "debug"); \ + } + +#define COMMON_DESTRUCTOR \ + if (m_handle) { \ + mpv_terminate_destroy(m_handle); \ + } + +#define COMMMON_COMMAND_SENDER \ + if (m_handle) { \ + mpv::qt::command_variant(m_handle, params); \ + } + +#define COMMON_PROPERTY_SETTER \ + if (m_handle) { \ + mpv::qt::set_property_variant(m_handle, name, value); \ + } + +#define COMMON_PROPERTY_GETTER \ + if (m_handle) { \ + return mpv::qt::get_property_variant(m_handle, name); \ + } \ + return QVariant(); + +#define COMMON_OPTION_SETTER \ + if (m_handle) { \ + mpv::qt::set_option_variant(m_handle, name, value); \ + } + +#define COMMMON_EVENT_HANDLER \ + while (m_handle) { \ + mpv_event *event = mpv_wait_event(m_handle, 0); \ + if (event->event_id == MPV_EVENT_NONE) { \ + break; \ + } \ + switch (event->event_id) { \ + case MPV_EVENT_FILE_LOADED: { \ + emit loaded(); \ + break; \ + } \ + case MPV_EVENT_PAUSE: { \ + emit paused(true); \ + break; \ + } \ + case MPV_EVENT_UNPAUSE: { \ + emit paused(false); \ + break; \ + } \ + case MPV_EVENT_END_FILE: { \ + mpv_event_end_file *prop = (mpv_event_end_file *)event->data; \ + if (prop->reason == MPV_END_FILE_REASON_ERROR) { \ + emit finished(); \ + emit error(QString(mpv_error_string(prop->error))); \ + } else if (prop->reason == MPV_END_FILE_REASON_EOF \ + || prop->reason == MPV_END_FILE_REASON_STOP \ + || prop->reason == MPV_END_FILE_REASON_QUIT) { \ + emit finished(); \ + } \ + break; \ + } \ + case MPV_EVENT_PROPERTY_CHANGE: { \ + mpv_event_property *prop = (mpv_event_property *)event->data; \ + if (strcmp(prop->name, "time-pos") == 0) { \ + double value = 0; \ + if (prop->format == MPV_FORMAT_DOUBLE) { \ + value = *(double *)prop->data; \ + } \ + emit position(value); \ + } else if (strcmp(prop->name, "seekable") == 0) { \ + bool value = false; \ + if (prop->format == MPV_FORMAT_FLAG) { \ + value = *(bool *)prop->data; \ + } \ + emit seekable(value); \ + } else if (strcmp(prop->name, "paused-for-cache") == 0) { \ + bool value = false; \ + if (prop->format == MPV_FORMAT_FLAG) { \ + value = *(bool *)prop->data; \ + } \ + emit buffering(value); \ + } \ + break; \ + } \ + case MPV_EVENT_LOG_MESSAGE: { \ + mpv_event_log_message *msg = (mpv_event_log_message *)event->data; \ + kDebug() << msg->text; \ + break; \ + } \ + case MPV_EVENT_QUEUE_OVERFLOW: { \ + kWarning() << i18n("event queue overflow"); \ + break; \ + } \ + default: { \ + /* Ignore uninteresting or unknown events. */ \ + } \ + } \ + } + +static void wakeup_audio(void *ctx) +{ + QMetaObject::invokeMethod(static_cast(ctx), "_processHandleEvents", Qt::QueuedConnection); +} + +KAudioPlayer::KAudioPlayer(QObject *parent) + : QObject(parent) +{ + COMMON_CONSTRUCTOR + + m_settings = new QSettings("KMediaPlayer", QCoreApplication::applicationName()); + if (m_handle) { + mpv_set_wakeup_callback(m_handle, wakeup_audio, this); + // TODO: newer releases use vid, video is compat! + // NOTE: the change is pre-2014 + setProperty("video", "no"); + + setVolume(m_settings->value("state/volume", 90).toInt()); + setMute(m_settings->value("state/mute", false).toBool()); + setFullscreen(m_settings->value("state/fullscreen", false).toBool()); + } +} + +KAudioPlayer::~KAudioPlayer() +{ + if (m_handle && m_settings && m_settings->isWritable()) { + m_settings->beginGroup("state"); + m_settings->setValue("volume", volume()); + m_settings->setValue("mute", mute()); + m_settings->setValue("fullScreen", isFullscreen()); + m_settings->endGroup(); + m_settings->sync(); + } else { + kWarning() << i18n("Could not save state"); + } + + COMMON_DESTRUCTOR +} + +void KAudioPlayer::command(const QVariant& params) +{ + COMMMON_COMMAND_SENDER +} + +void KAudioPlayer::setProperty(const QString& name, const QVariant& value) +{ + COMMON_PROPERTY_SETTER +} + +QVariant KAudioPlayer::property(const QString& name) const +{ + COMMON_PROPERTY_GETTER +} + +void KAudioPlayer::setOption(const QString& name, const QVariant& value) +{ + COMMON_OPTION_SETTER +} + +void KAudioPlayer::_processHandleEvents() +{ + COMMMON_EVENT_HANDLER +} + +bool KAudioPlayer::isMimeSupported(QString mime) +{ + return mime.startsWith("audio/") || mime == QLatin1String("application/octet-stream"); +} + +///// +static void wakeup_media(void *ctx) +{ + QMetaObject::invokeMethod(static_cast(ctx), "_processHandleEvents", Qt::QueuedConnection); +} + +KMediaPlayer::KMediaPlayer(QWidget *parent) + : QWidget(parent) +{ + COMMON_CONSTRUCTOR + + m_settings = new QSettings("KMediaPlayer", QCoreApplication::applicationName()); + if (m_handle) { + mpv_set_wakeup_callback(m_handle, wakeup_media, this); + QVariant wid; + if (parent) { + // QVariant cannot be constructed from WId type + wid = static_cast(parent->winId()); + } else { + wid = static_cast(winId()); + } + setOption("wid", wid); + + setVolume(m_settings->value("state/volume", 90).toInt()); + setMute(m_settings->value("state/mute", false).toBool()); + setFullscreen(m_settings->value("state/fullscreen", false).toBool()); + QStringList paths = m_settings->value("state/paths", QStringList()).toStringList(); + foreach (const QString path, paths) { + addPath(path); + } + } +} + +KMediaPlayer::~KMediaPlayer() +{ + if (m_handle && m_settings && m_settings->isWritable()) { + m_settings->beginGroup("state"); + m_settings->setValue("volume", volume()); + m_settings->setValue("mute", mute()); + m_settings->setValue("fullScreen", isFullscreen()); + m_settings->setValue("paths", m_paths); + m_settings->endGroup(); + m_settings->sync(); + } else { + kWarning() << i18n("Could not save state"); + } + + COMMON_DESTRUCTOR +} + +void KMediaPlayer::command(const QVariant& params) +{ + COMMMON_COMMAND_SENDER +} + +void KMediaPlayer::setProperty(const QString& name, const QVariant& value) +{ + COMMON_PROPERTY_SETTER +} + +QVariant KMediaPlayer::property(const QString& name) const +{ + COMMON_PROPERTY_GETTER +} + +void KMediaPlayer::setOption(const QString& name, const QVariant& value) +{ + COMMON_OPTION_SETTER +} + +void KMediaPlayer::_processHandleEvents() +{ + COMMMON_EVENT_HANDLER +} + +bool KMediaPlayer::isMimeSupported(QString mime) +{ + return mime.startsWith("audio/") || mime.startsWith("video/") + || mime == QLatin1String("application/octet-stream"); +} + +void KMediaPlayer::load(QString path) +{ + command(QStringList() << "loadfile" << path); + addPath(path); +} + +void KMediaPlayer::addPath(QString path) +{ + if (!m_paths.contains(path)) { + m_paths.append(path); + } +} + +void KMediaPlayer::removePath(QString path) +{ + m_paths.removeOne(path); +} + +void KMediaPlayer::setPaths(QStringList paths) +{ + foreach (const QString path, paths) { + addPath(path); + } +} + +void KMediaPlayer::clearPaths() +{ + m_paths.clear(); +} +QStringList KMediaPlayer::paths() +{ + return m_paths; +} + +void KMediaPlayer::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } +} + +void KMediaPlayer::dropEvent(QDropEvent *event) +{ + QList urls = event->mimeData()->urls(); + foreach (const QUrl url, urls) { + if (!isProtocolSupported(url.scheme())) { + continue; + } + addPath(url.toString()); + } + event->acceptProposedAction(); +} + +#include "moc_kmediaplayer.cpp" diff --git a/kutils/kmediaplayer/kmediaplayer.h b/kutils/kmediaplayer/kmediaplayer.h new file mode 100644 index 00000000..439a06a8 --- /dev/null +++ b/kutils/kmediaplayer/kmediaplayer.h @@ -0,0 +1,336 @@ +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KMEDIAPLAYER_H +#define KMEDIAPLAYER_H + +#include +#include +#include +#include +#include + +#ifdef MAKE_KMEDIAPLAYER_LIB +typedef struct mpv_handle mpv_handle; +#endif + +/*! + Base class for KAudioPlayer and KMediaPlayer + @since 4.19 +*/ +class KMEDIAPLAYER_EXPORT KAbstractPlayer +{ +public: + KAbstractPlayer() { }; + virtual ~KAbstractPlayer() { }; + + //@{ + /** + Low-level methods that you should most likely not use, if you do and the API has to change + (e.g. from MPV to a fork of MPV, who knows) then you will be on your own! It is available + in case the convenience methods bellow those are not enough for your use case, but it is + better to let us know your requirements instead of using them. They may serve you as + temporary solution, for testing purposes, etc. but beware there be dragons! + **/ + //! @brief A low-level player command sender + virtual void command(const QVariant& params) = 0; + //! @brief A low-level player property setter + virtual void setProperty(const QString& name, const QVariant& value) = 0; + //! @brief A low-level player property getter + virtual QVariant property(const QString& name) const = 0; + //! @brief A low-level player option setter + virtual void setOption(const QString& name, const QVariant& value) = 0; + //@} + + /*! + @brief Start playing from a path + @param path a path to load, it can start with "file://", "dvd://", "http://" and other + valid MPV protocols + @warning Some protocols may not be supported if MPV itself was not build with support for + such! That is choice of the vendors and you should be well aware of what yours is doing + @link https://github.com/mpv-player/mpv/blob/master/DOCS/man/mpv.rst#protocols + */ + virtual void load(QString path); + /*! + @brief Send a play command to the player, it may do nothing if a path was not loaded first + */ + void play(); + /*! + @brief Send a pause command to the player, it may do nothing if a path was not loaded first + */ + void pause(); + /*! + @brief Send a seek command to the player + @param position Position in seconds to seek to + */ + void seek(float position); + /*! + @brief Some GUI controls cannot handle float thus the overload + @overload + */ + void seek(int position); + /*! + @brief Send a stop command to the player + */ + void stop(); + /*! + @brief Gets you the current play time, the time should be threated as seconds + @return current play time, it may return 0 if not playing + */ + float currentTime(); + /*! + @brief Gets you the remaining play time, the time should be threated as seconds + @return remaining play time, it may return 0 if not playing + */ + float remainingTime(); + /*! + @brief Gets you the total play time, the time should be threated as seconds + @return total play time, it may return 0 if not playing + */ + float totalTime(); + /*! + @return currently set volume level, usually from 0-100 + @see setVolume + */ + float volume(); + /*! + @return Whether the player is muted + */ + bool mute(); + /*! + @return A list of valid protocols + @see isProtocolSupported + */ + QStringList protocols(); + /*! + @return Whether the current state is playing (not paused), does not mean it's not buffering + */ + bool isPlaying(); + /*! + @return Whether the current state is playing (not paused) and buffering at the same time + */ + bool isBuffering(); + /*! + @return Whether seek can be performed, maybe partitially + */ + bool isSeekable(); + /*! + @return Whether the current video is taking all screen space + */ + bool isFullscreen(); + /*! + @param mime MIME type in the format \/\, e.g. "audio/aac" (without + quotes) + @return Whether the MIME type is supported + */ + virtual bool isMimeSupported(QString mime) = 0; + /*! + @note You can obtain the scheme, which is the same as the meaning of protocol here, from a + KUrl/QUrl via url.scheme(). If you pass "http://" instead of just "http" the protocol will + be considered valid too. + @param protocol protocol type in the format \, e.g. "file" (without quotes) + @return Whether the protocol is supported + @see KUrl + @todo The check is incomplete and there is no protocols property (yet?). it implements + checks only for those listed in the MPV shipped .desktop file and should be improved + */ + static bool isProtocolSupported(QString protocol); + /*! + @note This will check MIME and protocol type, possibly some other things too. The MIME will + be obtained via KMimeType which may be slow + @param path file, directory or URL string, e.g. "file://home/joe/vid.mp4" (without quotes) + @return Whether the path is supported + @see isMimeSupported, isProtocolSupported + */ + bool isPathSupported(QString path); + /*! + @param volume desired volume level + @warning It does not do boundry check so you should be aware of the maximum volume value if + you are going to set it to something above 100. While MPV itself allows for a value greater + than 100 in recent versions it is discoraged for you to set it above 100 + */ + void setVolume(float volume); + /*! + @brief Some GUI controls cannot handle float thus the overload + @overload + */ + void setVolume(int volume); + /*! + @param mute mute state + */ + void setMute(bool mute); + /*! + @param fullscreen wheather it should take all screen space + @warning This will most likely fail and the property will be set but MPV will do nothing + because it is embeded, you will have to call QWidget::showFullscreen() on the parent wiget! + */ + void setFullscreen(bool fullscreen); +}; + +/*! + The KAudioPlayer class provides an object that can be used to playback from various media + sources including Hard-Drives (local and remote), Internet streams, CD, DVD, Blue-Ray, SMB, + file-descriptor, raw data, you name it. It supports per-application state too, this + includes volume, mute and fullscreen state currently. + + For an extended version of this class check out KMediaPlayer and KMediaWidget. + + @warning The API is not stable yet and it may break in the future! + @since 4.19 + @see KMediaPlayer, KMediaWidget +*/ +class KMEDIAPLAYER_EXPORT KAudioPlayer: public QObject, public KAbstractPlayer +{ + Q_OBJECT +public: + KAudioPlayer(QObject *parent = 0); + ~KAudioPlayer(); + + //! @brief A low-level player command sender + void command(const QVariant& params); + //! @brief A low-level player property setter + void setProperty(const QString& name, const QVariant& value); + //! @brief A low-level player property getter + QVariant property(const QString& name) const; + //! @brief A low-level player option setter + void setOption(const QString& name, const QVariant& value); + + bool isMimeSupported(QString mime); + +signals: + //! @brief Signals that a path was loaded + void loaded(); + //! @brief Signals that the playing state was paused/unpaused when buffering data + void buffering(bool buffering); + //! @brief Signals that the playing state was paused/unpaused + void paused(bool paused); + //! @brief Signals that the playing state can advance at position, maybe partitially + void seekable(bool seekable); + //! @brief Signals that the playing state was advanced at position in seconds + void position(double seconds); + /*! + @brief Signals that the playing state was finished + @warning It is not guaranteed that the playing was successfull, for an example if a stream + was interrupted and the player cannot continue it may emit the signal + */ + void finished(); + /*! + @brief Signals that playback was finished with error + @note You still have to connect to the finished signal + */ + void error(QString error); + +private slots: + void _processHandleEvents(); + +private: +#ifdef MAKE_KMEDIAPLAYER_LIB + mpv_handle *m_handle; +#endif // MAKE_KMEDIAPLAYER_LIB + QSettings *m_settings; +}; + + +/*! + The KMediaPlayer class provides an embedable widget that can be used to playback from various + media sources including Hard-Drives (local and remote), Internet streams, CD, DVD, Blue-Ray, + SMB, file-descriptor, raw data, you name it. It supports per-application state too, this + includes volume, mute, fullscreen and playlist state currently. + + For an extended version of this class check out KMediaWidget. + + @note Constructing it with parent widget will layer in top of it. + @warning The API is not stable yet and it may break in the future! + @since 4.19 + @see KMediaWidget +*/ +class KMEDIAPLAYER_EXPORT KMediaPlayer: public QWidget, public KAbstractPlayer +{ + Q_OBJECT +public: + KMediaPlayer(QWidget *parent = 0); + ~KMediaPlayer(); + + //! @brief A low-level player command sender + void command(const QVariant& params); + //! @brief A low-level player property setter + void setProperty(const QString& name, const QVariant& value); + //! @brief A low-level player property getter + QVariant property(const QString& name) const; + //! @brief A low-level player option setter + void setOption(const QString& name, const QVariant& value); + + bool isMimeSupported(QString mime); + + //! @brief Reimplementation to ensure that playlist is updated + void load(QString path); + //@{ + /**! + Paths managing methods. Paths playlist is not build on top of internal MPV functionality + because it will require great effort to manage the playlist natively. + @todo add move functionality, the player must be aware of anything MPV may have loaded + and finally notification signals to make KMediaWidget aware of any changes to the lists + **/ + void addPath(QString path); + void removePath(QString path); + void setPaths(QStringList paths); + void clearPaths(); + QStringList paths(); + //@} + +protected: + //! @brief Reimplementation to support Drag-n-Drop + virtual void dragEnterEvent(QDragEnterEvent *event); + //! @brief Reimplementation to support Drag-n-Drop + virtual void dropEvent(QDropEvent *event); + +signals: + //! @brief Signals that a path was loaded + void loaded(); + //! @brief Signals that the playing state was paused/unpaused when buffering data + void buffering(bool buffering); + //! @brief Signals that the playing state was paused/unpaused + void paused(bool paused); + //! @brief Signals that the playing state can advance at position, maybe partitially + void seekable(bool seekable); + //! @brief Signals that the playing state was advanced at position in seconds + void position(double seconds); + /*! + @brief Signals that the playing state was finished + @warning It is not guaranteed that the playing was successfull, for an example if a stream + was interrupted and the player cannot continue it may emit the signal + */ + void finished(); + /*! + @brief Signals that playback was finished with error + @note You still have to connect to the finished signal + */ + void error(QString error); + +private slots: + void _processHandleEvents(); + +private: +#ifdef MAKE_KMEDIAPLAYER_LIB + mpv_handle *m_handle; +#endif // MAKE_KMEDIAPLAYER_LIB + QSettings *m_settings; + QStringList m_paths; +}; + +#endif // KMEDIAPLAYER_H diff --git a/interfaces/kmediaplayer/kmediaplayer_export.h b/kutils/kmediaplayer/kmediaplayer_export.h similarity index 78% rename from interfaces/kmediaplayer/kmediaplayer_export.h rename to kutils/kmediaplayer/kmediaplayer_export.h index 2ddf82ab..a0bdfef0 100644 --- a/interfaces/kmediaplayer/kmediaplayer_export.h +++ b/kutils/kmediaplayer/kmediaplayer_export.h @@ -1,10 +1,9 @@ -/* This file is part of the KDE project - Copyright (C) 2007 David Faure +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + License version 2, as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,7 +23,7 @@ #include #ifndef KMEDIAPLAYER_EXPORT -# if defined(MAKE_KMEDIAPLAYER_LIB) +# if defined(MAKE_KMEDIAPLAYER_LIB) /* We are building this library */ # define KMEDIAPLAYER_EXPORT KDE_EXPORT # else @@ -33,4 +32,4 @@ # endif #endif -#endif +#endif // KMEDIAPLAYER_EXPORT_H diff --git a/kutils/kmediaplayer/kmediawidget.cpp b/kutils/kmediaplayer/kmediawidget.cpp new file mode 100644 index 00000000..857d0109 --- /dev/null +++ b/kutils/kmediaplayer/kmediawidget.cpp @@ -0,0 +1,468 @@ +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include +#ifndef QT_KATIE +#include +#endif + +#include "kmediaplayer.h" +#include "kmediawidget.h" +#include "ui_kmediawidget.h" +#include "ui_kplaylistmanager.h" + +KMediaWidget::KMediaWidget(QWidget *parent, KMediaOptions options) + : QWidget(parent) +{ + d = new Ui_KMediaWidgetPrivate(); + d->setupUi(this); + m_player = new KMediaPlayer(d->w_player); + m_options = options; + m_parent = parent; + + d->w_play->setEnabled(false); + d->w_position->setEnabled(false); + d->w_volume->setValue(m_player->volume()); + + connect(d->w_play, SIGNAL(clicked()), this, SLOT(setPlay())); + connect(d->w_position, SIGNAL(sliderMoved(int)), this, SLOT(setPosition(int))); + connect(d->w_volume, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int))); + + connect(m_player, SIGNAL(paused(bool)), this, SLOT(_updatePlay(bool))); + connect(m_player, SIGNAL(loaded()), this, SLOT(_updateMove())); + connect(m_player, SIGNAL(finished()), this, SLOT(_updateFinished())); + connect(m_player, SIGNAL(error(QString)), this, SLOT(_updateError(QString))); + connect(m_player, SIGNAL(seekable(bool)), this, SLOT(_updateSeekable(bool))); + connect(m_player, SIGNAL(position(double)), this, SLOT(_updatePosition(double))); + + if (options & DragDrop) { + setAcceptDrops(true); + m_player->setAcceptDrops(true); + } + + bool extcontrols = (options & ExtendedControls); + if (extcontrols) { + _updateStatus(i18n("Awaiting input...")); + + _updateMove(); + connect(d->w_previous, SIGNAL(clicked()), this, SLOT(_movePrevious())); + connect(d->w_next, SIGNAL(clicked()), this, SLOT(_moveNext())); + + m_menu = new QMenu(d->w_menu); + m_menu->addAction(KIcon("view-list-text"), i18n("&Playlist"), this, SLOT(_menuManagePaths())); + m_menu->addSeparator(); + m_menu->addAction(KIcon("document-open-remote"), i18n("O&pen URL"), this, SLOT(_menuOpenURL())); + m_menu->addAction(KIcon("document-open"), i18n("&Open"), this, SLOT(_menuOpen())); + m_menu->addSeparator(); + m_menu->addAction(KIcon("application-exit"), i18n("&Quit"), this, SLOT(_menuQuit())); + connect(d->w_menu, SIGNAL(clicked()), this, SLOT(_showMenu())); + + m_pathmanager = new QDialog(this); + d2 = new Ui_KPlaylistManagerPrivate(); + d2->setupUi(m_pathmanager); + connect(d2->w_open, SIGNAL(clicked()), this, SLOT(_pathsOpen())); + connect(d2->w_openurl, SIGNAL(clicked()), this, SLOT(_pathsOpenURL())); + connect(d2->w_ok, SIGNAL(clicked()), this, SLOT(_pathsSave())); + connect(d2->w_cancel, SIGNAL(clicked()), this, SLOT(_pathsReject())); + } + d->w_previous->setVisible(extcontrols); + d->w_next->setVisible(extcontrols); + d->w_menu->setVisible(extcontrols); + d->w_status->setVisible(extcontrols); + + if (options & HiddenControls) { + setMouseTracking(true); + } +} + +KMediaWidget::~KMediaWidget() +{ + delete m_player; + delete d; +} + +void KMediaWidget::open(QString path) +{ + m_path = path; + _updateStatus(i18n("Now playing: %1", path)); + + d->w_play->setEnabled(true); + d->w_position->setEnabled(true); + + m_player->load(path); + + d->w_position->setEnabled(m_player->isSeekable()); + + m_failed = false; + + if (m_options & HiddenControls) { + startTimer(200); + m_timer.start(); + } +} + +KMediaPlayer* KMediaWidget::player() +{ + return m_player; +} + +void KMediaWidget::setPlay(int value) +{ + // TODO: can we reliably store the position and restore it as well? + if (m_failed && !m_path.isEmpty()) { + open(m_path); + return; + } + + bool pause; + if (value == -1) { + pause = m_player->isPlaying(); + } else { + pause = bool(value); + } + if (pause) { + m_player->pause(); + } else { + m_player->play(); + } +} + +void KMediaWidget::setPosition(int value) +{ + m_player->seek(value); +} + +void KMediaWidget::setVolume(int value) +{ + m_player->setVolume(value); +} + +QSize KMediaWidget::sizeHint() const +{ + return d->w_player->sizeHint(); +} + +void KMediaWidget::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (m_options & FullscreenVideo) { + _fullscreen(); + event->ignore(); + } +} + +void KMediaWidget::mouseMoveEvent(QMouseEvent *event) +{ + if (m_options & HiddenControls) { + _updateControls(true); + m_timer.restart(); + event->ignore(); + } +} + +void KMediaWidget::timerEvent(QTimerEvent *event) +{ + if (m_timer.elapsed() > 3000) { + _updateControls(false); + } + Q_UNUSED(event); +} + +void KMediaWidget::_showMenu() +{ + m_menu->exec(QCursor::pos()); +} + +void KMediaWidget::_movePrevious() +{ + QStringList playlist = m_player->paths(); + int position = playlist.indexOf(m_path); + if (position > 0) { + open(playlist.at(position-1)); + } +} + +void KMediaWidget::_moveNext() +{ + QStringList playlist = m_player->paths(); + int position = playlist.indexOf(m_path); + if (position+1 < playlist.count()) { + open(playlist.at(position+1)); + } +} + +void KMediaWidget::_fullscreen() +{ + /* + Making a QWidget go fullscreen requires quite some magic for X11 + because showFullScreen() requires the parent of the widget to be + a window (QMainWindow) thus some black magic bellow. asking the + parent widget to go fullscreen is required to preserve the media + controls visible and interactive. Note that setting the MPV + property is just for consistency and possible clients quering it + and nothing more as it does nothing when MPV is embed (as of the + time of writing this) + */ + if (!m_parent && (parentWidget() == window()) && !m_parenthack) { + kDebug() << i18n("using parent widget from parentWidget()"); + m_parent = parentWidget(); + } else if (!m_parent && parentWidget()) { + kWarning() << i18n("creating a parent, detaching widget, starting voodoo dance.."); + m_parent = parentWidget(); + m_parentsizehack = m_parent->size(); + m_parenthack = new QMainWindow(parentWidget()); + } + if (m_player->isFullscreen()) { + if (m_parenthack && m_parent) { + kDebug() << i18n("restoring parent from hack widget"); + setParent(m_parent); + resize(m_parentsizehack); + show(); + delete m_parenthack; + m_parenthack = NULL; + } else if (m_parent) { + kDebug() << i18n("restoring from parent widget"); + m_parent->showNormal(); + } else { + kWarning() << i18n("cannot restore to non-fullscreen state"); + } + m_player->setFullscreen(false); + } else { + if (m_parenthack && m_parent) { + kDebug() << i18n("using parent hack widget"); + m_parenthack->setCentralWidget(this); + m_parenthack->showFullScreen(); + } else if (m_parent) { + kDebug() << i18n("using parent widget"); + m_parent->showFullScreen(); + } else { + kWarning() << i18n("cannot set fullscreen state"); + } + m_player->setFullscreen(true); + } +} + +void KMediaWidget::_updateControls(bool visible) +{ + if (m_visible != visible && !m_path.isEmpty()) { + m_visible = visible; + d->w_frame->setVisible(visible); + } +} + +void KMediaWidget::_updatePlay(bool paused) +{ + if (paused) { + d->w_play->setIcon(KIcon("media-playback-start")); + d->w_play->setText(i18n("Play")); + } else { + d->w_play->setIcon(KIcon("media-playback-pause")); + d->w_play->setText(i18n("Pause")); + } +} + +void KMediaWidget::_updateSeekable(bool seekable) +{ + d->w_position->setEnabled(seekable); + d->w_position->setMaximum(m_player->totalTime()); +} + +void KMediaWidget::_updatePosition(double seconds) +{ + d->w_position->setValue(seconds); +} + +void KMediaWidget::_updateMove() +{ + QStringList playlist = m_player->paths(); + d->w_previous->setEnabled(false); + d->w_next->setEnabled(false); + int position = playlist.indexOf(m_path); + if (position > 0) { + d->w_previous->setEnabled(true); + } + if (position+1 < playlist.count()) { + d->w_next->setEnabled(true); + } + + _updatePlay(!m_player->isPlaying()); + if (playlist.count() > 0) { + d->w_play->setEnabled(true); + m_path = playlist.first(); + } +} + +void KMediaWidget::_updateStatus(QString error) +{ + if (m_options & ExtendedControls) { + d->w_status->setText(error); + } +} + +void KMediaWidget::_updateFinished() +{ + _updateStatus(i18n("Was playing: %1", m_path)); + // BUG: it will move to start/end, what if there was a reason arg for finished()? + // TODO: _moveNext() +} + +void KMediaWidget::_updateError(QString error) +{ + if (m_options & HiddenControls) { + // show the controls until the next open + m_timer.invalidate(); + _updateControls(true); + } + // since there are not many ways to indicate an error when + // there are no extended controls use the play button to do so + if (m_options & ExtendedControls) { + d->w_status->setText(error); + } else { + d->w_play->setIcon(KIcon("dialog-error")); + d->w_play->setText(i18n("Error")); + } + + m_failed = true; + + d->w_position->setEnabled(false); +} + +void KMediaWidget::_menuManagePaths() +{ + d2->w_list->clear(); + QStringList playlist = m_player->paths(); + d2->w_list->insertStringList(playlist); + m_pathmanager->show(); +} + +void KMediaWidget::_pathsOpen() +{ + QStringList paths = QFileDialog::getOpenFileNames(this, i18n("Select paths")); + if (!paths.isEmpty()) { + QStringList invalid, duplicate; + foreach (const QString path, paths) { + if (!m_player->isPathSupported(path)) { + kDebug() << i18n("ignoring unsupported:\n%1", path); + invalid.append(path); + continue; + } else if (d2->w_list->items().contains(path)) { + duplicate.append(path); + continue; + } + d2->w_list->insertItem(path); + } + if (!duplicate.isEmpty()) { + QMessageBox::warning(this, i18n("Duplicate paths"), + i18n("Some paths are duplicate:\n%1", duplicate.join("\n"))); + } + if (!invalid.isEmpty()) { + QMessageBox::warning(this, i18n("Invalid paths"), + i18n("Some paths are invalid:\n%1", invalid.join("\n"))); + } + } +} + +void KMediaWidget::_pathsOpenURL() +{ + QString url = QInputDialog::getText(this, i18n("Input URL"), + i18n("Supported protocols are: %1", m_player->protocols().join(","))); + if (!url.isEmpty()) { + if (!m_player->isPathSupported(url)) { + kDebug() << i18n("ignoring unsupported:\n%1", url); + QMessageBox::warning(this, i18n("Invalid URL"), + i18n("Invalid URL:\n%1", url)); + } else if (d2->w_list->items().contains(url)) { + QMessageBox::warning(this, i18n("Duplicate URL"), + i18n("Duplicate URL:\n%1", url)); + } else { + d2->w_list->insertItem(url); + } + } +} + +void KMediaWidget::_pathsSave() +{ + m_player->clearPaths(); + QStringList playlist = d2->w_list->items(); + for (int i = 0; i < playlist.count(); ++i) { + m_player->addPath(playlist.at(i)); + } + _updateMove(); + if (!playlist.isEmpty()) { + d->w_play->setEnabled(true); + } + m_path = playlist.first(); + m_pathmanager->hide(); +} + +void KMediaWidget::_pathsReject() +{ + m_pathmanager->hide(); +} + +void KMediaWidget::_menuOpenURL() +{ + QString url = QInputDialog::getText(this, i18n("Input URL"), + i18n("Supported protocols are: %1", m_player->protocols().join(","))); + if (!url.isEmpty()) { + if (!m_player->isPathSupported(url)) { + kDebug() << i18n("ignoring unsupported:\n%1", url); + QMessageBox::warning(this, i18n("Invalid URL"), + i18n("Invalid URL:\n%1", url)); + } else { + open(url); + } + } +} + +void KMediaWidget::_menuOpen() +{ + QStringList paths = QFileDialog::getOpenFileNames(this, i18n("Select paths")); + if (!paths.isEmpty()) { + bool isfirst = true; + QStringList invalid; + foreach (const QString path, paths) { + if (!m_player->isPathSupported(path)) { + kDebug() << i18n("ignoring unsupported:\n%1", path); + invalid.append(path); + continue; + } + if (isfirst) { + open(path); + isfirst = false; + } + m_player->addPath(path); + } + if (!invalid.isEmpty()) { + QMessageBox::warning(this, i18n("Invalid paths"), + i18n("Some paths are invalid:\n%1", invalid.join("\n"))); + } + } +} + +void KMediaWidget::_menuQuit() +{ + qApp->quit(); +} + +#include "moc_kmediawidget.cpp" diff --git a/kutils/kmediaplayer/kmediawidget.h b/kutils/kmediaplayer/kmediawidget.h new file mode 100644 index 00000000..9993038e --- /dev/null +++ b/kutils/kmediaplayer/kmediawidget.h @@ -0,0 +1,175 @@ +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KMEDIAWIDGET_H +#define KMEDIAWIDGET_H + +#include +#include +#include +#include +#include +#include + +/*! + The KMediaPlayer class provides an embedable widget that can be used to playback from various + media sources including Hard-Drives (local and remote), Internet streams, CD, DVD, Blue-Ray, + SMB, file-descriptor, raw data, you name it. Unlike KMediaPlayer it provides interactive media + controls to play/pause, seek to position and set volume. It is ment to be a simple player but + supports drag-n-drop actions, fullscreen support, extended media controls and can automatically + hide the media controls optionally. + + For a simpler version of this class check out KMediaPlayer. + + @code + KMediaWidget *player = new KMediaWidget(this); + player->open("http://video.webmfiles.org/big-buck-bunny_trailer.webm"); + @endcode + + @note You should construct it with parent widget so that it can be layered on top of it. + Otherwise when a video is played the widget will be floating. Ensuring that the widget has + parent is a key to the fullscreen support as it will ask the parent to maximize itself when + that needs to happen to ensure that the media controls are visible. + @warning The API is not stable yet and it may break in the future! + @see KMediaPlayer + @todo keyboard shortcuts +*/ + +class Ui_KMediaWidgetPrivate; +class Ui_KPlaylistManagerPrivate; + +class KMEDIAPLAYER_EXPORT KMediaWidget: public QWidget +{ + Q_OBJECT +public: + enum KMediaOptions { + //! @brief No options at all + NoOptions = 0, + /*! + @long When URLs are dragged to the widget it will append them to the playlist + */ + DragDrop = 1, + /*! + @long Provide fullscreen option, it is option because it will ask the parent to do it + */ + FullscreenVideo = 2, + /*! + @long Currently previous/next buttons and a menu with some goodies + */ + ExtendedControls = 4, + /*! + @long After a certain ammount of time the controls will hide themselfs allowing more + screen space to be taken by the display widget + */ + HiddenControls = 5, + //! @brief All available options + AllOptions = DragDrop | FullscreenVideo | ExtendedControls | HiddenControls, + //! @brief Default options, currently none + DefaultOptions = NoOptions + }; + KMediaWidget(QWidget *parent, KMediaOptions options = DefaultOptions); + ~KMediaWidget(); + + /*! + @return The player instance + */ + KMediaPlayer* player(); + /*! + @brief Open a path + @long Aside from loading the path it will also setup the play/pause button state and enable + the position seeking slider if the path supports seeking. It is recommended to use this + method when a path must be loaded. + @param path a path to load + @see KMediaPlayer::load + */ + void open(QString path); + + //! @brief Reimplementation to provide more accurate size hint + virtual QSize sizeHint() const; +protected: + //! @brief Reimplementation to support fullscreen + virtual void mouseDoubleClickEvent(QMouseEvent *event); + //! @brief Reimplementation to support hidden controls + virtual void mouseMoveEvent(QMouseEvent *event); + //! @brief Reimplementation to support hidden controls + virtual void timerEvent(QTimerEvent *event); + +public slots: + /*! + @brief Set the state to play (unpaused) or paused + @param value A tristate value for the play state, if "-1" the state will be automatically + decided for you. If "0" it will set the state to play (unpaused) and if "1" it will set it + to pause (paused). Whenever called it updates the play/pause button state. + */ + void setPlay(int value = -1); + /*! + @brief Set the position of the path currently loaded + @param value A value in seconds + @note The value is integer because the slider itself uses integer + @see KMediaPlayer::currentTime, KMediaPlayer::remainingTime, KMediaPlayer::totalTime + */ + void setPosition(int value); + /*! + @brief Set the volume of the path currently loaded + @param value A value between 0-100 usually + @note The value is integer because the dial itself uses integer + @see KMediaPlayer::setVolume + */ + void setVolume(int value); + +private slots: + void _showMenu(); + void _fullscreen(); + void _updateControls(bool visible); + void _updatePlay(bool paused); + void _updateSeekable(bool seekable); + void _updatePosition(double seconds); + void _updateMove(); + void _updateStatus(QString error); + void _updateFinished(); + void _updateError(QString error); + void _movePrevious(); + void _moveNext(); + + void _pathsOpen(); + void _pathsOpenURL(); + void _pathsSave(); + void _pathsReject(); + + void _menuManagePaths(); + void _menuOpenURL(); + void _menuOpen(); + void _menuQuit(); + +private: + KMediaPlayer *m_player; + KMediaOptions m_options; + QWidget *m_parent; + QMainWindow *m_parenthack; + QSize m_parentsizehack; + QElapsedTimer m_timer; + bool m_visible; + QString m_path; + bool m_failed; + QMenu *m_menu; + Ui_KMediaWidgetPrivate *d; + QDialog *m_pathmanager; + Ui_KPlaylistManagerPrivate *d2; +}; + +#endif // KMEDIAWIDGET_H diff --git a/kutils/kmediaplayer/kmediawidget.ui b/kutils/kmediaplayer/kmediawidget.ui new file mode 100644 index 00000000..da527ed3 --- /dev/null +++ b/kutils/kmediaplayer/kmediawidget.ui @@ -0,0 +1,132 @@ + + + KMediaWidgetPrivate + + + + 0 + 0 + 575 + 445 + + + + KMediaWidget + + + + + + + + + + + + 0 + 0 + + + + + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + + + + Play + + + + + + + + + + + + + 30 + 30 + + + + + + + + + + + + + + + + + + + + + + + Qt::RichText + + + true + + + true + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse + + + + + + + Previous + + + + + + + + + + + + Next + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + + + diff --git a/kutils/kmediaplayer/kmediawidgettest.cpp b/kutils/kmediaplayer/kmediawidgettest.cpp new file mode 100644 index 00000000..9c33b124 --- /dev/null +++ b/kutils/kmediaplayer/kmediawidgettest.cpp @@ -0,0 +1,39 @@ +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include + +#include "kmediawidget.h" + +int main(int argc, char **argv) +{ + QApplication *app = new QApplication(argc, argv); + QMainWindow *window = new QMainWindow(); + + KMediaWidget *widget = new KMediaWidget(window, KMediaWidget::AllOptions); + window->setCentralWidget(widget); + window->show(); + widget->open("http://video.webmfiles.org/big-buck-bunny_trailer.webm"); + + // qDebug() << widget->player()->property("property-list"); + // qDebug() << widget->player()->property("audio-device-list"); + return app->exec(); +} \ No newline at end of file diff --git a/kutils/kmediaplayer/kplaylistmanager.ui b/kutils/kmediaplayer/kplaylistmanager.ui new file mode 100644 index 00000000..1f4aa81d --- /dev/null +++ b/kutils/kmediaplayer/kplaylistmanager.ui @@ -0,0 +1,88 @@ + + + KPlaylistManagerPrivate + + + + 0 + 0 + 400 + 300 + + + + Playlist manager + + + + + + + + + + + Open + + + + + + + + + + + + Open URL + + + + + + + + + + + + OK + + + + + + + + + + + + Cancel + + + + + + + + + + + + true + + + + + + + + KEditListWidget + QWidget +
keditlistwidget.h
+
+
+ + +
diff --git a/plasma/CMakeLists.txt b/plasma/CMakeLists.txt index 16a84131..b375dc36 100644 --- a/plasma/CMakeLists.txt +++ b/plasma/CMakeLists.txt @@ -191,15 +191,6 @@ kde4_add_kcfg_files(plasma_LIB_SRCS data/kconfigxt/libplasma-theme-global.kcfgc ) -if(PHONON_FOUND) - message(STATUS "Adding support for Phonon to libplasma") - include_directories(${KDE4_PHONON_INCLUDES}) - set(plasma_LIB_SRCS - ${plasma_LIB_SRCS} - widgets/videowidget.cpp - ) -endif() - add_library(plasma ${LIBRARY_TYPE} ${plasma_LIB_SRCS}) target_link_libraries(plasma @@ -220,10 +211,6 @@ if(X11_FOUND) target_link_libraries(plasma ${X11_LIBRARIES}) endif(X11_FOUND) -if(PHONON_FOUND) - target_link_libraries(plasma ${KDE4_PHONON_LIBS}) -endif(PHONON_FOUND) - if(DL_LIBRARY) target_link_libraries(plasma ${DL_LIBRARY}) endif(DL_LIBRARY) @@ -333,15 +320,6 @@ install( COMPONENT Devel ) -if(PHONON_FOUND) - install( - FILES - widgets/videowidget.h - DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets - COMPONENT Devel - ) -endif() - install( FILES animations/animation.h diff --git a/plasma/widgets/videowidget.cpp b/plasma/widgets/videowidget.cpp deleted file mode 100644 index 42e4d0df..00000000 --- a/plasma/widgets/videowidget.cpp +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Copyright 2009 Marco Martin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library 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 "videowidget.h" - -#include "config-plasma.h" - -#include -#include -#include -#include - -#include -#include - -#ifndef PLASMA_NO_KIO -#include -#else -#include -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace Plasma -{ - -class VideoWidgetPrivate -{ -public: - VideoWidgetPrivate(VideoWidget *video) - : q(video), - ticking(false), - forceControlsVisible(false), - animation(0), - hideTimer(0), - shownControls(VideoWidget::NoControls), - controlsWidget(0), - previousButton(0), - playButton(0), - pauseButton(0), - stopButton(0), - playPauseButton(0), - nextButton(0), - progress(0), - volume(0), - openFileButton(0) - { - } - - ~VideoWidgetPrivate() - { - } - - void playPause(); - void ticked(qint64 progress); - void totalTimeChanged(qint64 time); - void setPosition(int newProgress); - void setVolume(int value); - void volumeChanged(qreal value); - void showOpenFileDialog(); - void openFile(const QString &path); - void stateChanged(Phonon::State newState, Phonon::State oldState); - void animateControlWidget(bool show); - void hideControlWidget(); - void slidingCompleted(); - bool spaceForControlsAvailable(); - - - VideoWidget *q; - - Phonon::VideoWidget *videoWidget; - Phonon::AudioOutput *audioOutput; - Phonon::MediaObject *media; - - bool ticking; - bool forceControlsVisible; - - //control widgets - Plasma::Animation *animation; - QTimer *hideTimer; - VideoWidget::Controls shownControls; - Plasma::Frame *controlsWidget; - IconWidget *previousButton; - IconWidget *playButton; - IconWidget *pauseButton; - IconWidget *stopButton; - IconWidget *playPauseButton; - IconWidget *nextButton; - Slider *progress; - Slider *volume; - IconWidget *openFileButton; -}; - -void VideoWidgetPrivate::playPause() -{ - if (media->state() == Phonon::PlayingState) { - media->pause(); - } else { - media->play(); - } -} - -void VideoWidgetPrivate::ticked(qint64 newProgress) -{ - ticking = true; - progress->setValue(newProgress); - ticking = false; -} - -void VideoWidgetPrivate::totalTimeChanged(qint64 time) -{ - ticking = true; - //FIXME: this will break for veeery long stuff, butPhonon::SeekSlider seems to have the same problem - progress->setRange(0, time); - ticking = false; -} - -void VideoWidgetPrivate::setPosition(int progress) -{ - if (!ticking) { - media->seek(progress); - } -} - -void VideoWidgetPrivate::setVolume(int value) -{ - audioOutput->setVolume(qreal(value)/100.0); -} - -void VideoWidgetPrivate::volumeChanged(qreal value) -{ - volume->setValue(value*100); -} - -void VideoWidgetPrivate::showOpenFileDialog() -{ -#ifndef PLASMA_NO_KIO - openFile(KFileDialog::getOpenFileName()); -#else - openFile(QFileDialog::getOpenFileName()); -#endif -} - -void VideoWidgetPrivate::openFile(const QString &path) -{ - media->setCurrentSource(Phonon::MediaSource(KUrl(path))); - media->play(); -} - -void VideoWidgetPrivate::stateChanged(Phonon::State newState, Phonon::State oldState) -{ - Q_UNUSED(oldState) - - if (playPauseButton) { - if (newState == Phonon::PlayingState) { - playPauseButton->setIcon("media-playback-pause"); - } else { - playPauseButton->setIcon("media-playback-start"); - } - } -} - -void VideoWidgetPrivate::animateControlWidget(bool show) -{ - if (!controlsWidget || controlsWidget->isVisible() == show) { - return; - } - - const int distance = controlsWidget->size().height(); - if (!controlsWidget->isVisible()) { - controlsWidget->setPos(0, -distance); - controlsWidget->show(); - } - - //clip only when animating - q->setFlags(q->flags()|QGraphicsItem::ItemClipsChildrenToShape); - - if (!animation) { - animation = Plasma::Animator::create(Plasma::Animator::SlideAnimation, q); - animation->setTargetWidget(controlsWidget); - animation->setProperty("movementDirection", Animation::MoveDown); - q->connect(animation, SIGNAL(finished()), q, SLOT(slidingCompleted())); - } - - animation->setProperty("distance", distance); - animation->setProperty("direction", show? QAbstractAnimation::Forward : QAbstractAnimation::Backward); - animation->start(); -} - -void VideoWidgetPrivate::hideControlWidget() -{ - animateControlWidget(false); -} - -void VideoWidgetPrivate::slidingCompleted() -{ - if (!controlsWidget) { - return; - } - - //usually don't clip - q->setFlags(q->flags()^QGraphicsItem::ItemClipsChildrenToShape); - - if (controlsWidget->pos().y() < 0) { - controlsWidget->hide(); - } else if (!forceControlsVisible) { - hideTimer->start(3000); - } -} - -bool VideoWidgetPrivate::spaceForControlsAvailable() -{ - if (controlsWidget) { - QSize hint = controlsWidget->effectiveSizeHint(Qt::MinimumSize).toSize(); - return (q->size().width() >= hint.width()) && - (q->size().height() >= hint.height()); - } else { - return true; - } -} - - - -VideoWidget::VideoWidget(QGraphicsWidget *parent) - : QGraphicsProxyWidget(parent), - d(new VideoWidgetPrivate(this)) -{ - d->videoWidget = new Phonon::VideoWidget; - d->audioOutput = new Phonon::AudioOutput(this); - d->media = new Phonon::MediaObject(this); - //it appears that the path has to be created BEFORE setting the proxy - Phonon::createPath(d->media, d->videoWidget); - Phonon::createPath(d->media, d->audioOutput); - - - setWidget(d->videoWidget); - d->videoWidget->setWindowIcon(QIcon()); - setAcceptHoverEvents(true); - - connect(d->media, SIGNAL(tick(qint64)), this, SIGNAL(tick(qint64))); - connect(d->media, SIGNAL(aboutToFinish()), this, SIGNAL(aboutToFinish())); -} - -VideoWidget::~VideoWidget() -{ - delete d; -} - -Phonon::MediaObject *VideoWidget::mediaObject() const -{ - return d->media; -} - -Phonon::AudioOutput *VideoWidget::audioOutput() const -{ - return d->audioOutput; -} - -void VideoWidget::setUrl(const QString &url) -{ - if (url == d->media->currentSource().url().toString()) { - return; - } - - d->media->setCurrentSource(Phonon::MediaSource(KUrl(url))); -} - -QString VideoWidget::url() const -{ - return d->media->currentSource().url().toString(); -} - -void VideoWidget::setUsedControls(const Controls controls) -{ - if (controls == d->shownControls) { - return; - } - - d->shownControls = controls; - - //kDebug()<<"Setting used controls"<controlsWidget == 0) { - d->controlsWidget = new Plasma::Frame(this); - d->controlsWidget->setFrameShadow(Plasma::Frame::Raised); - controlsLayout = new QGraphicsLinearLayout(Qt::Horizontal, d->controlsWidget); - d->hideTimer = new QTimer(this); - connect(d->hideTimer, SIGNAL(timeout()), this, SLOT(hideControlWidget())); - //controls == NoControls - } else if (d->controlsWidget != 0) { - d->controlsWidget->deleteLater(); - d->hideTimer->deleteLater(); - d->controlsWidget = 0; - - //disconnect all the stuff that wasn't automatically disconnected 'cause widget deaths - disconnect(d->media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State))); - disconnect(d->media, SIGNAL(tick(qint64)), this, SLOT(ticked(qint64))); - disconnect(d->media, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); - disconnect(d->audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged(qreal))); - return; - } - - Q_ASSERT(controlsLayout); - - //empty the layout - while (controlsLayout->count() > 0) { - controlsLayout->removeAt(0); - } - - if (controls&Previous) { - if (!d->previousButton) { - d->previousButton = new IconWidget(d->controlsWidget); - d->previousButton->setIcon("media-playback-start"); - connect(d->playButton, SIGNAL(clicked()), this, SLOT(PreviousRequested())); - } - controlsLayout->addItem(d->previousButton); - } else { - d->previousButton->deleteLater(); - d->previousButton = 0; - } - - if (controls&Play) { - if (!d->playButton) { - d->playButton = new IconWidget(d->controlsWidget); - d->playButton->setIcon("media-playback-start"); - connect(d->playButton, SIGNAL(clicked()), this, SLOT(play())); - } - controlsLayout->addItem(d->playButton); - } else { - d->playButton->deleteLater(); - d->playButton = 0; - } - - if (controls&Pause) { - if (!d->pauseButton) { - d->pauseButton = new IconWidget(d->controlsWidget); - d->pauseButton->setIcon("media-playback-pause"); - connect(d->pauseButton, SIGNAL(clicked()), this, SLOT(pause())); - } - controlsLayout->addItem(d->pauseButton); - } else { - d->pauseButton->deleteLater(); - d->pauseButton = 0; - } - - if (controls&Stop) { - if (!d->stopButton) { - d->stopButton = new IconWidget(d->controlsWidget); - d->stopButton->setIcon("media-playback-stop"); - connect(d->stopButton, SIGNAL(clicked()), this, SLOT(stop())); - } - controlsLayout->addItem(d->stopButton); - } else { - d->stopButton->deleteLater(); - d->stopButton = 0; - } - - if (controls&PlayPause) { - if (!d->playPauseButton) { - d->playPauseButton = new IconWidget(d->controlsWidget); - d->playPauseButton->setIcon("media-playback-start"); - connect(d->playPauseButton, SIGNAL(clicked()), this, SLOT(playPause())); - } - controlsLayout->addItem(d->playPauseButton); - } else { - d->playPauseButton->deleteLater(); - d->playPauseButton = 0; - } - - if (controls&Next) { - if (!d->nextButton) { - d->nextButton = new IconWidget(d->nextButton); - d->nextButton->setIcon("media-playback-start"); - connect(d->nextButton, SIGNAL(clicked()), this, SIGNAL(nextRequested())); - } - controlsLayout->addItem(d->nextButton); - } else { - d->nextButton->deleteLater(); - d->nextButton = 0; - } - - connect(d->media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State))); - - - - - if (controls&Progress) { - if (!d->progress) { - d->progress = new Slider(d->controlsWidget); - d->progress->setMinimum(0); - d->progress->setMaximum(100); - d->progress->setOrientation(Qt::Horizontal); - controlsLayout->setStretchFactor(d->progress, 4); - d->progress->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); - - connect(d->media, SIGNAL(tick(qint64)), this, SLOT(ticked(qint64))); - connect(d->media, SIGNAL(totalTimeChanged(qint64)), SLOT(totalTimeChanged(qint64))); - connect(d->progress, SIGNAL(valueChanged(int)), this, SLOT(setPosition(int))); - } - controlsLayout->addItem(d->progress); - } else { - d->progress->deleteLater(); - d->progress = 0; - } - - - if (controls&Volume) { - if (!d->volume) { - d->volume = new Slider(d->controlsWidget); - d->volume->setMinimum(0); - d->volume->setMaximum(100); - d->volume->setValue(100); - d->volume->setOrientation(Qt::Horizontal); - d->volume->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - - connect(d->volume, SIGNAL(valueChanged(int)), SLOT(setVolume(int))); - connect(d->audioOutput, SIGNAL(volumeChanged(qreal)), SLOT(volumeChanged(qreal))); - } - controlsLayout->addItem(d->volume); - } else { - d->volume->deleteLater(); - d->volume = 0; - } - - - if (controls&OpenFile) { - if (!d->openFileButton) { - d->openFileButton = new IconWidget(d->controlsWidget); - d->openFileButton->setIcon(KIcon("document-open")); - connect(d->openFileButton, SIGNAL(clicked()), this, SLOT(showOpenFileDialog())); - } - controlsLayout->addItem(d->openFileButton); - } else { - d->openFileButton->deleteLater(); - d->openFileButton = 0; - } - - controlsLayout->activate(); - d->controlsWidget->setPos(0,-d->controlsWidget->size().height()); - d->controlsWidget->resize(size().width(), d->controlsWidget->size().height()); - d->controlsWidget->hide(); -} - -VideoWidget::Controls VideoWidget::usedControls() const -{ - return d->shownControls; -} - -void VideoWidget::play() -{ - if (d->media->state() == Phonon::PlayingState) { - return; - } - - d->media->play(); -} - -void VideoWidget::pause() -{ - if (d->media->state() == Phonon::PausedState) { - return; - } - - d->media->pause(); -} - -void VideoWidget::stop() -{ - if (d->media->state() == Phonon::StoppedState) { - return; - } - - d->media->stop(); -} - -void VideoWidget::seek(qint64 time) -{ - if (d->media->currentTime() == time) { - return; - } - - d->media->seek(time); -} - -qint64 VideoWidget::currentTime() const -{ - return d->media->currentTime(); -} - -qint64 VideoWidget::totalTime() const -{ - return d->media->totalTime(); -} - -qint64 VideoWidget::remainingTime() const -{ - return d->media->remainingTime(); -} - -void VideoWidget::setControlsVisible(bool visible) -{ - if (d->controlsWidget) { - d->forceControlsVisible = visible; - d->animateControlWidget(visible); - } -} - -bool VideoWidget::controlsVisible() const -{ - return d->controlsWidget != 0 && d->controlsWidget->isVisible(); -} - -void VideoWidget::setTickInterval(qint64 interval) -{ - d->media->setTickInterval(interval); -} - -qint64 VideoWidget::tickInterval() const -{ - return d->media->tickInterval(); -} - -void VideoWidget::setStyleSheet(const QString &stylesheet) -{ - d->videoWidget->setStyleSheet(stylesheet); -} - -QString VideoWidget::styleSheet() -{ - return d->videoWidget->styleSheet(); -} - -Phonon::VideoWidget *VideoWidget::nativeWidget() const -{ - return d->videoWidget; -} - - -void VideoWidget::resizeEvent(QGraphicsSceneResizeEvent *event) -{ - QGraphicsProxyWidget::resizeEvent(event); - - if (d->controlsWidget) { - QSize newControlsSize(event->newSize().width(), d->controlsWidget->size().height()); - int newHeight = event->newSize().height(); - qreal leftMargin, topMargin, rightMargin, bottomMargin; - d->controlsWidget->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); - - if (newHeight/5 >= KIconLoader::SizeEnormous) { - newControlsSize.setHeight(KIconLoader::SizeEnormous+topMargin+bottomMargin); - } else if (newHeight/5 >= KIconLoader::SizeHuge) { - newControlsSize.setHeight(KIconLoader::SizeHuge+topMargin+bottomMargin); - } else if (newHeight/5 >= KIconLoader::SizeLarge) { - newControlsSize.setHeight(KIconLoader::SizeLarge+topMargin+bottomMargin); - } else if (newHeight/5 >= KIconLoader::SizeMedium) { - newControlsSize.setHeight(KIconLoader::SizeMedium+topMargin+bottomMargin); - } else { - newControlsSize.setHeight(KIconLoader::SizeSmallMedium+topMargin+bottomMargin); - } - d->controlsWidget->resize(newControlsSize); - - if (d->spaceForControlsAvailable()) { - d->animateControlWidget(false); - } - } -} - -void VideoWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - - if (d->controlsWidget && - !d->forceControlsVisible && - d->spaceForControlsAvailable()) { - d->animateControlWidget(true); - } -} - -void VideoWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - - if (d->controlsWidget && !d->forceControlsVisible) { - d->hideTimer->start(1000); - } -} - -void VideoWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - - if (d->forceControlsVisible || !d->controlsWidget) { - return; - } - - d->hideTimer->start(3000); - - if (!d->controlsWidget->isVisible() && - d->spaceForControlsAvailable()) { - d->animateControlWidget(true); - } -} - -} // namespace Plasma - -#include "moc_videowidget.cpp" - diff --git a/plasma/widgets/videowidget.h b/plasma/widgets/videowidget.h deleted file mode 100644 index 82cb63de..00000000 --- a/plasma/widgets/videowidget.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2009 Marco Martin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library 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 PLASMA_VIDEOWIDGET_H -#define PLASMA_VIDEOWIDGET_H - -#include - -#include - -namespace Phonon { - class VideoWidget; - class MediaObject; - class AudioOutput; -} - -class KUrl; - -namespace Plasma -{ - -class VideoWidgetPrivate; - -/** - * @class VideoWidget plasma/widgets/videowidget.h - * a Video playing widget via Phonon, it encloses the - * Phonon::MediaObject and Phonon::AudioOutput too - * - * @short Provides a video player widget - * @since KDE4.3 - */ -class PLASMA_EXPORT VideoWidget : public QGraphicsProxyWidget -{ - Q_OBJECT - - Q_PROPERTY(QString url READ url WRITE setUrl) - Q_PROPERTY(qint64 currentTime READ currentTime) - Q_PROPERTY(qint64 totalTime READ totalTime) - Q_PROPERTY(qint64 remainingTime READ remainingTime) - Q_PROPERTY(Controls usedControls READ usedControls WRITE setUsedControls) - Q_PROPERTY(bool controlsVisible READ controlsVisible WRITE setControlsVisible) - Q_PROPERTY(qint32 tickInterval READ tickInterval WRITE setTickInterval) - Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) - Q_ENUMS(Control) - -public: - enum Control { - NoControls = 0, - Play = 1, - Pause = 2, - Stop = 4, - PlayPause = 8, - Previous = 16, - Next = 32, - Progress = 64, - Volume = 128, - OpenFile = 128, - DefaultControls = PlayPause|Progress|Volume|OpenFile - }; - Q_DECLARE_FLAGS(Controls, Control) - - explicit VideoWidget(QGraphicsWidget *parent = 0); - ~VideoWidget(); - - /** - * Load a certain url that can be a local file or a remote one - * @param path resource to play - */ - void setUrl(const QString &url); - - /** - * @return the url (local or remote) we are playing - */ - QString url() const; - - /** - * @return the Phonon::MediaObject being used - * @see Phonon::MediaObject - */ - Q_INVOKABLE Phonon::MediaObject *mediaObject() const; - - /** - * @return the Phonon::AudioOutput being used - * @see Phonon::AudioOutput - */ - Q_INVOKABLE Phonon::AudioOutput *audioOutput() const; - - /** - * @return the current time of the current media file - */ - qint64 currentTime() const; - - /** - * @return the total playing time of the current media file - */ - qint64 totalTime() const; - - /** - * @return the time remaining to the current media file - */ - qint64 remainingTime() const; - - /** - * Set what control widgets to use - * - * @param controls bitwise OR combination of Controls flags - * @see Controls - */ - void setUsedControls(const Controls controls); - - /** - * @return the video controls that are used and shown - * @see Controls - */ - Controls usedControls() const; - - /** - * Show/hide the main controls widget, if any of them is used - * - * @param visible if we want to show or hide the main controls - * @see setUsedControls() - */ - void setControlsVisible(bool visible); - - /** - * @return true if the controls widget is being shown right now - */ - bool controlsVisible() const; - - /** - * @param interval milliseconds the tick signal will be emitted - * @since 4.7.1 - */ - void setTickInterval(qint64 interval); - - /** - * @return milliseconds the tick signal will be emitted - * @see tickInterval() - * @since 4.7.1 - */ - qint64 tickInterval() const; - - /** - * Sets the stylesheet used to control the visual display of this VideoWidget - * - * @param stylesheet a CSS string - */ - void setStyleSheet(const QString &stylesheet); - - /** - * @return the stylesheet currently used with this widget - */ - QString styleSheet(); - - /** - * @return the native widget wrapped by this VideoWidget - */ - Phonon::VideoWidget *nativeWidget() const; - -public Q_SLOTS: - - /** - * Play the current file - */ - void play(); - - /** - * Pause the current file - */ - void pause(); - - /** - * Stop the current file - */ - void stop(); - - /** - * Jump at a given millisecond in the current file - * @param time where we want to jump - */ - void seek(qint64 time); - -Q_SIGNALS: - /** - * Emitted regularly when the playing is progressing - * @param time where we are - */ - void tick(qint64 time); - - /** - * Emitted an instant before the playback is finished - */ - void aboutToFinish(); - - /** - * The user pressed the "next" button - * @since 4.3 - */ - void nextRequested(); - - /** - * The user pressed the "previous" button - * @since 4.3 - */ - void previousRequested(); - -protected: - void resizeEvent(QGraphicsSceneResizeEvent *event); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - -private: - VideoWidgetPrivate * const d; - - Q_PRIVATE_SLOT(d, void playPause()) - Q_PRIVATE_SLOT(d, void ticked(qint64 progress)) - Q_PRIVATE_SLOT(d, void totalTimeChanged(qint64 time)) - Q_PRIVATE_SLOT(d, void setPosition(int progress)) - Q_PRIVATE_SLOT(d, void setVolume(int value)) - Q_PRIVATE_SLOT(d, void volumeChanged(qreal value)) - Q_PRIVATE_SLOT(d, void showOpenFileDialog()) - Q_PRIVATE_SLOT(d, void stateChanged(Phonon::State newState, Phonon::State oldState)) - Q_PRIVATE_SLOT(d, void hideControlWidget()) - Q_PRIVATE_SLOT(d, void slidingCompleted()) -}; - -} // namespace Plasma - -#endif // multiple inclusion guard