Commit a18d158c authored by conrad's avatar conrad

add exported granuleshift_metric


git-svn-id: http://svn.annodex.net/liboggz/trunk@804 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 0d7032c5
......@@ -221,6 +221,26 @@ int oggz_set_metric_linear (OGGZ * oggz, long serialno,
ogg_int64_t granule_rate_numerator,
ogg_int64_t granule_rate_denominator);
/**
* Specify that a logical bitstream has a granuleshift metric
* \param oggz An OGGZ handle
* \param serialno Identify the logical bitstream in \a oggz to attach
* this granuleshift metric to. A value of -1 indicates that the metric should
* be attached to all unattached logical bitstreams in \a oggz.
* \param granule_rate_numerator The numerator of the granule rate
* \param granule_rate_denominator The denominator of the granule rate
* \param granuleshift The granuleshift
* \returns 0 Success
* \retval OGGZ_ERR_BAD_SERIALNO \a serialno does not identify an existing
* logical bitstream in \a oggz.
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
*/
int
oggz_set_metric_granuleshift (OGGZ * oggz, long serialno,
ogg_int64_t granule_rate_numerator,
ogg_int64_t granule_rate_denominator,
int granuleshift);
/**
* This is the signature of a function to correlate Ogg streams.
* If every position in an Ogg stream can be described by a metric (eg. time)
......
......@@ -30,6 +30,7 @@
oggz_set_metric;
oggz_set_metric_linear;
oggz_set_metric_granuleshift;
oggz_tell;
oggz_tell_units;
......
......@@ -394,6 +394,34 @@ oggz_metric_default_linear (OGGZ * oggz, long serialno, ogg_int64_t granulepos,
return (ldata->gr_d * granulepos / ldata->gr_n);
}
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;
ogg_int64_t iframe, pframe;
ogg_int64_t units;
iframe = granulepos >> gdata->granuleshift;
pframe = granulepos - (iframe << gdata->granuleshift);
granulepos = (iframe + pframe);
units = granulepos * gdata->gr_d / gdata->gr_n;
#ifdef DEBUG
printf ("oggz_..._granuleshift: serialno %010ld Got frame %lld (%lld + %lld): %lld units\n",
serialno, granulepos, iframe, pframe, units);
#endif
return units;
}
int
oggz_set_metric_internal (OGGZ * oggz, long serialno,
OggzMetric metric, void * user_data, int internal)
......@@ -457,6 +485,31 @@ oggz_set_metric_zero (OGGZ * oggz, long serialno)
return oggz_set_metric_linear (oggz, serialno, 0, 1);
}
int
oggz_set_metric_granuleshift (OGGZ * oggz, long serialno,
ogg_int64_t granule_rate_numerator,
ogg_int64_t granule_rate_denominator,
int granuleshift)
{
oggz_metric_granuleshift_t * granuleshift_data;
/* we divide by the granulerate, ie. mult by gr_d/gr_n, so ensure
* numerator is non-zero */
if (granule_rate_numerator == 0) {
granule_rate_numerator = 1;
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;
return oggz_set_metric_internal (oggz, serialno,
oggz_metric_default_granuleshift,
granuleshift_data, 1);
}
/*
* Check if a stream in an oggz has a metric
*/
......
......@@ -311,6 +311,7 @@ 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 */
ogg_int64_t granule_rate_numerator = 0, granule_rate_denominator = 0;
int granuleshift;
if (op->bytes < 48) return 0;
......@@ -325,16 +326,25 @@ auto_fisbone (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
granule_rate_numerator = INT64_LE_AT(&header[20]);
granule_rate_denominator = INT64_LE_AT(&header[28]);
granuleshift = (int)header[48];
#ifdef DEBUG
printf ("Got fisbone granulerate %lld/%lld for serialno %010ld\n",
granule_rate_numerator, granule_rate_denominator,
printf ("Got fisbone granulerate %lld/%lld, granuleshift %d for serialno %010ld\n",
granule_rate_numerator, granule_rate_denominator, granuleshift,
fisbone_serialno);
#endif
oggz_set_metric_linear (oggz, fisbone_serialno,
granule_rate_numerator,
OGGZ_AUTO_MULT * granule_rate_denominator);
if (granuleshift == 0) {
oggz_set_metric_linear (oggz, fisbone_serialno,
granule_rate_numerator,
OGGZ_AUTO_MULT * granule_rate_denominator);
} else {
oggz_set_metric_granuleshift (oggz, fisbone_serialno,
granule_rate_numerator,
OGGZ_AUTO_MULT * granule_rate_denominator,
granuleshift);
}
return 1;
}
......
......@@ -22,8 +22,10 @@ oggz_write_feed @14
oggz_write @15
oggz_write_output @16
oggz_write_get_next_page_size @17
oggz_set_metric @18
oggz_set_metric_linear @19
oggz_set_metric_granuleshift @50
;
; Ogg file seeking functions
......
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