Remove "chunk_ms" from documentation

This commit is contained in:
badaix 2024-03-24 22:55:50 +01:00
parent b6d69ca919
commit f877308760
5 changed files with 8 additions and 247 deletions

View file

@ -35,7 +35,6 @@ Supported parameters for all source types:
- `codec`: Override the global codec - `codec`: Override the global codec
- `sampleformat`: Override the global sample format - `sampleformat`: Override the global sample format
- `chunk_ms`: Override the global `chunk_ms` - `chunk_ms`: Override the global `chunk_ms`
- `dryout_ms`: Supported by blocking sources: when no new data is read from the source, send silence to the clients
- `controlscript`: Script to control the stream source and read and provide meta data, see [stream_plugin.md](json_rpc_api/stream_plugin.md) - `controlscript`: Script to control the stream source and read and provide meta data, see [stream_plugin.md](json_rpc_api/stream_plugin.md)
- `controlscriptparams`: Control script command line arguments, must be url-encoded (use `%20` instead of a space " "), e.g. `--mopidy-host=192.168.42.23%20--debug` - `controlscriptparams`: Control script command line arguments, must be url-encoded (use `%20` instead of a space " "), e.g. `--mopidy-host=192.168.42.23%20--debug`
@ -46,7 +45,7 @@ Available audio source types are:
Captures audio from a named pipe Captures audio from a named pipe
```sh ```sh
pipe:///<path/to/pipe>?name=<name>[&mode=create][&dryout_ms=2000] pipe:///<path/to/pipe>?name=<name>[&mode=create]
``` ```
`mode` can be `create` or `read`. Sometimes your audio source might insist in creating the pipe itself. So the pipe creation mode can by changed to "not create, but only read mode", using the `mode` option set to `read` `mode` can be `create` or `read`. Sometimes your audio source might insist in creating the pipe itself. So the pipe creation mode can by changed to "not create, but only read mode", using the `mode` option set to `read`
@ -60,7 +59,7 @@ See [stackexchange](https://unix.stackexchange.com/questions/503111/group-permis
Launches librespot and reads audio from stdout Launches librespot and reads audio from stdout
```sh ```sh
librespot:///<path/to/librespot>?name=<name>[&dryout_ms=2000][&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&wd_timeout=7800][&volume=100][&onevent=""][&normalize=false][&autoplay=false][&cache=""][&disable_audio_cache=false][&killall=false][&params=extra-params] librespot:///<path/to/librespot>?name=<name>[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&wd_timeout=7800][&volume=100][&onevent=""][&normalize=false][&autoplay=false][&cache=""][&disable_audio_cache=false][&killall=false][&params=extra-params]
``` ```
Note that you need to have the librespot binary on your machine and the sampleformat will be set to `44100:16:2` Note that you need to have the librespot binary on your machine and the sampleformat will be set to `44100:16:2`
@ -91,7 +90,7 @@ Parameters introduced by Snapclient:
Launches [shairport-sync](https://github.com/mikebrady/shairport-sync) and reads audio from stdout Launches [shairport-sync](https://github.com/mikebrady/shairport-sync) and reads audio from stdout
```sh ```sh
airplay:///<path/to/shairport-sync>?name=<name>[&dryout_ms=2000][&devicename=Snapcast][&port=5000][&password=<my password>] airplay:///<path/to/shairport-sync>?name=<name>[&devicename=Snapcast][&port=5000][&password=<my password>]
``` ```
Note that you need to have the shairport-sync binary on your machine and the sampleformat will be set to `44100:16:2` Note that you need to have the shairport-sync binary on your machine and the sampleformat will be set to `44100:16:2`
@ -118,7 +117,7 @@ file:///<path/to/PCM/file>?name=<name>
Launches a process and reads audio from stdout Launches a process and reads audio from stdout
```sh ```sh
process:///<path/to/process>?name=<name>[&dryout_ms=2000][&wd_timeout=0][&log_stderr=false][&params=<process arguments>] process:///<path/to/process>?name=<name>[&wd_timeout=0][&log_stderr=false][&params=<process arguments>]
``` ```
#### Available parameters #### Available parameters

View file

@ -118,15 +118,14 @@ doc_root = /usr/share/snapserver/snapweb
# parameters have the form "key=value", they are concatenated with an "&" character # parameters have the form "key=value", they are concatenated with an "&" character
# parameter "name" is mandatory for all sources, while codec, sampleformat and chunk_ms are optional # parameter "name" is mandatory for all sources, while codec, sampleformat and chunk_ms are optional
# and will override the default codec, sampleformat or chunk_ms settings # and will override the default codec, sampleformat or chunk_ms settings
# Blocking sources support the dryout_ms parameter: when no new data is read from the source, send silence to the clients
# Available types are: # Available types are:
# pipe: pipe:///<path/to/pipe>?name=<name>[&mode=create][&dryout_ms=2000], mode can be "create" or "read" # pipe: pipe:///<path/to/pipe>?name=<name>[&mode=create], mode can be "create" or "read"
# librespot: librespot:///<path/to/librespot>?name=<name>[&dryout_ms=2000][&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&wd_timeout=7800][&volume=100][&onevent=""][&nomalize=false][&autoplay=false][&params=<generic librepsot process arguments>] # librespot: librespot:///<path/to/librespot>?name=<name>[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&wd_timeout=7800][&volume=100][&onevent=""][&nomalize=false][&autoplay=false][&params=<generic librepsot process arguments>]
# note that you need to have the librespot binary on your machine # note that you need to have the librespot binary on your machine
# sampleformat will be set to "44100:16:2" # sampleformat will be set to "44100:16:2"
# file: file:///<path/to/PCM/file>?name=<name> # file: file:///<path/to/PCM/file>?name=<name>
# process: process:///<path/to/process>?name=<name>[&dryout_ms=2000][&wd_timeout=0][&log_stderr=false][&params=<process arguments>] # process: process:///<path/to/process>?name=<name>[&wd_timeout=0][&log_stderr=false][&params=<process arguments>]
# airplay: airplay:///<path/to/airplay>?name=<name>[&dryout_ms=2000][&port=5000] # airplay: airplay:///<path/to/airplay>?name=<name>[&port=5000]
# note that you need to have the airplay binary on your machine # note that you need to have the airplay binary on your machine
# sampleformat will be set to "44100:16:2" # sampleformat will be set to "44100:16:2"
# tcp server: tcp://<listen IP, e.g. 127.0.0.1>:<port>?name=<name>[&mode=server] # tcp server: tcp://<listen IP, e.g. 127.0.0.1>:<port>?name=<name>[&mode=server]
@ -134,7 +133,6 @@ doc_root = /usr/share/snapserver/snapweb
# alsa: alsa:///?name=<name>&device=<alsa device>[&send_silence=false][&idle_threshold=100][&silence_threshold_percent=0.0] # alsa: alsa:///?name=<name>&device=<alsa device>[&send_silence=false][&idle_threshold=100][&silence_threshold_percent=0.0]
# meta: meta:///<name of source#1>/<name of source#2>/.../<name of source#N>?name=<name> # meta: meta:///<name of source#1>/<name of source#2>/.../<name of source#N>?name=<name>
source = pipe:///tmp/snapfifo?name=default source = pipe:///tmp/snapfifo?name=default
#source = tcp://127.0.0.1?name=mopidy_tcp
# Default sample format: <sample rate>:<bits per sample>:<channels> # Default sample format: <sample rate>:<bits per sample>:<channels>
#sampleformat = 48000:16:2 #sampleformat = 48000:16:2

View file

@ -83,9 +83,6 @@ void AlsaStream::start()
{ {
LOG(DEBUG, LOG_TAG) << "Start, sampleformat: " << sampleFormat_.toString() << "\n"; LOG(DEBUG, LOG_TAG) << "Start, sampleformat: " << sampleFormat_.toString() << "\n";
// idle_bytes_ = 0;
// max_idle_bytes_ = sampleFormat_.rate() * sampleFormat_.frameSize() * dryout_ms_ / 1000;
initAlsa(); initAlsa();
first_ = true; first_ = true;
tvEncodedChunk_ = std::chrono::steady_clock::now(); tvEncodedChunk_ = std::chrono::steady_clock::now();
@ -263,7 +260,6 @@ void AlsaStream::do_read()
LOG(INFO, LOG_TAG) << "No data availabale, playing silence.\n"; LOG(INFO, LOG_TAG) << "No data availabale, playing silence.\n";
// no data available, fill with silence // no data available, fill with silence
memset(chunk_->payload + len, 0, toRead - len); memset(chunk_->payload + len, 0, toRead - len);
// idle_bytes_ += toRead - len;
break; break;
} }
else if (count == 0) else if (count == 0)

View file

@ -1,177 +0,0 @@
/***
This file is part of snapcast
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "posix_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"
// standard headers
#include <cerrno>
#include <memory>
using namespace std;
using namespace std::chrono_literals;
namespace streamreader
{
static constexpr auto LOG_TAG = "PosixStream";
static constexpr auto kResyncTolerance = 50ms;
PosixStream::PosixStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: AsioStream<stream_descriptor>(pcmListener, ioc, server_settings, uri)
{
if (uri_.query.find("dryout_ms") != uri_.query.end())
dryout_ms_ = cpt::stoul(uri_.query["dryout_ms"]);
else
dryout_ms_ = 2000;
}
void PosixStream::connect()
{
if (!active_)
return;
idle_bytes_ = 0;
max_idle_bytes_ = sampleFormat_.rate() * sampleFormat_.frameSize() * dryout_ms_ / 1000;
try
{
do_connect();
}
catch (const std::exception& e)
{
LOG(ERROR, LOG_TAG) << "Connect exception: " << e.what() << "\n";
wait(read_timer_, 100ms, [this] { connect(); });
}
}
void PosixStream::do_disconnect()
{
if (stream_ && stream_->is_open())
stream_->close();
}
void PosixStream::do_read()
{
try
{
if (!stream_->is_open())
throw SnapException("failed to open stream: \"" + uri_.path + "\"");
if (first_)
{
LOG(TRACE, LOG_TAG) << "First read, initializing nextTick to now\n";
nextTick_ = std::chrono::steady_clock::now();
}
int toRead = chunk_->payloadSize;
auto duration = chunk_->duration<std::chrono::nanoseconds>();
int len = 0;
do
{
int count = read(stream_->native_handle(), chunk_->payload + len, toRead - len);
if (count < 0)
{
// no data available, fill with silence
memset(chunk_->payload + len, 0, toRead - len);
// avoid overflow after 186min 24s silence (at 48000:16:2)
if (idle_bytes_ <= max_idle_bytes_)
idle_bytes_ += toRead - len;
break;
}
else if (count == 0)
{
throw SnapException("end of file");
}
else
{
// LOG(DEBUG, LOG_TAG) << "count: " << count << "\n";
len += count;
bytes_read_ += len;
idle_bytes_ = 0;
}
} while (len < toRead);
// LOG(DEBUG, LOG_TAG) << "Received " << len << "/" << toRead << " bytes\n";
if (first_)
{
first_ = false;
// initialize the stream's base timestamp to now minus the chunk's duration
tvEncodedChunk_ = std::chrono::steady_clock::now() - duration;
}
if ((idle_bytes_ == 0) || (idle_bytes_ <= max_idle_bytes_))
{
// the encoder will update the tvEncodedChunk when a chunk is encoded
chunkRead(*chunk_);
}
else
{
// no data available
// set first_ = true will cause the timestamps to be updated without encoding
first_ = true;
}
nextTick_ += duration;
auto currentTick = std::chrono::steady_clock::now();
auto next_read = nextTick_ - currentTick;
if (next_read >= 0ms)
{
// synchronize reads to an interval of chunk_ms_
wait(read_timer_, nextTick_ - currentTick, [this] { do_read(); });
return;
}
else if (next_read >= -kResyncTolerance)
{
LOG(INFO, LOG_TAG) << "next read < 0 (" << getName() << "): " << std::chrono::duration_cast<std::chrono::microseconds>(next_read).count() / 1000.
<< " ms\n";
boost::asio::post(strand_, [this] { do_read(); });
}
else
{
// reading chunk_ms_ took longer than chunk_ms_
resync(-next_read);
first_ = true;
wait(read_timer_, duration + kResyncTolerance, [this] { do_read(); });
}
lastException_ = "";
}
catch (const std::exception& e)
{
if (lastException_ != e.what())
{
LOG(ERROR, LOG_TAG) << "Exception: " << e.what() << std::endl;
lastException_ = e.what();
}
disconnect();
wait(read_timer_, 100ms, [this] { connect(); });
}
}
} // namespace streamreader

View file

@ -1,55 +0,0 @@
/***
This file is part of snapcast
Copyright (C) 2014-2021 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef POSIX_STREAM_HPP
#define POSIX_STREAM_HPP
// local headers
#include "asio_stream.hpp"
namespace streamreader
{
using boost::asio::posix::stream_descriptor;
/// Reads and decodes PCM data from a file descriptor
/**
* Reads PCM from a file descriptor and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmStream::Listener
*/
class PosixStream : public AsioStream<stream_descriptor>
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
PosixStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
protected:
void connect() override;
void do_disconnect() override;
void do_read() override;
std::string lastException_;
size_t dryout_ms_;
int idle_bytes_;
int max_idle_bytes_;
};
} // namespace streamreader
#endif