Definitions for audio capture and encoding. More...
#include <algorithm>#include <array>#include <thread>#include <libavcodec/avcodec.h>#include <libavutil/avutil.h>#include <libavutil/channel_layout.h>#include <libavutil/frame.h>#include <opus/opus_multistream.h>#include "audio.h"#include "config.h"#include "globals.h"#include "logging.h"#include "platform/common.h"#include "thread_safe.h"#include "utility.h"Classes | |
| class | audio::ffmpeg_audio_encoder_t |
| Encode one interleaved stereo or 5.1 float PCM frame as an AC-3-family access unit. More... | |
Typedefs | |
| using | audio::opus_t = util::safe_ptr<OpusMSEncoder, opus_multistream_encoder_destroy> |
| Owning pointer for an Opus multistream encoder. | |
| using | audio::sample_queue_t = std::shared_ptr<safe::queue_t<std::vector<float>>> |
| Shared queue carrying captured PCM sample buffers to the encoder thread. | |
Functions | |
| bool | audio::ac3_available () |
| Check whether the linked FFmpeg build provides the AC-3 encoder. | |
| void | audio::capture (safe::mail_t mail, config_t config, stream::session_t *channel_data) |
| Run the capture loop for this backend. | |
| dolby_codec_e | audio::configure_dolby_audio (config_t &config, std::string_view offered, std::string_view accepted, bool ac3_encoder_available, bool eac3_encoder_available, bool high_quality) |
| Configure a Dolby stream only for an exact, supported client acceptance. | |
| int | audio::dolby_bitrate_kbps (bool eac3, bool high_quality, int channels) |
| Select a channel-aware bitrate for Dolby audio encoding. | |
| std::string_view | audio::dolby_codec_name (dolby_codec_e codec) |
| Return the codec label for the RTSP audio-codec response header. | |
| bool | audio::eac3_available () |
| Check whether the linked FFmpeg build provides the E-AC-3 encoder. | |
| void | audio::encodeThread (sample_queue_t samples, config_t config, stream::session_t *channel_data) |
| Encode captured PCM samples into Opus packets on the audio worker thread. | |
| audio_ctx_ref_t | audio::get_audio_ctx_ref () |
| Get the reference to the audio context. | |
| bool | audio::is_audio_ctx_sink_available (const audio_ctx_t &ctx) |
| Check if the audio sink held by audio context is available. | |
| int | audio::map_stream (int channels, bool quality) |
| Select the Opus stream configuration for a channel count and quality tier. | |
Variables | |
| constexpr auto | audio::SAMPLE_RATE = 48000 |
| Audio sample rate in hertz required by Opus. | |
| const std::array< opus_stream_config_t, MAX_STREAM_CONFIG > | audio::stream_configs |
| Opus stream layouts and bitrates advertised to clients. | |
Definitions for audio capture and encoding.
| bool audio::ac3_available | ( | ) |
Check whether the linked FFmpeg build provides the AC-3 encoder.
Check whether a compatible optional FFmpeg AC-3 encoder is available.
| void audio::capture | ( | safe::mail_t | mail, |
| config_t | config, | ||
| stream::session_t * | channel_data ) |
Run the capture loop for this backend.
Capture, encode, and publish audio packets for a stream.
| Mailbox used to publish encoded audio packets. | |
| config | Audio capture and encoder settings. |
| channel_data | Stream session that receives the encoded packets. |
| dolby_codec_e audio::configure_dolby_audio | ( | config_t & | config, |
| std::string_view | offered, | ||
| std::string_view | accepted, | ||
| bool | ac3_encoder_available, | ||
| bool | eac3_encoder_available, | ||
| bool | high_quality ) |
Configure a Dolby stream only for an exact, supported client acceptance.
| config | Audio configuration to update for the negotiated stream. |
| offered | Codec offered by Sunshine, or empty when using Opus. |
| accepted | Codec explicitly accepted by the client. |
| ac3_encoder_available | Whether the AC-3 encoder is available. |
| eac3_encoder_available | Whether the E-AC-3 encoder is available. |
| high_quality | Whether the higher Dolby bitrate was requested. |
| int audio::dolby_bitrate_kbps | ( | bool | eac3, |
| bool | high_quality, | ||
| int | channels ) |
Select a channel-aware bitrate for Dolby audio encoding.
| eac3 | True to select E-AC-3; false to select AC-3. |
| high_quality | Whether to use the higher Dolby bitrate. |
| channels | Number of output audio channels (stereo or 5.1). |
| std::string_view audio::dolby_codec_name | ( | dolby_codec_e | codec | ) |
Return the codec label for the RTSP audio-codec response header.
| codec | Selected audio codec. |
| bool audio::eac3_available | ( | ) |
Check whether the linked FFmpeg build provides the E-AC-3 encoder.
Check whether a compatible optional FFmpeg E-AC-3 encoder is available.
| void audio::encodeThread | ( | sample_queue_t | samples, |
| config_t | config, | ||
| stream::session_t * | channel_data ) |
Encode captured PCM samples into Opus packets on the audio worker thread.
| samples | Queue of captured PCM sample buffers to encode. |
| config | Audio stream settings negotiated with the client. |
| channel_data | Stream session carried with each encoded packet. |
| audio_ctx_ref_t audio::get_audio_ctx_ref | ( | ) |
Get the reference to the audio context.
Examples
| bool audio::is_audio_ctx_sink_available | ( | const audio_ctx_t & | ctx | ) |
Check if the audio sink held by audio context is available.
Examples
| ctx | Native context object used by the operation or callback. |
| int audio::map_stream | ( | int | channels, |
| bool | quality ) |
Select the Opus stream configuration for a channel count and quality tier.
| channels | Number of audio channels in the stream. |
| quality | Whether the high-quality Opus layout should be selected. |
| const std::array< opus_stream_config_t, MAX_STREAM_CONFIG > audio::stream_configs |
Opus stream layouts and bitrates advertised to clients.
Opus layouts and bitrates advertised for each supported stream mode.