Changeset 382
- Timestamp:
- 2004-02-05 03:14:02 (5 years ago)
- Files:
-
- liboggz/trunk/include/oggz/Makefile.am (modified) (1 diff)
- liboggz/trunk/include/oggz/oggz.h (modified) (1 diff)
- liboggz/trunk/include/oggz/oggz_constants.h (modified) (1 diff)
- liboggz/trunk/include/oggz/oggz_io.h (modified) (5 diffs)
- liboggz/trunk/src/liboggz/Makefile.am (modified) (1 diff)
- liboggz/trunk/src/liboggz/oggz.c (modified) (2 diffs)
- liboggz/trunk/src/liboggz/oggz_private.h (modified) (4 diffs)
- liboggz/trunk/src/liboggz/oggz_read.c (modified) (7 diffs)
- liboggz/trunk/src/liboggz/oggz_write.c (modified) (2 diffs)
- liboggz/trunk/src/tests/Makefile.am (modified) (2 diffs)
- liboggz/trunk/src/tests/oggz_tests.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
liboggz/trunk/include/oggz/Makefile.am
r346 r382 3 3 # Include files to install 4 4 includedir = $(prefix)/include/oggz 5 include_HEADERS = oggz.h oggz_constants.h oggz_ table.h5 include_HEADERS = oggz.h oggz_constants.h oggz_io.h oggz_table.h 6 6 liboggz/trunk/include/oggz/oggz.h
r372 r382 1095 1095 long oggz_serialno_new (OGGZ * oggz); 1096 1096 1097 #include <oggz/oggz_io.h> 1097 1098 1098 1099 #endif /* __OGGZ_H__ */ liboggz/trunk/include/oggz/oggz_constants.h
r346 r382 62 62 * once all bos pages have been delivered. */ 63 63 OGGZ_AUTO = 0x20 64 }; 65 66 enum OggzStopCtl { 67 /** Continue calling read callbacks */ 68 OGGZ_CONTINUE = 0, 69 70 /** Stop calling callbacks, but retain buffered packet data */ 71 OGGZ_STOP_OK = 1, 72 73 /** Stop calling callbacks, and purge buffered packet data */ 74 OGGZ_STOP_ERR = -1 64 75 }; 65 76 liboggz/trunk/include/oggz/oggz_io.h
r373 r382 63 63 * \retval "< 0" An error condition 64 64 */ 65 typedef long (*OggzIORead) (void * user_handle, void * buf, longn);65 typedef size_t (*OggzIORead) (void * user_handle, void * buf, size_t n); 66 66 67 67 /** … … 76 76 * \retval "< 0" An error condition 77 77 */ 78 typedef long (*OggzIOWrite) (void * user_handle, void * buf, longn);78 typedef size_t (*OggzIOWrite) (void * user_handle, void * buf, size_t n); 79 79 80 80 /** … … 87 87 * \retval ">= 0" The offset seeked to 88 88 * \retval "< 0" An error condition 89 */ 90 typedef off_t (*OggzIOSeek) (void * user_handle, off_t offset, int whence); 89 * 90 * \note If you provide an OggzIOSeek function, you MUST also provide 91 * an OggzIOTell function, or else all your seeks will fail. 92 */ 93 typedef int (*OggzIOSeek) (void * user_handle, long offset, int whence); 91 94 92 95 /** … … 99 102 * \retval "< 0" An error condition 100 103 */ 101 typedef off_t(*OggzIOTell) (void * user_handle);104 typedef long (*OggzIOTell) (void * user_handle); 102 105 103 106 /** … … 166 169 * \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ 167 170 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ 171 * 172 * \note If you provide an OggzIOSeek function, you MUST also provide 173 * an OggzIOTell function, or else all your seeks will fail. 168 174 */ 169 175 int oggz_io_set_seek (OGGZ * oggz, OggzIOSeek seek, void * user_handle); liboggz/trunk/src/liboggz/Makefile.am
r355 r382 13 13 oggz.c \ 14 14 oggz_private.h oggz_byteorder.h oggz_compat.h oggz_macros.h \ 15 oggz_io.c \ 15 16 oggz_read.c oggz_write.c \ 16 17 oggz_auto.c oggz_auto.h \ liboggz/trunk/src/liboggz/oggz.c
r355 r382 80 80 oggz->flags = flags; 81 81 oggz->file = NULL; 82 oggz->io = NULL; 82 83 83 84 oggz->offset = 0; … … 142 143 if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ; 143 144 144 if (oggz->file == NULL) return OGGZ_ERR_INVALID; 145 146 if (fflush (oggz->file) == EOF) { 147 return OGGZ_ERR_SYSTEM; 148 } 149 150 return 0; 145 return oggz_io_flush (oggz); 151 146 } 152 147 liboggz/trunk/src/liboggz/oggz_private.h
r372 r382 43 43 44 44 typedef struct _OGGZ OGGZ; 45 typedef struct _OggzIO OggzIO; 45 46 typedef struct _OggzReader OggzReader; 46 47 typedef struct _OggzWriter OggzWriter; … … 57 58 58 59 typedef int (*OggzWriteHungry) (OGGZ * oggz, int empty, void * user_data); 60 61 /* oggz_io */ 62 typedef size_t (*OggzIORead) (void * user_handle, void * buf, size_t n); 63 typedef size_t (*OggzIOWrite) (void * user_handle, void * buf, size_t n); 64 typedef int (*OggzIOSeek) (void * user_handle, long offset, int whence); 65 typedef long (*OggzIOTell) (void * user_handle); 66 typedef int (*OggzIOFlush) (void * user_handle); 59 67 60 68 typedef struct { … … 140 148 }; 141 149 150 struct _OggzIO { 151 OggzIORead read; 152 void * read_user_handle; 153 154 OggzIOWrite write; 155 void * write_user_handle; 156 157 OggzIOSeek seek; 158 void * seek_user_handle; 159 160 OggzIOTell tell; 161 void * tell_user_handle; 162 163 OggzIOFlush flush; 164 void * flush_user_handle; 165 }; 166 142 167 struct _OGGZ { 143 168 int flags; 144 169 FILE * file; 170 OggzIO * io; 145 171 146 172 ogg_packet current_packet; … … 185 211 int oggz_auto (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data); 186 212 213 /* oggz_io */ 214 size_t oggz_io_read (OGGZ * oggz, void * buf, size_t n); 215 size_t oggz_io_write (OGGZ * oggz, void * buf, size_t n); 216 int oggz_io_seek (OGGZ * oggz, long offset, int whence); 217 long oggz_io_tell (OGGZ * oggz); 218 int oggz_io_flush (OGGZ * oggz); 219 187 220 #endif /* __OGGZ_PRIVATE_H__ */ liboggz/trunk/src/liboggz/oggz_read.c
r381 r382 158 158 #if _UMMODIFIED_ 159 159 buffer = ogg_sync_buffer (&reader->ogg_sync, CHUNKSIZE); 160 if ((bytes = fread (buffer, 1, CHUNKSIZE, oggz->file)) == 0) {160 if ((bytes = oggz_io_read (oggz, buffer, CHUNKSIZE)) == 0) { 161 161 if (ferror (oggz->file)) { 162 162 oggz_set_error (oggz, OGGZ_ERR_SYSTEM); … … 189 189 /* Calculate the byte offset of the page which was found */ 190 190 if (bytes > 0) { 191 oggz->offset = ftell (oggz->file) - bytes + page_offset;191 oggz->offset = oggz_io_tell (oggz) - bytes + page_offset; 192 192 ret = oggz->offset; 193 193 } else { … … 276 276 } 277 277 278 /* If we've got a stop already, don't read more data in */ 279 if (cb_ret != 0) return cb_ret; 280 278 281 if(oggz_get_next_page_7 (oggz, &og) < 0) 279 282 return -404; /* eof. leave unitialized */ … … 349 352 bytes = MIN (remaining, 4096); 350 353 buffer = ogg_sync_buffer (&reader->ogg_sync, bytes); 351 if ((bytes_read = (long) fread (buffer, 1, bytes, oggz->file)) == 0) {354 if ((bytes_read = (long) oggz_io_read (oggz, buffer, bytes)) == 0) { 352 355 353 356 if (ferror (oggz->file)) { … … 433 436 oggz_off_t offset_at; 434 437 435 offset_at = ftell (oggz->file);438 offset_at = oggz_io_tell (oggz); 436 439 437 440 return offset_at; … … 447 450 oggz_off_t offset_at; 448 451 449 if (fseek (oggz->file, offset, whence) == -1) { 450 if (errno == ESPIPE) { 451 /*oggz_set_error (oggz, OGGZ_ERR_NOSEEK);*/ 452 } else { 453 /*oggz_set_error (oggz, OGGZ_ERR_SYSTEM);*/ 454 } 455 return -1; 456 } 457 458 offset_at = ftell (oggz->file); 452 if (oggz_io_seek (oggz, offset, whence) == -1) { 453 return -1; 454 } 455 456 offset_at = oggz_io_tell (oggz); 459 457 460 458 oggz->offset = offset_at; … … 555 553 556 554 buffer = ogg_sync_buffer (&reader->ogg_sync, CHUNKSIZE); 557 if ((bytes = (long) fread (buffer, 1, CHUNKSIZE, oggz->file)) == 0) {555 if ((bytes = (long) oggz_io_read (oggz, buffer, CHUNKSIZE)) == 0) { 558 556 if (ferror (oggz->file)) { 559 557 /*oggz_set_error (oggz, OGGZ_ERR_SYSTEM);*/ liboggz/trunk/src/liboggz/oggz_write.c
r355 r382 456 456 nwritten = write (fd, og->header + writer->page_offset, h); 457 457 #else 458 nwritten = (long)fwrite (og->header + writer->page_offset, 1, h, oggz->file); 459 #endif 458 nwritten = (long)oggz_io_write (oggz, og->header + writer->page_offset, h); 459 #endif 460 461 #ifdef DEBUG 460 462 if (nwritten < h) { 461 463 printf ("oggz_page_writeout: %ld < %ld\n", nwritten, h); 462 464 } 465 #endif 463 466 writer->page_offset += h; 464 467 n -= h; … … 473 476 og->body + (writer->page_offset - og->header_len), b); 474 477 #else 475 nwritten = (long) fwrite (og->body + (writer->page_offset - og->header_len),476 1, b, oggz->file); 477 # endif478 nwritten = (long)oggz_io_write (oggz, og->body + (writer->page_offset - og->header_len), b); 479 #endif 480 #ifdef DEBUG 478 481 if (nwritten < b) { 479 482 printf ("oggz_page_writeout: %ld < %ld\n", nwritten, b); 480 483 } 484 #endif 481 485 writer->page_offset += b; 482 486 n -= b; liboggz/trunk/src/tests/Makefile.am
r343 r382 18 18 endif 19 19 20 TESTS = $(write_tests) 20 if OGGZ_CONFIG_READ 21 if OGGZ_CONFIG_WRITE 22 rw_tests = read-generated read-stop-ok read-stop-err \ 23 io-read io-seek io-write 24 endif 25 endif 26 27 TESTS = $(write_tests) $(rw_tests) 21 28 22 29 noinst_PROGRAMS = $(TESTS) … … 49 56 write_bad_packetno_SOURCES = write-bad-packetno.c 50 57 write_bad_packetno_LDADD = $(OGGZ_LIBS) 58 59 read_generated_SOURCES = read-generated.c 60 read_generated_LDADD = $(OGGZ_LIBS) 61 62 read_stop_ok_SOURCES = read-stop-ok.c 63 read_stop_ok_LDADD = $(OGGZ_LIBS) 64 65 read_stop_err_SOURCES = read-stop-err.c 66 read_stop_err_LDADD = $(OGGZ_LIBS) 67 68 io_read_SOURCES = io-read.c 69 io_read_LDADD = $(OGGZ_LIBS) 70 71 io_seek_SOURCES = io-seek.c 72 io_seek_LDADD = $(OGGZ_LIBS) 73 74 io_write_SOURCES = io-write.c 75 io_write_LDADD = $(OGGZ_LIBS) liboggz/trunk/src/tests/oggz_tests.h
r343 r382 31 31 */ 32 32 33 #include "config.h" 34 33 35 #include <stdio.h> 34 36 #include <stdlib.h> 37 38 #ifdef HAVE_INTTYPES_H 39 # include <inttypes.h> 40 #else 41 # define PRId64 "I64d" 42 #endif 43 44 /* FIXME: on Mac OS X, off_t is 64-bits. Obviously we want a nicer 45 * way to do it than this, but a quick fix is a good fix */ 46 #ifdef __APPLE__ 47 # define PRI_off_t "q" 48 #else 49 # define PRI_off_t "l" 50 #endif 35 51 36 52 #define INFO(str) \ … … 42 58 #define FAIL(str) \ 43 59 { printf ("%s:%d: %s\n", __FILE__, __LINE__, (str)); exit(1); } 60 61 #undef MIN 62 #define MIN(a,b) ((a)<(b)?(a):(b))