diff --git a/src/liboggz/oggz.c b/src/liboggz/oggz.c index ad33217a5505ca07fc43059e084600a76f960351..b983391d37db018d2e583977ebace1122c46413f 100644 --- a/src/liboggz/oggz.c +++ b/src/liboggz/oggz.c @@ -449,6 +449,24 @@ oggz_set_metric_linear (OGGZ * oggz, long serialno, linear_data, 1); } +/* + * Check if a stream in an oggz has a metric + */ +int +oggz_stream_has_metric (OGGZ * oggz, long serialno) +{ + oggz_stream_t * stream; + + if (oggz->metric != NULL) return 1; + + stream = oggz_get_stream (oggz, serialno); + if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO; + + if (stream->metric != NULL) return 1; + + return 0; +} + /* * Check if an oggz has metrics for all streams */ diff --git a/src/liboggz/oggz_auto.c b/src/liboggz/oggz_auto.c index aff898e84b081fafd632046de65b2c825e4c901a..18c97251c3ec3f87be9a66245e0fa4011009a600 100644 --- a/src/liboggz/oggz_auto.c +++ b/src/liboggz/oggz_auto.c @@ -42,10 +42,11 @@ #include #include -#include "oggz_private.h" +#include #include "oggz_auto.h" #include "oggz_byteorder.h" #include "oggz_macros.h" +#include "oggz_stream.h" /* Allow use of internal metrics; ie. the user_data for these gets free'd * when the metric is overwritten, or on close */ @@ -299,7 +300,6 @@ auto_fisbone (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) { unsigned char * header = op->packet; long fisbone_serialno; /* The serialno referred to in this fisbone */ - oggz_stream_t * fisbone_stream; /* The stream of that serialno */ ogg_int64_t granule_rate_numerator = 0, granule_rate_denominator = 0; if (op->bytes < 48) return 0; @@ -307,10 +307,9 @@ auto_fisbone (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) if (strncmp ((char *)header, "fisbone", 7)) return 0; fisbone_serialno = (long) INT32_LE_AT(&header[12]); - fisbone_stream = oggz_get_stream (oggz, fisbone_serialno); /* Don't override an already assigned metric */ - if (fisbone_stream->metric) return 1; + if (oggz_stream_has_metric (oggz, fisbone_serialno)) return 1; granule_rate_numerator = INT64_LE_AT(&header[20]); granule_rate_denominator = INT64_LE_AT(&header[28]); diff --git a/src/liboggz/oggz_private.h b/src/liboggz/oggz_private.h index c3cf39d9adf066b9137cb0c694d55ebf00b77f79..ff4c9bbe55abcb45e7722a93936ad8a558292fe9 100644 --- a/src/liboggz/oggz_private.h +++ b/src/liboggz/oggz_private.h @@ -47,6 +47,9 @@ typedef struct _OggzIO OggzIO; typedef struct _OggzReader OggzReader; typedef struct _OggzWriter OggzWriter; +/* oggz_stream */ +#include "oggz_stream.h" + typedef int (*OggzReadPacket) (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data); typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og, long serialno, @@ -68,7 +71,7 @@ typedef int (*OggzIOSeek) (void * user_handle, long offset, int whence); typedef long (*OggzIOTell) (void * user_handle); typedef int (*OggzIOFlush) (void * user_handle); -typedef struct { +struct _oggz_stream_t { ogg_stream_state ogg_stream; /* non b_o_s packet has been written (not just queued) */ @@ -91,7 +94,7 @@ typedef struct { OggzReadPage read_page; void * read_page_user_data; -} oggz_stream_t; +}; struct _OggzReader { ogg_sync_state ogg_sync; @@ -207,9 +210,6 @@ OGGZ * oggz_write_init (OGGZ * oggz); int oggz_write_flush (OGGZ * oggz); OGGZ * oggz_write_close (OGGZ * oggz); -oggz_stream_t * oggz_get_stream (OGGZ * oggz, long serialno); -oggz_stream_t * oggz_add_stream (OGGZ * oggz, long serialno); - int oggz_get_bos (OGGZ * oggz, long serialno); ogg_int64_t oggz_get_unit (OGGZ * oggz, long serialno, ogg_int64_t granulepos); diff --git a/src/liboggz/oggz_stream.h b/src/liboggz/oggz_stream.h new file mode 100644 index 0000000000000000000000000000000000000000..bdabaf778a33733c5b5e88cf8d49a900b0c12064 --- /dev/null +++ b/src/liboggz/oggz_stream.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2003 Commonwealth Scientific and Industrial Research + Organisation (CSIRO) Australia + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of CSIRO Australia nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef __OGGZ_STREAM_H__ +#define __OGGZ_STREAM_H__ + +typedef struct _oggz_stream_t oggz_stream_t; + +oggz_stream_t * oggz_get_stream (OGGZ * oggz, long serialno); +oggz_stream_t * oggz_add_stream (OGGZ * oggz, long serialno); + +int oggz_stream_has_metric (OGGZ * oggz, long serialno); + +#endif /* __OGGZ_STREAM_H__ */