Miam-Player  0.8.0
A nice music player
AVDemuxer.h
Go to the documentation of this file.
1 /******************************************************************************
2  QtAV: Media play library based on Qt and FFmpeg
3  Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4 
5 * This file is part of QtAV
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 
22 #ifndef QAV_DEMUXER_H
23 #define QAV_DEMUXER_H
24 
25 #include <QtAV/AVError.h>
26 #include <QtAV/Packet.h>
27 #include <QtCore/QVariant>
28 #include <QtCore/QObject>
29 #include <QtCore/QScopedPointer>
30 
31 struct AVFormatContext;
32 struct AVCodecContext;
33 QT_BEGIN_NAMESPACE
34 class QIODevice;
35 QT_END_NAMESPACE
36 // TODO: force codec name. clean code
37 namespace QtAV {
38 class AVError;
39 class MediaIO;
40 class Q_AV_EXPORT AVDemuxer : public QObject
41 {
42  Q_OBJECT
43 public:
44  enum StreamType { //TODO: move to common MediaType
48  };
49  static const QStringList& supportedFormats();
50  static const QStringList& supportedExtensions();
52  static const QStringList& supportedProtocols();
53 
54  AVDemuxer(QObject *parent = 0);
55  ~AVDemuxer();
56  MediaStatus mediaStatus() const;
57  bool atEnd() const;
58  QString fileName() const;
59  QIODevice* ioDevice() const;
61  MediaIO* mediaIO() const;
66  bool setMedia(const QString& fileName);
67  bool setMedia(QIODevice* dev);
68  bool setMedia(MediaIO* in);
77  void setFormat(const QString& fmt);
78  QString formatForced() const;
79  bool load();
80  bool unload();
81  bool isLoaded() const;
89  bool readFrame(); // TODO: rename int readPacket(), return stream number
94  Packet packet() const;
99  int stream() const;
100 
101  bool isSeekable() const; // TODO: change in unload?
102  void setSeekUnit(SeekUnit unit);
103  SeekUnit seekUnit() const;
104  void setSeekType(SeekType target);
105  SeekType seekType() const;
112  bool seek(qint64 pos); //pos: ms
119  bool seek(qreal q);
120  AVFormatContext* formatContext();
121  QString formatName() const;
122  QString formatLongName() const;
123  // TODO: rename startPosition()
124  qint64 startTime() const; //ms, AVFormatContext::start_time/1000
125  qint64 duration() const; //ms, AVFormatContext::duration/1000
126  qint64 startTimeUs() const; //us, AVFormatContext::start_time
127  qint64 durationUs() const; //us, AVFormatContext::duration
128  //total bit rate
129  int bitRate() const; //AVFormatContext::bit_rate
130  qreal frameRate() const; //deprecated AVStream::avg_frame_rate
131  // if stream is -1, return the current video(or audio if no video) stream.
132  // TODO: audio/videoFrames?
133  qint64 frames(int stream = -1) const; //AVFormatContext::nb_frames
134  bool hasAttacedPicture() const;
141  bool setStreamIndex(StreamType st, int index);
142  // current open stream
143  int currentStream(StreamType st) const;
144  QList<int> streams(StreamType st) const;
145  // TODO: stream(StreamType), streams(StreamType)
146  // current open stream
147  int audioStream() const;
148  QList<int> audioStreams() const;
149  int videoStream() const;
150  QList<int> videoStreams() const;
151  int subtitleStream() const;
152  QList<int> subtitleStreams() const;
153  //codec. stream < 0: the stream going to play (or the stream set by setStreamIndex())
154  AVCodecContext* audioCodecContext(int stream = -1) const;
155  AVCodecContext* videoCodecContext(int stream = -1) const;
156  AVCodecContext* subtitleCodecContext(int stream = -1) const;
160  qint64 getInterruptTimeout() const;
165  void setInterruptTimeout(qint64 timeout);
166  bool isInterruptOnTimeout() const;
167  void setInterruptOnTimeout(bool value);
174  int getInterruptStatus() const;
180  void setInterruptStatus(int interrupt);
188  void setOptions(const QVariantHash &dict);
189  QVariantHash options() const;
190 signals:
191  void unloaded();
192  void userInterrupted(); //NO direct connection because it's emit before interrupted happens
193  void loaded();
194  /*emit when the first frame is read*/
195  void started();
196  void finished(); //end of file
197  void error(const QtAV::AVError& e); //explictly use QtAV::AVError in connection for Qt4 syntax
198  void mediaStatusChanged(QtAV::MediaStatus status);
199  void seekableChanged();
200 private:
201  void setMediaStatus(MediaStatus status);
202  // error code (errorCode) and message (msg) may be modified internally
203  void handleError(int averr, AVError::ErrorCode* errorCode, QString& msg);
204 
205  class Private;
206  QScopedPointer<Private> d;
207  class InterruptHandler;
208  friend class InterruptHandler;
209 };
210 
211 } //namespace QtAV
212 #endif // QAV_DEMUXER_H
ErrorCode
Definition: AVError.h:31
Definition: AVError.h:28
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
StreamType
Definition: AVDemuxer.h:44
Definition: AVDemuxer.h:46
Definition: MediaIO.h:43
Definition: AVDemuxer.h:47
Definition: Packet.h:33
SeekType
Definition: QtAV_Global.h:114
SeekUnit
Definition: QtAV_Global.h:109
Definition: avcodec.h:1676
Definition: AVDemuxer.h:40
Definition: avformat.h:1338
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
MediaStatus
Definition: QtAV_Global.h:83
Definition: AVDemuxer.h:45