From cecb015a4be8c6684a7e698fdd919f591ac44843 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 11 Jul 2012 11:45:11 +0200 Subject: [PATCH] More changes into the direction of the new HTTP connector style. --- src/Makefile.am | 4 +- src/conn_http.cpp | 148 +--------------------------------- src/conn_http_dynamic.cpp | 22 ++--- src/conn_http_progressive.cpp | 2 +- src/server_setup_http.h | 2 +- 5 files changed, 17 insertions(+), 161 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index dac4d77b..7b0a385e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/conn_http.cpp b/src/conn_http.cpp index 789005ae..d1abfc39 100644 --- a/src/conn_http.cpp +++ b/src/conn_http.cpp @@ -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 Flash_FragBuffer;///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="\n\n"; - Result += ""; - Result += MovieId; - Result += "\nvideo/mp4\n"; - Result += "live\n"; - Result += "streaming\n"; - Result += ""; - Result += Base64::encode(MP4::GenerateLiveBootstrap(1)); - Result += "\n"; - Result += "\n"; - Result += ""; - Result += Base64::encode(GetMetaData()); - Result += "\n"; - Result += "\n"; - Result += "\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()){ diff --git a/src/conn_http_dynamic.cpp b/src/conn_http_dynamic.cpp index 64bec69d..58aa8a19 100644 --- a/src/conn_http_dynamic.cpp +++ b/src/conn_http_dynamic.cpp @@ -65,16 +65,16 @@ namespace Connector_HTTP_Dynamic{ /// Returns a F4M-format manifest file std::string BuildManifest(std::string MovieId) { - std::string Result="\n" + - "\n" + - "" + MovieId + "\n" + - "video/mp4\n" + - "live\n" + - "streaming\n" + - "" + Base64::encode(MP4::GenerateLiveBootstrap(1)) + "\n" + - "\n" + - "" + Base64::encode(GetMetaData()) + "\n" + - "\n" + + std::string Result="\n" + "\n" + "" + MovieId + "\n" + "video/mp4\n" + "live\n" + "streaming\n" + "" + Base64::encode(MP4::GenerateLiveBootstrap(1)) + "\n" + "\n" + "" + Base64::encode(GetMetaData()) + "\n" + "\n" "\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" diff --git a/src/conn_http_progressive.cpp b/src/conn_http_progressive.cpp index 6ac9268c..c335d54d 100644 --- a/src/conn_http_progressive.cpp +++ b/src/conn_http_progressive.cpp @@ -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" diff --git a/src/server_setup_http.h b/src/server_setup_http.h index 48c91be7..6cc6590f 100644 --- a/src/server_setup_http.h +++ b/src/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