coggshoutcasticecastflac

Streaming OGG Flac to Icecast with libshout


I have a simple streamer developed in C++ using LibFlac and LibShout to stream to Icecast server. The flac Encoder is created in the following way:

  m_encoder = FLAC__stream_encoder_new();
  FLAC__stream_encoder_set_channels(m_encoder, 2);
  FLAC__stream_encoder_set_ogg_serial_number(m_encoder, rand());
  FLAC__stream_encoder_set_bits_per_sample(m_encoder, 16);
  FLAC__stream_encoder_set_sample_rate(m_encoder, in_samplerate);
  FLAC__stream_encoder_init_ogg_stream(m_encoder, NULL, writeByteArray, NULL, NULL, NULL, this);

The function writeByteArray sends encoded data to Icecast using shout_send_raw function from libshout. shout_send_raw returns an actual number of bytes being sent, so I assume that it works as it should, no error is happening. The problem is Icecast server does not stream the data that I send. I see followint in the log: [2018-02-15 15:31:47] DBUG stats/modify_node_event update "/radio" total_bytes_read (20735897) [2018-02-15 15:31:47] DBUG stats/modify_node_event update "/radio" total_bytes_sent (0) I see that Icecast receives the data, but it does not send it to connected clients. The mount point is radio and when I try to connect to that mount using any media player - it does nothing, no playback. So my question is how is that possible that Icecast receives the data but does not send it to connected clients? Maybe some additional libshout configuration is required, here is how I configure it: shout_set_format( m_ShoutData, SHOUT_FORMAT_OGG_AUDIO ); shout_set_mime( m_ShoutData, "application/ogg" ); Any help would be appreciated.


Solution

  • To sum up the solution from the comments:

    FLAC has a very significantly higher bitrate than any other commonly used audio codec. Thus the default settings will NOT work. The queue size must be increased significantly so that complete data frames will fit in it, otherwise, Icecast will not sync on the stream and refuse to data out to clients.

    The same obviously applies to streaming video. The queue size must be adjusted either for the appropriate mountpoints or globally.