1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/*C
(c) 2005 bl0rg.net
**/
#include "conf.h"
#include <assert.h>
#include <stdlib.h>
#include "buf.h"
#include "ogg.h"
#include "crc32.h"
#include "pack.h"
crc32_t ogg_crc32;
void ogg_init(void) {
crc32_init(&ogg_crc32, OGG_CRC32_POLY, 0, 0);
}
void ogg_page_init(ogg_page_t *page) {
assert(page != NULL);
page->raw.size = 0;
page->raw.data = NULL;
page->page_segments = 0;
page->page_no = 0;
page->stream = 0;
page->page_cksum = 0;
buf_alloc(&page->raw, 4000);
assert(page->raw.data != NULL);
page->size = 0;
}
void ogg_page_destroy(ogg_page_t *page) {
assert(page != NULL);
buf_free(&page->raw);
}
/* XXX make pointer array? */
unsigned char *ogg_segment(ogg_page_t *page, int num) {
assert(page != NULL);
if (num > page->page_segments)
return NULL;
unsigned char *res = page->raw.data +
OGG_HDR_MIN_SIZE + page->page_segments;
int i;
for (i = 0; i < num; i++)
res += page->lacing_values[i];
return res;
}
/*M
\emph{Converts a sample position in an OGG page to a number in
msecs.}
**/
unsigned long ogg_position_to_msecs(ogg_page_t *page,
unsigned long sample_rate) {
assert(page != NULL);
unsigned char *ptr = page->position;
unsigned long position[2];
position[0] = LE_UINT32_UNPACK(ptr);
position[1] = LE_UINT32_UNPACK(ptr);
double dmsecs = (position[0] + position[1] * 2147483648.0) /
(sample_rate / 1000.0);
return (unsigned long)dmsecs;
}
/*C
**/
|