1 #ifndef STANDALONE
2 #include <Python.h>
3 #endif
4 #include "bitstream.h"
5 
6 /********************************************************
7  Audio Tools, a module and set of tools for manipulating audio data
8  Copyright (C) 2007-2014  Brian Langenberger
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 *******************************************************/
24 
25 typedef enum {OGG_OK = 0,
26               OGG_STREAM_FINISHED = 1,
27               OGG_INVALID_MAGIC_NUMBER = -1,
28               OGG_INVALID_STREAM_VERSION = -2,
29               OGG_CHECKSUM_MISMATCH = -3,
30               OGG_PREMATURE_EOF = -4} ogg_status;
31 
32 struct ogg_page_header {
33     unsigned magic_number;
34     unsigned version;
35     unsigned packet_continuation;
36     unsigned stream_beginning;
37     unsigned stream_end;
38     int64_t granule_position;
39     unsigned bitstream_serial_number;
40     unsigned sequence_number;
41     unsigned checksum;
42     unsigned segment_count;
43     unsigned segment_lengths[0x100];
44 };
45 
46 struct ogg_page {
47     struct ogg_page_header header;
48     uint8_t segment[0x100][0x100];
49 };
50 
51 ogg_status
52 read_ogg_page_header(BitstreamReader *ogg_stream,
53                      struct ogg_page_header *header);
54 
55 ogg_status
56 read_ogg_page(BitstreamReader *ogg_stream,
57               struct ogg_page *page);
58 
59 void
60 write_ogg_page(BitstreamWriter *ogg_stream,
61                const struct ogg_page *page);
62 
63 
64 typedef struct OggPacketIterator_s {
65     BitstreamReader *reader;
66     struct ogg_page page;
67     uint8_t current_segment;
68 } OggPacketIterator;
69 
70 OggPacketIterator*
71 oggiterator_open(FILE *stream);
72 
73 void
74 oggiterator_close(OggPacketIterator *iterator);
75 
76 /*places a pointer to the next segment in "segment_data"
77   and its size in "segment_size"
78   the segment is pulled directly from an internal Ogg page
79   and should *not* be freed when finished*/
80 ogg_status
81 oggiterator_next_segment(OggPacketIterator *iterator,
82                          uint8_t **segment_data,
83                          uint8_t *segment_size);
84 
85 /*builds an entire Ogg packet from segments
86   and returns a BitsreamReader of its data for further parsing
87   the reader must be closed when finished with it
88 
89   endianness is applied to the newly created packet reader
90 
91   may return NULL and set "status" to something other than OGG_OK
92   if an error occurs reading segments from the stream*/
93 BitstreamReader*
94 oggiterator_next_packet(OggPacketIterator *iterator,
95                         bs_endianness endianness,
96                         ogg_status *status);
97 
98 
99 char *
100 ogg_strerror(ogg_status err);
101 
102 
103 #ifndef STANDALONE
104 PyObject*
105 ogg_exception(ogg_status err);
106 #endif
107