| 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 |
#ifndef __OGGZ_PRIVATE_H__ |
|---|
| 34 |
#define __OGGZ_PRIVATE_H__ |
|---|
| 35 |
|
|---|
| 36 |
#include <stdio.h> |
|---|
| 37 |
#include <sys/types.h> |
|---|
| 38 |
|
|---|
| 39 |
#include <ogg/ogg.h> |
|---|
| 40 |
#include <oggz/oggz_constants.h> |
|---|
| 41 |
#include <oggz/oggz_off_t.h> |
|---|
| 42 |
|
|---|
| 43 |
#include "oggz_macros.h" |
|---|
| 44 |
#include "oggz_vector.h" |
|---|
| 45 |
#include "oggz_dlist.h" |
|---|
| 46 |
|
|---|
| 47 |
#define OGGZ_AUTO_MULT 1000Ull |
|---|
| 48 |
|
|---|
| 49 |
typedef struct _OGGZ OGGZ; |
|---|
| 50 |
typedef struct _OggzComment OggzComment; |
|---|
| 51 |
typedef struct _OggzIO OggzIO; |
|---|
| 52 |
typedef struct _OggzReader OggzReader; |
|---|
| 53 |
typedef struct _OggzWriter OggzWriter; |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
typedef int (*OggzReadPacket) (OGGZ * oggz, ogg_packet * op, long serialno, |
|---|
| 57 |
void * user_data); |
|---|
| 58 |
typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og, long serialno, |
|---|
| 59 |
void * user_data); |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
#include "oggz_stream_private.h" |
|---|
| 63 |
|
|---|
| 64 |
typedef ogg_int64_t (*OggzMetric) (OGGZ * oggz, long serialno, |
|---|
| 65 |
ogg_int64_t granulepos, |
|---|
| 66 |
void * user_data); |
|---|
| 67 |
|
|---|
| 68 |
typedef int (*OggzOrder) (OGGZ * oggz, ogg_packet * op, void * target, |
|---|
| 69 |
void * user_data); |
|---|
| 70 |
|
|---|
| 71 |
typedef int (*OggzWriteHungry) (OGGZ * oggz, int empty, void * user_data); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
typedef size_t (*OggzIORead) (void * user_handle, void * buf, size_t n); |
|---|
| 75 |
typedef size_t (*OggzIOWrite) (void * user_handle, void * buf, size_t n); |
|---|
| 76 |
typedef int (*OggzIOSeek) (void * user_handle, long offset, int whence); |
|---|
| 77 |
typedef long (*OggzIOTell) (void * user_handle); |
|---|
| 78 |
typedef int (*OggzIOFlush) (void * user_handle); |
|---|
| 79 |
|
|---|
| 80 |
struct _oggz_stream_t { |
|---|
| 81 |
ogg_stream_state ogg_stream; |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
int content; |
|---|
| 85 |
int numheaders; |
|---|
| 86 |
int preroll; |
|---|
| 87 |
ogg_int64_t granulerate_n; |
|---|
| 88 |
ogg_int64_t granulerate_d; |
|---|
| 89 |
ogg_int64_t basegranule; |
|---|
| 90 |
int granuleshift; |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
char * vendor; |
|---|
| 94 |
OggzVector * comments; |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
int delivered_non_b_o_s; |
|---|
| 99 |
|
|---|
| 100 |
int b_o_s; |
|---|
| 101 |
int e_o_s; |
|---|
| 102 |
ogg_int64_t granulepos; |
|---|
| 103 |
ogg_int64_t packetno; |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
OggzMetric metric; |
|---|
| 107 |
void * metric_user_data; |
|---|
| 108 |
int metric_internal; |
|---|
| 109 |
|
|---|
| 110 |
OggzOrder order; |
|---|
| 111 |
void * order_user_data; |
|---|
| 112 |
|
|---|
| 113 |
OggzReadPacket read_packet; |
|---|
| 114 |
void * read_user_data; |
|---|
| 115 |
|
|---|
| 116 |
OggzReadPage read_page; |
|---|
| 117 |
void * read_page_user_data; |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
ogg_int64_t last_granulepos; |
|---|
| 121 |
ogg_int64_t page_granulepos; |
|---|
| 122 |
void * calculate_data; |
|---|
| 123 |
ogg_packet * last_packet; |
|---|
| 124 |
}; |
|---|
| 125 |
|
|---|
| 126 |
struct _OggzReader { |
|---|
| 127 |
ogg_sync_state ogg_sync; |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
ogg_stream_state ogg_stream; |
|---|
| 131 |
long current_serialno; |
|---|
| 132 |
|
|---|
| 133 |
OggzReadPacket read_packet; |
|---|
| 134 |
void * read_user_data; |
|---|
| 135 |
|
|---|
| 136 |
OggzReadPage read_page; |
|---|
| 137 |
void * read_page_user_data; |
|---|
| 138 |
|
|---|
| 139 |
ogg_int64_t current_unit; |
|---|
| 140 |
ogg_int64_t current_granulepos; |
|---|
| 141 |
|
|---|
| 142 |
#if 0 |
|---|
| 143 |
oggz_off_t offset_page_end; |
|---|
| 144 |
#endif |
|---|
| 145 |
}; |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
typedef struct { |
|---|
| 152 |
ogg_packet op; |
|---|
| 153 |
oggz_stream_t * stream; |
|---|
| 154 |
int flush; |
|---|
| 155 |
int * guard; |
|---|
| 156 |
} oggz_writer_packet_t; |
|---|
| 157 |
|
|---|
| 158 |
enum oggz_writer_state { |
|---|
| 159 |
OGGZ_MAKING_PACKETS = 0, |
|---|
| 160 |
OGGZ_WRITING_PAGES = 1 |
|---|
| 161 |
}; |
|---|
| 162 |
|
|---|
| 163 |
struct _OggzWriter { |
|---|
| 164 |
oggz_writer_packet_t * next_zpacket; |
|---|
| 165 |
OggzVector * packet_queue; |
|---|
| 166 |
|
|---|
| 167 |
OggzWriteHungry hungry; |
|---|
| 168 |
void * hungry_user_data; |
|---|
| 169 |
int hungry_only_when_empty; |
|---|
| 170 |
|
|---|
| 171 |
int writing; |
|---|
| 172 |
int state; |
|---|
| 173 |
|
|---|
| 174 |
int flushing; |
|---|
| 175 |
|
|---|
| 176 |
#if 0 |
|---|
| 177 |
int eog; |
|---|
| 178 |
int eop; |
|---|
| 179 |
#endif |
|---|
| 180 |
int eos; |
|---|
| 181 |
|
|---|
| 182 |
oggz_writer_packet_t * current_zpacket; |
|---|
| 183 |
|
|---|
| 184 |
int packet_offset; |
|---|
| 185 |
int page_offset; |
|---|
| 186 |
|
|---|
| 187 |
ogg_stream_state * current_stream; |
|---|
| 188 |
|
|---|
| 189 |
int no_more_packets; |
|---|
| 190 |
end of stream */ |
|---|
| 191 |
|
|---|
| 192 |
}; |
|---|
| 193 |
|
|---|
| 194 |
struct _OggzIO { |
|---|
| 195 |
OggzIORead read; |
|---|
| 196 |
void * read_user_handle; |
|---|
| 197 |
|
|---|
| 198 |
OggzIOWrite write; |
|---|
| 199 |
void * write_user_handle; |
|---|
| 200 |
|
|---|
| 201 |
OggzIOSeek seek; |
|---|
| 202 |
void * seek_user_handle; |
|---|
| 203 |
|
|---|
| 204 |
OggzIOTell tell; |
|---|
| 205 |
void * tell_user_handle; |
|---|
| 206 |
|
|---|
| 207 |
OggzIOFlush flush; |
|---|
| 208 |
void * flush_user_handle; |
|---|
| 209 |
}; |
|---|
| 210 |
|
|---|
| 211 |
struct _OggzComment { |
|---|
| 212 |
|
|---|
| 213 |
char * name; |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
char * value; |
|---|
| 217 |
}; |
|---|
| 218 |
|
|---|
| 219 |
struct _OGGZ { |
|---|
| 220 |
int flags; |
|---|
| 221 |
FILE * file; |
|---|
| 222 |
OggzIO * io; |
|---|
| 223 |
|
|---|
| 224 |
ogg_packet current_packet; |
|---|
| 225 |
ogg_page current_page; |
|---|
| 226 |
|
|---|
| 227 |
oggz_off_t offset; |
|---|
| 228 |
oggz_off_t offset_data_begin; |
|---|
| 229 |
|
|---|
| 230 |
long run_blocksize; |
|---|
| 231 |
int cb_next; |
|---|
| 232 |
|
|---|
| 233 |
OggzVector * streams; |
|---|
| 234 |
int all_at_eos; |
|---|
| 235 |
|
|---|
| 236 |
OggzMetric metric; |
|---|
| 237 |
void * metric_user_data; |
|---|
| 238 |
int metric_internal; |
|---|
| 239 |
|
|---|
| 240 |
OggzOrder order; |
|---|
| 241 |
void * order_user_data; |
|---|
| 242 |
|
|---|
| 243 |
union { |
|---|
| 244 |
OggzReader reader; |
|---|
| 245 |
OggzWriter writer; |
|---|
| 246 |
} x; |
|---|
| 247 |
|
|---|
| 248 |
OggzDList * packet_buffer; |
|---|
| 249 |
}; |
|---|
| 250 |
|
|---|
| 251 |
OGGZ * oggz_read_init (OGGZ * oggz); |
|---|
| 252 |
OGGZ * oggz_read_close (OGGZ * oggz); |
|---|
| 253 |
|
|---|
| 254 |
OGGZ * oggz_write_init (OGGZ * oggz); |
|---|
| 255 |
int oggz_write_flush (OGGZ * oggz); |
|---|
| 256 |
OGGZ * oggz_write_close (OGGZ * oggz); |
|---|
| 257 |
|
|---|
| 258 |
int oggz_map_return_value_to_error (int cb_ret); |
|---|
| 259 |
|
|---|
| 260 |
int oggz_get_bos (OGGZ * oggz, long serialno); |
|---|
| 261 |
ogg_int64_t oggz_get_unit (OGGZ * oggz, long serialno, ogg_int64_t granulepos); |
|---|
| 262 |
|
|---|
| 263 |
int oggz_set_metric_internal (OGGZ * oggz, long serialno, OggzMetric metric, |
|---|
| 264 |
void * user_data, int internal); |
|---|
| 265 |
int oggz_has_metrics (OGGZ * oggz); |
|---|
| 266 |
|
|---|
| 267 |
int oggz_purge (OGGZ * oggz); |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
int |
|---|
| 272 |
oggz_set_granulerate (OGGZ * oggz, long serialno, |
|---|
| 273 |
ogg_int64_t granule_rate_numerator, |
|---|
| 274 |
ogg_int64_t granule_rate_denominator); |
|---|
| 275 |
|
|---|
| 276 |
int |
|---|
| 277 |
oggz_get_granulerate (OGGZ * oggz, long serialno, |
|---|
| 278 |
ogg_int64_t * granulerate_n, |
|---|
| 279 |
ogg_int64_t * granulerate_d); |
|---|
| 280 |
|
|---|
| 281 |
int oggz_set_granuleshift (OGGZ * oggz, long serialno, int granuleshift); |
|---|
| 282 |
int oggz_get_granuleshift (OGGZ * oggz, long serialno); |
|---|
| 283 |
|
|---|
| 284 |
int oggz_set_preroll (OGGZ * oggz, long serialno, int preroll); |
|---|
| 285 |
int oggz_get_preroll (OGGZ * oggz, long serialno); |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
int |
|---|
| 290 |
oggz_auto_read_bos_page (OGGZ * oggz, ogg_page * og, long serialno, |
|---|
| 291 |
void * user_data); |
|---|
| 292 |
int |
|---|
| 293 |
oggz_auto_read_bos_packet (OGGZ * oggz, ogg_packet * op, long serialno, |
|---|
| 294 |
void * user_data); |
|---|
| 295 |
|
|---|
| 296 |
int |
|---|
| 297 |
oggz_auto_read_comments (OGGZ * oggz, oggz_stream_t * stream, long serialno, |
|---|
| 298 |
ogg_packet * op); |
|---|
| 299 |
|
|---|
| 300 |
int oggz_auto_identify_page (OGGZ *oggz, ogg_page *og, long serialno); |
|---|
| 301 |
int oggz_auto_identify_packet (OGGZ * oggz, ogg_packet * op, long serialno); |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
int oggz_comments_init (oggz_stream_t * stream); |
|---|
| 305 |
int oggz_comments_free (oggz_stream_t * stream); |
|---|
| 306 |
int oggz_comments_decode (OGGZ * oggz, long serialno, |
|---|
| 307 |
unsigned char * comments, long length); |
|---|
| 308 |
long oggz_comments_encode (OGGZ * oggz, long serialno, |
|---|
| 309 |
unsigned char * buf, long length); |
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
size_t oggz_io_read (OGGZ * oggz, void * buf, size_t n); |
|---|
| 313 |
size_t oggz_io_write (OGGZ * oggz, void * buf, size_t n); |
|---|
| 314 |
int oggz_io_seek (OGGZ * oggz, long offset, int whence); |
|---|
| 315 |
long oggz_io_tell (OGGZ * oggz); |
|---|
| 316 |
int oggz_io_flush (OGGZ * oggz); |
|---|
| 317 |
|
|---|
| 318 |
#endif |
|---|