D
D
Dobroe3lo2019-08-26 09:47:14
linux
Dobroe3lo, 2019-08-26 09:47:14

How to send an audio file over POST HTTP using PulseAudio?

Good morning.
Unable to send audio file to device.
There is the following code, which sends a request syntax via POST http to the api device (enables playback on the device), then streams the audio file. Used by lpulse - pa_simple_new().
When you run the collected file:
http is sent, the device works, but the audio is not played
when sending, the following error occurs in the terminal

Connect to: 192.168.13.122
cgiplay_AudioOut_HTTP.cpp: pa_simple_new() failed: No such file or directory
Segmentation fault (core dumped)

Code part:
int main(int argc, char*argv[]) {
  
char *servermessage;	
const char *header = "POST /cgi-bin/transmitaudio_cgi?user=admin&pwd=Admin123 HTTP/1.1\r\nConnection: Keep-Alive\r\nContent-Type: G.711U;boundary=audio\r\n\r\n";
const char *audio = "--audio";
fd = socket_connect("192.168.2.38", atoi("80"));

write(fd, header, strlen(header));

/* The Sample format to use */
static const pa_sample_spec ss = {
    .format = PA_SAMPLE_ULAW,
    .rate = 8000,
    .channels = 1
};

pa_simple *s_in, *s_out = NULL;
int ret = 1;
int error;


/* Create a new playback stream */
if (!(s_out = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "123", &ss, NULL, NULL, &error))) {
    fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", strerror(errno));
    goto finish;
}

for (;;) {
    uint8_t buf[BUFSIZE];
    ssize_t r;

    if (pa_simple_read(s_in, buf, sizeof(buf), &error) < 0) {

        fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
        goto finish;
    }

    if(write(fd, buf, BUFSIZE) != BUFSIZE)
            printf("\nErr\n");
    if(write(fd, audio, 7) != 7)
            printf("\nErr\n");*/
    
    if (pa_simple_write(s_out, buf, sizeof(buf), &error) < 0) {
        fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", strerror(errno));
        goto finish;
    }
}

I don’t understand where in the code to specify the audio file that needs to be streamed.
Right now, where pa_simple_new "123" is the name of the audio file, but as I understand it, it's not true.
Used Pulse

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2019-08-26
@res2001

As far as I know, pulseaudio itself cannot read sound files.
It can only write to (play) or read from (record) an audio device audio data.
From the audio file, the data must be read by other means. For example, you can use libsndfile . The read data is already ready to be played back in pulseaudio.
Something like this.
I haven't gotten to grips with pulseaudio myself yet, but I'll be doing it soon, so I'm still learning about it. libsndfile is a fairly simple library that supports several widely used audio file formats (mp3 is not supported due to licensing reasons).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question