Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAW_OUTPUT not opening FIFO #409

Closed
antiprism opened this issue Jun 12, 2021 · 2 comments
Closed

RAW_OUTPUT not opening FIFO #409

antiprism opened this issue Jun 12, 2021 · 2 comments

Comments

@antiprism
Copy link
Contributor

Hi Karl

I had an issue reported for mpd_oled yesterday that was introduced with the last cava commit: be7c5b8

http://moodeaudio.org/forum/showthread.php?tid=155&pid=34372#pid34372

mpd_oled creates a FIFO for cava to write to, and then runs cava with a configuration like

[output]
method = raw
data_format = binary
channels = mono
raw_target = /tmp/cava_fifo_307165
bit_format = 8bit

Which leads to this section of cava code being run

if (access(p.raw_target, F_OK) != -1) {
                          // testopening in case it's a fifo
                          fptest = open(p.raw_target, O_RDONLY | O_NONBLOCK, 0644);
  
                          if (fptest == -1) {
                              fprintf(stderr, "could not open file %s for writin  g\n", p.raw_target);
                              exit(1);
                          }
                      } else...

In the old code there was a later unconditional line

fp = open(p.raw_target, O_WRONLY | O_NONBLOCK | O_CREAT, 0644)  ;

This is removed and made conditional in the new code, which leads to no spectrum (and fp is being initialised to 0 for me, which is maybe standard input!)

I also noticed the commit left a printf

printf("creating fifo %s\n", p.raw_target);

Could the code be simplified to something like

case OUTPUT_RAW:
                  if (strcmp(p.raw_target, "/dev/stdout") != 0) {
                      // checking if file exists
                      if (access(p.raw_target, F_OK) == -1) {
                          fprintf(stderr, "creating fifo %s\n", p.raw_target);
                          if (mkfifo(p.raw_target, 0664) == -1) {
                              fprintf(stderr, "could not create fifo %s\n", p.raw_target);
                              exit(1);
                          }
                      }
                      fp = open(p.raw_target, O_RDWR | O_NONBLOCK, 0644);
                  } else {
                      fp = fileno(stdout);
                      fprintf(stderr, "Opening stdout\n");
                  }
                  if (fp == -1) {
                      fprintf(stderr, "could not open file %s for writing\n", p.raw_target);
                      exit(1);
                  }
                  fprintf(stderr, "open file %s for writing raw output\n", p.raw_target);

I checked this with mpd_oled creating the FIFO and then calling cava, and also letting cava create the FIFO and mpd_oled simply opening it, and it worked in both cases.

Adrian.

@karlstav
Copy link
Owner

should work now, I was a bit quick when merging the previous commit so the fifo was actually only opened when it did not already exist.

the code here is a bit confusing the fptest was needed in order to achieve something and I have forgotten what it was. I think it had to do with keeping it non_blocking.

@antiprism
Copy link
Contributor Author

Hi Karl

All working well with mpd_oled.

Thanks for the quick update!

Adrian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants