Remove no-longer used file.
[ardour.git] / libs / taglib / taglib / ogg / oggpage.h
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19  *   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_OGGPAGE_H
27 #define TAGLIB_OGGPAGE_H
28
29 #include "taglib_export.h"
30 #include "tbytevectorlist.h"
31
32 namespace TagLib {
33
34   namespace Ogg {
35
36     class File;
37     class PageHeader;
38
39     //! An implementation of Ogg pages
40
41     /*!
42      * This is an implementation of the pages that make up an Ogg stream.
43      * This handles parsing pages and breaking them down into packets and handles
44      * the details of packets spanning multiple pages and pages that contiain
45      * multiple packets.
46      *
47      * In most Xiph.org formats the comments are found in the first few packets,
48      * this however is a reasonably complete implementation of Ogg pages that
49      * could potentially be useful for non-meta data purposes.
50      */
51
52     class TAGLIB_EXPORT Page
53     {
54     public:
55       /*!
56        * Read an Ogg page from the \a file at the position \a pageOffset.
57        */
58       Page(File *file, long pageOffset);
59
60       virtual ~Page();
61
62       /*!
63        * Returns the page's position within the file (in bytes).
64        */
65       long fileOffset() const;
66
67       /*!
68        * Returns a pointer to the header for this page.  This pointer will become
69        * invalid when the page is deleted.
70        */
71       const PageHeader *header() const;
72
73       /*!
74        * Returns the index of the first packet wholly or partially contained in
75        * this page.
76        *
77        * \see setFirstPacketIndex()
78        */
79       int firstPacketIndex() const;
80
81       /*!
82        * Sets the index of the first packet in the page.
83        *
84        * \see firstPacketIndex()
85        */
86       void setFirstPacketIndex(int index);
87
88       /*!
89        * When checking to see if a page contains a given packet this set of flags
90        * represents the possible values for that packets status in the page.
91        *
92        * \see containsPacket()
93        */
94       enum ContainsPacketFlags {
95         //! No part of the packet is contained in the page
96         DoesNotContainPacket = 0x0000,
97         //! The packet is wholly contained in the page
98         CompletePacket       = 0x0001,
99         //! The page starts with the given packet
100         BeginsWithPacket     = 0x0002,
101         //! The page ends with the given packet
102         EndsWithPacket       = 0x0004
103       };
104
105       /*!
106        * Checks to see if the specified \a packet is contained in the current
107        * page.
108        *
109        * \see ContainsPacketFlags
110        */
111       ContainsPacketFlags containsPacket(int index) const;
112
113       /*!
114        * Returns the number of packets (whole or partial) in this page.
115        */
116       uint packetCount() const;
117
118       /*!
119        * Returns a list of the packets in this page.
120        *
121        * \note Either or both the first and last packets may be only partial.
122        * \see PageHeader::firstPacketContinued()
123        */
124       ByteVectorList packets() const;
125
126       /*!
127        * Returns the size of the page in bytes.
128        */
129       int size() const;
130
131       ByteVector render() const;
132
133       /*!
134        * Defines a strategy for pagination, or grouping pages into Ogg packets,
135        * for use with pagination methods.
136        *
137        * \note Yes, I'm aware that this is not a canonical "Strategy Pattern",
138        * the term was simply convenient.
139        */
140       enum PaginationStrategy {
141         /*!
142          * Attempt to put the specified set of packets into a single Ogg packet.
143          * If the sum of the packet data is greater than will fit into a single
144          * Ogg page -- 65280 bytes -- this will fall back to repagination using
145          * the recommended page sizes.
146          */
147         SinglePagePerGroup,
148         /*!
149          * Split the packet or group of packets into pages that conform to the
150          * sizes recommended in the Ogg standard.
151          */
152         Repaginate
153       };
154
155       /*!
156        * Pack \a packets into Ogg pages using the \a strategy for pagination.
157        * The page number indicater inside of the rendered packets will start
158        * with \a firstPage and be incremented for each page rendered.
159        * \a containsLastPacket should be set to true if \a packets contains the
160        * last page in the stream and will set the appropriate flag in the last
161        * rendered Ogg page's header.  \a streamSerialNumber should be set to
162        * the serial number for this stream.
163        *
164        * \note The "absolute granule position" is currently always zeroed using
165        * this method as this suffices for the comment headers.
166        *
167        * \warning The pages returned by this method must be deleted by the user.
168        * You can use List<T>::setAutoDelete(true) to set these pages to be
169        * automatically deleted when this list passes out of scope.
170        *
171        * \see PaginationStrategy
172        * \see List::setAutoDelete()
173        */
174       static List<Page *> paginate(const ByteVectorList &packets,
175                                    PaginationStrategy strategy,
176                                    uint streamSerialNumber,
177                                    int firstPage,
178                                    bool firstPacketContinued = false,
179                                    bool lastPacketCompleted = true,
180                                    bool containsLastPacket = false);
181
182     protected:
183       /*!
184        * Creates an Ogg packet based on the data in \a packets.  The page number
185        * for each page will be set to \a pageNumber.
186        */
187       Page(const ByteVectorList &packets,
188            uint streamSerialNumber,
189            int pageNumber,
190            bool firstPacketContinued = false,
191            bool lastPacketCompleted = true,
192            bool containsLastPacket = false);
193
194     private:
195       Page(const Page &);
196       Page &operator=(const Page &);
197
198       class PagePrivate;
199       PagePrivate *d;
200     };
201   }
202 }
203 #endif