Bug 106982

Summary: pulseaudio-12.0/src/pulsecore/sink-input.c:2017: confused logic ?
Product: PulseAudio Reporter: dcb314
Component: coreAssignee: pulseaudio-bugs
Status: RESOLVED FIXED QA Contact: pulseaudio-bugs
Severity: normal    
Priority: medium CC: lennart
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description dcb314 2018-06-21 07:25:22 UTC
pulseaudio-12.0/src/pulsecore/sink-input.c:2017]: (style) Redundant condition: If 'EXPR == 1', the comparison 'EXPR != 2' is always true.

Source code is

    if ((state == PA_SINK_INPUT_DRAINED || state == PA_SINK_INPUT_RUNNING) &&
        !(i->thread_info.state == PA_SINK_INPUT_DRAINED || i->thread_info.state != PA_SINK_INPUT_RUNNING))
Comment 1 Tanu Kaskinen 2018-06-26 10:02:46 UTC
This is ancient code, and I'm not sure what Lennart intended to do. I found out, though, that neither state nor i->thread_info.state can ever be DRAINED, so the code could be simplified to

    if (state == PA_SINK_INPUT_RUNNING && !(i->thread_info.state != PA_SINK_INPUT_RUNNING))

and that can be simplified to

    if (state == PA_SINK_INPUT_RUNNING && i->thread_info.state == PA_SINK_INPUT_RUNNING)

That condition is never true, because there's an earlier check:

if (state == i->thread_info.state)
    return;

I think the intent was to use == rather than != in the last comparison, so if the state changes from non-running to running, then the sink input is marked as drained.

In any case, the only purpose of the DRAINED state seems to be to show when the sink input playback buffer is empty in the command line interface. In all other contexts the DRAINED and RUNNING states are handled identically. I think the usage doesn't justify the complexity, so I'll make a patch that removes the DRAINED state altogether.
Comment 2 Tanu Kaskinen 2018-06-26 13:27:21 UTC
I submitted a patch: https://patchwork.freedesktop.org/patch/232141/
Comment 3 Tanu Kaskinen 2018-07-09 12:23:06 UTC
The fix is in master now.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.