Changeset 2339
- Timestamp:
- 2006-06-18 23:08:03 (2 years ago)
- Files:
-
- liboggz/trunk/include/oggz/oggz_constants.h (modified) (1 diff)
- liboggz/trunk/include/oggz/oggz_read.h (modified) (1 diff)
- liboggz/trunk/src/liboggz/Makefile.am (modified) (1 diff)
- liboggz/trunk/src/liboggz/Version_script.in (modified) (1 diff)
- liboggz/trunk/src/liboggz/oggz_auto.c (modified) (12 diffs)
- liboggz/trunk/src/liboggz/oggz_auto.h (modified) (1 diff)
- liboggz/trunk/src/liboggz/oggz_private.h (modified) (3 diffs)
- liboggz/trunk/src/liboggz/oggz_read.c (modified) (2 diffs)
- liboggz/trunk/src/liboggz/oggz_stream.c (modified) (2 diffs)
- liboggz/trunk/src/liboggz/oggz_stream.h (modified) (2 diffs)
- liboggz/trunk/src/liboggz/oggz_write.c (modified) (1 diff)
- liboggz/trunk/src/tools/oggz-scan.c (modified) (1 diff)
- liboggz/trunk/src/tools/oggz-validate.c (modified) (1 diff)
- liboggz/trunk/src/tools/oggz_tools.c (modified) (2 diffs)
- liboggz/trunk/src/tools/oggz_tools.h (modified) (1 diff)
- liboggz/trunk/src/tools/oggzdump.c (modified) (1 diff)
- liboggz/trunk/src/tools/oggzinfo.c (modified) (2 diffs)
- liboggz/trunk/src/tools/oggzmerge.c (modified) (1 diff)
- liboggz/trunk/src/tools/oggzrip.c (modified) (3 diffs)
- liboggz/trunk/win32/liboggz.def (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
liboggz/trunk/include/oggz/oggz_constants.h
r2015 r2339 98 98 99 99 /** 100 * Definition of stream content types 101 */ 102 typedef enum OggzStreamContent { 103 OGGZ_CONTENT_THEORA = 0, 104 OGGZ_CONTENT_VORBIS, 105 OGGZ_CONTENT_SPEEX, 106 OGGZ_CONTENT_PCM, 107 OGGZ_CONTENT_CMML, 108 OGGZ_CONTENT_ANX2, 109 OGGZ_CONTENT_SKELETON, 110 OGGZ_CONTENT_FLAC0, 111 OGGZ_CONTENT_FLAC, 112 OGGZ_CONTENT_ANXDATA, 113 OGGZ_CONTENT_UNKNOWN 114 } OggzStreamContent; 115 116 /** 100 117 * Definitions of error return values 101 118 */ liboggz/trunk/include/oggz/oggz_read.h
r2028 r2339 182 182 int oggz_purge (OGGZ * oggz); 183 183 184 /** 185 * Determine the content type of the oggz stream referred to by \a serialno 186 * 187 * \param oggz An OGGZ handle 188 * \param serialno An ogg stream serialno 189 * \retval OGGZ_CONTENT_THEORA..OGGZ_CONTENT_UNKNOWN content successfully 190 * identified 191 * \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ 192 * \retval OGGZ_ERR_BAD_SERIALNO \a serialno does not refer to an existing 193 * stream 194 */ 195 OggzStreamContent oggz_stream_get_content (OGGZ * oggz, long serialno); 196 197 /** 198 * Return human-readable string representation of content type of oggz stream 199 * referred to by \a serialno 200 * 201 * \param oggz An OGGZ handle 202 * \param serialno An ogg stream serialno 203 * \retval string the name of the content type 204 * \retval NULL \a oggz or \a serialno invalid 205 */ 206 const char * oggz_stream_get_content_type (OGGZ *oggz, long serialno); 207 184 208 #endif /* __OGGZ_READ_H__ */ liboggz/trunk/src/liboggz/Makefile.am
r835 r2339 20 20 oggz_table.c \ 21 21 oggz_vector.c oggz_vector.h \ 22 metric_internal.c 22 metric_internal.c 23 23 24 24 liboggz_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ @SHLIB_VERSION_ARG@ liboggz/trunk/src/liboggz/Version_script.in
r2027 r2339 57 57 oggz_io_get_flush_user_handle; 58 58 59 oggz_stream_get_content; 60 oggz_stream_get_content_type; 61 59 62 oggz_table_new; 60 63 oggz_table_delete; liboggz/trunk/src/liboggz/oggz_auto.c
r2062 r2339 74 74 if (op->bytes < 68) return 0; 75 75 76 if (strncmp ((char *)header, "Speex ", 8)) return 0;77 if (!op->b_o_s) return 0;78 79 76 granule_rate = (ogg_int64_t) INT32_LE_AT(&header[36]); 80 77 #ifdef DEBUG … … 94 91 95 92 if (op->bytes < 30) return 0; 96 97 if (header[0] != 0x01) return 0;98 if (strncmp ((char *)&header[1], "vorbis", 6)) return 0;99 if (!op->b_o_s) return 0;100 93 101 94 granule_rate = (ogg_int64_t) INT32_LE_AT(&header[12]); … … 130 123 if (op->bytes < 41) return 0; 131 124 132 if (header[0] != 0x80) return 0;133 if (strncmp ((char *)&header[1], "theora", 6)) return 0;134 if (!op->b_o_s) return 0;135 136 125 fps_numerator = INT32_BE_AT(&header[22]); 137 126 fps_denominator = INT32_BE_AT(&header[26]); … … 168 157 auto_annodex (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) 169 158 { 170 unsigned char * header = op->packet;171 172 if (op->bytes < 8) return 0;173 174 if (strncmp ((char *)header, "Annodex", 8)) return 0;175 if (!op->b_o_s) return 0;176 177 159 /* Apply a zero metric */ 178 160 oggz_set_granulerate (oggz, serialno, 0, 1); … … 188 170 189 171 if (op->bytes < 28) return 0; 190 191 if (strncmp ((char *)header, "AnxData", 8)) return 0;192 if (!op->b_o_s) return 0;193 172 194 173 granule_rate_numerator = INT64_LE_AT(&header[8]); … … 210 189 { 211 190 unsigned char * header = op->packet; 212 int content;213 191 ogg_int64_t granule_rate = 0; 214 192 215 if (op->b_o_s) { 216 if (op->bytes < 4) return 0; 217 if (strncmp ((char *)header, "fLaC", 4)) return 0; 218 oggz_stream_set_content (oggz, serialno, OGGZ_CONTENT_FLAC0); 219 } else { 220 content = oggz_stream_get_content (oggz, serialno); 221 if (content != OGGZ_CONTENT_FLAC0) return 0; 222 223 granule_rate = (ogg_int64_t) (header[14] << 12) | (header[15] << 4) | ((header[16] >> 4)&0xf); 193 granule_rate = (ogg_int64_t) (header[14] << 12) | (header[15] << 4) | 194 ((header[16] >> 4)&0xf); 224 195 #ifdef DEBUG 225 196 printf ("Got flac rate %d\n", (int)granule_rate); 226 197 #endif 227 198 228 oggz_set_granulerate (oggz, serialno, granule_rate, OGGZ_AUTO_MULT); 229 } 199 oggz_set_granulerate (oggz, serialno, granule_rate, OGGZ_AUTO_MULT); 230 200 231 201 return 1; … … 240 210 if (op->bytes < 51) return 0; 241 211 242 if (header[0] != 0x7f) return 0; 243 if (strncmp ((char *)&header[1], "FLAC", 4)) return 0; 244 if (!op->b_o_s) return 0; 245 246 granule_rate = (ogg_int64_t) (header[27] << 12) | (header[28] << 4) | ((header[29] >> 4)&0xf); 212 granule_rate = (ogg_int64_t) (header[27] << 12) | (header[28] << 4) | 213 ((header[29] >> 4)&0xf); 247 214 #ifdef DEBUG 248 215 printf ("Got flac rate %d\n", (int)granule_rate); … … 266 233 if (op->bytes < 28) return 0; 267 234 268 if (strncmp ((char *)header, "PCM ", 8)) return 0;269 if (!op->b_o_s) return 0;270 271 235 granule_rate = (ogg_int64_t) INT32_BE_AT(&header[16]); 272 236 #ifdef DEBUG … … 287 251 288 252 if (op->bytes < 28) return 0; 289 290 if (strncmp ((char *)header, "CMML", 4)) return 0;291 if (!op->b_o_s) return 0;292 253 293 254 granule_rate_numerator = INT64_LE_AT(&header[12]); … … 312 273 313 274 static int 314 auto_fishead (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)315 {316 unsigned char * header = op->packet;317 int content;318 319 if (op->b_o_s) {320 if (op->bytes < 8) return 0;321 if (strncmp ((char *)header, "fishead", 8)) return 0;322 oggz_stream_set_content (oggz, serialno, OGGZ_CONTENT_SKELETON);323 } else if (op->e_o_s) {324 content = oggz_stream_get_content (oggz, serialno);325 if (content != OGGZ_CONTENT_SKELETON) return 0;326 327 /* Finished processing the skeleton; apply a zero metric */328 oggz_set_granulerate (oggz, serialno, 0, 1);329 }330 331 return 1;332 }333 334 static int335 275 auto_fisbone (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) 336 276 { 337 int content;338 277 unsigned char * header = op->packet; 339 278 long fisbone_serialno; /* The serialno referred to in this fisbone */ … … 342 281 343 282 if (op->bytes < 48) return 0; 344 345 if (strncmp ((char *)header, "fisbone", 7)) return 0;346 content = oggz_stream_get_content (oggz, serialno);347 if (content != OGGZ_CONTENT_SKELETON) return 0;348 283 349 284 fisbone_serialno = (long) INT32_LE_AT(&header[12]); … … 370 305 } 371 306 372 static const OggzReadPacket auto_readers[] = { 373 auto_speex, 374 auto_vorbis, 375 auto_theora, 376 auto_annodex, 377 auto_anxdata, 378 auto_flac0, 379 auto_flac, 380 auto_cmml, 381 auto_fishead, 382 auto_fisbone, 383 auto_oggpcm2, 384 NULL 385 }; 307 static int 308 auto_fishead (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) 309 { 310 if (!op->b_o_s) 311 { 312 return auto_fisbone(oggz, op, serialno, user_data); 313 } 314 315 oggz_set_granulerate (oggz, serialno, 0, 1); 316 317 return 1; 318 } 319 320 const oggz_auto_contenttype_t oggz_auto_codec_ident[] = { 321 {"\200theora", 7, "Theora", auto_theora}, 322 {"\001vorbis", 7, "Vorbis", auto_vorbis}, 323 {"Speex", 5, "Speex", auto_speex}, 324 {"PCM ", 8, "PCM", auto_oggpcm2}, 325 {"CMML\0\0\0\0", 8, "CMML", auto_cmml}, 326 {"Annodex", 8, "Annodex", auto_annodex}, 327 {"fishead", 7, "Skeleton", auto_fishead}, 328 {"fLaC", 4, "Flac0", auto_flac0}, 329 {"\177FLAC", 4, "Flac", auto_flac}, 330 {"AnxData", 7, "AnxData", auto_anxdata}, 331 {"", 0, "Unknown"} 332 }; 333 334 int oggz_auto_identify (OGGZ *oggz, ogg_page *og, long serialno) { 335 336 int i; 337 338 for (i = 0; i < OGGZ_CONTENT_UNKNOWN; i++) 339 { 340 const oggz_auto_contenttype_t *codec = oggz_auto_codec_ident + i; 341 342 if (og->body_len >= codec->bos_str_len && 343 memcmp (og->body, codec->bos_str, codec->bos_str_len) == 0) { 344 345 oggz_stream_set_content (oggz, serialno, i); 346 347 return 1; 348 } 349 } 350 351 oggz_stream_set_content (oggz, serialno, OGGZ_CONTENT_UNKNOWN); 352 return 0; 353 } 386 354 387 355 int 388 oggz_auto (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) 356 oggz_auto_get_granulerate (OGGZ * oggz, ogg_packet * op, long serialno, 357 void * user_data) 389 358 { 390 359 OggzReadPacket read_packet; 391 int i = 0; 392 393 for (read_packet = auto_readers[0]; read_packet; 394 read_packet = auto_readers[++i]) { 395 if (read_packet (oggz, op, serialno, user_data)) return 0; 360 int content = 0; 361 int will_run_function; 362 363 content = oggz_stream_get_content(oggz, serialno); 364 if (content < 0 || content >= OGGZ_CONTENT_UNKNOWN) { 365 return 0; 396 366 } 397 367 368 oggz_auto_codec_ident[content].reader(oggz, op, serialno, user_data); 398 369 return 0; 399 370 } liboggz/trunk/src/liboggz/oggz_auto.h
r2062 r2339 389 389 */ 390 390 391 int oggz_auto_identify (OGGZ *oggz, ogg_page *og, long serialno); 392 391 393 #endif /* __OGGZ_AUTO_H__ */ liboggz/trunk/src/liboggz/oggz_private.h
r2027 r2339 48 48 typedef struct _OggzWriter OggzWriter; 49 49 50 /* oggz_stream */51 #include "oggz_stream.h"52 50 53 51 typedef int (*OggzReadPacket) (OGGZ * oggz, ogg_packet * op, long serialno, … … 55 53 typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og, long serialno, 56 54 void * user_data); 55 56 /* oggz_stream */ 57 #include "oggz_stream.h" 57 58 58 59 typedef ogg_int64_t (*OggzMetric) (OGGZ * oggz, long serialno, … … 236 237 int oggz_purge (OGGZ * oggz); 237 238 238 int oggz_auto (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data); 239 int oggz_auto_get_granulerate (OGGZ * oggz, ogg_packet * op, long serialno, 240 void * user_data); 239 241 240 242 /* oggz_io */ liboggz/trunk/src/liboggz/oggz_read.c
r2106 r2339 294 294 granulepos = op->granulepos; 295 295 296 if (!stream->metric && (oggz->flags & OGGZ_AUTO)) { 297 oggz_auto (oggz, op, serialno, NULL); 296 /* 297 * need to call oggz_auto to process Anx v2 streams which were headed 298 * with AnxData packets. This enables the AnxData-provided granulerate 299 * to be overridden by the stream's rate if present 300 */ 301 if 302 ( 303 ( 304 !stream->metric 305 || 306 (oggz_stream_get_content(oggz, serialno) == OGGZ_CONTENT_SKELETON) 307 ) 308 && 309 (oggz->flags & OGGZ_AUTO) 310 ) 311 { 312 oggz_auto_get_granulerate (oggz, op, serialno, NULL); 298 313 } 299 314 … … 333 348 return -7; 334 349 } 335 } 350 351 /* identify stream type */ 352 oggz_auto_identify(oggz, &og, serialno); 353 } 354 else if (oggz_stream_get_content(oggz, serialno) == OGGZ_CONTENT_ANXDATA) 355 { 356 /* 357 * re-identify ANXDATA streams as these are now content streams 358 */ 359 oggz_auto_identify(oggz, &og, serialno); 360 } 361 336 362 os = &stream->ogg_stream; 337 363 liboggz/trunk/src/liboggz/oggz_stream.c
r714 r2339 48 48 } 49 49 50 int50 OggzStreamContent 51 51 oggz_stream_get_content (OGGZ * oggz, long serialno) 52 52 { 53 53 oggz_stream_t * stream; 54 54 55 if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ; 56 55 57 stream = oggz_get_stream (oggz, serialno); 56 58 if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO; … … 58 60 return stream->content; 59 61 } 62 63 const char * 64 oggz_stream_get_content_type (OGGZ *oggz, long serialno) 65 { 66 int content = oggz_stream_get_content(oggz, serialno); 67 68 if (content == OGGZ_ERR_BAD_SERIALNO || content == OGGZ_ERR_BAD_OGGZ) 69 { 70 return NULL; 71 } 72 73 return oggz_auto_codec_ident[content].content_type; 74 } liboggz/trunk/src/liboggz/oggz_stream.h
r826 r2339 34 34 #define __OGGZ_STREAM_H__ 35 35 36 enum { 37 OGGZ_CONTENT_UNKNOWN = 0, 38 OGGZ_CONTENT_SKELETON = 1, 39 OGGZ_CONTENT_FLAC0 = 13 40 }; 36 typedef struct { 37 const char *bos_str; 38 int bos_str_len; 39 const char *content_type; 40 OggzReadPacket reader; 41 } oggz_auto_contenttype_t; 42 43 extern const oggz_auto_contenttype_t oggz_auto_codec_ident[]; 41 44 42 45 typedef struct _oggz_stream_t oggz_stream_t; … … 47 50 int oggz_stream_has_metric (OGGZ * oggz, long serialno); 48 51 int oggz_stream_set_content (OGGZ * oggz, long serialno, int content); 49 int oggz_stream_get_content (OGGZ * oggz, long serialno); 52 OggzStreamContent oggz_stream_get_content (OGGZ * oggz, long serialno); 53 const char * oggz_stream_get_content_type (OGGZ *oggz, long serialno); 50 54 51 55 #endif /* __OGGZ_STREAM_H__ */ liboggz/trunk/src/liboggz/oggz_write.c
r2016 r2339 278 278 279 279 if (!stream->metric && (oggz->flags & OGGZ_AUTO)) { 280 oggz_auto (oggz, op, serialno, NULL);280 oggz_auto_get_granulerate (oggz, op, serialno, NULL); 281 281 } 282 282 liboggz/trunk/src/tools/oggz-scan.c
r2121 r2339 109 109 /* set scanning callback for keyframe calculation on theora pages only */ 110 110 if (osdata->keyframes && ogg_page_bos ((ogg_page *)og)) { 111 ident = ot_page_identify (og , NULL);111 ident = ot_page_identify (oggz, og, NULL); 112 112 if (ident && (strcasecmp ("theora", ident) == 0)) { 113 113 oggz_set_read_callback (oggz, serialno, osdata->read_packet, osdata); liboggz/trunk/src/tools/oggz-validate.c
r2065 r2339 174 174 175 175 if (ogg_page_bos ((ogg_page *)og)) { 176 content_type = ot_page_identify (og , NULL);176 content_type = ot_page_identify (oggz, og, NULL); 177 177 178 178 if (content_type) { liboggz/trunk/src/tools/oggz_tools.c
r2121 r2339 116 116 typedef char * (* OTCodecInfoFunc) (unsigned char * data, long n); 117 117 118 typedef struct {119 const char *bos_str;120 int bos_str_len;121 const char *content_type;122 OTCodecInfoFunc info_func;123 } OTCodecIdent;124 125 118 static char * 126 119 ot_theora_info (unsigned char * data, long len) … … 210 203 } 211 204 212 static const OTCodecIdent codec_ident[] = { 213 {"\200theora", 7, "Theora", ot_theora_info}, 214 {"\001vorbis", 7, "Vorbis", ot_vorbis_info}, 215 {"Speex", 5, "Speex", ot_speex_info}, 216 {"PCM ", 8, "PCM", ot_oggpcm2_info}, 217 {"CMML\0\0\0\0", 8, "CMML", NULL}, 218 {"Annodex", 8, "Annodex", NULL}, 219 {"fishead", 8, "Skeleton", ot_skeleton_info}, 220 {NULL} 205 static const OTCodecInfoFunc codec_ident[] = { 206 ot_theora_info, 207 ot_vorbis_info, 208 ot_speex_info, 209 ot_oggpcm2_info, 210 NULL, /* CMML */ 211 NULL, /* ANNODEX */ 212 ot_skeleton_info, 213 NULL, /* FLAC0 */ 214 NULL, /* FLAC */ 215 NULL, /* ANXDATA */ 216 NULL /* UNKOWN */ 221 217 }; 222 218 223 219 const char * 224 ot_page_identify ( const ogg_page * og, char ** info)220 ot_page_identify (OGGZ *oggz, const ogg_page * og, char ** info) 225 221 { 226 222 const char * ret = NULL; 227 int i; 228 229 /* try to identify stream codec name by looking at the first bytes of the 230 * first packet */ 231 for (i = 0;; i++) { 232 const OTCodecIdent *ident = &codec_ident[i]; 233 234 if (ident->bos_str == NULL) { 235 ret = NULL; 236 break; 237 } 238 239 if (og->body_len >= ident->bos_str_len && 240 memcmp (og->body, ident->bos_str, ident->bos_str_len) == 0) { 241 ret = ident->content_type; 242 if (info) { 243 if (ident->info_func) { 244 *info = ident->info_func (og->body, og->body_len); 245 } else { 246 *info = NULL; 247 } 248 } 249 break; 223 int serial_no; 224 int content; 225 226 /* 227 * identify stream content using oggz_stream_get_content, identify 228 * stream content name using oggz_stream_get_content_type 229 */ 230 231 serial_no = ogg_page_serialno(og); 232 233 content = oggz_stream_get_content(oggz, serial_no); 234 ret = oggz_stream_get_content_type(oggz, serial_no); 235 236 if (info != NULL) 237 { 238 if (codec_ident[content] != NULL) 239 { 240 *info = codec_ident[content](og->body, og->body_len); 250 241 } 251 242 } liboggz/trunk/src/tools/oggz_tools.h
r1187 r2339 37 37 38 38 const char * 39 ot_page_identify ( const ogg_page * og, char ** info);39 ot_page_identify (OGGZ *oggz, const ogg_page * og, char ** info); 40 40 41 41 /* liboggz/trunk/src/tools/oggzdump.c
r2121 r2339 312 312 313 313 if (ogg_page_bos ((ogg_page *)og)) { 314 ident = ot_page_identify (og , NULL);314 ident = ot_page_identify (oggz, og, NULL); 315 315 if (ident) { 316 316 n = oggz_table_size (oddata->content_types_table); liboggz/trunk/src/tools/oggzinfo.c
r2066 r2339 275 275 276 276 if (ogg_page_bos ((ogg_page *)og)) { 277 oit->codec_name = ot_page_identify (og , &oit->codec_info);277 oit->codec_name = ot_page_identify (oggz, og, &oit->codec_info); 278 278 } 279 279 … … 338 338 OI_TrackInfo * oit; 339 339 long deviation; 340 340 341 341 oit = oggz_table_lookup (info->tracks, serialno); 342 342 liboggz/trunk/src/tools/oggzmerge.c
r2066 r2339 220 220 int is_vorbis = 0; 221 221 222 if ((codec_name = ot_page_identify (input->og, NULL)) != NULL) 222 if ((codec_name = 223 ot_page_identify (input->reader, input->og, NULL)) != NULL) 223 224 is_vorbis = !strcmp (codec_name, "Vorbis"); 224 225 liboggz/trunk/src/tools/oggzrip.c
r2121 r2339 167 167 168 168 static ORStream * 169 orstream_new (const ORData *ordata, const ogg_page *og, long serialno) 169 orstream_new (OGGZ *oggz, const ORData *ordata, const ogg_page *og, 170 long serialno) 170 171 { 171 172 const char * ident; … … 178 179 stream->content_type = "unknown"; 179 180 180 ident = ot_page_identify (og , NULL);181 ident = ot_page_identify (oggz, og, NULL); 181 182 if (ident != NULL) stream->content_type = ident; 182 183 … … 234 235 235 236 if (ogg_page_bos ((ogg_page *)og)) { 236 stream = orstream_new (o rdata, og, serialno);237 stream = orstream_new (oggz, ordata, og, serialno); 237 238 stream = oggz_table_insert (ordata->streams, serialno, stream); 238 239 assert (stream != NULL); liboggz/trunk/win32/liboggz.def
r2123 r2339 82 82 oggz_table_nth @48 83 83 84 ; 85 ;oggz stream functions (determining content type) 86 ; 87 oggz_stream_get_content @100 88 oggz_stream_get_content_type @101