Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libavdevice/pulse_audio_enc: remove inevitable early return in mute state and volume change callback
@ 2022-12-18 21:30 Varun Dhar
  2022-12-18 21:30 ` Varun Dhar
  0 siblings, 1 reply; 2+ messages in thread
From: Varun Dhar @ 2022-12-18 21:30 UTC (permalink / raw)
  To: ffmpeg-devel


This patch removes an inevitable early return in libavdevice/pulse_audio_enc.c that prevents the user from accessing the volume or mute state of a pulseaudio output device. This happens because pulse_update_sink_input_info() passes a new pulseaudio context to pulse_audio_sink_input_cb(), causing the early return condition s->ctx != ctx (pulse_audio_enc.c:98) to always be true as ctx is a new context whereas s->ctx is the old context. As the early return is inevitable, the user is unable to access the volume or mute state. With this patch, the user will be able to access the volume or mute state of a pulseaudio output device.

The following code is an example showing the issue. It creates a pulse output device, sets the volume, then gets the volume:

#include <stddef.h>
#include <assert.h>

#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
#include <libavcodec/avcodec.h>

//volume callback
int get_volume(AVFormatContext *ctx, int type, void *data, size_t size){
	if(type == AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED){
		*(double*)ctx->opaque = *(double*)data;
		return 0;
	}
	return AVERROR(ENOSYS);
}

int main(){
	avdevice_register_all();
	//set up pulse output stream
	AVFormatContext* ctx = NULL;
	avformat_alloc_output_context2(&ctx,NULL,"pulse",NULL);
	AVStream* stream = avformat_new_stream(ctx,NULL);
	AVCodecParameters* stream_params = stream->codecpar;
	stream_params->codec_type = AVMEDIA_TYPE_AUDIO;
	stream_params->codec_id = AV_CODEC_ID_PCM_S16LE;
	stream_params->sample_rate = 48000;
	stream_params->ch_layout.nb_channels = 2;
	stream_params->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
	avformat_write_header(ctx,NULL);

	//set volume to 50%
	double vol = 0.5;
	avdevice_app_to_dev_control_message(ctx,AV_APP_TO_DEV_SET_VOLUME,&vol,sizeof(vol));
	vol = 0;

	//get volume (should be 50% (0.5))
	ctx->opaque = &vol;
	ctx->control_message_cb = &get_volume;
	avdevice_app_to_dev_control_message(ctx,AV_APP_TO_DEV_GET_VOLUME,NULL,0);
	assert(vol == 0.5);

	av_write_trailer(ctx);
	avformat_free_context(ctx);
}


_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-18 21:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-18 21:30 [FFmpeg-devel] [PATCH] libavdevice/pulse_audio_enc: remove inevitable early return in mute state and volume change callback Varun Dhar
2022-12-18 21:30 ` Varun Dhar

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git