Miam-Player  0.8.0
A nice music player
Subtitle.h
Go to the documentation of this file.
1 /******************************************************************************
2  QtAV: Multimedia framework based on Qt and FFmpeg
3  Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4 
5 * This file is part of QtAV (from 2014)
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ******************************************************************************/
21 #ifndef QTAV_SUBTITLE_H
22 #define QTAV_SUBTITLE_H
23 #include <QtAV/SubImage.h>
24 #include <QtCore/QObject>
25 #include <QtCore/QStringList>
26 #include <QtCore/QUrl>
27 #include <QtGui/QImage>
28 /*
29  * to avoid read error, subtitle size > 10*1024*1024 will be ignored.
30  */
31 namespace QtAV {
33 {
34 public:
36  begin(0)
37  , end(0)
38  {}
39  // valied: begin < end
40  bool isValid() const { return begin < end;}
41  operator bool() const { return isValid();}
42  bool operator !() const { return !isValid();}
43  inline bool operator <(const SubtitleFrame& f) const { return end < f.end;}
44  inline bool operator <(qreal t) const { return end < t;}
45  qreal begin;
46  qreal end;
47  QString text; //plain text. always valid
48 };
49 
50 class Q_AV_EXPORT Subtitle : public QObject
51 {
52  Q_OBJECT
53  Q_PROPERTY(QByteArray codec READ codec WRITE setCodec NOTIFY codecChanged)
54  // QList<SubtitleProcessorId>
55  Q_PROPERTY(QStringList engines READ engines WRITE setEngines NOTIFY enginesChanged)
56  Q_PROPERTY(QString engine READ engine NOTIFY engineChanged)
57  Q_PROPERTY(bool fuzzyMatch READ fuzzyMatch WRITE setFuzzyMatch NOTIFY fuzzyMatchChanged)
58  Q_PROPERTY(QByteArray rawData READ rawData WRITE setRawData NOTIFY rawDataChanged)
59  Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
60  Q_PROPERTY(QStringList dirs READ dirs WRITE setDirs NOTIFY dirsChanged)
61  Q_PROPERTY(QStringList suffixes READ suffixes WRITE setSuffixes NOTIFY suffixesChanged)
62  Q_PROPERTY(QStringList supportedSuffixes READ supportedSuffixes NOTIFY supportedSuffixesChanged)
63  Q_PROPERTY(qreal timestamp READ timestamp WRITE setTimestamp)
64  Q_PROPERTY(qreal delay READ delay WRITE setDelay NOTIFY delayChanged)
65  Q_PROPERTY(QString text READ getText)
66  Q_PROPERTY(bool loaded READ isLoaded)
67  Q_PROPERTY(bool canRender READ canRender NOTIFY canRenderChanged)
68  // font properties for libass engine
69  Q_PROPERTY(QString fontFile READ fontFile WRITE setFontFile NOTIFY fontFileChanged)
70  Q_PROPERTY(QString fontsDir READ fontsDir WRITE setFontsDir NOTIFY fontsDirChanged)
71  Q_PROPERTY(bool fontFileForced READ isFontFileForced WRITE setFontFileForced NOTIFY fontFileForcedChanged)
72 public:
73  explicit Subtitle(QObject *parent = 0);
74  virtual ~Subtitle();
82  void setCodec(const QByteArray& value);
83  QByteArray codec() const;
89  bool isLoaded() const;
96  void setEngines(const QStringList& value);
97  QStringList engines() const;
102  QString engine() const;
103  void setFuzzyMatch(bool value);
104  bool fuzzyMatch() const;
105  void setRawData(const QByteArray& data);
106  QByteArray rawData() const;
113  void setFileName(const QString& name);
114  QString fileName() const;
119  void setDirs(const QStringList& value);
120  QStringList dirs() const;
126  QStringList supportedSuffixes() const;
131  void setSuffixes(const QStringList& value);
132  QStringList suffixes() const;
133 
134  qreal timestamp() const;
141  qreal delay() const;
142  void setDelay(qreal value);
148  bool canRender() const;
149  // call setTimestamp before getText/Image
150  //plain text. separated by '\n' if more more than 1 text rects found
151  QString getText() const;
160  QImage getImage(int width, int height, QRect* boundingRect = 0);
161  SubImageSet getSubImages(int width, int height, QRect* boundingRect = 0);
162  // used for embedded subtitles.
168  bool processHeader(const QByteArray &codec, const QByteArray& data);
169  // ffmpeg decodes subtitle lines and call processLine. if AVPacket contains plain text, no decoding is ok
170  bool processLine(const QByteArray& data, qreal pts = -1, qreal duration = 0);
171 
172  QString fontFile() const;
173  void setFontFile(const QString& value);
178  QString fontsDir() const;
179  void setFontsDir(const QString& value);
180  bool isFontFileForced() const;
181  void setFontFileForced(bool value);
182 public slots:
187  void load();
188  void loadAsync();
189  void setTimestamp(qreal t);
190 signals:
191  // TODO: also add to AVPlayer?
193  void loaded(const QString& path = QString());
194  void canRenderChanged();
195  void codecChanged();
196  void enginesChanged();
197  void fuzzyMatchChanged();
202  void contentChanged();
203  void rawDataChanged();
204  void fileNameChanged();
205  void dirsChanged();
206  void suffixesChanged();
207  void supportedSuffixesChanged();
208  void engineChanged();
209  void delayChanged();
210  void fontFileChanged();
211  void fontsDirChanged();
212  void fontFileForcedChanged();
213 private:
214  void checkCapability();
215  class Private;
216  Private *priv;
217 };
218 
219 // internal use
221 public:
222  SubtitleAPIProxy(QObject* obj);
223  void setSubtitle(Subtitle *sub);
224  // API from Subtitle
230  void setCodec(const QByteArray& value);
231  QByteArray codec() const;
232  bool isLoaded() const;
233  void setEngines(const QStringList& value);
234  QStringList engines() const;
235  QString engine() const;
236  void setFuzzyMatch(bool value);
237  bool fuzzyMatch() const;
238  //always use exact file path by setFile(). file name is used internally
239  //void setFileName(const QString& name);
240  //QString fileName() const;
241  void setDirs(const QStringList& value);
242  QStringList dirs() const;
243  QStringList supportedSuffixes() const;
244  void setSuffixes(const QStringList& value);
245  QStringList suffixes() const;
246  bool canRender() const; // TODO: rename to capability()
247  qreal delay() const;
248  void setDelay(qreal value);
249 
250  QString fontFile() const;
251  void setFontFile(const QString& value);
252  QString fontsDir() const;
253  void setFontsDir(const QString& value);
254  bool isFontFileForced() const;
255  void setFontFileForced(bool value);
256 
257  // API from PlayerSubtitle
258  /*
259  void setFile(const QString& file);
260  QString file() const;
261  void setAutoLoad(bool value);
262  bool autoLoad() const;
263  */
264 private:
265  QObject *m_obj;
266  Subtitle *m_s;
267 };
268 
269 } //namespace QtAV
270 #endif // QTAV_SUBTITLE_H
Definition: Subtitle.h:32
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
qreal end
Definition: Subtitle.h:46
qreal begin
Definition: Subtitle.h:45
Definition: Subtitle.h:50
Definition: SubImage.h:45
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
QString text
Definition: Subtitle.h:47
SubtitleFrame()
Definition: Subtitle.h:35
bool isValid() const
Definition: Subtitle.h:40
Definition: Subtitle.h:220