Miam-Player  0.8.0
A nice music player
MediaIO.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_MediaIO_H
22 #define QTAV_MediaIO_H
23 
24 #include <stdio.h> //SEEK_SET
25 #include <QtAV/QtAV_Global.h>
26 #include <QtCore/QStringList>
27 #include <QtCore/QObject>
28 
29 namespace QtAV {
41 typedef int MediaIOId;
42 class MediaIOPrivate;
43 class Q_AV_EXPORT MediaIO : public QObject
44 {
45  Q_OBJECT
47  Q_DISABLE_COPY(MediaIO)
48  Q_ENUMS(AccessMode)
49 public:
50  enum AccessMode {
51  Read, // default
52  Write
53  };
54 
56  static QStringList builtInNames();
63  static MediaIO* createForProtocol(const QString& protocol);
70  static MediaIO* createForUrl(const QString& url);
71 
72  virtual ~MediaIO();
73  virtual QString name() const = 0;
79  void setUrl(const QString& url = QString());
80  QString url() const;
87  bool setAccessMode(AccessMode value);
88  AccessMode accessMode() const;
89 
91  virtual const QStringList& protocols() const;
92  virtual bool isSeekable() const = 0;
93  virtual bool isWritable() const { return false;}
98  virtual qint64 read(char *data, qint64 maxSize) = 0;
103  virtual qint64 write(const char* data, qint64 maxSize) {
104  Q_UNUSED(data);
105  Q_UNUSED(maxSize);
106  return 0;
107  }
113  virtual bool seek(qint64 offset, int from = SEEK_SET) = 0;
119  virtual qint64 position() const = 0;
124  virtual qint64 size() const = 0;
132  virtual bool isVariableSize() const { return false;}
133  // The followings are for internal use. used by AVDemuxer, AVMuxer
134  //struct AVIOContext; //anonymous struct in FFmpeg1.0.x
135  void* avioContext(); //const?
136  void release(); //TODO: how to remove it?
137 public:
138  static void registerAll();
139  template<class C> static bool Register(MediaIOId id, const char* name) { return Register(id, create<C>, name);}
140  static MediaIO* create(MediaIOId id);
141  static MediaIO* create(const char* name);
147  static MediaIOId* next(MediaIOId* id = 0);
148  static const char* name(MediaIOId id);
149  static MediaIOId id(const char* name);
150 private:
151  template<class C> static MediaIO* create() { return new C();}
152  typedef MediaIO* (*MediaIOCreator)();
153  static bool Register(MediaIOId id, MediaIOCreator, const char *name);
154 protected:
155  MediaIO(MediaIOPrivate& d, QObject* parent = 0);
160  virtual void onUrlChanged();
162 //private: // must add QT+=av-private if default ctor is private
163  // base class, not direct create. only final class has public ctor is enough
164  // FIXME: it's required by Q_DECLARE_METATYPE (also copy ctor)
165  MediaIO(QObject* parent = 0);
166 };
167 Q_DECL_DEPRECATED typedef MediaIO AVInput; // for source compatibility
168 } //namespace QtAV
169 
170 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
171 #include <QtCore/QMetaType>
172 Q_DECLARE_METATYPE(QtAV::MediaIO*)
173 Q_DECLARE_METATYPE(QIODevice*)
174 #endif
175 #endif // QTAV_MediaIO_H
Definition: MediaIO.h:51
AccessMode
Definition: MediaIO.h:50
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
virtual bool isWritable() const
Definition: MediaIO.h:93
#define DPTR_DECLARE_PRIVATE(Class)
Definition: dptr.h:107
size_t size
Definition: mem.h:207
virtual qint64 write(const char *data, qint64 maxSize)
write write at most maxSize bytes from data, and return the bytes were actually written ...
Definition: MediaIO.h:103
Definition: MediaIO.h:43
static bool Register(MediaIOId id, const char *name)
Definition: MediaIO.h:139
Definition: MediaIO_p.h:33
#define DPTR_DECLARE(Class)
Definition: dptr.h:105
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
virtual bool isVariableSize() const
isVariableSize Experiment: A hack for size() changes during playback.
Definition: MediaIO.h:132
int MediaIOId
MediaIO Built-in io (use MediaIO::create(name), example: MediaIO *qio = MediaIO::create("QIODevice"))...
Definition: MediaIO.h:41
Q_DECL_DEPRECATED typedef MediaIO AVInput
Definition: MediaIO.h:167