Created
April 16, 2009 07:37
-
-
Save nevali/96295 to your computer and use it in GitHub Desktop.
A patch against VideoLAN's miniSAPServer to allow custom SDP announcements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ruN minisapserver-0.3.6/message.cpp minisapserver-0.3.6-customsdp/message.cpp | |
--- minisapserver-0.3.6/message.cpp 2009-01-11 19:53:25.000000000 +0000 | |
+++ minisapserver-0.3.6-customsdp/message.cpp 2009-04-15 00:21:19.000000000 +0100 | |
@@ -96,59 +96,65 @@ | |
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"; | |
+ { | |
+ string ipv = (p->GetAddress().find(':') == string::npos) ? "IP4" : "IP6"; | |
- /* 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"; | |
+ 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()) | |
- { | |
- m += "a=rtpmap:33 MP2T/90000\r\n"; | |
- if (p->IsRTP() & 1) | |
+ 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) | |
diff -ruN minisapserver-0.3.6/parser.cpp minisapserver-0.3.6-customsdp/parser.cpp | |
--- minisapserver-0.3.6/parser.cpp 2009-01-11 19:50:43.000000000 +0000 | |
+++ minisapserver-0.3.6-customsdp/parser.cpp 2009-04-14 23:38:48.000000000 +0100 | |
@@ -373,6 +373,12 @@ | |
something=1; | |
pp->SetPort(atoi(tline)); | |
} | |
+ if(strstr(line,"customsdp=")) | |
+ { | |
+ strgeta(line,tline,'='); | |
+ something=1; | |
+ pp->SetCustomSDP(tline); | |
+ } | |
} | |
if(something) | |
diff -ruN minisapserver-0.3.6/program.cpp minisapserver-0.3.6-customsdp/program.cpp | |
--- minisapserver-0.3.6/program.cpp 2009-01-11 19:50:43.000000000 +0000 | |
+++ minisapserver-0.3.6-customsdp/program.cpp 2009-04-15 00:02:39.000000000 +0100 | |
@@ -27,6 +27,7 @@ | |
#include <arpa/inet.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
+#include <errno.h> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
@@ -43,6 +44,7 @@ | |
machine = "localhost"; | |
user = "VideoLAN"; | |
site = "http://www.videolan.org"; | |
+ custom_sdp = ""; | |
} | |
Program::~Program() {return;} | |
@@ -54,11 +56,11 @@ | |
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;} | |
@@ -68,7 +70,6 @@ | |
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) | |
@@ -82,3 +83,25 @@ | |
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; | |
+} | |
diff -ruN minisapserver-0.3.6/program.h minisapserver-0.3.6-customsdp/program.h | |
--- minisapserver-0.3.6/program.h 2009-01-11 19:50:43.000000000 +0000 | |
+++ minisapserver-0.3.6-customsdp/program.h 2009-04-15 00:20:16.000000000 +0100 | |
@@ -38,6 +38,7 @@ | |
uint16_t GetPort(); | |
string GetTTL(); | |
string GetPlGroup(); | |
+ string GetCustomSDP(); | |
/* Functions to set the values */ | |
void SetName(const char*); | |
@@ -50,10 +51,12 @@ | |
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 @@ | |
string address; | |
string program_ttl; | |
string pl_group; | |
+ string custom_sdp; | |
bool permanent; | |
bool b_rtp; | |
bool b_has_pl_group; | |
diff -ruN minisapserver-0.3.6/sap.cfg minisapserver-0.3.6-customsdp/sap.cfg | |
--- minisapserver-0.3.6/sap.cfg 2008-02-06 21:05:34.000000000 +0000 | |
+++ minisapserver-0.3.6-customsdp/sap.cfg 2009-04-15 00:18:40.000000000 +0100 | |
@@ -39,7 +39,9 @@ | |
# 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment