masmu / pulseaudio-dlna

A lightweight streaming server which brings DLNA / UPNP and Chromecast support to PulseAudio and Linux
GNU General Public License v3.0
1.25k stars 162 forks source link

pacat/parec internal encoder #84

Closed rommon closed 7 years ago

rommon commented 9 years ago

did you tried to use the already integrated encoder? parec already supports lots of codecs out of the box.

parec --list-file-formats
aiff    AIFF (Apple/SGI)
au      AU (Sun/NeXT)
avr     AVR (Audio Visual Research)
caf     CAF (Apple Core Audio File)
flac    FLAC (FLAC Lossless Audio Codec)
htk     HTK (HMM Tool Kit)
iff     IFF (Amiga IFF/SVX8/SV16)
mat     MAT4 (GNU Octave 2.0 / Matlab 4.2)
mat     MAT5 (GNU Octave 2.1 / Matlab 5.0)
mpc     MPC (Akai MPC 2k)
oga     OGG (OGG Container format)
paf     PAF (Ensoniq PARIS)
pvf     PVF (Portable Voice Format)
raw     RAW (header-less)
rf64    RF64 (RIFF 64)
sd2     SD2 (Sound Designer II)
sds     SDS (Midi Sample Dump Standard)
sf      SF (Berkeley/IRCAM/CARL)
voc     VOC (Creative Labs)
w64     W64 (SoundFoundry WAVE 64)
wav     WAV (Microsoft)
wav     WAV (NIST Sphere)
wav     WAVEX (Microsoft)
wve     WVE (Psion Series 3)
xi      XI (FastTracker 2)

I tested it locally and vlc was able to directly play it. The file is increasing fast, after 1,5 minutes it is already about 11 MB. I guess you have the same "problem" with the current approach.

parec -r --monitor-stream=0 --file-format=flac testfile4.flac

maybe that will remove some delay and distortion caused by the encoder.

I opened the file with vlc in parallel while recording and vlc had no problems playing the file.

masmu commented 9 years ago

I did not. But that is awesome. Somehow I missed that all the time. Will play with that around!

rommon commented 9 years ago

I would like to help you with that. Would you point me to the files and maybe give some hints?

masmu commented 9 years ago

That would be great!

I did a little bit of research and that is my current state: At the moment always a command like parec --format=s16le -d wohnzimmer_dlna.monitor is used to record the audio data. This data is piped through an encoder with specific arguments and the output of this is transported by HTTP. So basiclly it is e.g. parec --format=s16le -d wohnzimmer_dlna.monitor | lame -b 192.

When I just enter parec --format=s16le -d wohnzimmer_dlna.monitor in a terminal parec writes the data to stdout and I get many cryptic symbols representing the actual recorded data. But as soon as i add the --file-format=wav option it does not print the data to stdout. Instead it creates a file named wav and writes the data into it.

But we need it to write it to stdout. Thats the problem at the moment. So I also tried it with named pipes but that just worked for the flac format. (parec --format=s16le -d wohnzimmer_dlna.monitor --file-format=flac >(cat)) It did not work with named pipes and wav or oga ...

masmu commented 8 years ago

I just pushed a new branch where i made some changes necessary for the file format stuff.

A sample codec looks like the following:

class PaFlacCodec(BaseCodec):

    SUPPORTED_MIME_TYPES = ['audio/flac', 'audio/x-flac']
    IDENTIFIER = 'pa_flac'

    def __init__(self, mime_string=None):
        BaseCodec.__init__(self)
        self.priority = 9
        self.suffix = 'flac'
        self.mime_type = mime_string or 'audio/flac'

    @property
    def encoder(self):
        return pulseaudio_dlna.encoders.NullEncoder()

    def get_recorder(self, monitor):
        return pulseaudio_dlna.recorders.PulseaudioRecorder(monitor, 'flac')
rommon commented 8 years ago

in this branch there isn't the sample code included, right?

I replaced the FlacCodec class with PaFlacCodec (FlacCodec is not in the code anymore). Furthermore I replaced the identifier to pa_flac in the devices.json file.

It directly worked.

09-26 13:55:50 pulseaudio_dlna.streamserver                   DEBUG    Starting processes "parec --format=s16le -d 192168242sonosplay3_dlna.monitor --file-format=flac | cat"
09-26 13:55:50 pulseaudio_dlna.streamserver                   INFO     Processes of /dWRuPXV1aWQ6UklOQ09OXzAwMEU1OEZFM0MyNjAxNDAwX01S/stream.flac initialized ...

There was some stuttering again at the begining, but I "fixed" that with sliding the volume in pavucontrol.

I have to say that it reacts way faster now on changes in the music streaming, maybe 1,5 seconds. At the beginning it felt like less than a second.

masmu commented 8 years ago

Oh that's cool. What is your OS and pulseaudio version? I did not managed to get it working here ... probably because of different pulseaudio versions.

masmu commented 8 years ago

in this branch there isn't the sample code included, right?

Correct.

masmu commented 8 years ago

Did you try out other codecs? wav would be interesting ...

rommon commented 8 years ago
rommon commented 8 years ago

I am currently testing with wav, but you are right that it is more complicated.

It shows the following.

09-26 17:14:05 pulseaudio_dlna.streamserver                   INFO     Got request from SonosZP.fritz.box - GET /dWRuPXV1aWQ6UklOQ09OXzAwMEU1OEZFM0MyNjAxNDAwX01S/stream.wav HTTP/1.1,200,-
09-26 17:14:05 pulseaudio_dlna.streamserver                   INFO     Client 192.168.2.42 registered to stream /dWRuPXV1aWQ6UklOQ09OXzAwMEU1OEZFM0MyNjAxNDAwX01S/stream.wav.
09-26 17:14:05 pulseaudio_dlna.streamserver                   DEBUG    Starting processes "parec --format=s16le -d 192168242sonosplay3_dlna.monitor --file-format=wav | cat"
09-26 17:14:05 pulseaudio_dlna.streamserver                   INFO     Processes of /dWRuPXV1aWQ6UklOQ09OXzAwMEU1OEZFM0MyNjAxNDAwX01S/stream.wav initialized ...
Failed to open audio file.
09-26 17:14:05 pulseaudio_dlna.streamserver                   DEBUG    Starting processes "parec --format=s16le -d 192168242sonosplay3_dlna.monitor --file-format=wav | cat"
09-26 17:14:05 pulseaudio_dlna.streamserver                   INFO     Processes of /dWRuPXV1aWQ6UklOQ09OXzAwMEU1OEZFM0MyNjAxNDAwX01S/stream.wav reinitialized ...
Failed to open audio file.
09-26 17:14:05 pulseaudio_dlna.streamserver                   DEBUG    Starting processes "parec --format=s16le -d 192168242sonosplay3_dlna.monitor --file-format=wav | cat"
09-26 17:14:05 pulseaudio_dlna.streamserver                   INFO     Processes of /dWRuPXV1aWQ6UklOQ09OXzAwMEU1OEZFM0MyNjAxNDAwX01S/stream.wav reinitialized ...
Failed to open audio file.
09-26 17:14:05 pulseaudio_dlna.streamserver                   ERROR    There were more than 3 attempts to reinitialize the record process. Aborting.
09-26 17:14:05 pulseaudio_dlna.streamserver                   INFO     Processes of /dWRuPXV1aWQ6UklOQ09OXzAwMEU1OEZFM0MyNjAxNDAwX01S/stream.wav reinitialized ...
^C09-26 17:15:06 pulseaudio_dlna.pulseaudio                     INFO     Remove "192168242sonosplay3_dlna" sink ...
Application is shutting down.
09-26 17:15:06 pulseaudio_dlna.pulseaudio                     INFO     Remove "192168242sonosplay3_dlna" sink ...
Failure: No such entity
09-26 17:15:06 pulseaudio_dlna.pulseaudio                     ERROR    Could not remove entity 40
09-26 17:15:06 pulseaudio_dlna.pulseaudio                     ERROR    Could not remove entity 40
masmu commented 8 years ago

If it does reinitialize the process there is something wrong with the command line. Normally it would start the process over and over again, but i inserted a security rule to do this max 3 times in a certain time period.