I am decoding ogg opus data which is streaming live from icecast server. I am using libopus to decode. Data gets decoded sometimes but most of the times op_decode() returns -4 which indicates corrupted stream. This is the callback function used to access data using curl library.
#define SAMPLE_RATE 48000
#define CHANNELS 2
#define MAX_FRAME_SIZE 6*960
size_t play_stream(void *buffer, size_t size, size_t nmemb, void *userp)
{
FILE *fp;
opus_int16 out[MAX_FRAME_SIZE * CHANNELS];
int error;
int i;
unsigned char pcm_bytes[MAX_FRAME_SIZE * CHANNELS * 2];
int frame_size;
frame_size = opus_decode(decoder, (unsigned char*)buffer, (opus_int32)size * nmemb, out, MAX_FRAME_SIZE, 0);
if (frame_size < 0)
{
fprintf(stderr, "decoder failed: %s\n", opus_strerror(frame_size));
}
return size * nmemb;
}
Can someone please help me out?
The opus_decode() function decodes an Opus packet, not an Ogg Opus stream. You could use the Ogg library to get the packets out of the stream and then libopus to decode the packets, but an easier way to is to use the opusfile library. Opusfile can even read the stream directly from the network.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With