How to receive mp3 stream in UPNP media renderer using libsoup?



Hi all.

I'm somewhat new to Gnome libraries and I have some specific questions
for using libsoup for an embedded UPNP device.

How do I receive HTTP headers only and then disconnect using Libsoup?
And how to do it in non-blocking way and integrate with range requests
and chunked responses?

The long story:

I have partly implemented a UPNP proxy (using Gupnp) which will receive
MP3 stream from one device, process it in specific ways, format it and
send to another UPNP device.

Now I want to receive http-get audio/mpeg stream from UPNP source
server, but there are some tricky scenarios to deal with:

  -  source server might not accept range requests but report
Content-Length - in this case I'll have to download entire mp3 file into
reasonably limited size RAM cache

   - source might not report Content-Length at all and not accept range
requests - in this case I'll download mp3 file in background up to
reasonably sane limit

   - source might accept range requests - in this case I'll download
chunks of mp3 file on a timer at pace required by audio playback endpoint

   - source might send data as Transfer-Encoding: chunked in which case
I'll have to download separate chunks without missing any (it might be
live stream)

In all these cases I have to receive the HTTP headers alone first and
inspect them to find out how to set up internal data structures and how
to continue streaming and whether it is possible to continue at all (if
not, I'll have to send corresponding UPNP state and position events to
UPNP control points).

Also, while receiving HTTP headers (and later also mp3 stream) my
program should not block - it should continue streaming out the audio
data it already had received and also respond to UPNP requests.

I have already implemented simple HTTP Soup client using
soup_session_queue_message but I'm confused in which cases I should use
soup_session_send_async instead and how to abort connection right after
receiving HTTP headers and then how to proceed receiving mp3 data in
background.

I have been reading libsoup documentation and while it has some useful
code pieces, it doesn't give answers about use cases - which approach
should be used when, and how to achieve non-blocking but grained control
over the process without using explicit multithreading (which seems to
be discouraged in the libsoup documentation and I also would like to
avoid it, if possible).

I know that it might be possible to use gstreamer for the streaming
stuff, but I don't want to add dependency of it and also I'll need to
have access to raw audio samples and do some conditional dispatching
(the target UPNP device is picky and in some cases I can feed it initial
mp3 data, but in some other cases I'll have to re-encode it using
lame-mp3). Also I've heard that gstreamer is not meant to be used as a
plug-in in my code but vice versa.

If you have any suggestions or maybe know any tutorials or simple
projects which have already implemented similar use cases
(range/chunked/entire file mp3 stream receiving for UPNP media
renderer), I'd be grateful for some links.

Regards,
Martin

---
Avast antivīrusa programmatūra pārbaudīja, vai šajā e-pasta ziņojumā nav vīrusu.
https://www.avast.com/antivirus



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]