From: Varun Dhar <vdhar1@protonmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] libavdevice/pulse_audio_enc: remove inevitable early return in mute state and volume change callback Date: Sun, 18 Dec 2022 21:30:07 +0000 Message-ID: <20221218212952.1267905-1-vdhar1@protonmail.com> (raw) 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".
next reply other threads:[~2022-12-18 21:30 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-18 21:30 Varun Dhar [this message] 2022-12-18 21:30 ` Varun Dhar
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221218212952.1267905-1-vdhar1@protonmail.com \ --to=vdhar1@protonmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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