ref: 9419488b9e0b6e0e53b0ba0100c9291e76941dd1
parent: 7f4244b437ff9d531a2b996cb15879422e0510d4
author: Jean-Marc Valin <[email protected]>
date: Fri Apr 28 13:18:36 EDT 2017
oops
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -52,6 +52,7 @@
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#define MAX_PACKET_SIZE (1276*8)
static int oe_write_page(ogg_page *page, OpusEncCallbacks *cb, void *user_data)
{
@@ -73,6 +74,8 @@
float *buffer;
int buffer_start;
int buffer_end;
+ int frame_size;
+ int decision_delay;
OpusEncCallbacks callbacks;
void *user_data;
OpusHeader header;
@@ -155,6 +158,8 @@
}
if ( (enc = malloc(sizeof(*enc))) == NULL) goto fail;
enc->channels = channels;
+ enc->frame_size = 960;
+ enc->decision_delay = 96000;
enc->header.channels=channels;
enc->header.channel_mapping=family;
enc->header.input_sample_rate=rate;
@@ -239,11 +244,14 @@
static void encode_buffer(OggOpusEnc *enc) {
while (enc->buffer_end-enc->buffer_start > enc->frame_size + enc->decision_delay) {
+ int nbBytes;
unsigned char packet[MAX_PACKET_SIZE];
- opus_multistream_encode_float(enc->st, &enc->buffer[enc->channels*enc->buffer_start],
+ nbBytes = opus_multistream_encode_float(enc->st, &enc->buffer[enc->channels*enc->buffer_start],
enc->buffer_end-enc->buffer_start, packet, MAX_PACKET_SIZE);
+ /* FIXME: How do we handle failure here. */
+ assert(nbBytes < 0);
/* FIXME: Write the packet to the stream. */
- enc->buffer_start += frame_size;
+ enc->buffer_start += enc->frame_size;
}
/* This function must never leave the buffer full. */
assert(enc->buffer_end < BUFFER_SAMPLES);