Commit 645e2c1e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Support for custom SDP file

Patch by Mo McRoberts <mo@nevali.net>
parent 5202876a
......@@ -100,59 +100,65 @@ Message::~Message(void)
bool Message::AddProgram(Program *p)
{
string sdp = "v=0\r\n"; // SDP version
/* FIXME */
/* RFC 2327 Compliance ? */
string ipv = (p->GetAddress().find(':') == string::npos) ? "IP4" : "IP6";
string sdp = "v=0\r\n"; // SDP version
string ver="";
stringstream ssin(ver);
ssin << version;
ver = ssin.str();
sdp += "o=" + p->GetUser() + " " + ver + " 1 IN " + ipv + " "
+ p->GetMachine() + "\r\n";
sdp += "s=" + p->GetName() + "\r\n";
sdp += "u=" + p->GetSite() + "\r\n";
sdp += "c=IN " + ipv + " " + p->GetAddress();
if (ipv == "IP4")
sdp += "/" + p->GetTTL(); /* only IPv4 multicast shall have a TTL */
sdp += "\r\n";
if (p->IsPermanent())
sdp += "t=0 0\r\n";
if (p->HasCustomSDP())
{
sdp = p->GetCustomSDP();
}
else
return false;
/* Session level attributes */
sdp += "a=tool:" + (string)PACKAGE_STRING + "\r\n";
if (p->HasPlGroup())
sdp += "a=x-plgroup:" + p->GetPlGroup() + "\r\n";
/* Media and media-level attributes */
sdp += "a=type:broadcast\r\n";
sdp += "a=charset:UTF-8\r\n";
char portbuf[6];
snprintf(portbuf, sizeof(portbuf), "%u", (unsigned)p->GetPort());
string port = portbuf;
string m = "m=video " + port + " "
+ (p->IsRTP() ? "RTP/AVP 33" : "udp mpeg") +"\r\n";
if (p->IsRTP())
{
m += "a=rtpmap:33 MP2T/90000\r\n";
if (p->IsRTP() & 1)
string ipv = (p->GetAddress().find(':') == string::npos) ? "IP4" : "IP6";
string ver="";
stringstream ssin(ver);
ssin << version;
ver = ssin.str();
sdp += "o=" + p->GetUser() + " " + ver + " 1 IN " + ipv + " "
+ p->GetMachine() + "\r\n";
sdp += "s=" + p->GetName() + "\r\n";
sdp += "u=" + p->GetSite() + "\r\n";
sdp += "c=IN " + ipv + " " + p->GetAddress();
if (ipv == "IP4")
sdp += "/" + p->GetTTL(); /* only IPv4 multicast shall have a TTL */
sdp += "\r\n";
if (p->IsPermanent())
sdp += "t=0 0\r\n";
else
return false;
/* Session level attributes */
sdp += "a=tool:" + (string)PACKAGE_STRING + "\r\n";
if (p->HasPlGroup())
sdp += "a=x-plgroup:" + p->GetPlGroup() + "\r\n";
/* Media and media-level attributes */
sdp += "a=type:broadcast\r\n";
sdp += "a=charset:UTF-8\r\n";
char portbuf[6];
snprintf(portbuf, sizeof(portbuf), "%u", (unsigned)p->GetPort());
string port = portbuf;
string m = "m=video " + port + " "
+ (p->IsRTP() ? "RTP/AVP 33" : "udp mpeg") +"\r\n";
if (p->IsRTP())
{
snprintf(portbuf, sizeof(portbuf), "%u", 1 + p->GetPort());
port = portbuf;
m += "a=rtcp:" + port + "\r\n";
m += "a=rtpmap:33 MP2T/90000\r\n";
if (p->IsRTP() & 1)
{
snprintf(portbuf, sizeof(portbuf), "%u", 1 + p->GetPort());
port = portbuf;
m += "a=rtcp:" + port + "\r\n";
}
}
}
sdp += m;
sdp += m;
}
puts (sdp.c_str ());
if (msg_len + sdp.length () > 1024)
......
......@@ -373,6 +373,12 @@ int Config::Parse()
something=1;
pp->SetPort(atoi(tline));
}
if(strstr(line,"customsdp="))
{
strgeta(line,tline,'=');
something=1;
pp->SetCustomSDP(tline);
}
}
if(something)
......
......@@ -31,6 +31,7 @@
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string>
#include <vector>
using namespace std;
......@@ -47,6 +48,7 @@ Program::Program() : b_rtp(false), b_has_pl_group(false)
machine = "localhost";
user = "VideoLAN";
site = "http://www.videolan.org";
custom_sdp = "";
}
Program::~Program() {return;}
......@@ -58,11 +60,11 @@ string Program::GetAddress(void){return address;}
uint16_t Program::GetPort(void){return port;}
string Program::GetTTL(void){return program_ttl;}
string Program::GetPlGroup(void){return pl_group;}
string Program::GetCustomSDP(void){return custom_sdp;}
bool Program::IsPermanent(void){return permanent;}
bool Program::IsRTP(void){return b_rtp;}
bool Program::HasPlGroup(void){return b_has_pl_group;}
bool Program::HasCustomSDP(void){return custom_sdp.size() ? true : false;}
void Program::SetName(const char* n){name=n;}
void Program::SetUser(const char* u){user=u;}
void Program::SetMachine(const char* m){machine=m;}
......@@ -72,7 +74,6 @@ void Program::SetPlGroup(const char *h){pl_group=h;}
void Program::SetRTP(bool b){b_rtp = b;}
void Program::SetHasPlGroup(bool b){b_has_pl_group = b ;}
void Program::SetPort(uint16_t p) { port = p; }
void Program::SetTTL(const char *p){program_ttl=p;}
Program::Program(string n, string u, string m, string s, string a,uint16_t p)
......@@ -86,3 +87,25 @@ Program::Program(string n, string u, string m, string s, string a,uint16_t p)
port=p;
permanent=true;
}
void Program::SetCustomSDP(const char *fname)
{
/* Although it's a (relatively small) fixed-sized buffer, we can't serve
* SDP any larger than this in any case - see the condition in
* Message::AddProgram():
* if(msg_len + sdp.length () > 1024) - RFC 2974 Chap 6.
*/
char buf[1024];
FILE *f;
ssize_t l;
if(NULL == (f = fopen(fname, "rb")))
{
fprintf(stderr, "%s: %s\n", fname, strerror(errno));
exit(1);
}
l = fread(buf, 1, sizeof(buf) - 1, f);
fclose(f);
buf[l] = '\0';
custom_sdp = buf;
}
......@@ -38,6 +38,7 @@ class Program
uint16_t GetPort();
string GetTTL();
string GetPlGroup();
string GetCustomSDP();
/* Functions to set the values */
void SetName(const char*);
......@@ -50,10 +51,12 @@ class Program
void SetPlGroup(const char *);
void SetHasPlGroup(bool);
void SetRTP(bool);
void SetCustomSDP(const char *);
bool IsPermanent();
bool IsRTP();
bool HasPlGroup();
bool HasCustomSDP();
private:
string name;
......@@ -63,6 +66,7 @@ class Program
string address;
string program_ttl;
string pl_group;
string custom_sdp;
bool permanent;
bool b_rtp;
bool b_has_pl_group;
......
......@@ -39,7 +39,9 @@ port=1234
# The name of the playlistgroup your announce will be part of in the VLC playlist
playlist_group=organisationTV
# If you wish to send custom SDP to clients, specify the full path to the
# SDP file
#customsdp=/path/to/broadcast.sdp
# IPv6 example
[program]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment