More changes into the direction of the new HTTP connector style.
This commit is contained in:
parent
af12c6a94e
commit
cecb015a4b
5 changed files with 17 additions and 161 deletions
|
@ -1,9 +1,11 @@
|
|||
AM_CPPFLAGS = $(MIST_CFLAGS)
|
||||
LDADD = $(MIST_LIBS)
|
||||
SUBDIRS=converters analysers
|
||||
bin_PROGRAMS=MistBuffer MistController MistConnRAW MistConnRTMP MistConnHTTP
|
||||
bin_PROGRAMS=MistBuffer MistController MistConnRAW MistConnRTMP MistConnHTTP MistConnHTTPProgressive MistConnHTTPDynamic
|
||||
MistBuffer_SOURCES=buffer.cpp buffer_user.h buffer_user.cpp buffer_stream.h buffer_stream.cpp tinythread.cpp tinythread.h ../VERSION
|
||||
MistController_SOURCES=controller.cpp ../VERSION
|
||||
MistConnRAW_SOURCES=conn_raw.cpp ../VERSION
|
||||
MistConnRTMP_SOURCES=conn_rtmp.cpp server_setup.h ../VERSION
|
||||
MistConnHTTP_SOURCES=conn_http.cpp server_setup.h ../VERSION
|
||||
MistConnHTTPProgressive_SOURCES=conn_http_progressive.cpp server_setup_http.h ../VERSION
|
||||
MistConnHTTPDynamic_SOURCES=conn_http_dynamic.cpp server_setup_http.h ../VERSION
|
||||
|
|
|
@ -23,155 +23,9 @@
|
|||
/// Holds everything unique to HTTP Connector.
|
||||
namespace Connector_HTTP{
|
||||
|
||||
/// Defines the type of handler used to process this request.
|
||||
enum {HANDLER_NONE, HANDLER_PROGRESSIVE, HANDLER_FLASH, HANDLER_APPLE, HANDLER_MICRO, HANDLER_JSCRIPT};
|
||||
|
||||
std::queue<std::string> Flash_FragBuffer;///<Fragment buffer for F4V
|
||||
DTSC::Stream Strm;///< Incoming stream buffer.
|
||||
HTTP::Parser HTTP_R, HTTP_S;///<HTTP Receiver en HTTP Sender.
|
||||
|
||||
/// Returns AMF-format metadata for Adobe HTTP Dynamic Streaming.
|
||||
std::string GetMetaData( ) {
|
||||
/// \todo Make this actually do what it should - even though it seems to be ignored completely by all media players.
|
||||
AMF::Object amfreply("container", AMF::AMF0_DDV_CONTAINER);
|
||||
amfreply.addContent(AMF::Object("onMetaData",AMF::AMF0_STRING));
|
||||
amfreply.addContent(AMF::Object("",AMF::AMF0_ECMA_ARRAY));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("trackinfo", AMF::AMF0_STRICT_ARRAY));
|
||||
amfreply.getContentP(1)->getContentP(0)->addContent(AMF::Object("arrVal"));
|
||||
//amfreply.getContentP(1)->getContentP(0)->getContentP(0)->addContent(AMF::Object("timescale",(double)1000));
|
||||
//amfreply.getContentP(1)->getContentP(0)->getContentP(0)->addContent(AMF::Object("length",(double)59641700));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(0)->addContent(AMF::Object("language","eng"));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(0)->addContent(AMF::Object("sampledescription", AMF::AMF0_STRICT_ARRAY));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(0)->getContentP(1)->addContent(AMF::Object("arrVal"));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(0)->getContentP(1)->getContentP(0)->addContent(AMF::Object("sampletype","avc1"));
|
||||
amfreply.getContentP(1)->getContentP(0)->addContent(AMF::Object("arrVal"));
|
||||
//amfreply.getContentP(1)->getContentP(0)->getContentP(1)->addContent(AMF::Object("timescale",(double)44100));
|
||||
//amfreply.getContentP(1)->getContentP(0)->getContentP(1)->addContent(AMF::Object("length",(double)28630000));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(1)->addContent(AMF::Object("language","eng"));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(1)->addContent(AMF::Object("sampledescription", AMF::AMF0_STRICT_ARRAY));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(1)->getContentP(1)->addContent(AMF::Object("arrVal"));
|
||||
amfreply.getContentP(1)->getContentP(0)->getContentP(1)->getContentP(1)->getContentP(0)->addContent(AMF::Object("sampletype","mp4a"));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("audiochannels",(double)2));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("audiosamplerate",(double)44100));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("videoframerate",(double)25));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("aacaot",(double)2));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("avclevel",(double)12));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("avcprofile",(double)77));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("audiocodecid","mp4a"));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("videocodecid","avc1"));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("width",(double)1280));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("height",(double)720));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("frameWidth",(double)1280));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("frameHeight",(double)720));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("displayWidth",(double)1280));
|
||||
amfreply.getContentP(1)->addContent(AMF::Object("displayHeight",(double)720));
|
||||
//amfreply.getContentP(1)->addContent(AMF::Object("moovposition",(double)35506700));
|
||||
//amfreply.getContentP(1)->addContent(AMF::Object("duration",(double)596.458));
|
||||
return amfreply.Pack( );
|
||||
}//getMetaData
|
||||
|
||||
/// Returns a F4M-format manifest file for Adobe HTTP Dynamic Streaming.
|
||||
std::string BuildManifest(std::string MovieId) {
|
||||
std::string Result="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n";
|
||||
Result += "<id>";
|
||||
Result += MovieId;
|
||||
Result += "</id>\n<mimeType>video/mp4</mimeType>\n";
|
||||
Result += "<streamType>live</streamType>\n";
|
||||
Result += "<deliveryType>streaming</deliveryType>\n";
|
||||
Result += "<bootstrapInfo profile=\"named\" id=\"bootstrap1\">";
|
||||
Result += Base64::encode(MP4::GenerateLiveBootstrap(1));
|
||||
Result += "</bootstrapInfo>\n";
|
||||
Result += "<media streamId=\"1\" bootstrapInfoId=\"bootstrap1\" url=\"";
|
||||
Result += MovieId;
|
||||
Result += "/\">\n";
|
||||
Result += "<metadata>";
|
||||
Result += Base64::encode(GetMetaData());
|
||||
Result += "</metadata>\n";
|
||||
Result += "</media>\n";
|
||||
Result += "</manifest>\n";
|
||||
return Result;
|
||||
}//BuildManifest
|
||||
|
||||
/// Handles Progressive download streaming requests
|
||||
void Progressive(FLV::Tag & tag, HTTP::Parser HTTP_S, Socket::Connection & conn, DTSC::Stream & Strm){
|
||||
static bool progressive_has_sent_header = false;
|
||||
if (!progressive_has_sent_header){
|
||||
HTTP_S.Clean();//make sure no parts of old requests are left in any buffers
|
||||
HTTP_S.SetHeader("Content-Type", "video/x-flv");//Send the correct content-type for FLV files
|
||||
//HTTP_S.SetHeader("Transfer-Encoding", "chunked");
|
||||
HTTP_S.protocol = "HTTP/1.0";
|
||||
conn.Send(HTTP_S.BuildResponse("200", "OK"));//no SetBody = unknown length - this is intentional, we will stream the entire file
|
||||
conn.Send(std::string(FLV::Header, 13));//write FLV header
|
||||
static FLV::Tag tmp;
|
||||
//write metadata
|
||||
tmp.DTSCMetaInit(Strm);
|
||||
conn.Send(std::string(tmp.data, tmp.len));
|
||||
//write video init data, if needed
|
||||
if (Strm.metadata.getContentP("video") && Strm.metadata.getContentP("video")->getContentP("init")){
|
||||
tmp.DTSCVideoInit(Strm);
|
||||
conn.Send(std::string(tmp.data, tmp.len));
|
||||
}
|
||||
//write audio init data, if needed
|
||||
if (Strm.metadata.getContentP("audio") && Strm.metadata.getContentP("audio")->getContentP("init")){
|
||||
tmp.DTSCAudioInit(Strm);
|
||||
conn.Send(std::string(tmp.data, tmp.len));
|
||||
}
|
||||
progressive_has_sent_header = true;
|
||||
#if DEBUG >= 1
|
||||
fprintf(stderr, "Sent progressive FLV header\n");
|
||||
#endif
|
||||
}
|
||||
conn.Send(std::string(tag.data, tag.len));//write the tag contents
|
||||
}
|
||||
|
||||
/// Handles Flash Dynamic HTTP streaming requests
|
||||
void FlashDynamic(FLV::Tag & tag, DTSC::Stream & Strm){
|
||||
static std::string FlashBuf;
|
||||
static FLV::Tag tmp;
|
||||
if (Strm.getPacket(0).getContentP("keyframe")){
|
||||
if (FlashBuf != ""){
|
||||
Flash_FragBuffer.push(FlashBuf);
|
||||
while (Flash_FragBuffer.size() > 2){
|
||||
Flash_FragBuffer.pop();
|
||||
}
|
||||
#if DEBUG >= 4
|
||||
fprintf(stderr, "Received a fragment. Now %i in buffer.\n", (int)Flash_FragBuffer.size());
|
||||
#endif
|
||||
}
|
||||
FlashBuf.clear();
|
||||
//fill buffer with init data, if needed.
|
||||
if (Strm.metadata.getContentP("audio") && Strm.metadata.getContentP("audio")->getContentP("init")){
|
||||
tmp.DTSCAudioInit(Strm);
|
||||
FlashBuf.append(tmp.data, tmp.len);
|
||||
}
|
||||
if (Strm.metadata.getContentP("video") && Strm.metadata.getContentP("video")->getContentP("init")){
|
||||
tmp.DTSCVideoInit(Strm);
|
||||
FlashBuf.append(tmp.data, tmp.len);
|
||||
}
|
||||
}
|
||||
FlashBuf.append(tag.data, tag.len);
|
||||
}
|
||||
|
||||
|
||||
/// Main function for Connector_HTTP
|
||||
int Connector_HTTP(Socket::Connection conn){
|
||||
int handler = HANDLER_PROGRESSIVE;///< The handler used for processing this request.
|
||||
bool ready4data = false;///< Set to true when streaming is to begin.
|
||||
bool inited = false;
|
||||
Socket::Connection ss(-1);
|
||||
std::string streamname;
|
||||
FLV::Tag tag;///< Temporary tag buffer.
|
||||
std::string recBuffer = "";
|
||||
|
||||
std::string Movie;
|
||||
std::string Quality;
|
||||
int Segment = -1;
|
||||
int ReqFragment = -1;
|
||||
int temp;
|
||||
int Flash_RequestPending = 0;
|
||||
unsigned int lastStats = 0;
|
||||
int Handle_Connection(Socket::Connection conn){
|
||||
conn.setBlocking(false);//do not block on conn.spool() when no data is available
|
||||
|
||||
while (conn.connected()){
|
||||
//only parse input if available or not yet init'ed
|
||||
if (conn.spool()){
|
||||
|
|
|
@ -65,16 +65,16 @@ namespace Connector_HTTP_Dynamic{
|
|||
|
||||
/// Returns a F4M-format manifest file
|
||||
std::string BuildManifest(std::string MovieId) {
|
||||
std::string Result="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||
"<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n" +
|
||||
"<id>" + MovieId + "</id>\n" +
|
||||
"<mimeType>video/mp4</mimeType>\n" +
|
||||
"<streamType>live</streamType>\n" +
|
||||
"<deliveryType>streaming</deliveryType>\n" +
|
||||
"<bootstrapInfo profile=\"named\" id=\"bootstrap1\">" + Base64::encode(MP4::GenerateLiveBootstrap(1)) + "</bootstrapInfo>\n" +
|
||||
"<media streamId=\"1\" bootstrapInfoId=\"bootstrap1\" url=\"" + MovieId + "/\">\n" +
|
||||
"<metadata>" + Base64::encode(GetMetaData()) + "</metadata>\n" +
|
||||
"</media>\n" +
|
||||
std::string Result="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
"<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n"
|
||||
"<id>" + MovieId + "</id>\n"
|
||||
"<mimeType>video/mp4</mimeType>\n"
|
||||
"<streamType>live</streamType>\n"
|
||||
"<deliveryType>streaming</deliveryType>\n"
|
||||
"<bootstrapInfo profile=\"named\" id=\"bootstrap1\">" + Base64::encode(MP4::GenerateLiveBootstrap(1)) + "</bootstrapInfo>\n"
|
||||
"<media streamId=\"1\" bootstrapInfoId=\"bootstrap1\" url=\"" + MovieId + "/\">\n"
|
||||
"<metadata>" + Base64::encode(GetMetaData()) + "</metadata>\n"
|
||||
"</media>\n"
|
||||
"</manifest>\n";
|
||||
return Result;
|
||||
}//BuildManifest
|
||||
|
@ -231,5 +231,5 @@ namespace Connector_HTTP_Dynamic{
|
|||
|
||||
// Load http setup file with the correct settings for this HTTP connector
|
||||
#define MAINHANDLER Connector_HTTP_Dynamic::Connector_HTTP_Dynamic
|
||||
#define CONNECTOR dynamic
|
||||
#define CONNECTOR "dynamic"
|
||||
#include "server_setup_http.h"
|
||||
|
|
|
@ -141,5 +141,5 @@ namespace Connector_HTTP_Progressive{
|
|||
|
||||
// Load http setup file with the correct settings for this HTTP connector
|
||||
#define MAINHANDLER Connector_HTTP_Progressive::Connector_HTTP_Progressive
|
||||
#define CONNECTOR progressive
|
||||
#define CONNECTOR "progressive"
|
||||
#include "server_setup_http.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#ifndef CONNECTOR
|
||||
/// Connector name for the socket.
|
||||
#define CONNECTOR NoConnector
|
||||
#define CONNECTOR "NoConnector"
|
||||
#error "No connector was set!"
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue