snapshot
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file communication-audiokit-rtsp.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Provide Microphone from AudioKit via RTSP. Depends on https://github.com/pschatzmann/Micro-RTSP-Audio
|
||||
* @version 0.1
|
||||
* @date 2022-05-02
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#define USE_RTSP_LOGIN // activate RTSP login support
|
||||
#include "AudioTools/Communication/RTSP.h"
|
||||
|
||||
int port = 554;
|
||||
AudioBoardStream kit(AudioKitEs8388V1); // Audio source
|
||||
RTSPAudioSource source(kit); // IAudioSource for RTSP
|
||||
RTSPAudioStreamer<RTSPPlatformWiFi> streamer(source); // Stream audio via RTSP
|
||||
RTSPServer<RTSPPlatformWiFi> rtsp(streamer, port);
|
||||
|
||||
const char* wifi = "wifi";
|
||||
const char* password = "password";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup Audiokit as source
|
||||
auto cfg = kit.defaultConfig(RX_MODE);
|
||||
cfg.input_device = ADC_INPUT_LINE2;
|
||||
cfg.channels = 1;
|
||||
cfg.sample_rate = 8000;
|
||||
cfg.bits_per_sample = 16;
|
||||
kit.begin(cfg);
|
||||
|
||||
// Start Wifi
|
||||
rtsp.begin(wifi, password);
|
||||
|
||||
}
|
||||
|
||||
void loop() { delay(1000); }
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @file communication-codec-rtsp.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Provide Audio via RTSP using a codec. Depends on https://github.com/pschatzmann/Micro-RTSP-Audio
|
||||
* @version 0.1
|
||||
* @date 2022-05-02
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecG7xx.h" // https://github.com/pschatzmann/arduino-libg7xx.git
|
||||
#define USE_RTSP_LOGIN // activate RTSP login support
|
||||
#include "AudioTools/Communication/RTSP.h"
|
||||
|
||||
int port = 554;
|
||||
AudioInfo info(8000, 1, 16);
|
||||
const char* wifi = "SSID";
|
||||
const char* password = "password";
|
||||
|
||||
// Sine tone generator
|
||||
SineFromTable<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
// rtsp
|
||||
RTSPFormatG711 format;
|
||||
G711_ULAWEncoder encoder;
|
||||
RTSPOutput<RTSPPlatformWiFi> rtsp_stream(format, encoder);
|
||||
StreamCopy copier(rtsp_stream, sound); // rtsp to sine
|
||||
// Server
|
||||
RTSPServer<RTSPPlatformWiFi> rtsp(*rtsp_stream.streamer(), port);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// Start Output Stream
|
||||
rtsp_stream.begin(info);
|
||||
|
||||
// Start Wifi & rtsp server
|
||||
rtsp.begin(wifi, password);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (rtsp_stream) {
|
||||
copier.copy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file communication-generator-rtsp.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Provide generated sine tone via RTSP.
|
||||
* @version 0.1
|
||||
* @date 2022-05-02
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
#define USE_RTSP_LOGIN // activate RTSP login support
|
||||
#include "AudioTools/Communication/RTSP.h"
|
||||
|
||||
int port = 554;
|
||||
AudioInfo info(16000,1,16); // AudioInfo for RTSP
|
||||
const char* wifi = "ssid";
|
||||
const char* password = "password";
|
||||
|
||||
SineFromTable<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
RTSPAudioSource source(sound, info); // Stream sound via RTSP
|
||||
RTSPAudioStreamer<RTSPPlatformWiFi> streamer(source);
|
||||
RTSPServer<RTSPPlatformWiFi> rtsp(streamer, port);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfgS = sineWave.defaultConfig();
|
||||
cfgS.copyFrom(info);
|
||||
sineWave.begin(cfgS, N_B4);
|
||||
|
||||
// Start Wifi & rtsp server
|
||||
rtsp.begin(wifi, password);
|
||||
}
|
||||
|
||||
void loop() { delay(1000); }
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
// Use the AudioPlayer to publish mp3 data as-is
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSourceSDMMC.h"
|
||||
#include "AudioTools/AudioCodecs/MP3Parser.h"
|
||||
#define USE_RTSP_LOGIN // activate RTSP login support
|
||||
#include "AudioTools/Communication/RTSP.h"
|
||||
|
||||
int port = 554;
|
||||
const char* wifi = "SSID";
|
||||
const char* password = "password";
|
||||
|
||||
// rtsp
|
||||
MP3ParserEncoder enc; // mp3 packaging
|
||||
RTSPFormatMP3 mp3format(enc); // RTSP mp3
|
||||
MetaDataFilterEncoder filter(enc);
|
||||
RTSPOutput<RTSPPlatformWiFi> rtsp_out(mp3format, filter);
|
||||
AudioSourceSDMMC source("/", ".mp3");
|
||||
CopyDecoder dec; // no decoding, just copy
|
||||
AudioPlayer player(source, rtsp_out, dec);
|
||||
RTSPServer<RTSPPlatformWiFi> rtsp(rtsp_out.streamer(), port);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// delay between mp3 files
|
||||
source.setTimeoutAutoNext(1000);
|
||||
|
||||
// start the player
|
||||
player.begin();
|
||||
|
||||
// Start Output Stream
|
||||
rtsp_out.begin();
|
||||
|
||||
// Start Wifi & rtsp server
|
||||
rtsp.begin(wifi, password);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (rtsp_out && rtsp) {
|
||||
player.copy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
|
||||
// Use the AudioPlayer to decode mp3 and publish as adpcm data
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSourceSDMMC.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "AudioTools/AudioCodecs/CodecADPCM.h"
|
||||
#define USE_RTSP_LOGIN // activate RTSP login support
|
||||
#include "AudioTools/Communication/RTSP.h"
|
||||
|
||||
int port = 554;
|
||||
const char* wifi = "SSID";
|
||||
const char* password = "password";
|
||||
|
||||
// mp3 data
|
||||
AudioSourceSDMMC source("/", ".mp3");
|
||||
MP3DecoderHelix mp3; // no decoding, just copy
|
||||
// rtsp
|
||||
ADPCMEncoder adpcm(AV_CODEC_ID_ADPCM_IMA_WAV, 512); // ima adpcm encoder
|
||||
RTSPFormatADPCM<ADPCMEncoder> adpcm_format(adpcm); // RTSP adpcm: provide info from encoder
|
||||
RTSPOutput<RTSPPlatformWiFi> rtsp_out(adpcm_format, adpcm);
|
||||
FormatConverterStream convert(rtsp_out);
|
||||
RTSPServer<RTSPPlatformWiFi> rtsp(rtsp_out.streamer(), port);
|
||||
// player
|
||||
AudioPlayer player(source, convert, mp3);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// no delay between mp3 files
|
||||
source.setTimeoutAutoNext(0);
|
||||
|
||||
// start the player
|
||||
player.begin();
|
||||
|
||||
// Start Output Stream
|
||||
rtsp_out.begin();
|
||||
|
||||
// convert the data format
|
||||
convert.begin(mp3.audioInfo(), rtsp_out.audioInfo());
|
||||
|
||||
// Start Wifi & rtsp server
|
||||
rtsp.begin(wifi, password);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (rtsp_out) {
|
||||
player.copy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
|
||||
/**
|
||||
* @file communication-rtsp-audiokit.ino
|
||||
* @brief RTSP client demo using the new UDP/RTP client and AudioKit output.
|
||||
* Connects to an RTSP server, decodes audio via MultiDecoder, and plays
|
||||
* out via `AudioBoardStream` (AudioKit ES8388). Tested with RTSP
|
||||
* servers. Requires WiFi on ESP32.
|
||||
*
|
||||
* Steps:
|
||||
* - Update WiFi credentials and RTSP server address/path below
|
||||
* - Builds a fixed pipeline: MultiDecoder -> ResampleStream -> AudioKit output
|
||||
* - Call client.copy() in loop to push received RTP payloads into decoders
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecADPCM.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h" // https://github.com/pschatzmann/arduino-libhelix
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/Communication/RTSP.h" // brings RTSPClientWiFi alias
|
||||
|
||||
const char* SSID = "ssid";
|
||||
const char* PASS = "password";
|
||||
IPAddress srv(192, 168, 1, 39); // change to your RTSP server IP
|
||||
const uint16_t rtspPort = 8554; // typical RTSP port
|
||||
const char* rtspPath =
|
||||
"stream"; // change to your RTSP server path (e.g., "audio", "stream1")
|
||||
AudioBoardStream i2s(AudioKitEs8388V1);
|
||||
RTSPClientWiFi client(i2s);
|
||||
MP3DecoderHelix mp3; // Decoder for "audio/mpeg" (MP3) payloads
|
||||
ADPCMDecoder adpcm(AV_CODEC_ID_ADPCM_IMA_WAV, 512); // ima adpcm decoder
|
||||
|
||||
void startWiFi() {
|
||||
WiFi.begin(SSID, PASS);
|
||||
Serial.print("Connecting to WiFi");
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("WiFi connected, IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
WiFi.setSleep(false);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// Connect WiFi
|
||||
startWiFi();
|
||||
|
||||
// Configure and start I2S/AudioKit output
|
||||
auto cfg = i2s.defaultConfig(TX_MODE);
|
||||
cfg.sd_active = false;
|
||||
i2s.begin(cfg);
|
||||
|
||||
// Start RTSP session
|
||||
client.addDecoder("audio/mpeg", mp3);
|
||||
client.addDecoder("audio/adpcm", adpcm);
|
||||
client.setResampleFactor(1.0); // no resampling
|
||||
// Servers often require a concrete path; also extend header timeout if needed
|
||||
client.setHeaderTimeoutMs(8000);
|
||||
if (!client.begin(srv, rtspPort, rtspPath)) {
|
||||
Serial.println("Failed to start RTSP client");
|
||||
stop();
|
||||
}
|
||||
Serial.println("RTSP client started");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Push next available RTP payload to decoder chain
|
||||
client.copy();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
/**
|
||||
* @file communication-rtsp555-i2s.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Demo for RTSP Client that is playing mp3. I tested with the live555 server with linux
|
||||
* @version 0.1
|
||||
* @date 2022-05-02
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h" // https://github.com/pschatzmann/arduino-audio-tools
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h" // https://github.com/pschatzmann/arduino-libhelix
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h" // https://github.com/pschatzmann/arduino-audio-driver
|
||||
#include "AudioTools/Communication/RTSPClient555.h" // install https://github.com/pschatzmann/arduino-live555
|
||||
|
||||
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
|
||||
EncodedAudioStream out_mp3(&i2s, new MP3DecoderHelix()); // Decoding stream
|
||||
AudioClientRTSP rtsp(1024);
|
||||
|
||||
void setup(){
|
||||
rtsp.setLogin("ssid", "password");
|
||||
rtsp.begin("https://samples.mplayerhq.hu/A-codecs/MP3/01%20-%20Charity%20Case.mp3", out_mp3);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
rtsp.loop();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @file communication-rtsp666-i2s.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Demo for RTSP Client that is playing mp3: tested with the live555 server with linux
|
||||
* @version 0.1
|
||||
* @date 2022-05-02
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "AudioTools.h" // https://github.com/pschatzmann/arduino-audio-tools
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h" // https://github.com/pschatzmann/arduino-libhelix
|
||||
#include "RTSPSimpleClient.hh" // https://github.com/pschatzmann/arduino-live555.git
|
||||
|
||||
I2SStream i2s;
|
||||
EncodedAudioStream out_mp3(&i2s, new MP3DecoderHelix()); // Decoding stream
|
||||
RTSPSimpleClient rtsp;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup output: make sure we can buffer 1 decoded frame
|
||||
auto cfg_i2s = i2s.defaultConfig(TX_MODE);
|
||||
cfg_i2s.buffer_size = 1024;
|
||||
cfg_i2s.buffer_count = 10;
|
||||
i2s.begin(cfg_i2s);
|
||||
|
||||
out_mp3.begin();
|
||||
|
||||
// setup rtsp data source
|
||||
auto cfg = rtsp.defaultConfig();
|
||||
cfg.ssid = "ssid";
|
||||
cfg.password = "password";
|
||||
cfg.url = "rtsp://192.168.1.38:8554/test.mp3";
|
||||
cfg.output = &out_mp3;
|
||||
cfg.buffer_size = 1024*2; // space for 1 encoded frame
|
||||
//cfg.is_tcp = false; // use udp when false (default false)
|
||||
//cfg.is_blocking = false; // call singleStep in loop if false (default false)
|
||||
rtsp.begin(cfg);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
rtsp.singleStep();
|
||||
}
|
||||
Reference in New Issue
Block a user