Miam-Player  0.8.0
A nice music player
AudioOutputBackend.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 2015)
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_AUDIOOUTPUTBACKEND_H
23 #define QAV_AUDIOOUTPUTBACKEND_H
24 
25 #include <QtCore/QObject>
26 #include <QtAV/AudioFormat.h>
27 #include <QtAV/AudioOutput.h>
28 
29 namespace QtAV {
30 
33 {
34  Q_OBJECT
35 public:
37  bool available; // default is true. set to false when failed to create backend
41  static QStringList defaultPriority();
46  AudioOutputBackend(AudioOutput::DeviceFeatures f, QObject *parent);
47  virtual ~AudioOutputBackend() {}
48  virtual QString name() const = 0;
49  virtual bool open() = 0;
50  virtual bool close() = 0;
51  virtual bool write(const QByteArray& data) = 0; //MUST
52  virtual bool play() = 0; //MUST
53  virtual bool flush() { return false;}
54  virtual bool clear() { return false;}
55  virtual bool isSupported(const AudioFormat& format) const { return isSupported(format.sampleFormat()) && isSupported(format.channelLayout());}
56  virtual bool isSupported(AudioFormat::SampleFormat) const { return true;}
57  virtual bool isSupported(AudioFormat::ChannelLayout) const { return true;}
74  User = 0, // You have to reimplement waitForNextBuffer()
75  Blocking = 1,
76  BytesCallback = 1 << 1,
77  CountCallback = 1 << 2,
78  PlayedCount = 1 << 3, //number of buffers played since last buffer dequeued
79  PlayedBytes = 1 << 4,
80  OffsetIndex = 1 << 5, //current playing offset
81  OffsetBytes = 1 << 6, //current playing offset by bytes
82  WritableBytes = 1 << 7,
83  };
84  virtual BufferControl bufferControl() const = 0;
85  // called by callback with Callback control
86  virtual void onCallback();
87  //default return -1. means not the control
88  virtual int getPlayedCount() {return -1;} //PlayedCount
94  virtual int getPlayedBytes() {return -1;} // PlayedBytes
95  virtual int getOffset() {return -1;} // OffsetIndex
96  virtual int getOffsetByBytes() {return -1;}// OffsetBytes
97  virtual int getWritableBytes() {return -1;} //WritableBytes
98  // not virtual. called in ctor
99  AudioOutput::DeviceFeatures supportedFeatures() { return m_features;}
106  virtual bool setVolume(qreal value) { Q_UNUSED(value); return false;}
107  virtual qreal getVolume() const { return 1.0;}
108  virtual bool setMute(bool value = true) { Q_UNUSED(value); return false;}
109  virtual bool getMute() const { return false;}
110 
111 Q_SIGNALS:
112  /*
113  * \brief reportVolume
114  * Volume can be changed by per-app volume control from system outside this library. Useful for synchronizing ui to system.
115  * Volume control from QtAV may invoke it too. And it may be invoked even if volume is not changed.
116  * If volume changed, signal volumeChanged() will be emitted and volume() will be updated.
117  * Only supported by some backends, e.g. pulseaudio
118  */
119  void volumeReported(qreal value);
120  void muteReported(bool value);
121 public:
122  template<class C> static bool Register(AudioOutputBackendId id, const char* name) { return Register(id, create<C>, name);}
123  static AudioOutputBackend* create(AudioOutputBackendId id);
124  static AudioOutputBackend* create(const char* name);
130  static AudioOutputBackendId* next(AudioOutputBackendId* id = 0);
131  static const char* name(AudioOutputBackendId id);
132  static AudioOutputBackendId id(const char* name);
133 private:
134  template<class C> static AudioOutputBackend* create() { return new C();}
135  typedef AudioOutputBackend* (*AudioOutputBackendCreator)();
136  static bool Register(AudioOutputBackendId id, AudioOutputBackendCreator, const char *name);
137 private:
138  AudioOutput::DeviceFeatures m_features;
139  Q_DISABLE_COPY(AudioOutputBackend)
140 };
141 } //namespace QtAV
142 #endif //QAV_AUDIOOUTPUTBACKEND_H
virtual bool isSupported(AudioFormat::ChannelLayout) const
Definition: AudioOutputBackend.h:57
ChannelLayout
Definition: AudioFormat.h:63
int buffer_size
Definition: AudioOutputBackend.h:38
AudioOutput::DeviceFeatures supportedFeatures()
Definition: AudioOutputBackend.h:99
int buffer_count
Definition: AudioOutputBackend.h:39
virtual bool setVolume(qreal value)
setVolume Set volume by backend api.
Definition: AudioOutputBackend.h:106
SampleFormat sampleFormat() const
virtual int getOffset()
Definition: AudioOutputBackend.h:95
Definition: AudioFormat.h:68
#define Q_AV_PRIVATE_EXPORT
Definition: QtAV_Global.h:43
Definition: AudioOutput.h:45
virtual bool clear()
Definition: AudioOutputBackend.h:54
virtual bool isSupported(const AudioFormat &format) const
Definition: AudioOutputBackend.h:55
virtual ~AudioOutputBackend()
Definition: AudioOutputBackend.h:47
ChannelLayout channelLayout() const
virtual bool isSupported(AudioFormat::SampleFormat) const
Definition: AudioOutputBackend.h:56
virtual int getOffsetByBytes()
Definition: AudioOutputBackend.h:96
Definition: AudioFormat.h:50
virtual int getPlayedCount()
Definition: AudioOutputBackend.h:88
Definition: AudioFormat.h:35
SampleFormat
The SampleFormat enum s8, u16, u24, s24, u32 are not listed in ffmpeg sample format and have not plan...
Definition: AudioFormat.h:44
AudioOutput * audio
Definition: AudioOutputBackend.h:36
virtual qreal getVolume() const
Definition: AudioOutputBackend.h:107
virtual bool getMute() const
Definition: AudioOutputBackend.h:109
virtual AudioFormat::ChannelLayout preferredChannelLayout() const
preferredChannelLayout
Definition: AudioOutputBackend.h:68
bool available
Definition: AudioOutputBackend.h:37
Definition: AudioOutputBackend.h:32
virtual bool setMute(bool value=true)
Definition: AudioOutputBackend.h:108
virtual int getWritableBytes()
Definition: AudioOutputBackend.h:97
AudioFormat format
Definition: AudioOutputBackend.h:40
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
virtual int getPlayedBytes()
getPlayedBytes reimplement this if bufferControl() is PlayedBytes.
Definition: AudioOutputBackend.h:94
BufferControl
The BufferControl enum Used to adapt to different audio playback backend.
Definition: AudioOutputBackend.h:73
static bool Register(AudioOutputBackendId id, const char *name)
Definition: AudioOutputBackend.h:122
int AudioOutputBackendId
Definition: AudioOutputBackend.h:31
virtual AudioFormat::SampleFormat preferredSampleFormat() const
preferredSampleFormat
Definition: AudioOutputBackend.h:63
virtual bool flush()
Definition: AudioOutputBackend.h:53