1 /***************************************************************************
2 copyright : (C) 2002 - 2008 by Scott Wheeler
3 email : wheeler@kde.org
4 ***************************************************************************/
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. *
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. *
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 *
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 ***************************************************************************/
26 #ifndef TAGLIB_OGGPAGE_H
27 #define TAGLIB_OGGPAGE_H
29 #include "taglib_export.h"
30 #include "tbytevectorlist.h"
39 //! An implementation of Ogg pages
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
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.
52 class TAGLIB_EXPORT Page
56 * Read an Ogg page from the \a file at the position \a pageOffset.
58 Page(File *file, long pageOffset);
63 * Returns the page's position within the file (in bytes).
65 long fileOffset() const;
68 * Returns a pointer to the header for this page. This pointer will become
69 * invalid when the page is deleted.
71 const PageHeader *header() const;
74 * Returns the index of the first packet wholly or partially contained in
77 * \see setFirstPacketIndex()
79 int firstPacketIndex() const;
82 * Sets the index of the first packet in the page.
84 * \see firstPacketIndex()
86 void setFirstPacketIndex(int index);
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.
92 * \see containsPacket()
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
106 * Checks to see if the specified \a packet is contained in the current
109 * \see ContainsPacketFlags
111 ContainsPacketFlags containsPacket(int index) const;
114 * Returns the number of packets (whole or partial) in this page.
116 uint packetCount() const;
119 * Returns a list of the packets in this page.
121 * \note Either or both the first and last packets may be only partial.
122 * \see PageHeader::firstPacketContinued()
124 ByteVectorList packets() const;
127 * Returns the size of the page in bytes.
131 ByteVector render() const;
134 * Defines a strategy for pagination, or grouping pages into Ogg packets,
135 * for use with pagination methods.
137 * \note Yes, I'm aware that this is not a canonical "Strategy Pattern",
138 * the term was simply convenient.
140 enum PaginationStrategy {
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.
149 * Split the packet or group of packets into pages that conform to the
150 * sizes recommended in the Ogg standard.
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.
164 * \note The "absolute granule position" is currently always zeroed using
165 * this method as this suffices for the comment headers.
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.
171 * \see PaginationStrategy
172 * \see List::setAutoDelete()
174 static List<Page *> paginate(const ByteVectorList &packets,
175 PaginationStrategy strategy,
176 uint streamSerialNumber,
178 bool firstPacketContinued = false,
179 bool lastPacketCompleted = true,
180 bool containsLastPacket = false);
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.
187 Page(const ByteVectorList &packets,
188 uint streamSerialNumber,
190 bool firstPacketContinued = false,
191 bool lastPacketCompleted = true,
192 bool containsLastPacket = false);
196 Page &operator=(const Page &);