b-fitzpatrick / cpiped

Captures an audio stream and outputs to a pipe with buffering and silence detection
GNU General Public License v3.0
71 stars 13 forks source link

Allow for parameters in silence and start commands #7

Open maweki opened 6 years ago

maweki commented 6 years ago

I wanted to start a custom script with a parameter when cpiped detects a sound but there is a check whether this is a valid file. But since I have a space with the parameters, that is not a valid file. Removing the check from the source code works.

I am not good at writing C or I would have sent a fix. Sorry

At the end I get

Invalid start command: /root/cpiped-snapcast-ctrl/playing.py chromecast

but actually executing it works fine.

b-fitzpatrick commented 6 years ago

You can just create a script to call other the script with a parameter.

maweki commented 6 years ago

That is one way. Because of orthogonality I think that the check is superfluous and should be omitted. It doesn't work for commands that have parameters. It doesn't work for commands that are in PATH and it doesn't work for commands that are part of the shell and don't actually have a corresponding file. But all are actually callable by system().

I think it is pretty hard to find out beforehand whether a command is valid or not.

In my ansible orchestration after cloning and before making I replace the stat-checks with zero and skip that part. It works fine and you never care about the return code of the actual invocation anyways.

So yeah, I just think the check really narrows the use cases of that feature.

Edit: the check also doesn't check whether the file is executable or not so it still might not be invokable after all.

dmckminard commented 5 years ago

@maweki , can you explain a bit how you've make it working please ?

maweki commented 5 years ago

Again, I wholeheartedly believe that the checks in https://github.com/b-fitzpatrick/cpiped/blob/master/cpiped.c#L128 and https://github.com/b-fitzpatrick/cpiped/blob/master/cpiped.c#L136 are a bad idea and are really limiting.

To fix this, in my ansible deployment I have the following lines:

- name: repair cpiped start and end command
  replace:
    path: ~/cpiped/cpiped.c
    replace: '0'
    regexp: 'stat\((.)*cmd\,\ \&status\)\ \!\=\ 0'

@dmckminard so for you, you would replace the lines 128 and 136 so that they read if (0) { instead of if (stat(startcmd, &status) != 0) { and if (stat(endcmd, &status) != 0) {.

You could delete the whole if-construct but that would be more invasive.

dmckminard commented 5 years ago

Ok thanks a lot, it works ! And maybe, do you know something that could check if I've got an input sound (like this cpiped -s/cpiped -e) but independently from cpiped ?