Fixed a minor ordering bug in FLV2DTSC, made Connector_RTMP fully functional in DTSC environment (push support).
This commit is contained in:
parent
2a8ce23db0
commit
9ae274b0c1
2 changed files with 36 additions and 36 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <sstream>
|
||||||
#include "../util/socket.h"
|
#include "../util/socket.h"
|
||||||
#include "../util/flv_tag.h"
|
#include "../util/flv_tag.h"
|
||||||
#include "../util/amf.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.
|
/// Tries to get and parse one RTMP chunk at a time.
|
||||||
void Connector_RTMP::parseChunk(std::string & inbuffer){
|
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;
|
static RTMPStream::Chunk next;
|
||||||
FLV::Tag F;
|
FLV::Tag F;
|
||||||
static AMF::Object amfdata("empty", AMF::AMF0_DDV_CONTAINER);
|
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());
|
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)
|
Socket.write(RTMPStream::SendCTL(5, RTMPStream::snd_window_size));//send window acknowledgement size (msg 5)
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8://audio data
|
||||||
F.ChunkLoader(next);
|
case 9://video data
|
||||||
|
case 18://meta data
|
||||||
if (SS.connected()){
|
if (SS.connected()){
|
||||||
#if DEBUG >= 4
|
F.ChunkLoader(next);
|
||||||
fprintf(stderr, "A");
|
DTSC::DTMI pack_out = F.toDTSC(meta_out);
|
||||||
#endif
|
if (!pack_out.isEmpty()){
|
||||||
/// \TODO Convert to DTSC properly.
|
if (!sending){
|
||||||
SS.write(std::string(F.data, F.len));
|
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{
|
}else{
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 4
|
||||||
fprintf(stderr, "Received useless audio data\n");
|
fprintf(stderr, "Received useless media 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");
|
|
||||||
#endif
|
#endif
|
||||||
Socket.close();
|
Socket.close();
|
||||||
}
|
}
|
||||||
|
@ -268,15 +276,6 @@ void Connector_RTMP::parseChunk(std::string & inbuffer){
|
||||||
parseAMFCommand(amfdata, 17, next.msg_stream_id);
|
parseAMFCommand(amfdata, 17, next.msg_stream_id);
|
||||||
}//parsing AMF0-style
|
}//parsing AMF0-style
|
||||||
} break;
|
} 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:
|
case 19:
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 4
|
||||||
fprintf(stderr, "Received AFM0 shared object\n");
|
fprintf(stderr, "Received AFM0 shared object\n");
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace Converters{
|
||||||
if (pack_out.isEmpty()){continue;}
|
if (pack_out.isEmpty()){continue;}
|
||||||
if (!sending){
|
if (!sending){
|
||||||
counter++;
|
counter++;
|
||||||
if (counter > 10){
|
if (counter > 8){
|
||||||
sending = true;
|
sending = true;
|
||||||
meta_out.Pack(true);
|
meta_out.Pack(true);
|
||||||
meta_out.packed.replace(0, 4, DTSC::Magic_Header);
|
meta_out.packed.replace(0, 4, DTSC::Magic_Header);
|
||||||
|
@ -40,11 +40,12 @@ namespace Converters{
|
||||||
std::cout << prebuffer.rdbuf();
|
std::cout << prebuffer.rdbuf();
|
||||||
prebuffer.str("");
|
prebuffer.str("");
|
||||||
std::cerr << "Buffer done, starting real-time output..." << std::endl;
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue