From 16343ed016d782896bedaed00b641ea626888692 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 23 Aug 2013 10:36:25 +0200 Subject: [PATCH] Added waitForMeta function to DTSC::Stream object. --- lib/dtsc.cpp | 23 +++++++++++++++++++++++ lib/dtsc.h | 1 + 2 files changed, 24 insertions(+) diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index 010a5eff..b3c7d195 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -189,6 +189,29 @@ void DTSC::Stream::endStream(){ } } +/// Blocks until either the stream has metadata available or the sourceSocket errors. +/// This function is intended to be run before any commands are sent and thus will not throw away anything important. +void DTSC::Stream::waitForMeta(Socket::Connection & sourceSocket){ + while ( !metadata && sourceSocket.connected()){ + //we have data? attempt to read header + if (sourceSocket.Received().size()){ + //return value is ignore because we're not interested in data packets, just metadata. + parsePacket(sourceSocket.Received()); + } + //still no header? check for more data + if ( !metadata){ + if (sourceSocket.spool()){ + //more received? attempt to read + //return value is ignore because we're not interested in data packets, just metadata. + parsePacket(sourceSocket.Received()); + }else{ + //nothing extra to receive? wait a bit and retry + Util::sleep(5); + } + } + } +} + void DTSC::Stream::addPacket(JSON::Value & newPack){ bool updateMeta = false; long long unsigned int now = Util::getMS(); diff --git a/lib/dtsc.h b/lib/dtsc.h index b61f9801..81675c85 100644 --- a/lib/dtsc.h +++ b/lib/dtsc.h @@ -215,6 +215,7 @@ namespace DTSC { bool isNewest(DTSC::livePos & pos); DTSC::livePos getNext(DTSC::livePos & pos, std::set & allowedTracks); void endStream(); + void waitForMeta(Socket::Connection & sourceSocket); private: std::map buffers; std::map > keyframes;