From 9ae274b0c19df4a7486e45ec9a25793f4abc883d Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 18 Apr 2012 11:23:33 +0200 Subject: [PATCH] Fixed a minor ordering bug in FLV2DTSC, made Connector_RTMP fully functional in DTSC environment (push support). --- Connector_RTMP/main.cpp | 63 ++++++++++++++++++++--------------------- tools/FLV2DTSC/main.cpp | 9 +++--- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Connector_RTMP/main.cpp b/Connector_RTMP/main.cpp index d6eb2769..94a737a2 100644 --- a/Connector_RTMP/main.cpp +++ b/Connector_RTMP/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "../util/socket.h" #include "../util/flv_tag.h" #include "../util/amf.h" @@ -137,6 +138,12 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){ /// Tries to get and parse one RTMP chunk at a time. void Connector_RTMP::parseChunk(std::string & inbuffer){ + //for DTSC conversion + static DTSC::DTMI meta_out; + static std::stringstream prebuffer; // Temporary buffer before sending real data + static bool sending = false; + static unsigned int counter = 0; + //for chunk parsing static RTMPStream::Chunk next; FLV::Tag F; static AMF::Object amfdata("empty", AMF::AMF0_DDV_CONTAINER); @@ -209,32 +216,33 @@ void Connector_RTMP::parseChunk(std::string & inbuffer){ RTMPStream::snd_window_size = ntohl(*(int*)next.data.c_str()); Socket.write(RTMPStream::SendCTL(5, RTMPStream::snd_window_size));//send window acknowledgement size (msg 5) break; - case 8: - F.ChunkLoader(next); + case 8://audio data + case 9://video data + case 18://meta data if (SS.connected()){ - #if DEBUG >= 4 - fprintf(stderr, "A"); - #endif - /// \TODO Convert to DTSC properly. - SS.write(std::string(F.data, F.len)); + F.ChunkLoader(next); + DTSC::DTMI pack_out = F.toDTSC(meta_out); + if (!pack_out.isEmpty()){ + if (!sending){ + counter++; + if (counter > 8){ + sending = true; + meta_out.Pack(true);//pack metadata + meta_out.packed.replace(0, 4, DTSC::Magic_Header);//prepare proper header + SS.write(meta_out.packed);//write header/metadata + SS.write(prebuffer.str());//write buffer + prebuffer.str("");//clear buffer + SS.write(pack_out.Pack(true));//simply write + }else{ + prebuffer << pack_out.Pack(true);//buffer + } + }else{ + SS.write(pack_out.Pack(true));//simple write + } + } }else{ #if DEBUG >= 4 - fprintf(stderr, "Received useless audio data\n"); - #endif - Socket.close(); - } - break; - case 9: - F.ChunkLoader(next); - if (SS.connected()){ - #if DEBUG >= 4 - fprintf(stderr, "V"); - #endif - /// \TODO Convert to DTSC properly. - SS.write(std::string(F.data, F.len)); - }else{ - #if DEBUG >= 4 - fprintf(stderr, "Received useless video data\n"); + fprintf(stderr, "Received useless media data\n"); #endif Socket.close(); } @@ -268,15 +276,6 @@ void Connector_RTMP::parseChunk(std::string & inbuffer){ parseAMFCommand(amfdata, 17, next.msg_stream_id); }//parsing AMF0-style } break; - case 18: - #if DEBUG >= 4 - fprintf(stderr, "Received AFM0 data message (metadata)\n"); - #endif - F.ChunkLoader(next); - if (SS.connected()){ - SS.write(std::string(F.data, F.len)); - } - break; case 19: #if DEBUG >= 4 fprintf(stderr, "Received AFM0 shared object\n"); diff --git a/tools/FLV2DTSC/main.cpp b/tools/FLV2DTSC/main.cpp index 6ae6516c..e1ad8b55 100644 --- a/tools/FLV2DTSC/main.cpp +++ b/tools/FLV2DTSC/main.cpp @@ -32,7 +32,7 @@ namespace Converters{ if (pack_out.isEmpty()){continue;} if (!sending){ counter++; - if (counter > 10){ + if (counter > 8){ sending = true; meta_out.Pack(true); meta_out.packed.replace(0, 4, DTSC::Magic_Header); @@ -40,11 +40,12 @@ namespace Converters{ std::cout << prebuffer.rdbuf(); prebuffer.str(""); std::cerr << "Buffer done, starting real-time output..." << std::endl; + }else{ + prebuffer << pack_out.Pack(true);//buffer + continue;//don't also write } - prebuffer << pack_out.Pack(true); - }else{ - std::cout << pack_out.Pack(true); } + std::cout << pack_out.Pack(true);//simply write } }