From: Tucker Kern Date: Fri, 13 Sep 2024 19:10:56 +0000 (+0000) Subject: Send pvol metadata on mute X-Git-Tag: 4.3.5^2~21^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=feed0cb13fede4c24ce5d73c119e541c941e881c;p=thirdparty%2Fshairport-sync.git Send pvol metadata on mute --- diff --git a/player.c b/player.c index 102085a4..a41ed3ef 100644 --- a/player.c +++ b/player.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -3296,6 +3297,30 @@ void *player_thread_func(void *arg) { pthread_exit(NULL); } +static void player_send_volume_metadata(bool vol_mode_both, double airplay_volume, double scaled_attenuation, int32_t max_db, int32_t min_db, int32_t hw_max_db) +{ +#ifdef CONFIG_METADATA + // here, send the 'pvol' metadata message when the airplay volume information + // is being used by shairport sync to control the output volume + char dv[128]; + memset(dv, 0, 128); + if (config.ignore_volume_control == 0) { + if (vol_mode_both) { + // normalise the maximum output to the hardware device's max output + snprintf(dv, 127, "%.2f,%.2f,%.2f,%.2f", airplay_volume, + (scaled_attenuation - max_db + hw_max_db) / 100.0, + (min_db - max_db + hw_max_db) / 100.0, (max_db - max_db + hw_max_db) / 100.0); + } else { + snprintf(dv, 127, "%.2f,%.2f,%.2f,%.2f", airplay_volume, scaled_attenuation / 100.0, + min_db / 100.0, max_db / 100.0); + } + } else { + snprintf(dv, 127, "%.2f,%.2f,%.2f,%.2f", airplay_volume, 0.0, 0.0, 0.0); + } + send_ssnc_metadata('pvol', dv, strlen(dv), 1); +#endif +} + void player_volume_without_notification(double airplay_volume, rtsp_conn_info *conn) { debug_mutex_lock(&conn->volume_control_mutex, 5000, 1); // first, see if we are hw only, sw only, both with hw attenuation on the top or both with sw @@ -3384,6 +3409,8 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c volume_mode, airplay_volume); } } + + player_send_volume_metadata(volume_mode == vol_both, airplay_volume, 0, 0, 0, 0); } else { int32_t max_db = 0, min_db = 0; switch (volume_mode) { @@ -3494,26 +3521,7 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c inform("Output Level set to: %.2f dB.", scaled_attenuation / 100.0); } -#ifdef CONFIG_METADATA - // here, send the 'pvol' metadata message when the airplay volume information - // is being used by shairport sync to control the output volume - char dv[128]; - memset(dv, 0, 128); - if (config.ignore_volume_control == 0) { - if (volume_mode == vol_both) { - // normalise the maximum output to the hardware device's max output - snprintf(dv, 127, "%.2f,%.2f,%.2f,%.2f", airplay_volume, - (scaled_attenuation - max_db + hw_max_db) / 100.0, - (min_db - max_db + hw_max_db) / 100.0, (max_db - max_db + hw_max_db) / 100.0); - } else { - snprintf(dv, 127, "%.2f,%.2f,%.2f,%.2f", airplay_volume, scaled_attenuation / 100.0, - min_db / 100.0, max_db / 100.0); - } - } else { - snprintf(dv, 127, "%.2f,%.2f,%.2f,%.2f", airplay_volume, 0.0, 0.0, 0.0); - } - send_ssnc_metadata('pvol', dv, strlen(dv), 1); -#endif + player_send_volume_metadata(volume_mode == vol_both, airplay_volume, scaled_attenuation, max_db, min_db, hw_max_db); if (config.output->mute) config.output->mute(0);