1/***************************************************************************
2 copyright : (C) 2002 - 2008 by Scott Wheeler
3 email : wheeler@kde.org
4 ***************************************************************************/
5
6/***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
10 * *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19 * 02110-1301 USA *
20 * *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
25
26#ifndef TAGLIB_MPEGHEADER_H
27#define TAGLIB_MPEGHEADER_H
28
29#include "taglib_export.h"
30
31namespace TagLib {
32
33 class ByteVector;
34
35 namespace MPEG {
36
37 //! An implementation of MP3 frame headers
38
39 /*!
40 * This is an implementation of MPEG Layer III headers. The API follows more
41 * or less the binary format of these headers. I've used
42 * <a href="http://www.mp3-tech.org/programmer/frame_header.html">this</a>
43 * document as a reference.
44 */
45
46 class TAGLIB_EXPORT Header
47 {
48 public:
49 /*!
50 * Parses an MPEG header based on \a data.
51 */
52 Header(const ByteVector &data);
53
54 /*!
55 * Does a shallow copy of \a h.
56 */
57 Header(const Header &h);
58
59 /*!
60 * Destroys this Header instance.
61 */
62 virtual ~Header();
63
64 /*!
65 * Returns true if the frame is at least an appropriate size and has
66 * legal values.
67 */
68 bool isValid() const;
69
70 /*!
71 * The MPEG Version.
72 */
73 enum Version {
74 //! MPEG Version 1
75 Version1 = 0,
76 //! MPEG Version 2
77 Version2 = 1,
78 //! MPEG Version 2.5
79 Version2_5 = 2
80 };
81
82 /*!
83 * Returns the MPEG Version of the header.
84 */
85 Version version() const;
86
87 /*!
88 * Returns the layer version. This will be between the values 1-3.
89 */
90 int layer() const;
91
92 /*!
93 * Returns true if the MPEG protection bit is enabled.
94 */
95 bool protectionEnabled() const;
96
97 /*!
98 * Returns the bitrate encoded in the header.
99 */
100 int bitrate() const;
101
102 /*!
103 * Returns the sample rate in Hz.
104 */
105 int sampleRate() const;
106
107 /*!
108 * Returns true if the frame is padded.
109 */
110 bool isPadded() const;
111
112 /*!
113 * There are a few combinations or one or two channel audio that are
114 * possible:
115 */
116 enum ChannelMode {
117 //! Stereo
118 Stereo = 0,
119 //! Stereo
120 JointStereo = 1,
121 //! Dual Mono
122 DualChannel = 2,
123 //! Mono
124 SingleChannel = 3
125 };
126
127 /*!
128 * Returns the channel mode for this frame.
129 */
130 ChannelMode channelMode() const;
131
132 /*!
133 * Returns true if the copyrighted bit is set.
134 */
135 bool isCopyrighted() const;
136
137 /*!
138 * Returns true if the "original" bit is set.
139 */
140 bool isOriginal() const;
141
142 /*!
143 * Returns the frame length.
144 */
145 int frameLength() const;
146
147 /*!
148 * Returns the number of frames per sample.
149 */
150 int samplesPerFrame() const;
151
152 /*!
153 * Makes a shallow copy of the header.
154 */
155 Header &operator=(const Header &h);
156
157 private:
158 void parse(const ByteVector &data);
159
160 class HeaderPrivate;
161 HeaderPrivate *d;
162 };
163 }
164}
165
166#endif
167