TooTallNate / node-ogg

Node.js native binding to libogg
MIT License
65 stars 36 forks source link

Does not work with radio (startless/endless) streams? #15

Closed hjri closed 5 years ago

hjri commented 7 years ago

Hi. I'm trying to use node-ogg and node-vorbis in conjuction with icy to read an Icecast ogg stream (and redirect it somewhere else), but seems to have run into a problem - ogg decoder crashes.

Consider this code:

const logger = require('winston')
const Icecast = require('icy')
const Vorbis = require('vorbis')
// const Lame = require('lame')
const Speaker = require('speaker')
const OGG = require('ogg')

logger.level = 'debug'
global.logger = logger

var od = new OGG.Decoder()
var vd = new Vorbis.Decoder()

vd.on('format', format => {
    logger.debug('vd', format)
})

vd.on('error',err => {
    logger.debug('vd', err)
})

od.on('stream', stream => {
    stream.pipe(vd)
})

od.on('error',err => {
    logger.debug('od', err)
})

//  **This code (same radio but using mp3 stream) works.**
/*
 this._ice = Icecast.get('https://example.com:8001/radio.mp3', res => {
     logger.info('Icecast info:', res.headers)
     res.pipe(new Lame.Decoder()).pipe(new Speaker())
 })
*/

this._ice = Icecast.get('https://example.com:8001/radio.ogg', res => {
    logger.info('Icecast info:', res.headers)
    res.pipe(od)//.pipe(new Speaker()) // this gives off 'Cannot pipe. Not readable' error
})

when I run this code I get following output:

$ node --harmony src/RadioChannel.js
info: Icecast info: accept-ranges=none, content-type=application/ogg, icy-br=128, ice-audio-info=channels=2;samplerate=44100;bitrate=128, icy-description=Liquidsoap Radio!, icy-genre=Misc, icy-name=radio.ogg, icy-pub=1, icy-url=http://savonet.sf.net, server=Icecast 2.3.3-kh11, cache-control=no-cache, no-store, pragma=no-cache, access-control-allow-origin=*, access-control-allow-headers=Origin, Accept, X-Requested-With, Content-Type, access-control-allow-methods=GET, OPTIONS, HEAD, connection=close, expires=Mon, 26 Jul 1997 05:00:00 GMT
debug: vd channels=2, sampleRate=44100, bitDepth=32, float=true, signed=true, version=0, bitrateUpper=128000, bitrateNominal=128000, bitrateLower=128000, bitrateWindow=0
debug: od Error: ogg_stream_packetout() error: -1
    at afterPacketout (/home/houka/gits/jh/node_modules/ogg/lib/decoder-stream.js:137:10)

According to https://xiph.org/ogg/doc/libogg/ogg_stream_packetout.html this function returns -1 when, quote "if we are out of sync and there is a gap in the data. This is usually a recoverable error and subsequent calls to ogg_stream_packetout are likely to succeed.".

I replaced urls to radio for privacy's sake, it's a private radio.

hjri commented 7 years ago

seems like #6 should fix it.

LinusU commented 5 years ago

Should be fixed by #6/#19, released as 1.2.6, please reopen if it still doesn't work

Sorry for the delay in publishing the fix 🙈