Commit 313e7a26 authored by Rafaël Carré's avatar Rafaël Carré

opus_header: remove dependency on ogg

parent ed8daf3f
...@@ -74,7 +74,7 @@ typedef struct { ...@@ -74,7 +74,7 @@ typedef struct {
int pos; int pos;
} ROPacket; } ROPacket;
static int write_uint32(Packet *p, ogg_uint32_t val) static int write_uint32(Packet *p, uint32_t val)
{ {
if (p->pos>p->maxlen-4) if (p->pos>p->maxlen-4)
return 0; return 0;
...@@ -86,7 +86,7 @@ static int write_uint32(Packet *p, ogg_uint32_t val) ...@@ -86,7 +86,7 @@ static int write_uint32(Packet *p, ogg_uint32_t val)
return 1; return 1;
} }
static int write_uint16(Packet *p, ogg_uint16_t val) static int write_uint16(Packet *p, uint16_t val)
{ {
if (p->pos>p->maxlen-2) if (p->pos>p->maxlen-2)
return 0; return 0;
...@@ -105,24 +105,24 @@ static int write_chars(Packet *p, const unsigned char *str, int nb_chars) ...@@ -105,24 +105,24 @@ static int write_chars(Packet *p, const unsigned char *str, int nb_chars)
return 1; return 1;
} }
static int read_uint32(ROPacket *p, ogg_uint32_t *val) static int read_uint32(ROPacket *p, uint32_t *val)
{ {
if (p->pos>p->maxlen-4) if (p->pos>p->maxlen-4)
return 0; return 0;
*val = (ogg_uint32_t)p->data[p->pos ]; *val = (uint32_t)p->data[p->pos ];
*val |= (ogg_uint32_t)p->data[p->pos+1]<< 8; *val |= (uint32_t)p->data[p->pos+1]<< 8;
*val |= (ogg_uint32_t)p->data[p->pos+2]<<16; *val |= (uint32_t)p->data[p->pos+2]<<16;
*val |= (ogg_uint32_t)p->data[p->pos+3]<<24; *val |= (uint32_t)p->data[p->pos+3]<<24;
p->pos += 4; p->pos += 4;
return 1; return 1;
} }
static int read_uint16(ROPacket *p, ogg_uint16_t *val) static int read_uint16(ROPacket *p, uint16_t *val)
{ {
if (p->pos>p->maxlen-2) if (p->pos>p->maxlen-2)
return 0; return 0;
*val = (ogg_uint16_t)p->data[p->pos ]; *val = (uint16_t)p->data[p->pos ];
*val |= (ogg_uint16_t)p->data[p->pos+1]<<8; *val |= (uint16_t)p->data[p->pos+1]<<8;
p->pos += 2; p->pos += 2;
return 1; return 1;
} }
...@@ -141,7 +141,7 @@ int opus_header_parse(const unsigned char *packet, int len, OpusHeader *h) ...@@ -141,7 +141,7 @@ int opus_header_parse(const unsigned char *packet, int len, OpusHeader *h)
char str[9]; char str[9];
ROPacket p; ROPacket p;
unsigned char ch; unsigned char ch;
ogg_uint16_t shortval; uint16_t shortval;
p.data = packet; p.data = packet;
p.maxlen = len; p.maxlen = len;
...@@ -372,13 +372,12 @@ int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header) ...@@ -372,13 +372,12 @@ int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header)
unsigned char header_data[100]; unsigned char header_data[100];
const int packet_size = opus_header_to_packet(header, header_data, const int packet_size = opus_header_to_packet(header, header_data,
sizeof(header_data)); sizeof(header_data));
ogg_packet headers[2];
headers[0].packet = header_data; unsigned char *data[2];
headers[0].bytes = packet_size; size_t size[2];
headers[0].b_o_s = 1;
headers[0].e_o_s = 0; data[0] = header_data;
headers[0].granulepos = 0; size[0] = packet_size;
headers[0].packetno = 0;
size_t comments_length; size_t comments_length;
char *comments = comment_init(&comments_length); char *comments = comment_init(&comments_length);
...@@ -397,22 +396,15 @@ int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header) ...@@ -397,22 +396,15 @@ int opus_write_header(uint8_t **p_extra, int *i_extra, OpusHeader *header)
return 1; return 1;
} }
headers[1].packet = (unsigned char *) comments; data[1] = (unsigned char *) comments;
headers[1].bytes = comments_length; size[1] = comments_length;
headers[1].b_o_s = 0;
headers[1].e_o_s = 0;
headers[1].granulepos = 0;
headers[1].packetno = 1;
for (unsigned i = 0; i < ARRAY_SIZE(headers); ++i) for (unsigned i = 0; i < ARRAY_SIZE(data); ++i)
{ if (xiph_AppendHeaders(i_extra, (void **) p_extra, size[i], data[i]))
if (xiph_AppendHeaders(i_extra, (void **) p_extra,
headers[i].bytes, headers[i].packet))
{ {
*i_extra = 0; *i_extra = 0;
*p_extra = NULL; *p_extra = NULL;
} }
}
return 0; return 0;
} }
......
...@@ -28,14 +28,13 @@ ...@@ -28,14 +28,13 @@
#ifndef OPUS_HEADER_H #ifndef OPUS_HEADER_H
#define OPUS_HEADER_H #define OPUS_HEADER_H
#include <ogg/ogg.h>
#include <stdint.h> #include <stdint.h>
typedef struct { typedef struct {
int version; int version;
int channels; /* Number of channels: 1..255 */ int channels; /* Number of channels: 1..255 */
int preskip; int preskip;
ogg_uint32_t input_sample_rate; uint32_t input_sample_rate;
int gain; /* in dB S7.8 should be zero whenever possible */ int gain; /* in dB S7.8 should be zero whenever possible */
int channel_mapping; int channel_mapping;
/* The rest is only used if channel_mapping != 0 */ /* The rest is only used if channel_mapping != 0 */
......
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