Commit 43c649cc authored by conrad's avatar conrad

move granulerate/granuleshift info directly into each stream, get rid of

allocated metric data for internal metrics


git-svn-id: http://svn.annodex.net/liboggz/trunk@817 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 54575e38
......@@ -34,25 +34,22 @@
#include "oggz_private.h"
typedef struct {
ogg_int64_t gr_n;
ogg_int64_t gr_d;
int granuleshift;
} oggz_metric_granuleshift_t;
static ogg_int64_t
oggz_metric_default_granuleshift (OGGZ * oggz, long serialno,
ogg_int64_t granulepos, void * user_data)
{
oggz_metric_granuleshift_t * gdata = (oggz_metric_granuleshift_t *)user_data;
oggz_stream_t * stream;
ogg_int64_t iframe, pframe;
ogg_int64_t units;
iframe = granulepos >> gdata->granuleshift;
pframe = granulepos - (iframe << gdata->granuleshift);
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) return -1;
iframe = granulepos >> stream->granuleshift;
pframe = granulepos - (iframe << stream->granuleshift);
granulepos = (iframe + pframe);
units = granulepos * gdata->gr_d / gdata->gr_n;
units = granulepos * stream->granulerate_d / stream->granulerate_n;
#ifdef DEBUG
printf ("oggz_..._granuleshift: serialno %010ld Got frame %lld (%lld + %lld): %lld units\n",
......@@ -68,7 +65,10 @@ oggz_set_metric_granuleshift (OGGZ * oggz, long serialno,
ogg_int64_t granule_rate_denominator,
int granuleshift)
{
oggz_metric_granuleshift_t * granuleshift_data;
oggz_stream_t * stream;
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) return -1;
/* we divide by the granulerate, ie. mult by gr_d/gr_n, so ensure
* numerator is non-zero */
......@@ -77,12 +77,11 @@ oggz_set_metric_granuleshift (OGGZ * oggz, long serialno,
granule_rate_denominator = 0;
}
granuleshift_data = oggz_malloc (sizeof (oggz_metric_granuleshift_t));
granuleshift_data->gr_n = granule_rate_numerator;
granuleshift_data->gr_d = granule_rate_denominator;
granuleshift_data->granuleshift = granuleshift;
stream->granulerate_n = granule_rate_numerator;
stream->granulerate_d = granule_rate_denominator;
stream->granuleshift = granuleshift;
return oggz_set_metric_internal (oggz, serialno,
oggz_metric_default_granuleshift,
granuleshift_data, 1);
NULL, 1);
}
......@@ -34,18 +34,16 @@
#include "oggz_private.h"
typedef struct {
ogg_int64_t gr_n;
ogg_int64_t gr_d;
} oggz_metric_linear_t;
static ogg_int64_t
oggz_metric_default_linear (OGGZ * oggz, long serialno, ogg_int64_t granulepos,
void * user_data)
{
oggz_metric_linear_t * ldata = (oggz_metric_linear_t *)user_data;
oggz_stream_t * stream;
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) return -1;
return (ldata->gr_d * granulepos / ldata->gr_n);
return (stream->granulerate_d * granulepos / stream->granulerate_n);
}
int
......@@ -53,7 +51,10 @@ oggz_set_metric_linear (OGGZ * oggz, long serialno,
ogg_int64_t granule_rate_numerator,
ogg_int64_t granule_rate_denominator)
{
oggz_metric_linear_t * linear_data;
oggz_stream_t * stream;
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) return -1;
/* we divide by the granulerate, ie. mult by gr_d/gr_n, so ensure
* numerator is non-zero */
......@@ -62,12 +63,12 @@ oggz_set_metric_linear (OGGZ * oggz, long serialno,
granule_rate_denominator = 0;
}
linear_data = oggz_malloc (sizeof (oggz_metric_linear_t));
linear_data->gr_n = granule_rate_numerator;
linear_data->gr_d = granule_rate_denominator;
stream->granulerate_n = granule_rate_numerator;
stream->granulerate_d = granule_rate_denominator;
stream->granuleshift = 0;
return oggz_set_metric_internal (oggz, serialno, oggz_metric_default_linear,
linear_data, 1);
NULL, 1);
}
int
......
......@@ -261,6 +261,12 @@ oggz_add_stream (OGGZ * oggz, long serialno)
ogg_stream_init (&stream->ogg_stream, (int)serialno);
stream->content = OGGZ_CONTENT_UNKNOWN;
stream->nr_headers = 0;
stream->preroll = 0;
stream->granulerate_n = 1;
stream->granulerate_d = 1;
stream->basegranule = 0;
stream->granuleshift = 0;
stream->delivered_non_b_o_s = 0;
stream->b_o_s = 1;
......@@ -389,7 +395,7 @@ oggz_set_metric_internal (OGGZ * oggz, long serialno,
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (serialno == -1) {
if (oggz->metric_internal)
if (oggz->metric_internal && oggz->metric_user_data)
oggz_free (oggz->metric_user_data);
oggz->metric = metric;
oggz->metric_user_data = user_data;
......@@ -398,7 +404,7 @@ oggz_set_metric_internal (OGGZ * oggz, long serialno,
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO;
if (stream->metric_internal)
if (stream->metric_internal && stream->metric_user_data)
oggz_free (stream->metric_user_data);
stream->metric = metric;
stream->metric_user_data = user_data;
......
......@@ -74,8 +74,16 @@ typedef int (*OggzIOFlush) (void * user_handle);
struct _oggz_stream_t {
ogg_stream_state ogg_stream;
/** STATIC INFO */
int content;
int nr_headers;
int preroll;
ogg_int64_t granulerate_n;
ogg_int64_t granulerate_d;
ogg_int64_t basegranule;
int granuleshift;
/** CURRENT STATE **/
/* non b_o_s packet has been written (not just queued) */
int delivered_non_b_o_s;
......@@ -84,6 +92,7 @@ struct _oggz_stream_t {
ogg_int64_t granulepos;
ogg_int64_t packetno;
/** CALLBACKS **/
OggzMetric metric;
void * metric_user_data;
int metric_internal;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment