annotate libmpdemux/demux_rtp.cpp @ 12007:b41cc72bb8ad

We now allow for the possibility of the RTCP audio/video synchronization being incorrect. (I encounted a stream for which this was the case.) Now, if audio and video are out-of-sync by >60 seconds, we assume that the RTCP sync is incorrect, and we don't discard any packets.
author rsf
date Tue, 02 Mar 2004 08:52:59 +0000
parents 94e1953fbe8e
children 8d45dcfc016f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
1 ////////// Routines (with C-linkage) that interface between "MPlayer"
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
2 ////////// and the "LIVE.COM Streaming Media" libraries:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
3
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
4 extern "C" {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
5 #include "demux_rtp.h"
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
6 #include "stheader.h"
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
7 }
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
8 #include "demux_rtp_internal.h"
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
9
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
10 #include "BasicUsageEnvironment.hh"
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
11 #include "liveMedia.hh"
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
12 #include "GroupsockHelper.hh"
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
13 #include <unistd.h>
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
14
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
15 extern "C" stream_t* stream_open_sdp(int fd, off_t fileSize,
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
16 int* file_format) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
17 *file_format = DEMUXER_TYPE_RTP;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
18 stream_t* newStream = NULL;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
19 do {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
20 char* sdpDescription = (char*)malloc(fileSize+1);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
21 if (sdpDescription == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
22
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
23 ssize_t numBytesRead = read(fd, sdpDescription, fileSize);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
24 if (numBytesRead != fileSize) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
25 sdpDescription[fileSize] = '\0'; // to be safe
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
26
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
27 newStream = (stream_t*)calloc(sizeof (stream_t), 1);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
28 if (newStream == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
29
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
30 // Store the SDP description in the 'priv' field, for later use:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
31 newStream->priv = sdpDescription;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
32 } while (0);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
33 return newStream;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
34 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
35
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
36 extern "C" int _rtsp_streaming_seek(int /*fd*/, off_t /*pos*/,
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
37 streaming_ctrl_t* /*streaming_ctrl*/) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
38 return -1; // For now, we don't handle RTSP stream seeking
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
39 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
40
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
41 extern "C" int rtsp_streaming_start(stream_t* stream) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
42 stream->streaming_ctrl->streaming_seek = _rtsp_streaming_seek;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
43
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
44 return 0;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
45 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
46
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
47 // A data structure representing input data for each stream:
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
48 class ReadBufferQueue {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
49 public:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
50 ReadBufferQueue(MediaSubsession* subsession, demuxer_t* demuxer,
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
51 char const* tag);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
52 virtual ~ReadBufferQueue();
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
53
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
54 FramedSource* readSource() const { return fReadSource; }
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
55 RTPSource* rtpSource() const { return fRTPSource; }
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
56 demuxer_t* ourDemuxer() const { return fOurDemuxer; }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
57 char const* tag() const { return fTag; }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
58
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
59 char blockingFlag; // used to implement synchronous reads
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
60
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
61 // For A/V synchronization:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
62 Boolean prevPacketWasSynchronized;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
63 float prevPacketPTS;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
64 ReadBufferQueue** otherQueue;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
65
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
66 // The 'queue' actually consists of just a single "demux_packet_t"
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
67 // (because the underlying OS does the actual queueing/buffering):
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
68 demux_packet_t* dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
69
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
70 // However, we sometimes inspect buffers before delivering them.
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
71 // For this, we maintain a queue of pending buffers:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
72 void savePendingBuffer(demux_packet_t* dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
73 demux_packet_t* getPendingBuffer();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
74
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
75 private:
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
76 demux_packet_t* pendingDPHead;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
77 demux_packet_t* pendingDPTail;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
78
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
79 FramedSource* fReadSource;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
80 RTPSource* fRTPSource;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
81 demuxer_t* fOurDemuxer;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
82 char const* fTag; // used for debugging
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
83 };
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
84
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
85 // A structure of RTP-specific state, kept so that we can cleanly
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
86 // reclaim it:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
87 typedef struct RTPState {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
88 char const* sdpDescription;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
89 RTSPClient* rtspClient;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
90 SIPClient* sipClient;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
91 MediaSession* mediaSession;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
92 ReadBufferQueue* audioBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
93 ReadBufferQueue* videoBufferQueue;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
94 unsigned flags;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
95 struct timeval firstSyncTime;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
96 };
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
97
9904
afbbf103a662 Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents: 9786
diff changeset
98 extern "C" char* network_username;
afbbf103a662 Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents: 9786
diff changeset
99 extern "C" char* network_password;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
100 static char* openURL_rtsp(RTSPClient* client, char const* url) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
101 // If we were given a user name (and optional password), then use them:
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
102 if (network_username != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
103 char const* password = network_password == NULL ? "" : network_password;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
104 return client->describeWithPassword(url, network_username, password);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
105 } else {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
106 return client->describeURL(url);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
107 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
108 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
109
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
110 static char* openURL_sip(SIPClient* client, char const* url) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
111 // If we were given a user name (and optional password), then use them:
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
112 if (network_username != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
113 char const* password = network_password == NULL ? "" : network_password;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
114 return client->inviteWithPassword(url, network_username, password);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
115 } else {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
116 return client->invite(url);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
117 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
118 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
119
7664
b10d6345f2a6 Added support for RTSP stream over TCP.
bertrand
parents: 7534
diff changeset
120 int rtspStreamOverTCP = 0;
b10d6345f2a6 Added support for RTSP stream over TCP.
bertrand
parents: 7534
diff changeset
121
11984
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
122 extern "C" demuxer_t* demux_open_rtp(demuxer_t* demuxer) {
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
123 do {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
124 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
125 if (scheduler == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
126 UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
127 if (env == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
128
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
129 RTSPClient* rtspClient = NULL;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
130 SIPClient* sipClient = NULL;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
131
9457
ea1c0a4520bf Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents: 9370
diff changeset
132 if (demuxer == NULL || demuxer->stream == NULL) break; // shouldn't happen
ea1c0a4520bf Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents: 9370
diff changeset
133 demuxer->stream->eof = 0; // just in case
ea1c0a4520bf Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents: 9370
diff changeset
134
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
135 // Look at the stream's 'priv' field to see if we were initiated
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
136 // via a SDP description:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
137 char* sdpDescription = (char*)(demuxer->stream->priv);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
138 if (sdpDescription == NULL) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
139 // We weren't given a SDP description directly, so assume that
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
140 // we were given a RTSP or SIP URL:
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
141 char const* protocol = demuxer->stream->streaming_ctrl->url->protocol;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
142 char const* url = demuxer->stream->streaming_ctrl->url->url;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
143 extern int verbose;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
144 if (strcmp(protocol, "rtsp") == 0) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
145 rtspClient = RTSPClient::createNew(*env, verbose, "MPlayer");
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
146 if (rtspClient == NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
147 fprintf(stderr, "Failed to create RTSP client: %s\n",
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
148 env->getResultMsg());
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
149 break;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
150 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
151 sdpDescription = openURL_rtsp(rtspClient, url);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
152 } else { // SIP
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
153 unsigned char desiredAudioType = 0; // PCMU (use 3 for GSM)
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
154 sipClient = SIPClient::createNew(*env, desiredAudioType, NULL,
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
155 verbose, "MPlayer");
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
156 if (sipClient == NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
157 fprintf(stderr, "Failed to create SIP client: %s\n",
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
158 env->getResultMsg());
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
159 break;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
160 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
161 sipClient->setClientStartPortNum(8000);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
162 sdpDescription = openURL_sip(sipClient, url);
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
163 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
164
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
165 if (sdpDescription == NULL) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
166 fprintf(stderr, "Failed to get a SDP description from URL \"%s\": %s\n",
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
167 url, env->getResultMsg());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
168 break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
169 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
170 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
171
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
172 // Now that we have a SDP description, create a MediaSession from it:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
173 MediaSession* mediaSession = MediaSession::createNew(*env, sdpDescription);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
174 if (mediaSession == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
175
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
176
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
177 // Create a 'RTPState' structure containing the state that we just created,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
178 // and store it in the demuxer's 'priv' field, for future reference:
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
179 RTPState* rtpState = new RTPState;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
180 rtpState->sdpDescription = sdpDescription;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
181 rtpState->rtspClient = rtspClient;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
182 rtpState->sipClient = sipClient;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
183 rtpState->mediaSession = mediaSession;
9370
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
184 rtpState->audioBufferQueue = rtpState->videoBufferQueue = NULL;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
185 rtpState->flags = 0;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
186 rtpState->firstSyncTime.tv_sec = rtpState->firstSyncTime.tv_usec = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
187 demuxer->priv = rtpState;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
188
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
189 // Create RTP receivers (sources) for each subsession:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
190 MediaSubsessionIterator iter(*mediaSession);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
191 MediaSubsession* subsession;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
192 unsigned desiredReceiveBufferSize;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
193 while ((subsession = iter.next()) != NULL) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
194 // Ignore any subsession that's not audio or video:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
195 if (strcmp(subsession->mediumName(), "audio") == 0) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
196 desiredReceiveBufferSize = 100000;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
197 } else if (strcmp(subsession->mediumName(), "video") == 0) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
198 desiredReceiveBufferSize = 2000000;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
199 } else {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
200 continue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
201 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
202
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
203 if (!subsession->initiate()) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
204 fprintf(stderr, "Failed to initiate \"%s/%s\" RTP subsession: %s\n", subsession->mediumName(), subsession->codecName(), env->getResultMsg());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
205 } else {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
206 fprintf(stderr, "Initiated \"%s/%s\" RTP subsession\n", subsession->mediumName(), subsession->codecName());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
207
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
208 // Set the OS's socket receive buffer sufficiently large to avoid
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
209 // incoming packets getting dropped between successive reads from this
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
210 // subsession's demuxer. Depending on the bitrate(s) that you expect,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
211 // you may wish to tweak the "desiredReceiveBufferSize" values above.
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
212 int rtpSocketNum = subsession->rtpSource()->RTPgs()->socketNum();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
213 int receiveBufferSize
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
214 = increaseReceiveBufferTo(*env, rtpSocketNum,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
215 desiredReceiveBufferSize);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
216 if (verbose > 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
217 fprintf(stderr, "Increased %s socket receive buffer to %d bytes \n",
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
218 subsession->mediumName(), receiveBufferSize);
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
219 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
220
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
221 if (rtspClient != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
222 // Issue a RTSP "SETUP" command on the chosen subsession:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
223 if (!rtspClient->setupMediaSubsession(*subsession, False,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
224 rtspStreamOverTCP)) break;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
225 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
226 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
227 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
228
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
229 if (rtspClient != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
230 // Issue a RTSP aggregate "PLAY" command on the whole session:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
231 if (!rtspClient->playMediaSession(*mediaSession)) break;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
232 } else if (sipClient != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
233 sipClient->sendACK(); // to start the stream flowing
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
234 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
235
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
236 // Now that the session is ready to be read, do additional
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
237 // MPlayer codec-specific initialization on each subsession:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
238 iter.reset();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
239 while ((subsession = iter.next()) != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
240 if (subsession->readSource() == NULL) continue; // not reading this
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
241
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
242 unsigned flags = 0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
243 if (strcmp(subsession->mediumName(), "audio") == 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
244 rtpState->audioBufferQueue
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
245 = new ReadBufferQueue(subsession, demuxer, "audio");
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
246 rtpState->audioBufferQueue->otherQueue = &(rtpState->videoBufferQueue);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
247 rtpCodecInitialize_audio(demuxer, subsession, flags);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
248 } else if (strcmp(subsession->mediumName(), "video") == 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
249 rtpState->videoBufferQueue
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
250 = new ReadBufferQueue(subsession, demuxer, "video");
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
251 rtpState->videoBufferQueue->otherQueue = &(rtpState->audioBufferQueue);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
252 rtpCodecInitialize_video(demuxer, subsession, flags);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
253 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
254 rtpState->flags |= flags;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
255 }
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
256 } while (0);
11984
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
257
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
258 // Hack: If audio and video are demuxed together on a single RTP stream,
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
259 // then create a new "demuxer_t" structure to allow the higher-level
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
260 // code to recognize this:
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
261 if (demux_is_multiplexed_rtp_stream(demuxer)) {
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
262 stream_t* s = new_ds_stream(demuxer->video);
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
263 demuxer_t* od = demux_open(s, DEMUXER_TYPE_UNKNOWN, -1, -1, -1, NULL);
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
264 demuxer = new_demuxers_demuxer(od, od, od);
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
265 }
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
266
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
267 return demuxer;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
268 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
269
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
270 extern "C" int demux_is_mpeg_rtp_stream(demuxer_t* demuxer) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
271 // Get the RTP state that was stored in the demuxer's 'priv' field:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
272 RTPState* rtpState = (RTPState*)(demuxer->priv);
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
273
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
274 return (rtpState->flags&RTPSTATE_IS_MPEG12_VIDEO) != 0;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
275 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
276
10477
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
277 extern "C" int demux_is_multiplexed_rtp_stream(demuxer_t* demuxer) {
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
278 // Get the RTP state that was stored in the demuxer's 'priv' field:
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
279 RTPState* rtpState = (RTPState*)(demuxer->priv);
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
280
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
281 return (rtpState->flags&RTPSTATE_IS_MULTIPLEXED) != 0;
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
282 }
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
283
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
284 static demux_packet_t* getBuffer(demuxer_t* demuxer, demux_stream_t* ds,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
285 Boolean mustGetNewData,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
286 float& ptsBehind); // forward
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
287
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
288 extern "C" int demux_rtp_fill_buffer(demuxer_t* demuxer, demux_stream_t* ds) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
289 // Get a filled-in "demux_packet" from the RTP source, and deliver it.
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
290 // Note that this is called as a synchronous read operation, so it needs
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
291 // to block in the (hopefully infrequent) case where no packet is
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
292 // immediately available.
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
293
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
294 while (1) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
295 float ptsBehind;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
296 demux_packet_t* dp = getBuffer(demuxer, ds, False, ptsBehind); // blocking
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
297 if (dp == NULL) return 0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
298
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
299 if (demuxer->stream->eof) return 0; // source stream has closed down
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
300
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
301 // Before using this packet, check to make sure that its presentation
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
302 // time is not far behind the other stream (if any). If it is,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
303 // then we discard this packet, and get another instead. (The rest of
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
304 // MPlayer doesn't always do a good job of synchronizing when the
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
305 // audio and video streams get this far apart.)
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
306 // (We don't do this when streaming over TCP, because then the audio and
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
307 // video streams are interleaved.)
12007
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
308 // (Also, if the stream is *excessively* far behind, then we allow
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
309 // the packet, because in this case it probably means that there was
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
310 // an error in the source's timestamp synchronization.)
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
311 const float ptsBehindThreshold = 1.0; // seconds
12007
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
312 const float ptsBehindLimit = 60.0; // seconds
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
313 if (ptsBehind < ptsBehindThreshold ||
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
314 ptsBehind > ptsBehindLimit ||
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
315 rtspStreamOverTCP) { // packet's OK
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
316 ds_add_packet(ds, dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
317 break;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
318 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
319
9786
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
320 #ifdef DEBUG_PRINT_DISCARDED_PACKETS
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
321 RTPState* rtpState = (RTPState*)(demuxer->priv);
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
322 ReadBufferQueue* bufferQueue = ds == demuxer->video ? rtpState->videoBufferQueue : rtpState->audioBufferQueue;
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
323 fprintf(stderr, "Discarding %s packet (%fs behind)\n", bufferQueue->tag(), ptsBehind);
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
324 #endif
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
325 free_demux_packet(dp); // give back this packet, and get another one
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
326 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
327
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
328 return 1;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
329 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
330
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
331 Boolean awaitRTPPacket(demuxer_t* demuxer, demux_stream_t* ds,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
332 unsigned char*& packetData, unsigned& packetDataLen,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
333 float& pts) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
334 // Similar to "demux_rtp_fill_buffer()", except that the "demux_packet"
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
335 // is not delivered to the "demux_stream".
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
336 float ptsBehind;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
337 demux_packet_t* dp = getBuffer(demuxer, ds, True, ptsBehind); // blocking
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
338 if (dp == NULL) return False;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
339
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
340 packetData = dp->buffer;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
341 packetDataLen = dp->len;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
342 pts = dp->pts;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
343
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
344 return True;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
345 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
346
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
347 Boolean insertRTPData(demuxer_t* demuxer, demux_stream_t* ds,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
348 unsigned char* data, unsigned dataLen) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
349 // Begin by finding the buffer queue that we want to add data to.
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
350 // (Get this from the RTP state, which we stored in
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
351 // the demuxer's 'priv' field)
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
352 RTPState* rtpState = (RTPState*)(demuxer->priv);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
353 ReadBufferQueue* bufferQueue = NULL;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
354 if (ds == demuxer->video) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
355 bufferQueue = rtpState->videoBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
356 } else if (ds == demuxer->audio) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
357 bufferQueue = rtpState->audioBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
358 } else {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
359 fprintf(stderr, "(demux_rtp)insertRTPData: internal error: unknown stream\n");
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
360 return False;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
361 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
362
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
363 if (data == NULL || dataLen == 0) return False;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
364
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
365 demux_packet_t* dp = new_demux_packet(dataLen);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
366 if (dp == NULL) return False;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
367
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
368 // Copy our data into the buffer, and save it:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
369 memmove(dp->buffer, data, dataLen);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
370 dp->len = dataLen;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
371 dp->pts = 0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
372 bufferQueue->savePendingBuffer(dp);
9904
afbbf103a662 Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents: 9786
diff changeset
373 return True;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
374 }
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
375
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
376 static void teardownRTSPorSIPSession(RTPState* rtpState); // forward
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
377
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
378 extern "C" void demux_close_rtp(demuxer_t* demuxer) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
379 // Reclaim all RTP-related state:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
380
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
381 // Get the RTP state that was stored in the demuxer's 'priv' field:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
382 RTPState* rtpState = (RTPState*)(demuxer->priv);
7143
fdfc10c2e2d2 - Tell the RTSP client code to use the string "mplayer" in RTSP
arpi
parents: 7008
diff changeset
383 if (rtpState == NULL) return;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
384
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
385 teardownRTSPorSIPSession(rtpState);
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
386
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
387 UsageEnvironment* env = NULL;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
388 TaskScheduler* scheduler = NULL;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
389 if (rtpState->mediaSession != NULL) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
390 env = &(rtpState->mediaSession->envir());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
391 scheduler = &(env->taskScheduler());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
392 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
393 Medium::close(rtpState->mediaSession);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
394 Medium::close(rtpState->rtspClient);
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
395 Medium::close(rtpState->sipClient);
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
396 delete rtpState->audioBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
397 delete rtpState->videoBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
398 delete rtpState->sdpDescription;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
399 delete rtpState;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
400
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
401 delete env; delete scheduler;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
402 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
403
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
404 ////////// Extra routines that help implement the above interface functions:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
405
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
406 #define MAX_RTP_FRAME_SIZE 50000
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
407 // >= the largest conceivable frame composed from one or more RTP packets
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
408
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
409 static void afterReading(void* clientData, unsigned frameSize,
11755
a79a318585ce Changed to conform to recent changes to the "LIVE.COM Streaming Media" code.
rsf
parents: 10937
diff changeset
410 unsigned /*numTruncatedBytes*/,
a79a318585ce Changed to conform to recent changes to the "LIVE.COM Streaming Media" code.
rsf
parents: 10937
diff changeset
411 struct timeval presentationTime,
a79a318585ce Changed to conform to recent changes to the "LIVE.COM Streaming Media" code.
rsf
parents: 10937
diff changeset
412 unsigned /*durationInMicroseconds*/) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
413 if (frameSize >= MAX_RTP_FRAME_SIZE) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
414 fprintf(stderr, "Saw an input frame too large (>=%d). Increase MAX_RTP_FRAME_SIZE in \"demux_rtp.cpp\".\n",
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
415 MAX_RTP_FRAME_SIZE);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
416 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
417 ReadBufferQueue* bufferQueue = (ReadBufferQueue*)clientData;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
418 demuxer_t* demuxer = bufferQueue->ourDemuxer();
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
419 RTPState* rtpState = (RTPState*)(demuxer->priv);
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
420
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
421 if (frameSize > 0) demuxer->stream->eof = 0;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
422
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
423 demux_packet_t* dp = bufferQueue->dp;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
424 dp->len = frameSize;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
425
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
426 // Set the packet's presentation time stamp, depending on whether or
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
427 // not our RTP source's timestamps have been synchronized yet:
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
428 Boolean hasBeenSynchronized
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
429 = bufferQueue->rtpSource()->hasBeenSynchronizedUsingRTCP();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
430 if (hasBeenSynchronized) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
431 if (verbose > 0 && !bufferQueue->prevPacketWasSynchronized) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
432 fprintf(stderr, "%s stream has been synchronized using RTCP \n",
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
433 bufferQueue->tag());
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
434 }
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
435
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
436 struct timeval* fst = &(rtpState->firstSyncTime); // abbrev
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
437 if (fst->tv_sec == 0 && fst->tv_usec == 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
438 *fst = presentationTime;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
439 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
440
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
441 // For the "pts" field, use the time differential from the first
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
442 // synchronized time, rather than absolute time, in order to avoid
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
443 // round-off errors when converting to a float:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
444 dp->pts = presentationTime.tv_sec - fst->tv_sec
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
445 + (presentationTime.tv_usec - fst->tv_usec)/1000000.0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
446 bufferQueue->prevPacketPTS = dp->pts;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
447 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
448 if (verbose > 0 && bufferQueue->prevPacketWasSynchronized) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
449 fprintf(stderr, "%s stream is no longer RTCP-synchronized \n",
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
450 bufferQueue->tag());
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
451 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
452
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
453 // use the previous packet's "pts" once again:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
454 dp->pts = bufferQueue->prevPacketPTS;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
455 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
456 bufferQueue->prevPacketWasSynchronized = hasBeenSynchronized;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
457
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
458 dp->pos = demuxer->filepos;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
459 demuxer->filepos += frameSize;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
460
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
461 // Signal any pending 'doEventLoop()' call on this queue:
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
462 bufferQueue->blockingFlag = ~0;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
463 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
464
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
465 static void onSourceClosure(void* clientData) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
466 ReadBufferQueue* bufferQueue = (ReadBufferQueue*)clientData;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
467 demuxer_t* demuxer = bufferQueue->ourDemuxer();
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
468
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
469 demuxer->stream->eof = 1;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
470
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
471 // Signal any pending 'doEventLoop()' call on this queue:
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
472 bufferQueue->blockingFlag = ~0;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
473 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
474
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
475 static demux_packet_t* getBuffer(demuxer_t* demuxer, demux_stream_t* ds,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
476 Boolean mustGetNewData,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
477 float& ptsBehind) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
478 // Begin by finding the buffer queue that we want to read from:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
479 // (Get this from the RTP state, which we stored in
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
480 // the demuxer's 'priv' field)
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
481 RTPState* rtpState = (RTPState*)(demuxer->priv);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
482 ReadBufferQueue* bufferQueue = NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
483 if (ds == demuxer->video) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
484 bufferQueue = rtpState->videoBufferQueue;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
485 } else if (ds == demuxer->audio) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
486 bufferQueue = rtpState->audioBufferQueue;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
487 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
488 fprintf(stderr, "(demux_rtp)getBuffer: internal error: unknown stream\n");
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
489 return NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
490 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
491
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
492 if (bufferQueue == NULL || bufferQueue->readSource() == NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
493 fprintf(stderr, "(demux_rtp)getBuffer failed: no appropriate RTP subsession has been set up\n");
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
494 return NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
495 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
496
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
497 demux_packet_t* dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
498 if (!mustGetNewData) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
499 // Check whether we have a previously-saved buffer that we can use:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
500 dp = bufferQueue->getPendingBuffer();
9911
fa45d335a43b Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents: 9904
diff changeset
501 if (dp != NULL) {
fa45d335a43b Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents: 9904
diff changeset
502 ptsBehind = 0.0; // so that we always accept this data
fa45d335a43b Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents: 9904
diff changeset
503 return dp;
fa45d335a43b Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents: 9904
diff changeset
504 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
505 }
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
506
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
507 // Allocate a new packet buffer, and arrange to read into it:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
508 dp = new_demux_packet(MAX_RTP_FRAME_SIZE);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
509 bufferQueue->dp = dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
510 if (dp == NULL) return NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
511
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
512 // Schedule the read operation:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
513 bufferQueue->blockingFlag = 0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
514 bufferQueue->readSource()->getNextFrame(dp->buffer, MAX_RTP_FRAME_SIZE,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
515 afterReading, bufferQueue,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
516 onSourceClosure, bufferQueue);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
517 // Block ourselves until data becomes available:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
518 TaskScheduler& scheduler
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
519 = bufferQueue->readSource()->envir().taskScheduler();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
520 scheduler.doEventLoop(&bufferQueue->blockingFlag);
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
521
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
522 // Set the "ptsBehind" result parameter:
10937
384f6a88a31d Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents: 10477
diff changeset
523 if (bufferQueue->prevPacketPTS != 0.0
384f6a88a31d Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents: 10477
diff changeset
524 && bufferQueue->prevPacketWasSynchronized
384f6a88a31d Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents: 10477
diff changeset
525 && *(bufferQueue->otherQueue) != NULL
384f6a88a31d Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents: 10477
diff changeset
526 && (*(bufferQueue->otherQueue))->prevPacketPTS != 0.0
384f6a88a31d Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents: 10477
diff changeset
527 && (*(bufferQueue->otherQueue))->prevPacketWasSynchronized) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
528 ptsBehind = (*(bufferQueue->otherQueue))->prevPacketPTS
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
529 - bufferQueue->prevPacketPTS;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
530 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
531 ptsBehind = 0.0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
532 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
533
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
534 if (mustGetNewData) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
535 // Save this buffer for future reads:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
536 bufferQueue->savePendingBuffer(dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
537 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
538
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
539 return dp;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
540 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
541
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
542 static void teardownRTSPorSIPSession(RTPState* rtpState) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
543 MediaSession* mediaSession = rtpState->mediaSession;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
544 if (mediaSession == NULL) return;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
545 if (rtpState->rtspClient != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
546 MediaSubsessionIterator iter(*mediaSession);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
547 MediaSubsession* subsession;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
548
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
549 while ((subsession = iter.next()) != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
550 rtpState->rtspClient->teardownMediaSubsession(*subsession);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
551 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
552 } else if (rtpState->sipClient != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
553 rtpState->sipClient->sendBYE();
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
554 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
555 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
556
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
557 ////////// "ReadBuffer" and "ReadBufferQueue" implementation:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
558
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
559 ReadBufferQueue::ReadBufferQueue(MediaSubsession* subsession,
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
560 demuxer_t* demuxer, char const* tag)
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
561 : prevPacketWasSynchronized(False), prevPacketPTS(0.0), otherQueue(NULL),
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
562 dp(NULL), pendingDPHead(NULL), pendingDPTail(NULL),
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
563 fReadSource(subsession == NULL ? NULL : subsession->readSource()),
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
564 fRTPSource(subsession == NULL ? NULL : subsession->rtpSource()),
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
565 fOurDemuxer(demuxer), fTag(strdup(tag)) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
566 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
567
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
568 ReadBufferQueue::~ReadBufferQueue() {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
569 delete fTag;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
570
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
571 // Free any pending buffers (that never got delivered):
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
572 demux_packet_t* dp = pendingDPHead;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
573 while (dp != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
574 demux_packet_t* dpNext = dp->next;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
575 dp->next = NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
576 free_demux_packet(dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
577 dp = dpNext;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
578 }
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
579 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
580
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
581 void ReadBufferQueue::savePendingBuffer(demux_packet_t* dp) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
582 // Keep this buffer around, until MPlayer asks for it later:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
583 if (pendingDPTail == NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
584 pendingDPHead = pendingDPTail = dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
585 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
586 pendingDPTail->next = dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
587 pendingDPTail = dp;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
588 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
589 dp->next = NULL;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
590 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
591
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
592 demux_packet_t* ReadBufferQueue::getPendingBuffer() {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
593 demux_packet_t* dp = pendingDPHead;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
594 if (dp != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
595 pendingDPHead = dp->next;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
596 if (pendingDPHead == NULL) pendingDPTail = NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
597
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
598 dp->next = NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
599 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
600
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
601 return dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
602 }