File indexing completed on 2024-04-28 04:50:47

0001 /*
0002  * abstractmediawidget.h
0003  *
0004  * Copyright (C) 2010-2012 Christoph Pfister <christophpfister@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License along
0017  * with this program; if not, write to the Free Software Foundation, Inc.,
0018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0019  */
0020 
0021 #ifndef ABSTRACTMEDIAWIDGET_H
0022 #define ABSTRACTMEDIAWIDGET_H
0023 
0024 #include <QMap>
0025 #include "mediawidget.h"
0026 
0027 class AbstractMediaWidget : public QWidget
0028 {
0029 public:
0030     explicit AbstractMediaWidget(QWidget *parent);
0031     virtual ~AbstractMediaWidget() {};
0032 
0033     void connectToMediaWidget(MediaWidget *mediaWidget_);
0034 
0035     // zero-based numbering is used everywhere (e.g. first audio channel = 0)
0036 
0037     MediaWidget::PlaybackStatus getPlaybackStatus() const { return playbackStatus; }
0038     int getCurrentTime() const { return currentTime; } // milliseconds
0039     int getTotalTime() const { return totalTime; } // milliseconds
0040     bool isSeekable() const { return seekable; }
0041     QMap<MediaWidget::MetadataType, QString> getMetadata() const { return metadata; }
0042     QStringList getAudioStreams() const { return audioStreams; }
0043     int getCurrentAudioStream() const { return currentAudioStream; }
0044     QStringList getSubtitles() const { return subtitles; }
0045     int getCurrentSubtitle() const { return currentSubtitle; }
0046     int getTitleCount() const { return titleCount; }
0047     int getCurrentTitle() const { return currentTitle; }
0048     int getChapterCount() const { return chapterCount; }
0049     int getCurrentChapter() const { return currentChapter; }
0050     int getAngleCount() const { return angleCount; }
0051     int getCurrentAngle() const { return currentAngle; }
0052     bool hasDvdMenu() const { return dvdMenu; }
0053     QSize getVideoSize() const { return videoSize; }
0054 
0055     virtual QStringList getAudioDevices() = 0;
0056     virtual void setAudioDevice(QString device) = 0;
0057     virtual void setMuted(bool muted) = 0;
0058     virtual void setVolume(int volume) = 0; // [0 - 200]
0059     virtual void setAspectRatio(MediaWidget::AspectRatio aspectRatio) = 0;
0060     virtual void resizeToVideo(float scale) = 0;
0061     virtual void setDeinterlacing(MediaWidget::DeinterlaceMode) = 0;
0062     virtual void play(const MediaSource &source) = 0;
0063     virtual void stop() = 0;
0064     virtual void setPaused(bool paused) = 0;
0065     virtual void seek(int time) = 0; // milliseconds
0066     virtual void setCurrentAudioStream(int currentAudioStream) = 0;
0067     virtual void setCurrentSubtitle(int currentSubtitle) = 0;
0068     virtual void setExternalSubtitle(const QUrl &subtitleUrl) = 0;
0069     virtual void setCurrentTitle(int currentTitle) = 0;
0070     virtual void setCurrentChapter(int currentChapter) = 0;
0071     virtual void setCurrentAngle(int currentAngle) = 0;
0072     virtual bool jumpToPreviousChapter() = 0;
0073     virtual bool jumpToNextChapter() = 0;
0074     virtual void showDvdMenu() = 0;
0075     virtual void dvdNavigate(int key) = 0;
0076 
0077     enum PendingUpdate
0078     {
0079         Nothing = 0,
0080         PlaybackFinished = (1 << 0),
0081         PlaybackStatus = (1 << 1),
0082         CurrentTotalTime = (1 << 2),
0083         Seekable = (1 << 3),
0084         Metadata = (1 << 4),
0085         AudioStreams = (1 << 5),
0086         Subtitles = (1 << 6),
0087         Titles = (1 << 7),
0088         Chapters = (1 << 8),
0089         Angles = (1 << 9),
0090         DvdMenu = (1 << 10),
0091         VideoSize = (1 << 11)
0092     };
0093 
0094     Q_DECLARE_FLAGS(PendingUpdates, PendingUpdate)
0095 
0096 protected:
0097     void addPendingUpdates(PendingUpdates pendingUpdatesToBeAdded); // thread-safe
0098 
0099     virtual int updatePlaybackStatus() = 0;
0100     virtual void updateCurrentTotalTime() = 0;
0101     virtual void updateSeekable() = 0;
0102     virtual void updateMetadata() = 0;
0103     virtual void updateAudioStreams() = 0;
0104     virtual void updateSubtitles() = 0;
0105     virtual void updateTitles() = 0;
0106     virtual void updateChapters() = 0;
0107     virtual void updateAngles() = 0;
0108     virtual void updateDvdMenu() = 0;
0109     virtual void updateVideoSize() = 0;
0110 
0111     MediaWidget::PlaybackStatus playbackStatus;
0112     int currentTime;
0113     int totalTime;
0114     bool seekable;
0115     QMap<MediaWidget::MetadataType, QString> metadata;
0116     QStringList audioStreams;
0117     int currentAudioStream;
0118     QStringList subtitles;
0119     int currentSubtitle;
0120     int titleCount;
0121     int currentTitle;
0122     int chapterCount;
0123     int currentChapter;
0124     int angleCount;
0125     int currentAngle;
0126     bool dvdMenu;
0127     QSize videoSize;
0128 
0129 private:
0130     void customEvent(QEvent *event) override;
0131 
0132     MediaWidget *mediaWidget;
0133     QAtomicInt pendingUpdates;
0134 };
0135 
0136 Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMediaWidget::PendingUpdates)
0137 
0138 class DummyMediaWidget : public AbstractMediaWidget
0139 {
0140 public:
0141     explicit DummyMediaWidget(QWidget *parent): AbstractMediaWidget(parent) {};
0142     ~DummyMediaWidget() {};
0143 
0144     QStringList getAudioDevices() override { QStringList empty; return empty; };
0145     void setAudioDevice(QString) override {};
0146     void setMuted(bool) override {};
0147     void setVolume(int) override {}; // [0 - 200]
0148     void setAspectRatio(MediaWidget::AspectRatio) override {};
0149     void resizeToVideo(float) override {};
0150     void setDeinterlacing(MediaWidget::DeinterlaceMode) override {};
0151     void play(const MediaSource &) override {};
0152     void stop() override {};
0153     void setPaused(bool) override {};
0154     void seek(int) override {}; // milliseconds
0155     void setCurrentAudioStream(int) override {};
0156     void setCurrentSubtitle(int) override {};
0157     void setExternalSubtitle(const QUrl &) override {};
0158     void setCurrentTitle(int) override {};
0159     void setCurrentChapter(int) override {};
0160     void setCurrentAngle(int) override {};
0161     bool jumpToPreviousChapter() override { return false; };
0162     bool jumpToNextChapter() override { return false; }
0163     void showDvdMenu() override {};
0164     void dvdNavigate(int) override {};
0165 
0166     int updatePlaybackStatus() override { return true; };
0167     void updateCurrentTotalTime() override {};
0168     void updateSeekable() override {};
0169     void updateMetadata() override {};
0170     void updateAudioDevices() {};
0171     void updateAudioStreams() override {};
0172     void updateSubtitles() override {};
0173     void updateTitles() override {};
0174     void updateChapters() override {};
0175     void updateAngles() override {};
0176     void updateDvdMenu() override {};
0177     void updateVideoSize() override {};
0178 };
0179 
0180 #endif /* ABSTRACTMEDIAWIDGET_H */