From 1705640f24e4c5558ff4cf4dc7c0977db6943aa7 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 17 Feb 2011 02:26:18 +0100 Subject: [PATCH] Progressive mode edits, RTMP edits. Also, TODO: AMF3 implementen. *barf* --- Buffer/play1000kbit.sh | 3 ++- Connector_HTTP/Makefile | 2 +- Connector_HTTP/main.cpp | 14 ++++++-------- Connector_RTMP/chunkstream.cpp | 4 ++-- Connector_RTMP/main.cpp | 2 +- Connector_RTMP/parsechunks.cpp | 6 +++--- util/http_parser.cpp | 22 ++++++++++++++++++++++ 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Buffer/play1000kbit.sh b/Buffer/play1000kbit.sh index 4393b22e..f8ff8b22 100755 --- a/Buffer/play1000kbit.sh +++ b/Buffer/play1000kbit.sh @@ -1,4 +1,5 @@ #!/bin/bash -ffmpeg -re -i "$1" -b 1024000 -ar 11025 -f flv - 2> /dev/null | ./Buffer 500 +ffmpeg -re -i "$1" -b 1024000 -ar 11025 -f flv - 2> /dev/null | ./Buffer 500 $2 + diff --git a/Connector_HTTP/Makefile b/Connector_HTTP/Makefile index 65fa5642..92cc8357 100644 --- a/Connector_HTTP/Makefile +++ b/Connector_HTTP/Makefile @@ -1,4 +1,4 @@ -SRC = main.cpp ../sockets/sw_base.cpp ../sockets/sw_inet.cpp ../sockets/sw_unix.cpp +SRC = main.cpp OBJ = $(SRC:.cpp=.o) OUT = Connector_HTTP INCLUDES = diff --git a/Connector_HTTP/main.cpp b/Connector_HTTP/main.cpp index 84e7e266..cb7484c1 100644 --- a/Connector_HTTP/main.cpp +++ b/Connector_HTTP/main.cpp @@ -140,8 +140,7 @@ int mainHandler(int CONN_fd){ HTTP_S.SetHeader("Content-Type","video/mp4"); HTTP_S.SetBody(Interface::mdatFold(FlashBuf)); FlashBuf = ""; - std::string tmpresp = HTTP_S.BuildResponse("200", "OK"); - DDV_write(tmpresp.c_str(), tmpresp.size(), CONN_fd);//schrijf de HTTP response header + HTTP_S.SendResponse(CONN_fd, "200", "OK");//schrijf de HTTP response header }else{ Movie = HTTP_R.url.substr(1); Movie = Movie.substr(0,Movie.find("/")); @@ -212,8 +211,7 @@ int mainHandler(int CONN_fd){ HTTP_S.SetHeader("Content-Type","text/xml"); HTTP_S.SetHeader("Cache-Control","no-cache"); HTTP_S.SetBody(BuildManifest(FlashMeta, Movie, 0)); - std::string tmpresp = HTTP_S.BuildResponse("200", "OK"); - DDV_write(tmpresp.c_str(), tmpresp.size(), CONN_fd);//schrijf de HTTP response header + HTTP_S.SendResponse(CONN_fd, "200", "OK"); } } } @@ -221,12 +219,12 @@ int mainHandler(int CONN_fd){ if (!progressive_has_sent_header){ HTTP_S.Clean();//troep opruimen die misschien aanwezig is... HTTP_S.SetHeader("Content-Type", "video/x-flv");//FLV files hebben altijd dit content-type. - std::string tmpresp = HTTP_S.BuildResponse("200", "OK");//geen SetBody = unknown length! Dat willen we hier. - DDV_write(tmpresp.c_str(), tmpresp.size(), CONN_fd);//schrijf de HTTP response header - DDV_write(FLVHeader, 13, CONN_fd);//schrijf de FLV header, altijd 13 chars lang + HTTP_S.SetHeader("Transfer-Encoding", "chunked"); + HTTP_S.SendResponse(CONN_fd, "200", "OK");//geen SetBody = unknown length! Dat willen we hier. + HTTP_S.SendBodyPart(CONN_fd, FLVHeader, 13);//schrijf de FLV header progressive_has_sent_header = true; } - DDV_write(tag->data, tag->len, CONN_fd);//schrijf deze FLV tag onbewerkt weg + HTTP_S.SendBodyPart(CONN_fd, tag->data, tag->len);//schrijf deze FLV tag onbewerkt weg }//PROGRESSIVE handler } break; diff --git a/Connector_RTMP/chunkstream.cpp b/Connector_RTMP/chunkstream.cpp index 5681277b..d27cbd45 100644 --- a/Connector_RTMP/chunkstream.cpp +++ b/Connector_RTMP/chunkstream.cpp @@ -11,8 +11,8 @@ unsigned int getNowMS(){ } -unsigned int chunk_rec_max = 102400; -unsigned int chunk_snd_max = 102400; +unsigned int chunk_rec_max = 128; +unsigned int chunk_snd_max = 128; unsigned int rec_window_size = 0xFA00; unsigned int snd_window_size = 1024*500; unsigned int rec_window_at = 0; diff --git a/Connector_RTMP/main.cpp b/Connector_RTMP/main.cpp index 59061e0c..e7e246c0 100644 --- a/Connector_RTMP/main.cpp +++ b/Connector_RTMP/main.cpp @@ -4,7 +4,7 @@ //debugging level 3 = status information //debugging level 4 = extremely verbose status information //debugging level 5 = save all streams to FLV files -#define DEBUG 3 +#define DEBUG 4 #include #include diff --git a/Connector_RTMP/parsechunks.cpp b/Connector_RTMP/parsechunks.cpp index 6220388a..61a3612b 100644 --- a/Connector_RTMP/parsechunks.cpp +++ b/Connector_RTMP/parsechunks.cpp @@ -122,14 +122,14 @@ void parseChunk(){ amfreply.addContent(amfdata.getContent(1));//same transaction ID // amfreply.addContent(AMFType("", (double)0, 0x05));//null - command info amfreply.addContent(AMFType(""));//server properties - amfreply.getContentP(2)->addContent(AMFType("fmsVer", "FMS/3,0,1,123"));//stolen from examples + amfreply.getContentP(2)->addContent(AMFType("fmsVer", "FMS/3,5,2,654"));//stolen from examples amfreply.getContentP(2)->addContent(AMFType("capabilities", (double)31));//stolen from examples + amfreply.getContentP(2)->addContent(AMFType("mode", (double)1));//stolen from examples + amfreply.getContentP(2)->addContent(AMFType("objectEncoding", (double)0)); amfreply.addContent(AMFType(""));//info amfreply.getContentP(3)->addContent(AMFType("level", "status")); amfreply.getContentP(3)->addContent(AMFType("code", "NetConnection.Connect.Success")); amfreply.getContentP(3)->addContent(AMFType("description", "Connection succeeded.")); - amfreply.getContentP(3)->addContent(AMFType("capabilities", (double)33));//from red5 server - amfreply.getContentP(3)->addContent(AMFType("fmsVer", "PLS/1,0,0,0"));//from red5 server #if DEBUG >= 4 amfreply.Print(); #endif diff --git a/util/http_parser.cpp b/util/http_parser.cpp index df866b1a..6f7d619f 100644 --- a/util/http_parser.cpp +++ b/util/http_parser.cpp @@ -14,6 +14,9 @@ class HTTPReader{ void SetBody(char * buffer, int len); std::string BuildRequest(); std::string BuildResponse(std::string code, std::string message); + void SendResponse(int conn, std::string code, std::string message); + void SendBodyPart(int conn, char * buffer, int len); + void SendBodyPart(int conn, std::string bodypart); void Clean(); std::string method; std::string url; @@ -171,4 +174,23 @@ bool HTTPReader::parse(){ return false; //we should never get here... }//HTTPReader::parse +void HTTPReader::SendResponse(int conn, std::string code, std::string message){ + std::string tmp = BuildResponse(code, message); + DDV_write(tmp.c_str(), tmp.size(), conn); +} + +void HTTPReader::SendBodyPart(int conn, char * buffer, int len){ + std::string tmp; + tmp.append(buffer, len); + SendBodyPart(conn, tmp); +} + +void HTTPReader::SendBodyPart(int conn, std::string bodypart){ + static char len[10]; + int sizelen; + sizelen = snprintf(len, 10, "%x\r\n", (unsigned int)bodypart.size()); + DDV_write(len, sizelen, conn); + DDV_write(bodypart.c_str(), bodypart.size(), conn); + DDV_write(len+sizelen-2, 2, conn); +}