Miam-Player  0.8.0
A nice music player
AudioFormat.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 QTAV_AUDIOFORMAT_H
23 #define QTAV_AUDIOFORMAT_H
24 
25 #include <QtCore/QSharedDataPointer>
26 #include <QtCore/QString>
27 #include <QtAV/QtAV_Global.h>
28 
29 QT_BEGIN_NAMESPACE
30 class QDebug;
31 QT_END_NAMESPACE
32 namespace QtAV {
33 
34 class AudioFormatPrivate;
36 {
37  enum { kSize = 12, kFloat = 1<<(kSize+1), kUnsigned = 1<<(kSize+2), kPlanar = 1<<(kSize+3), kByteOrder = 1<<(kSize+4) };
38 public:
44  enum SampleFormat {
45  SampleFormat_Unknown = 0,
46  SampleFormat_Input = SampleFormat_Unknown,
47  SampleFormat_Unsigned8 = 1 | kUnsigned,
48  SampleFormat_Signed8 = 1,
49  SampleFormat_Unigned16 = 2 | kUnsigned,
50  SampleFormat_Signed16 = 2,
51  SampleFormat_Unsigned24 = 3 | kUnsigned,
52  SampleFormat_Signed24 = 3,
53  SampleFormat_Unsigned32 = 4 | kUnsigned,
54  SampleFormat_Signed32 = 4,
55  SampleFormat_Float = 4 | kFloat,
56  SampleFormat_Double = 8 | kFloat,
57  SampleFormat_Unsigned8Planar = SampleFormat_Unsigned8 | kPlanar,
58  SampleFormat_Signed16Planar = SampleFormat_Signed16 | kPlanar,
59  SampleFormat_Signed32Planar = SampleFormat_Signed32 | kPlanar,
60  SampleFormat_FloatPlanar = SampleFormat_Float | kPlanar,
61  SampleFormat_DoublePlanar = SampleFormat_Double | kPlanar
62  };
67  ChannelLayout_Mono = ChannelLayout_Center,
69  ChannelLayout_Unsupported //ok. now it's not complete
70  };
71  //typedef qint64 ChannelLayout; //currently use latest FFmpeg's
72 
73  static ChannelLayout channelLayoutFromFFmpeg(qint64 clff);
74  static qint64 channelLayoutToFFmpeg(ChannelLayout cl);
75  static SampleFormat sampleFormatFromFFmpeg(int fffmt);
76  static int sampleFormatToFFmpeg(SampleFormat fmt);
77  static bool isPlanar(SampleFormat format);
78  static SampleFormat planarSampleFormat(SampleFormat fmt);
79  static SampleFormat packedSampleFormat(SampleFormat fmt);
80 
81  AudioFormat();
82  AudioFormat(const AudioFormat &other);
83  ~AudioFormat();
84 
85  AudioFormat& operator=(const AudioFormat &other);
86  bool operator==(const AudioFormat &other) const;
87  bool operator!=(const AudioFormat &other) const;
88 
89  bool isValid() const;
90  bool isFloat() const;
91  bool isUnsigned() const;
92  bool isPlanar() const;
93  int planeCount() const;
94 
95  void setSampleRate(int sampleRate);
96  int sampleRate() const;
97 
101  void setChannelLayoutFFmpeg(qint64 layout);
102  qint64 channelLayoutFFmpeg() const;
103  //currently a limitted set of channel layout is supported. call setChannelLayoutFFmpeg is recommended
104  void setChannelLayout(ChannelLayout layout);
105  ChannelLayout channelLayout() const;
106  QString channelLayoutName() const;
110  void setChannels(int channels);
116  int channels() const;
117 
118  void setSampleFormat(SampleFormat sampleFormat);
119  SampleFormat sampleFormat() const;
120  void setSampleFormatFFmpeg(int ffSampleFormat);
121  int sampleFormatFFmpeg() const;
122  QString sampleFormatName() const;
123 
124  // Helper functions
125  // in microseconds
126  qint32 bytesForDuration(qint64 duration) const;
127  qint64 durationForBytes(qint32 byteCount) const;
128 
129  qint32 bytesForFrames(qint32 frameCount) const;
130  qint32 framesForBytes(qint32 byteCount) const;
131 
132  // in microseconds
133  qint32 framesForDuration(qint64 duration) const;
134  qint64 durationForFrames(qint32 frameCount) const;
135 
136  // 1 frame = 1 sample with channels
141  int bytesPerFrame() const;
146  int bytesPerSample() const;
147  int sampleSize() const; // the same as bytesPerSample()
148  int bitRate() const; //bits per second
149  int bytesPerSecond() const;
150 private:
151  QSharedDataPointer<AudioFormatPrivate> d;
152 };
153 
154 #ifndef QT_NO_DEBUG_STREAM
155 Q_AV_EXPORT QDebug operator<<(QDebug debug, const AudioFormat &fmt);
156 Q_AV_EXPORT QDebug operator<<(QDebug debug, AudioFormat::SampleFormat sampleFormat);
157 Q_AV_EXPORT QDebug operator<<(QDebug debug, AudioFormat::ChannelLayout channelLayout);
158 #endif
159 
160 } //namespace QtAV
161 
162 Q_DECLARE_METATYPE(QtAV::AudioFormat)
163 Q_DECLARE_METATYPE(QtAV::AudioFormat::SampleFormat)
164 Q_DECLARE_METATYPE(QtAV::AudioFormat::ChannelLayout)
165 
166 #endif // QTAV_AUDIOFORMAT_H
ChannelLayout
Definition: AudioFormat.h:63
Definition: AudioFormat.h:66
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
Definition: AudioFormat.h:68
Q_AV_EXPORT QDebug operator<<(QDebug debug, const AudioFormat &fmt)
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
bool operator==(const TagButton &t1, const TagButton &t2)
Definition: tagbutton.h:61
Definition: AudioFormat.h:65
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
Definition: AudioFormat.h:64