From ab31f0724016f5dd3cc1e9afaafeb01587c220f3 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 6 May 2008 21:00:37 +0000 Subject: [PATCH] Stream end detection --- playerliveradio.cc | 2 +- playerliveradio.h | 2 +- playerlivetv.cc | 8 +++++++- playerlivetv.h | 2 +- vdr.cc | 19 +++++++++++++++---- vdr.h | 4 +++- vdrresponsepacket.cc | 5 ++++- vdrresponsepacket.h | 5 ++++- 8 files changed, 36 insertions(+), 11 deletions(-) diff --git a/playerliveradio.cc b/playerliveradio.cc index cafd539..7a27112 100644 --- a/playerliveradio.cc +++ b/playerliveradio.cc @@ -148,7 +148,7 @@ void PlayerLiveRadio::call(void* caller) // ----------------------------------- -void PlayerLiveRadio::streamReceive(void* data, ULONG len) +void PlayerLiveRadio::streamReceive(ULONG flag, void* data, ULONG len) { if (streamChunks.size() < 11) { diff --git a/playerliveradio.h b/playerliveradio.h index 97e29fb..abf9145 100644 --- a/playerliveradio.h +++ b/playerliveradio.h @@ -68,7 +68,7 @@ class PlayerLiveRadio : public PlayerLive, public Thread_TYPE, public Callback, void call(void*); // for callback interface - virtual void streamReceive(void*, ULONG); // stream receiver interface + virtual void streamReceive(ULONG, void*, ULONG); // stream receiver interface // Player events diff --git a/playerlivetv.cc b/playerlivetv.cc index 16fef2d..982bf6d 100644 --- a/playerlivetv.cc +++ b/playerlivetv.cc @@ -210,8 +210,14 @@ void PlayerLiveTV::call(void* caller) // ----------------------------------- -void PlayerLiveTV::streamReceive(void* data, ULONG len) +void PlayerLiveTV::streamReceive(ULONG flag, void* data, ULONG len) { + // Flag: + // 0 = normal stream packet + // 1 = stream end + + logger->log("PlayerLiveTV", Log::DEBUG, "Received a streamchunk from VDR, flag = %lu", flag); + if (streamChunks.size() < 11) { StreamChunk s; diff --git a/playerlivetv.h b/playerlivetv.h index c06a55b..c82e37d 100644 --- a/playerlivetv.h +++ b/playerlivetv.h @@ -70,7 +70,7 @@ class PlayerLiveTV : public PlayerLive, public Thread_TYPE, public Callback, pub void call(void*); // for callback interface - virtual void streamReceive(void*, ULONG); // stream receiver interface + virtual void streamReceive(ULONG, void*, ULONG); // stream receiver interface // Player events diff --git a/vdr.cc b/vdr.cc index 1c1fe83..33632e8 100644 --- a/vdr.cc +++ b/vdr.cc @@ -43,6 +43,7 @@ VDR::VDR() connected = false; maxChannelNumber = 0; channelNumberWidth = 1; + TEMP_SINGLE_VDR_PR = NULL; } VDR::~VDR() @@ -190,6 +191,7 @@ void VDR::threadMethod() UCHAR* userData; ULONG streamID; + ULONG flag; VDR_ResponsePacket* vresp; @@ -236,6 +238,10 @@ void VDR::threadMethod() { if (!tcp->readData((UCHAR*)&streamID, sizeof(ULONG))) break; streamID = ntohl(streamID); + + if (!tcp->readData((UCHAR*)&flag, sizeof(ULONG))) break; + flag = ntohl(flag); + if (!tcp->readData((UCHAR*)&userDataLength, sizeof(ULONG))) break; userDataLength = ntohl(userDataLength); if (userDataLength > 0) @@ -248,8 +254,8 @@ void VDR::threadMethod() { userData = NULL; } - vresp->setStream(streamID, userData, userDataLength); - Log::getInstance()->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, len=%lu", streamID, userDataLength); + vresp->setStream(streamID, flag, userData, userDataLength); + Log::getInstance()->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, flag=%lu, len=%lu", streamID, flag, userDataLength); } else { @@ -355,7 +361,7 @@ bool VDR_PacketReceiver::call(void* userTag) { // It's a stream packet. VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag; - streamReceiver->streamReceive(vresp->getUserData(), vresp->getUserDataLength()); + streamReceiver->streamReceive(vresp->getFlag(), vresp->getUserData(), vresp->getUserDataLength()); delete vresp; return false; } @@ -554,11 +560,12 @@ int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver) if (!vrp.addULONG(number)) return 0; - VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver(); // FIXME - leaked + VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver(); vdrpr->receiverChannel = VDR::CHANNEL_STREAM; vdrpr->streamID = vrp.getSerial(); vdrpr->streamReceiver = tstreamReceiver; edRegister(vdrpr); + TEMP_SINGLE_VDR_PR = vdrpr; VDR_ResponsePacket* vresp = RequestResponse(&vrp); if (vresp->noResponse()) @@ -580,6 +587,10 @@ int VDR::stopStreaming() VDR_RequestPacket vrp; if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0; + edUnregister(TEMP_SINGLE_VDR_PR); + delete TEMP_SINGLE_VDR_PR; + TEMP_SINGLE_VDR_PR = NULL; + VDR_ResponsePacket* vresp = RequestResponse(&vrp); if (vresp->noResponse()) { delete vresp; return 0; } diff --git a/vdr.h b/vdr.h index eca8b6f..26c5b60 100644 --- a/vdr.h +++ b/vdr.h @@ -80,7 +80,7 @@ class RecMan; class StreamReceiver { public: - virtual void streamReceive(void*, ULONG)=0; + virtual void streamReceive(ULONG, void*, ULONG)=0; }; class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc @@ -209,6 +209,8 @@ class VDR : public Thread_TYPE, public EventDispatcher bool connected; ULONG maxChannelNumber; ULONG channelNumberWidth; + + VDR_PacketReceiver* TEMP_SINGLE_VDR_PR; const static ULONG VDR_LOGIN = 1; const static ULONG VDR_GETRECORDINGLIST = 2; diff --git a/vdrresponsepacket.cc b/vdrresponsepacket.cc index b196667..c7a077e 100644 --- a/vdrresponsepacket.cc +++ b/vdrresponsepacket.cc @@ -34,6 +34,8 @@ VDR_ResponsePacket::VDR_ResponsePacket() requestID = 0; streamID = 0; + + flag = 0; } VDR_ResponsePacket::~VDR_ResponsePacket() @@ -51,10 +53,11 @@ void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG t userDataLength = tuserDataLength; } -void VDR_ResponsePacket::setStream(ULONG tstreamID, UCHAR* tuserData, ULONG tuserDataLength) +void VDR_ResponsePacket::setStream(ULONG tstreamID, ULONG tflag, UCHAR* tuserData, ULONG tuserDataLength) { channelID = VDR::CHANNEL_STREAM; streamID = tstreamID; + flag = tflag; userData = tuserData; userDataLength = tuserDataLength; } diff --git a/vdrresponsepacket.h b/vdrresponsepacket.h index 0b0baab..3d8d5f3 100644 --- a/vdrresponsepacket.h +++ b/vdrresponsepacket.h @@ -39,7 +39,7 @@ class VDR_ResponsePacket ~VDR_ResponsePacket(); void setResponse(ULONG requestID, UCHAR* packet, ULONG packetLength); - void setStream(ULONG streamID, UCHAR* packet, ULONG packetLength); + void setStream(ULONG streamID, ULONG flag, UCHAR* packet, ULONG packetLength); bool noResponse() { return (userData == NULL); }; int serverError(); @@ -48,6 +48,7 @@ class VDR_ResponsePacket ULONG getChannelID() { return channelID; } ULONG getRequestID() { return requestID; } ULONG getStreamID() { return streamID; } + ULONG getFlag() { return flag; } char* extractString(); UCHAR extractUCHAR(); @@ -71,6 +72,8 @@ class VDR_ResponsePacket ULONG requestID; ULONG streamID; + + ULONG flag; // stream only bool ownBlock; }; -- 2.39.5