Miam-Player  0.8.0
A nice music player
AudioOutput.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
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_AUDIOOUTPUT_H
23 #define QAV_AUDIOOUTPUT_H
24 
25 #include <QtCore/QObject>
26 #include <QtCore/QStringList>
27 #include <QtAV/AVOutput.h>
28 #include <QtAV/AudioFrame.h>
29 
41 namespace QtAV {
42 
43 class AudioFormat;
44 class AudioOutputPrivate;
45 class Q_AV_EXPORT AudioOutput : public QObject, public AVOutput
46 {
47  Q_OBJECT
49  Q_ENUMS(DeviceFeature)
50  Q_FLAGS(DeviceFeatures)
51  Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
52  Q_PROPERTY(bool mute READ isMute WRITE setMute NOTIFY muteChanged)
53  Q_PROPERTY(DeviceFeatures deviceFeatures READ deviceFeatures WRITE setDeviceFeatures NOTIFY deviceFeaturesChanged)
54  Q_PROPERTY(QStringList backends READ backends WRITE setBackends NOTIFY backendsChanged)
55 public:
61  NoFeature = 0,
62  SetVolume = 1,
63  SetMute = 1 << 1,
64  SetSampleRate = 1 << 2,
65  };
66  Q_DECLARE_FLAGS(DeviceFeatures, DeviceFeature)
72  static QStringList backendsAvailable();
77  AudioOutput(QObject *parent = 0);
78  virtual ~AudioOutput();
84  void setBackends(const QStringList &backendNames = QStringList());
85  QStringList backends() const;
90  QString backend() const;
96  void flush();
101  void clear();
102  bool open();
103  bool close();
104  bool isOpen() const;
113  bool play(const QByteArray& data, qreal pts = 0.0);
115  void setAudioFormat(const AudioFormat& format);
116  AudioFormat& audioFormat();
117  const AudioFormat& audioFormat() const;
118 
119  void setSampleRate(int rate); //deprecated
120  int sampleRate() const; //deprecated
121  void setChannels(int channels); //deprecated
122  int channels() const; //deprecated
130  void setVolume(qreal value);
131  qreal volume() const;
137  void setMute(bool value = true);
138  bool isMute() const;
148  void setSpeed(qreal speed);
149  qreal speed() const;
156  bool isSupported(const AudioFormat& format) const;
157  bool isSupported(AudioFormat::SampleFormat sampleFormat) const;
158  bool isSupported(AudioFormat::ChannelLayout channelLayout) const;
164  AudioFormat::SampleFormat preferredSampleFormat() const;
169  AudioFormat::ChannelLayout preferredChannelLayout() const;
176  int bufferSamples() const;
177  void setBufferSamples(int value);
178  int bufferSize() const;
179 
185  int bufferCount() const;
186  void setBufferCount(int value);
187  int bufferSizeTotal() const { return bufferCount() * bufferSize();}
193  void setDeviceFeatures(DeviceFeatures value);
198  DeviceFeatures deviceFeatures() const;
203  DeviceFeatures supportedDeviceFeatures() const;
204  qreal timestamp() const;
205  // timestamp of current playing data
206 Q_SIGNALS:
207  void volumeChanged(qreal);
208  void muteChanged(bool);
209  void deviceFeaturesChanged();
210  void backendsChanged();
211 protected:
212  // Store and fill data to audio buffers
213  bool receiveData(const QByteArray &data, qreal pts = 0.0);
218  virtual bool waitForNextBuffer();
219 private Q_SLOTS:
220  void reportVolume(qreal value);
221  void reportMute(bool value);
222 private:
223  void onCallback();
224  friend class AudioOutputBackend;
225  Q_DISABLE_COPY(AudioOutput)
226 };
227 
228 } //namespace QtAV
229 #endif // QAV_AUDIOOUTPUT_H
ChannelLayout
Definition: AudioFormat.h:63
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
DeviceFeature
DeviceFeature Feature enum features supported by the audio playback api (we call device or backend he...
Definition: AudioOutput.h:60
#define DPTR_DECLARE_PRIVATE(Class)
Definition: dptr.h:107
Definition: AudioOutput.h:45
int bufferSizeTotal() const
Definition: AudioOutput.h:187
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
Definition: AudioOutputBackend.h:32
Definition: AVOutput.h:39
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31