diff options
author | phintuka <phintuka> | 2006-07-04 02:09:39 +0000 |
---|---|---|
committer | phintuka <phintuka> | 2006-07-04 02:09:39 +0000 |
commit | 0a887afc8374eb8a467c7773a2632a55d05be074 (patch) | |
tree | 7b3f43434b08715bbd8295a24f5d36bda9a438f4 /tools | |
parent | c28700c6d8d2c075b9c653f5adcc1281b2bd694e (diff) | |
download | xineliboutput-0a887afc8374eb8a467c7773a2632a55d05be074.tar.gz xineliboutput-0a887afc8374eb8a467c7773a2632a55d05be074.tar.bz2 |
RTCP support
Diffstat (limited to 'tools')
-rw-r--r-- | tools/udp_pes_scheduler.c | 63 | ||||
-rw-r--r-- | tools/udp_pes_scheduler.h | 12 |
2 files changed, 71 insertions, 4 deletions
diff --git a/tools/udp_pes_scheduler.c b/tools/udp_pes_scheduler.c index d44d3c38..e80f0226 100644 --- a/tools/udp_pes_scheduler.c +++ b/tools/udp_pes_scheduler.c @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: udp_pes_scheduler.c,v 1.5 2006-06-11 21:02:54 phintuka Exp $ + * $Id: udp_pes_scheduler.c,v 1.6 2006-07-04 02:09:39 phintuka Exp $ * */ @@ -12,6 +12,7 @@ #include <inttypes.h> #include <stdint.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> @@ -28,6 +29,13 @@ #include "udp_pes_scheduler.h" #include "../xine_input_vdr_net.h" // frame headers +#include "../config.h" // rtp address & port + + +#include <sys/types.h> +#include <linux/unistd.h> +#include <errno.h> +_syscall0(pid_t, gettid) //----------------------- cTimePts ------------------------------------------ @@ -78,6 +86,8 @@ const int64_t INITIAL_BURST_TIME = (int64_t)(45000); // pts units (90kHz) // assume seek when when pts difference between two frames exceeds this (1.5 seconds) const int64_t JUMP_LIMIT_TIME = (int64_t)(3*90000/2); // pts units (90kHz) +const int RTCP_MIN_INTERVAL = 90000; // max. once in second + typedef enum { eScrDetect, eScrFromAudio, @@ -102,6 +112,11 @@ cUdpScheduler::cUdpScheduler() last_delay_time = 0; + srandom(time(NULL) ^ gettid()); + m_ssrc = random(); + LOGDBG("RTP SSRC: 0x%08x", m_ssrc); + m_LastRtcpTime = 0; + // queuing int i; @@ -298,6 +313,52 @@ int cUdpScheduler::calc_elapsed_vtime(int64_t pts, bool Audio) return (int) diff; } +void cUdpScheduler::Send_RTCP(int fd_rtcp, uint32_t Frames, uint64_t Octets) +{ + uint64_t scr = RtpScr.Now(); + + if(scr > (m_LastRtcpTime + RTCP_MIN_INTERVAL)) { + uint8_t frame[2048], *content = frame; + rtcp_packet_t *msg = (rtcp_packet_t *)content; + struct timeval tv; + gettimeofday(&tv,NULL); + + // SR (Sender report) + msg->hdr.raw[0] = 0x81; // RTP version = 2, Report count = 1 */ + msg->hdr.ptype = RTCP_SR; + msg->hdr.length = htons(6); // length 6 dwords + + msg->sr.ssrc = htonl(m_ssrc); + msg->sr.ntp_sec = htonl(tv.tv_sec + 0x83AA7E80); + msg->sr.ntp_frac = htonl((uint32_t)((double)tv.tv_usec*(double)(1LL<<32)*1.0e-6)); + msg->sr.rtp_ts = htonl((uint32_t)(scr & 0xffffffff)); + msg->sr.psent = htonl((uint32_t)(Frames & 0xffffffff)); + msg->sr.osent = htonl((uint32_t)(Octets & 0xffffffff)); + + content += sizeof(rtcp_common_t) + sizeof(rtcp_sr_t); + msg = (rtcp_packet_t *)content; + + // SDES + msg->hdr.raw[0] = 0x81; // RTP version = 2, Report count = 1 */ + msg->hdr.ptype = RTCP_SDES; + msg->hdr.count = 1; + + msg->sdes.ssrc = m_ssrc; + msg->sdes.item[0].type = RTCP_SDES_CNAME; + sprintf(msg->sdes.item[0].data, "VDR@%s:%d%c%c%c", xc.remote_rtp_addr, xc.remote_rtp_port, 0, 0, 0); + msg->sdes.item[0].length = strlen(msg->sdes.item[0].data); + + msg->hdr.length = htons(1 + ((msg->sdes.item[0].length - 2) + 3) / 4); + + content += sizeof(rtcp_common_t) + 4*ntohs(msg->hdr.length); + msg = (rtcp_packet_t *)content; + + // Send + int err = send(fd_rtcp, frame, content - frame, 0); + //LOGMSG("RTCP send (%d)", err); + } +} + void cUdpScheduler::Schedule(const uchar *Data, int Length) { bool Audio=false, Video=false; diff --git a/tools/udp_pes_scheduler.h b/tools/udp_pes_scheduler.h index 57fce688..4fa81a1b 100644 --- a/tools/udp_pes_scheduler.h +++ b/tools/udp_pes_scheduler.h @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: udp_pes_scheduler.h,v 1.1 2006-06-03 10:04:28 phintuka Exp $ + * $Id: udp_pes_scheduler.h,v 1.2 2006-07-04 02:08:27 phintuka Exp $ * */ @@ -55,6 +55,8 @@ class cUdpScheduler : public cThread void Clear(void); bool Flush(int TimeoutMs); + void Send_RTCP(int fd_rtcp, uint32_t Frames, uint64_t Octets); + protected: // Data for payload handling & buffering @@ -73,13 +75,17 @@ class cUdpScheduler : public cThread // Data for scheduling algorithm - cTimePts RtpScr; // 90 kHz monotonic time source for RTP packets cTimePts MasterClock; // Current MPEG PTS (synchronized with current stream) cCondWait CondWait; int64_t current_audio_vtime; int64_t current_video_vtime; - + + // RTP + uint32_t m_ssrc; // RTP synchronization source id + cTimePts RtpScr; // 90 kHz monotonic time source for RTP timestamps + uint64_t m_LastRtcpTime; + #if 0 int data_sent; /* in current time interval, bytes */ int frames_sent; /* in current time interval */ |