aboutsummaryrefslogtreecommitdiffstats
path: root/taglib/mpeg/xingheader.h
blob: f512e2340ac6133e9f58f031471abae9658c9446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/***************************************************************************
    copyright            : (C) 2003 by Ismael Orenstein
    email                : orenstein@kde.org
 ***************************************************************************/

/***************************************************************************
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Lesser General Public License version   *
 *   2.1 as published by the Free Software Foundation.                     *
 *                                                                         *
 *   This library is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with this library; if not, write to the Free Software   *
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         *
 *   02110-1301  USA                                                       *
 *                                                                         *
 *   Alternatively, this file is available under the Mozilla Public        *
 *   License Version 1.1.  You may obtain a copy of the License at         *
 *   http://www.mozilla.org/MPL/                                           *
 ***************************************************************************/

#ifndef TAGLIB_XINGHEADER_H
#define TAGLIB_XINGHEADER_H

#include "mpegheader.h"
#include "taglib_export.h"

namespace TagLib {

  class ByteVector;

  namespace MPEG {

    class File;

    //! An implementation of the Xing/VBRI headers

    /*!
     * This is a minimalistic implementation of the Xing/VBRI VBR headers.
     * Xing/VBRI headers are often added to VBR (variable bit rate) MP3 streams
     * to make it easy to compute the length and quality of a VBR stream.  Our
     * implementation is only concerned with the total size of the stream (so
     * that we can calculate the total playing time and the average bitrate).
     * It uses <a href="http://home.pcisys.net/~melanson/codecs/mp3extensions.txt">
     * this text</a> and the XMMS sources as references.
     */

    class TAGLIB_EXPORT XingHeader
    {
    public:
      /*!
       * The type of the VBR header.
       */
      enum HeaderType
      {
        /*!
         * Invalid header or no VBR header found.
         */
        Invalid = 0,

        /*!
         * Xing header.
         */
        Xing = 1,

        /*!
         * VBRI header.
         */
        VBRI = 2,
      };

      /*!
       * Parses an Xing/VBRI header based on \a data which contains the entire
       * first MPEG frame.
       */
      XingHeader(const ByteVector &data);

      /*!
       * Destroy this XingHeader instance.
       */
      virtual ~XingHeader();

      /*!
       * Returns true if the data was parsed properly and if there is a valid
       * Xing/VBRI header present.
       */
      bool isValid() const;

      /*!
       * Returns the total number of frames.
       */
      unsigned int totalFrames() const;

      /*!
       * Returns the total size of stream in bytes.
       */
      unsigned int totalSize() const;

      /*!
       * Returns the type of the VBR header.
       */
      HeaderType type() const;

      /*!
       * Returns the offset for the start of this Xing header, given the
       * version and channels of the frame
       *
       * \deprecated Always returns 0.
       */
      static int xingHeaderOffset(TagLib::MPEG::Header::Version v,
                                  TagLib::MPEG::Header::ChannelMode c);

    private:
      XingHeader(const XingHeader &);
      XingHeader &operator=(const XingHeader &);

      void parse(const ByteVector &data);

      class XingHeaderPrivate;
      XingHeaderPrivate *d;
    };
  }
}

#endif