[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[574] mplayerxp/libmpstream2
Brought to you by:
olov
From: <nic...@us...> - 2012-12-18 16:08:03
|
Revision: 574 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=574&view=rev Author: nickols_k Date: 2012-12-18 16:07:55 +0000 (Tue, 18 Dec 2012) Log Message: ----------- convert static struct rtpbuffer rtpbuf into class Rtp Modified Paths: -------------- mplayerxp/libmpstream2/librtsp/rtsp_session.cpp mplayerxp/libmpstream2/librtsp/rtsp_session.h mplayerxp/libmpstream2/network_real_rtsp.cpp mplayerxp/libmpstream2/network_rtp.cpp mplayerxp/libmpstream2/network_rtp.h mplayerxp/libmpstream2/network_rtsp.cpp mplayerxp/libmpstream2/rtp.cpp mplayerxp/libmpstream2/rtp.h Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -83,10 +83,7 @@ char *mrl_line = NULL; rmff_header_t *h; - rtsp_session = new Rtsp_Session; - rtsp_session->s = NULL; - rtsp_session->real_session = NULL; - rtsp_session->rtp_session = NULL; + rtsp_session = new(zeromem) Rtsp_Session; //connect: *redir = 0; @@ -199,6 +196,8 @@ } rtsp_session->rtp_session = Rtp_Rtsp_Session::setup_and_play (*rtsp_session->s); + tcp=rtsp_session->rtp_session->get_rtp_socket(); + rtsp_session->rtp = new(zeromem) Rtp(tcp); /* neither a Real or an RTP server */ if (!rtsp_session->rtp_session) @@ -216,7 +215,7 @@ return rtsp_session; } -int Rtsp_Session::read(Tcp& tcp,char *data, int len) { +int Rtsp_Session::read(char *data, int len) { if (real_session) { int to_copy=len; @@ -256,9 +255,7 @@ return len; } else if (rtp_session) { int l = 0; - Tcp _tcp(tcp.get_libinput(),rtp_session->get_rtp_socket()); - - l = read_rtp_from_server (_tcp, data, len); + l = rtp->read_from_server (data, len); /* send RTSP and RTCP keepalive */ rtp_session->rtcp_send_rr (*s); if (l == 0) end (); @@ -270,9 +267,11 @@ void Rtsp_Session::end() { s->close(); if (real_session) free_real_rtsp_session (real_session); + real_session = NULL; if (rtp_session) delete rtp_session; + rtp_session = NULL; } Rtsp_Session::Rtsp_Session() {} -Rtsp_Session::~Rtsp_Session() {} -} // namespace mpxp \ No newline at end of file +Rtsp_Session::~Rtsp_Session() { end(); if(rtp) delete rtp; } +} // namespace mpxp Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 16:07:55 UTC (rev 574) @@ -33,7 +33,7 @@ #ifndef HAVE_RTSP_SESSION_H #define HAVE_RTSP_SESSION_H - +#include "../rtp.h" struct real_rtsp_session_t; namespace mpxp { class Rtp_Rtsp_Session; @@ -45,12 +45,13 @@ static Rtsp_Session* start(Tcp& tcp, char **mrl, const std::string& path, const std::string& host, int port, int *redir, uint32_t bandwidth, const std::string& user, const std::string& pass); - virtual int read(Tcp& tcp,char *data, int len); + virtual int read(char *data, int len); virtual void end(); private: Rtsp* s; real_rtsp_session_t*real_session; Rtp_Rtsp_Session* rtp_session; + Rtp* rtp; }; } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network_real_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -15,7 +15,7 @@ int RealRtsp_Networking::read( Tcp& tcp, char *_buffer, int size) { Rtsp_Session& rtsp=*static_cast<Rtsp_Session*>(data); - return rtsp.read(tcp, _buffer, size); + return rtsp.read(_buffer, size); } Networking* RealRtsp_Networking::start( Tcp& tcp, network_protocol_t& protocol ) { Modified: mplayerxp/libmpstream2/network_rtp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_rtp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -15,7 +15,7 @@ } int Rtp_Networking::read(Tcp& tcp, char *_buffer, int size) { - return read_rtp_from_server(tcp, _buffer, size ); + return rtp->read_from_server(_buffer, size ); } Networking* Rtp_Networking::start(Tcp& tcp,network_protocol_t& protocol, int raw_udp ) { @@ -31,6 +31,7 @@ rv->prebuffer_size = 64*1024; // KBytes rv->buffering = 0; rv->status = networking_playing_e; + rv->rtp = new(zeromem) Rtp(tcp); return rv; } Modified: mplayerxp/libmpstream2/network_rtp.h =================================================================== --- mplayerxp/libmpstream2/network_rtp.h 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_rtp.h 2012-12-18 16:07:55 UTC (rev 574) @@ -2,6 +2,7 @@ #define __NETWORK_RP_H_INCLUDED #include "network_nop.h" +#include "rtp.h" namespace mpxp { struct Rtp_Networking : public Nop_Networking { @@ -13,6 +14,7 @@ virtual int seek( Tcp& fd, off_t pos); private: Rtp_Networking(); + Rtp* rtp; }; } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -69,7 +69,7 @@ int Rtsp_Networking::read(Tcp& tcp, char *_buffer, int size) { Rtsp_Session& rtsp = *static_cast<Rtsp_Session*>(data); - return rtsp.read (tcp, buffer, size); + return rtsp.read (buffer, size); } Rtsp_Networking::Rtsp_Networking() {} Modified: mplayerxp/libmpstream2/rtp.cpp =================================================================== --- mplayerxp/libmpstream2/rtp.cpp 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/rtp.cpp 2012-12-18 16:07:55 UTC (rev 574) @@ -41,6 +41,7 @@ // write rtp packets in cache // get rtp packets reordered +namespace mpxp { #define MAXRTPPACKETSIN 32 // The number of max packets being reordered struct rtpbits { @@ -59,17 +60,6 @@ int ssrc; /* random */ }; -struct rtpbuffer -{ - unsigned char data[MAXRTPPACKETSIN][STREAM_BUFFER_SIZE]; - unsigned short seq[MAXRTPPACKETSIN]; - unsigned short len[MAXRTPPACKETSIN]; - unsigned short first; -}; -static struct rtpbuffer rtpbuf; - -static int getrtp2(Tcp& fd, struct rtpheader *rh, char** data, int* lengthData); - // RTP Reordering functions // Algorithm works as follows: // If next packet is in sequence just copy it to buffer @@ -78,178 +68,167 @@ // and keeps track of expected sequence // Initialize rtp cache -static void rtp_cache_reset(unsigned short seq) -{ - int i; +void Rtp::cache_reset(unsigned short seq) { + int i; - rtpbuf.first = 0; - rtpbuf.seq[0] = ++seq; + rtp_first = 0; + rtp_seq[0] = ++seq; - for (i=0; i<MAXRTPPACKETSIN; i++) { - rtpbuf.len[i] = 0; - } + for (i=0; i<MAXRTPPACKETSIN; i++) rtp_len[i] = 0; } // Write in a cache the rtp packet in right rtp sequence order -static int rtp_cache(Tcp& tcp, char *buffer, int length) -{ - struct rtpheader rh; - int newseq; - char *data; - unsigned short seq; - static int is_first = 1; +int Rtp::cache(char *buffer, int length) { + struct rtpheader rh; + int newseq; + char *data; + unsigned short seq; + static int is_first = 1; - getrtp2(tcp, &rh, &data, &length); - if(!length) - return 0; - seq = rh.b.sequence; + getrtp2(&rh, &data, &length); + if(!length) return 0; + seq = rh.b.sequence; - newseq = seq - rtpbuf.seq[rtpbuf.first]; + newseq = seq - rtp_seq[rtp_first]; - if ((newseq == 0) || is_first) - { - is_first = 0; + if ((newseq == 0) || is_first) { + is_first = 0; - rtpbuf.first = ( 1 + rtpbuf.first ) % MAXRTPPACKETSIN; - rtpbuf.seq[rtpbuf.first] = ++seq; - goto feed; - } + rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; + rtp_seq[rtp_first] = ++seq; + goto feed; + } - if (newseq > MAXRTPPACKETSIN) - { - MSG_DBG2("Overrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); - rtp_cache_reset(seq); - goto feed; - } + if (newseq > MAXRTPPACKETSIN) { + MSG_DBG2("Overrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + cache_reset(seq); + goto feed; + } - if (newseq < 0) - { - int i; + if (newseq < 0) { + int i; - // Is it a stray packet re-sent to network? - for (i=0; i<MAXRTPPACKETSIN; i++) { - if (rtpbuf.seq[i] == seq) { - MSG_ERR("Stray packet (seq[%d]=%d seq=%d, newseq=%d found at %d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq, i); - return 0; // Yes, it is! - } - } - // Some heuristic to decide when to drop packet or to restart everything - if (newseq > -(3 * MAXRTPPACKETSIN)) { - MSG_ERR("Too Old packet (seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); - return 0; // Yes, it is! - } + // Is it a stray packet re-sent to network? + for (i=0; i<MAXRTPPACKETSIN; i++) { + if (rtp_seq[i] == seq) { + MSG_ERR("Stray packet (seq[%d]=%d seq=%d, newseq=%d found at %d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq, i); + return 0; // Yes, it is! + } + } + // Some heuristic to decide when to drop packet or to restart everything + if (newseq > -(3 * MAXRTPPACKETSIN)) { + MSG_ERR("Too Old packet (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + return 0; // Yes, it is! + } - MSG_ERR("Underrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); + MSG_ERR("Underrun(seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); - rtp_cache_reset(seq); - goto feed; - } + cache_reset(seq); + goto feed; + } - MSG_DBG3("Out of Seq (seq[%d]=%d seq=%d, newseq=%d)\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first], seq, newseq); - newseq = ( newseq + rtpbuf.first ) % MAXRTPPACKETSIN; - memcpy (rtpbuf.data[newseq], data, length); - rtpbuf.len[newseq] = length; - rtpbuf.seq[newseq] = seq; + MSG_DBG3("Out of Seq (seq[%d]=%d seq=%d, newseq=%d)\n", rtp_first, rtp_seq[rtp_first], seq, newseq); + newseq = ( newseq + rtp_first ) % MAXRTPPACKETSIN; + memcpy (rtp_data[newseq], data, length); + rtp_len[newseq] = length; + rtp_seq[newseq] = seq; - return 0; + return 0; feed: - memcpy (buffer, data, length); - return length; + memcpy (buffer, data, length); + return length; } // Get next packet in cache // Look in cache to get first packet in sequence -static int rtp_get_next(Tcp& tcp, char *buffer, int length) -{ - int i; - unsigned short nextseq; +int Rtp::get_next(char *buffer, int length) { + int i; + unsigned short nextseq; - // If we have empty buffer we loop to fill it - for (i=0; i < MAXRTPPACKETSIN -3; i++) { - if (rtpbuf.len[rtpbuf.first] != 0) break; + // If we have empty buffer we loop to fill it + for (i=0; i < MAXRTPPACKETSIN -3; i++) { + if (rtp_len[rtp_first] != 0) break; - length = rtp_cache(tcp, buffer, length) ; + length = cache(buffer, length); - // returns on first packet in sequence - if (length > 0) { - return length; - } else if (length < 0) break; + // returns on first packet in sequence + if (length > 0) return length; + else if (length < 0) break; + // Only if length == 0 loop continues! + } - // Only if length == 0 loop continues! - } + i = rtp_first; + while (rtp_len[i] == 0) { + MSG_ERR("Lost packet %hu\n", rtp_seq[i]); + i = ( 1 + i ) % MAXRTPPACKETSIN; + if (rtp_first == i) break; + } + rtp_first = i; - i = rtpbuf.first; - while (rtpbuf.len[i] == 0) { - MSG_ERR("Lost packet %hu\n", rtpbuf.seq[i]); - i = ( 1 + i ) % MAXRTPPACKETSIN; - if (rtpbuf.first == i) break; - } - rtpbuf.first = i; + // Copy next non empty packet from cache + MSG_DBG3( "Getting rtp from cache [%d] %hu\n", rtp_first, rtp_seq[rtp_first]); + memcpy (buffer, rtp_data[rtp_first], rtp_len[rtp_first]); + length = rtp_len[rtp_first]; // can be zero? - // Copy next non empty packet from cache - MSG_DBG3( "Getting rtp from cache [%d] %hu\n", rtpbuf.first, rtpbuf.seq[rtpbuf.first]); - memcpy (buffer, rtpbuf.data[rtpbuf.first], rtpbuf.len[rtpbuf.first]); - length = rtpbuf.len[rtpbuf.first]; // can be zero? + // Reset fisrt slot and go next in cache + rtp_len[rtp_first] = 0; + nextseq = rtp_seq[rtp_first]; + rtp_first = ( 1 + rtp_first ) % MAXRTPPACKETSIN; + rtp_seq[rtp_first] = nextseq + 1; - // Reset fisrt slot and go next in cache - rtpbuf.len[rtpbuf.first] = 0; - nextseq = rtpbuf.seq[rtpbuf.first]; - rtpbuf.first = ( 1 + rtpbuf.first ) % MAXRTPPACKETSIN; - rtpbuf.seq[rtpbuf.first] = nextseq + 1; - - return length; + return length; } // Read next rtp packet using cache -int read_rtp_from_server(Tcp& tcp, char *buffer, int length) { - // Following test is ASSERT (i.e. uneuseful if code is correct) - if(buffer==NULL || length<STREAM_BUFFER_SIZE) { - MSG_ERR("RTP buffer invalid; no data return from network\n"); - return 0; - } +int Rtp::read_from_server(char *buffer, int length) { + // Following test is ASSERT (i.e. uneuseful if code is correct) + if(buffer==NULL || length<STREAM_BUFFER_SIZE) { + MSG_ERR("RTP buffer invalid; no data return from network\n"); + return 0; + } - // loop just to skip empty packets - while ((length = rtp_get_next(tcp, buffer, length)) == 0) { - MSG_ERR("Got empty packet from RTP cache!?\n"); - } - - return(length); + // loop just to skip empty packets + while ((length = get_next(buffer, length)) == 0) { + MSG_ERR("Got empty packet from RTP cache!?\n"); + } + return(length); } -static int getrtp2(Tcp& tcp, struct rtpheader *rh, char** data, int* lengthData) { - static char buf[1600]; - unsigned int intP; - char* charP = (char*) &intP; - int headerSize; - int lengthPacket; - lengthPacket=tcp.read((uint8_t*)(buf),1590); - if (lengthPacket<0) - MSG_ERR("rtp: socket read error\n"); - else if (lengthPacket<12) - MSG_ERR("rtp: packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket); - if(lengthPacket<12) { - *lengthData = 0; - return 0; - } - rh->b.v = (unsigned int) ((buf[0]>>6)&0x03); - rh->b.p = (unsigned int) ((buf[0]>>5)&0x01); - rh->b.x = (unsigned int) ((buf[0]>>4)&0x01); - rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f); - rh->b.m = (unsigned int) ((buf[1]>>7)&0x01); - rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f); - intP = 0; - memcpy(charP+2,&buf[2],2); - rh->b.sequence = ntohl(intP); - intP = 0; - memcpy(charP,&buf[4],4); - rh->timestamp = ntohl(intP); +int Rtp::getrtp2(struct rtpheader *rh, char** data, int* lengthData) const { + static char buf[1600]; + unsigned int intP; + char* charP = (char*) &intP; + int headerSize; + int lengthPacket; + lengthPacket=tcp.read((uint8_t*)(buf),1590); + if (lengthPacket<0) MSG_ERR("rtp: socket read error\n"); + else if (lengthPacket<12) MSG_ERR("rtp: packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket); + if(lengthPacket<12) { + *lengthData = 0; + return 0; + } + rh->b.v = (unsigned int) ((buf[0]>>6)&0x03); + rh->b.p = (unsigned int) ((buf[0]>>5)&0x01); + rh->b.x = (unsigned int) ((buf[0]>>4)&0x01); + rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f); + rh->b.m = (unsigned int) ((buf[1]>>7)&0x01); + rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f); + intP = 0; + memcpy(charP+2,&buf[2],2); + rh->b.sequence = ntohl(intP); + intP = 0; + memcpy(charP,&buf[4],4); + rh->timestamp = ntohl(intP); - headerSize = 12 + 4*rh->b.cc; /* in bytes */ + headerSize = 12 + 4*rh->b.cc; /* in bytes */ - *lengthData = lengthPacket - headerSize; - *data = (char*) buf + headerSize; + *lengthData = lengthPacket - headerSize; + *data = (char*) buf + headerSize; - return 0; + return 0; } +Rtp::Rtp(Tcp& _tcp):tcp(_tcp) {} +Rtp::~Rtp() {} +} // namespace mpxp Modified: mplayerxp/libmpstream2/rtp.h =================================================================== --- mplayerxp/libmpstream2/rtp.h 2012-12-18 15:09:54 UTC (rev 573) +++ mplayerxp/libmpstream2/rtp.h 2012-12-18 16:07:55 UTC (rev 574) @@ -4,11 +4,38 @@ * http://svn.mplayerhq.hu/mplayer/trunk/ * $Id: rtp.h,v 1.2 2007/11/17 12:43:37 nickols_k Exp $ */ - -#ifndef RTP_H -#define RTP_H +#ifndef __RTP_H_INCLUDED +#define __RTP_H_INCLUDED 1 #include "network.h" +#include "tcp.h" +#include <stdint.h> -int read_rtp_from_server(Tcp& fd, char *buffer, int length); +namespace mpxp { +// RTP reorder routines +// Also handling of repeated UDP packets (a bug of ExtremeNetworks switches firmware) +// rtpreord procedures +// write rtp packets in cache +// get rtp packets reordered +#define MAXRTPPACKETSIN 32 // The number of max packets being reordered + + class Rtp : public Opaque { + public: + Rtp(Tcp& tcp); + virtual ~Rtp(); + + virtual int read_from_server(char *buffer, int length); + private: + void cache_reset(unsigned short seq); + int cache(char *buffer, int length); + int get_next(char *buffer, int length); + int getrtp2(struct rtpheader *rh, char** data, int* lengthData) const; + + Tcp& tcp; + uint8_t rtp_data[MAXRTPPACKETSIN][STREAM_BUFFER_SIZE]; + uint16_t rtp_seq[MAXRTPPACKETSIN]; + uint16_t rtp_len[MAXRTPPACKETSIN]; + uint16_t rtp_first; + }; +} // namespace mpxp #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |