Introduction

I wanted to make some music streaming functionality available on Arduino. There are plenty of private music services using custom protocols which are out of reach. Fortunately there are also the open source protocols RTP and RTSP:

  • RTP is the transport protocol for real-time data. It provides timestamp, sequence number, and other means to handle the timing issues in real-time data transport.
  • RTSP is a control protocol that initiates and directs delivery of streaming multimedia data from media servers.

So, I took the effort to make the LIVE555 library also available for Arduino. For the time being I only support the ESP32 microcontroller.

At some point of time I thought I had it working, but the sound is breaking up very badly. I spent a couple of days to resolve the issue, but so far did not have any success! It would be interesting to hear from you if you get the same issue – so that I can exclude my home infrastructure as cause of the problem.

LIVE555

LIVE555 is a set of open source (LGPL) C++ libraries developed by Live Networks, Inc. for multimedia streaming. The libraries support open standards such as RTP/RTCP and RTSP for streaming, and can also manage video RTP payload formats such as MPEG, AAC, AMR, AC-3 and Vorbis.

It is used internally by well-known software such as VLC and MPlayer.

In order to make the library available for Arduino I have

  • Created the src directory with symlinks to all source files
  • Deactivated exceptions (with the help of #defines)
  • Used lwip as network interface
  • Replaced printf(stderr, …) with a separate LOG() method, so that we can handle them properly in Arduino
  • Renamed inet.c to inet.cpp so that we can use c++ classes
  • Implemented plenty of platform specific corrections
  • Provided a file abstraction layer to replace the stdio.h operations so that we can use different SD libraries

The biggest challenge was with the last point. Unfortunately Arduino does not provide a proper stdio.h implementation that can be used to access files. On the other hand most projects assume that stdio.h is available and therefore do not use any additional abstraction layer: live555 is here not an exception.

Example Arduino Sketch

I have also created a simple mp3 streaming API. Here is an example that uses the SdFat library from Bill Greiman to access the mp3 files on a SD card:

#include "FileAccessSdFat.hh"
#include "SimpleStreamer.hh"

SimpleMP3Streamer mp3(new FileAccessSdFat());

void setup() {
  Serial.begin(115200);

  auto cfg = mp3.defaultConfig();
  cfg.destinationAddress = "192.168.1.255";
  cfg.filePath = "/Music/Conquistadores.mp3";
  cfg.isAutoRestart = true;
  cfg.ssid = "SSID";
  cfg.password = "password";

  if (mp3.begin(cfg)){
    mp3.play();
  }
}


void loop() {
  mp3.doEventLoop();
}

In the constructor of the SimpleMP3Streamer we indicate the file access class. For starting the streaming we need to provide the file and the destination ip address: 192.168.1.255 is a broadcast address.
If we did not start the network yet we need to provide the ssid and password.
The cfg.isAutoRestart = true; is making shure that when the end of the file is reached that we restart again.

VLC Player

The VLC Player can be used to receive the streamed music. Just use -> File -> Open Network and enter the udp://@:6666 address.

Github

The project can be found on Github!


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *