@@ -730,6 +730,8 @@ static bool connect_disconnect_rec_stream(
730730static void context_state_callback (pa_context * c , void * userdata ) {
731731 struct userdata * u = userdata ;
732732 pa_stream_flags_t flags = 0 ;
733+ pa_cvolume cvolume = {1 , {u -> volume }};
734+ pa_cvolume * vol = (u -> volume != -1 ) ? & cvolume : NULL ;
733735
734736 assert (c );
735737
@@ -773,7 +775,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
773775 if (verbose > 1 )
774776 flags |= PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_INTERPOLATE_TIMING ;
775777
776- if (pa_stream_connect_playback (u -> play_stream , u -> play_device , bufattr , flags , NULL /* volume */ , NULL ) < 0 ) {
778+ if (pa_stream_connect_playback (u -> play_stream , u -> play_device , bufattr , flags , vol /* volume */ , NULL ) < 0 ) {
777779 pacat_log ("pa_stream_connect_playback() failed: %s" , pa_strerror (pa_context_errno (c )));
778780 goto fail ;
779781 }
@@ -1132,6 +1134,7 @@ static _Noreturn void usage(char *arg0, int arg) {
11321134 fprintf (stream , " -v - verbose logging (a lot of output, may affect performance)\n" );
11331135 fprintf (stream , " -t size - target playback buffer fill, implies -l, default %d\n" ,
11341136 custom_bufattr .tlength );
1137+ fprintf (stream , " -V volume - set the target playback volume\n" );
11351138 fprintf (stream , " -h - print this message\n" );
11361139 if (fflush (NULL ) || ferror (stdout ) || ferror (stderr ))
11371140 exit (1 );
@@ -1151,9 +1154,10 @@ int main(int argc, char *argv[])
11511154 char * endptr ;
11521155
11531156 memset (& u , 0 , sizeof (u ));
1157+ u .volume = -1 ; // by default the volume is not readjusted
11541158 if (argc <= 2 )
11551159 usage (argv [0 ], 1 );
1156- while ((i = getopt (argc , argv , "+lnbvt:h" )) != -1 ) {
1160+ while ((i = getopt (argc , argv , "+lnbvt:V: h" )) != -1 ) {
11571161 switch (i ) {
11581162 case 'l' :
11591163 bufattr = & custom_bufattr ;
@@ -1179,6 +1183,17 @@ int main(int argc, char *argv[])
11791183 bufattr = & custom_bufattr ;
11801184 custom_bufattr .tlength = tlength ;
11811185 break ;
1186+ case 'V' :
1187+ errno = 0 ;
1188+ u .volume = strtoul (optarg , & endptr , 0 );
1189+ if (* endptr )
1190+ errx (1 , "Invalid -V argument: %s" , optarg );
1191+ if (u .volume > 150 ) // pluse accepts volume greater than 100%
1192+ errno = ERANGE ;
1193+ if (errno )
1194+ err (1 , "Invalid -V argument: %s" , optarg );
1195+ u .volume = PA_VOLUME_NORM * u .volume / 100 ;
1196+ break ;
11821197 case 'h' :
11831198 usage (argv [0 ], 0 );
11841199 default :
@@ -1205,7 +1220,6 @@ int main(int argc, char *argv[])
12051220 if (create_pidfile (u .domid , & pidfile_path , & pidfile_fd ) < 0 )
12061221 /* error already printed by create_pidfile() */
12071222 exit (1 );
1208- goto main ;
12091223
12101224main :
12111225 u .ret = 1 ;
0 commit comments