annotate libmpdemux/demux_rtp.cpp @ 24424:0c4f1a88eaae

warning fixes: input.c: In function 'mp_input_set_section': input.c:1640: warning: suggest parentheses around assignment used as truth value input.c:1643: warning: suggest parentheses around assignment used as truth value mga_common.c: In function 'mga_init': mga_common.c:394: warning: suggest parentheses around assignment used as truth value playtreeparser.c: In function 'parse_smil': playtreeparser.c:523: warning: suggest parentheses around assignment used as truth value libmpdemux/demux_ts.c: In function 'ts_parse': libmpdemux/demux_ts.c:2795: warning: suggest parentheses around assignment used as truth value libmpdemux/demux_ts.c: In function 'demux_open_ts': libmpdemux/demux_ts.c:591: warning: 'frame_length' may be used uninitialized in this function
author diego
date Thu, 13 Sep 2007 13:16:30 +0000
parents ba3868fbe12c
children 5411b440eb24
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"
16572
56a5f69e9b35 "LIVE.COM Streaming Media" is now called "LIVE555 Streaming Media".
rsf
parents: 16175
diff changeset
2 ////////// and the "LIVE555 Streaming Media" libraries:
9250
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" {
12531
834e7844ab3b MinGW compilation fix from a patch by Joey Parrish, approved by Sascha
diego
parents: 12521
diff changeset
5 // on MinGW, we must include windows.h before the things it conflicts
834e7844ab3b MinGW compilation fix from a patch by Joey Parrish, approved by Sascha
diego
parents: 12521
diff changeset
6 #ifdef __MINGW32__ // with. they are each protected from
834e7844ab3b MinGW compilation fix from a patch by Joey Parrish, approved by Sascha
diego
parents: 12521
diff changeset
7 #include <windows.h> // windows.h, but not the other way around.
834e7844ab3b MinGW compilation fix from a patch by Joey Parrish, approved by Sascha
diego
parents: 12521
diff changeset
8 #endif
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
9 #include "demux_rtp.h"
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
10 #include "stheader.h"
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
11 }
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
12 #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
13
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
14 #include "BasicUsageEnvironment.hh"
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
15 #include "liveMedia.hh"
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
16 #include "GroupsockHelper.hh"
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
17 #include <unistd.h>
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
18
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
19 // 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
20 class ReadBufferQueue {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
21 public:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
22 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
23 char const* tag);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
24 virtual ~ReadBufferQueue();
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
25
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
26 FramedSource* readSource() const { return fReadSource; }
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
27 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
28 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
29 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
30
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
31 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
32
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
33 // For A/V synchronization:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
34 Boolean prevPacketWasSynchronized;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
35 float prevPacketPTS;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
36 ReadBufferQueue** otherQueue;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
37
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
38 // 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
39 // (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
40 demux_packet_t* dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
41
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
42 // 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
43 // 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
44 void savePendingBuffer(demux_packet_t* dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
45 demux_packet_t* getPendingBuffer();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
46
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
47 // For H264 over rtsp using AVParser, the next packet has to be saved
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
48 demux_packet_t* nextpacket;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
49
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
50 private:
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
51 demux_packet_t* pendingDPHead;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
52 demux_packet_t* pendingDPTail;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
53
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
54 FramedSource* fReadSource;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
55 RTPSource* 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* fOurDemuxer;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
57 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
58 };
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
59
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
60 // 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
61 // reclaim it:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
62 typedef struct RTPState {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
63 char const* sdpDescription;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
64 RTSPClient* rtspClient;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
65 SIPClient* sipClient;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
66 MediaSession* mediaSession;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
67 ReadBufferQueue* audioBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
68 ReadBufferQueue* videoBufferQueue;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
69 unsigned flags;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
70 struct timeval firstSyncTime;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
71 };
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
72
9904
afbbf103a662 Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents: 9786
diff changeset
73 extern "C" char* network_username;
afbbf103a662 Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents: 9786
diff changeset
74 extern "C" char* network_password;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
75 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
76 // 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
77 if (network_username != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
78 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
79 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
80 } else {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
81 return client->describeURL(url);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
82 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
83 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
84
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
85 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
86 // 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
87 if (network_username != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
88 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
89 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
90 } else {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
91 return client->invite(url);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
92 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
93 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
94
7664
b10d6345f2a6 Added support for RTSP stream over TCP.
bertrand
parents: 7534
diff changeset
95 int rtspStreamOverTCP = 0;
18832
7d60e0c9f58a don't declare same global var twice (break live555 compilation)
ben
parents: 17650
diff changeset
96 extern int rtsp_port;
7664
b10d6345f2a6 Added support for RTSP stream over TCP.
bertrand
parents: 7534
diff changeset
97
12521
27ed4672c619 Added "audio_id", "video_id", "dvdsub_id" to the call to "demux_open()".
rsf
parents: 12043
diff changeset
98 extern "C" int audio_id, video_id, dvdsub_id;
11984
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
99 extern "C" demuxer_t* demux_open_rtp(demuxer_t* demuxer) {
12043
8d45dcfc016f Fixed a bug that was accidentally introduced by the addition of MPEG Transport
rsf
parents: 12007
diff changeset
100 Boolean success = False;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
101 do {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
102 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
103 if (scheduler == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
104 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
105 if (env == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
106
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
107 RTSPClient* rtspClient = NULL;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
108 SIPClient* sipClient = NULL;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
109
9457
ea1c0a4520bf Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents: 9370
diff changeset
110 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
111 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
112
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
113 // 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
114 // via a SDP description:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
115 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
116 if (sdpDescription == NULL) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
117 // 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
118 // 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
119 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
120 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
121 extern int verbose;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
122 if (strcmp(protocol, "rtsp") == 0) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
123 rtspClient = RTSPClient::createNew(*env, verbose, "MPlayer");
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
124 if (rtspClient == NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
125 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
126 env->getResultMsg());
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
127 break;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
128 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
129 sdpDescription = openURL_rtsp(rtspClient, url);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
130 } else { // SIP
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
131 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
132 sipClient = SIPClient::createNew(*env, desiredAudioType, NULL,
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
133 verbose, "MPlayer");
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
134 if (sipClient == NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
135 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
136 env->getResultMsg());
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
137 break;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
138 }
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
139 sipClient->setClientStartPortNum(8000);
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
140 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
141 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
142
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
143 if (sdpDescription == NULL) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
144 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
145 url, env->getResultMsg());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
146 break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
147 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
148 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
149
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
150 // 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
151 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
152 if (mediaSession == NULL) break;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
153
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
154
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
155 // Create a 'RTPState' structure containing the state that we just created,
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
156 // 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
157 RTPState* rtpState = new RTPState;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
158 rtpState->sdpDescription = sdpDescription;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
159 rtpState->rtspClient = rtspClient;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
160 rtpState->sipClient = sipClient;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
161 rtpState->mediaSession = mediaSession;
9370
88bd19564b64 Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents: 9250
diff changeset
162 rtpState->audioBufferQueue = rtpState->videoBufferQueue = NULL;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
163 rtpState->flags = 0;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
164 rtpState->firstSyncTime.tv_sec = rtpState->firstSyncTime.tv_usec = 0;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
165 demuxer->priv = rtpState;
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
166
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
167 // 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
168 MediaSubsessionIterator iter(*mediaSession);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
169 MediaSubsession* subsession;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
170 unsigned desiredReceiveBufferSize;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
171 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
172 // 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
173 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
174 desiredReceiveBufferSize = 100000;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
175 } 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
176 desiredReceiveBufferSize = 2000000;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
177 } else {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
178 continue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
179 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
180
17650
d6e575c86bb8 Allows the LIVE555 library to forces the client's port to be used
bertrand
parents: 16572
diff changeset
181 if (rtsp_port)
d6e575c86bb8 Allows the LIVE555 library to forces the client's port to be used
bertrand
parents: 16572
diff changeset
182 subsession->setClientPortNum (rtsp_port);
d6e575c86bb8 Allows the LIVE555 library to forces the client's port to be used
bertrand
parents: 16572
diff changeset
183
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
184 if (!subsession->initiate()) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
185 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
186 } else {
17650
d6e575c86bb8 Allows the LIVE555 library to forces the client's port to be used
bertrand
parents: 16572
diff changeset
187 fprintf(stderr, "Initiated \"%s/%s\" RTP subsession on port %d\n", subsession->mediumName(), subsession->codecName(), subsession->clientPortNum());
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
188
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
189 // 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
190 // 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
191 // 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
192 // 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
193 int rtpSocketNum = subsession->rtpSource()->RTPgs()->socketNum();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
194 int receiveBufferSize
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
195 = increaseReceiveBufferTo(*env, rtpSocketNum,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
196 desiredReceiveBufferSize);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
197 if (verbose > 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
198 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
199 subsession->mediumName(), receiveBufferSize);
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
200 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
201
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
202 if (rtspClient != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
203 // 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
204 if (!rtspClient->setupMediaSubsession(*subsession, False,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
205 rtspStreamOverTCP)) break;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
206 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
207 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
208 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
209
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
210 if (rtspClient != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
211 // 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
212 if (!rtspClient->playMediaSession(*mediaSession)) break;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
213 } else if (sipClient != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
214 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
215 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
216
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
217 // 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
218 // 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
219 iter.reset();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
220 while ((subsession = iter.next()) != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
221 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
222
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
223 unsigned flags = 0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
224 if (strcmp(subsession->mediumName(), "audio") == 0) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
225 rtpState->audioBufferQueue
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
226 = new ReadBufferQueue(subsession, demuxer, "audio");
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
227 rtpState->audioBufferQueue->otherQueue = &(rtpState->videoBufferQueue);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
228 rtpCodecInitialize_audio(demuxer, subsession, flags);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
229 } 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
230 rtpState->videoBufferQueue
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
231 = new ReadBufferQueue(subsession, demuxer, "video");
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
232 rtpState->videoBufferQueue->otherQueue = &(rtpState->audioBufferQueue);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
233 rtpCodecInitialize_video(demuxer, subsession, flags);
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 rtpState->flags |= flags;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
236 }
12043
8d45dcfc016f Fixed a bug that was accidentally introduced by the addition of MPEG Transport
rsf
parents: 12007
diff changeset
237 success = True;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
238 } while (0);
12043
8d45dcfc016f Fixed a bug that was accidentally introduced by the addition of MPEG Transport
rsf
parents: 12007
diff changeset
239 if (!success) return NULL; // an error occurred
11984
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
240
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
241 // 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
242 // 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
243 // code to recognize this:
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
244 if (demux_is_multiplexed_rtp_stream(demuxer)) {
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
245 stream_t* s = new_ds_stream(demuxer->video);
12521
27ed4672c619 Added "audio_id", "video_id", "dvdsub_id" to the call to "demux_open()".
rsf
parents: 12043
diff changeset
246 demuxer_t* od = demux_open(s, DEMUXER_TYPE_UNKNOWN,
27ed4672c619 Added "audio_id", "video_id", "dvdsub_id" to the call to "demux_open()".
rsf
parents: 12043
diff changeset
247 audio_id, video_id, dvdsub_id, NULL);
11984
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
248 demuxer = new_demuxers_demuxer(od, od, od);
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
249 }
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
250
94e1953fbe8e Added support for multiplexed audio+video RTP streams.
rsf
parents: 11755
diff changeset
251 return demuxer;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
252 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
253
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
254 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
255 // 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
256 RTPState* rtpState = (RTPState*)(demuxer->priv);
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
257
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
258 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
259 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
260
10477
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
261 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
262 // 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
263 RTPState* rtpState = (RTPState*)(demuxer->priv);
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
264
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
265 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
266 }
c34185f47b62 Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents: 10054
diff changeset
267
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
268 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
269 Boolean mustGetNewData,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
270 float& ptsBehind); // forward
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
271
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
272 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
273 // 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
274 // 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
275 // 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
276 // immediately available.
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
277
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
278 while (1) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
279 float ptsBehind;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
280 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
281 if (dp == NULL) return 0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
282
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
283 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
284
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
285 // 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
286 // 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
287 // 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
288 // 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
289 // 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
290 // (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
291 // video streams are interleaved.)
12007
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
292 // (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
293 // 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
294 // 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
295 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
296 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
297 if (ptsBehind < ptsBehindThreshold ||
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
298 ptsBehind > ptsBehindLimit ||
b41cc72bb8ad We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents: 11984
diff changeset
299 rtspStreamOverTCP) { // packet's OK
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
300 ds_add_packet(ds, dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
301 break;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
302 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
303
9786
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
304 #ifdef DEBUG_PRINT_DISCARDED_PACKETS
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
305 RTPState* rtpState = (RTPState*)(demuxer->priv);
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
306 ReadBufferQueue* bufferQueue = ds == demuxer->video ? rtpState->videoBufferQueue : rtpState->audioBufferQueue;
177a3393057c Added some optional debugging printfs (disabled by default)
rsf
parents: 9565
diff changeset
307 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
308 #endif
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
309 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
310 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
311
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
312 return 1;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
313 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
314
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
315 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
316 unsigned char*& packetData, unsigned& packetDataLen,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
317 float& pts) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
318 // 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
319 // 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
320 float ptsBehind;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
321 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
322 if (dp == NULL) return False;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
323
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
324 packetData = dp->buffer;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
325 packetDataLen = dp->len;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
326 pts = dp->pts;
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 True;
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
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
331 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
332
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
333 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
334 // 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
335
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
336 // 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
337 RTPState* rtpState = (RTPState*)(demuxer->priv);
7143
fdfc10c2e2d2 - Tell the RTSP client code to use the string "mplayer" in RTSP
arpi
parents: 7008
diff changeset
338 if (rtpState == NULL) return;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
339
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
340 teardownRTSPorSIPSession(rtpState);
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
341
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
342 UsageEnvironment* env = NULL;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
343 TaskScheduler* scheduler = NULL;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
344 if (rtpState->mediaSession != NULL) {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
345 env = &(rtpState->mediaSession->envir());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
346 scheduler = &(env->taskScheduler());
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
347 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
348 Medium::close(rtpState->mediaSession);
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
349 Medium::close(rtpState->rtspClient);
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
350 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
351 delete rtpState->audioBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
352 delete rtpState->videoBufferQueue;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
353 delete rtpState->sdpDescription;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
354 delete rtpState;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
355
12866
332f24a1dd5c Updated to conform to a small change in the LIVE.COM API.
rsf
parents: 12531
diff changeset
356 env->reclaim(); delete scheduler;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
357 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
358
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
359 ////////// 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
360
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
361 #define MAX_RTP_FRAME_SIZE 50000
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
362 // >= 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
363
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
364 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
365 unsigned /*numTruncatedBytes*/,
a79a318585ce Changed to conform to recent changes to the "LIVE.COM Streaming Media" code.
rsf
parents: 10937
diff changeset
366 struct timeval presentationTime,
a79a318585ce Changed to conform to recent changes to the "LIVE.COM Streaming Media" code.
rsf
parents: 10937
diff changeset
367 unsigned /*durationInMicroseconds*/) {
22463
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
368 int headersize = 0;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
369 if (frameSize >= MAX_RTP_FRAME_SIZE) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
370 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
371 MAX_RTP_FRAME_SIZE);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
372 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
373 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
374 demuxer_t* demuxer = bufferQueue->ourDemuxer();
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
375 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
376
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
377 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
378
22851
e878a71cb27f Cosmetics: Move variable declaration and initialization up.
cehoyos
parents: 22759
diff changeset
379 demux_packet_t* dp = bufferQueue->dp;
e878a71cb27f Cosmetics: Move variable declaration and initialization up.
cehoyos
parents: 22759
diff changeset
380
22463
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
381 if (bufferQueue->readSource()->isAMRAudioSource())
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
382 headersize = 1;
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
383 else if (bufferQueue == rtpState->videoBufferQueue &&
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
384 ((sh_video_t*)demuxer->video->sh)->format == mmioFOURCC('H','2','6','4')) {
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
385 dp->buffer[0]=0x00;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
386 dp->buffer[1]=0x00;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
387 dp->buffer[2]=0x01;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
388 headersize = 3;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
389 }
22463
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
390
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
391 resize_demux_packet(dp, frameSize + headersize);
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
392
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
393 // Set the packet's presentation time stamp, depending on whether or
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
394 // 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
395 Boolean hasBeenSynchronized
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
396 = bufferQueue->rtpSource()->hasBeenSynchronizedUsingRTCP();
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
397 if (hasBeenSynchronized) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
398 if (verbose > 0 && !bufferQueue->prevPacketWasSynchronized) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
399 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
400 bufferQueue->tag());
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
401 }
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
402
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
403 struct timeval* fst = &(rtpState->firstSyncTime); // abbrev
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
404 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
405 *fst = presentationTime;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
406 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
407
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
408 // 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
409 // 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
410 // 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
411 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
412 + (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
413 bufferQueue->prevPacketPTS = dp->pts;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
414 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
415 if (verbose > 0 && bufferQueue->prevPacketWasSynchronized) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
416 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
417 bufferQueue->tag());
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
418 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
419
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
420 // 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
421 dp->pts = bufferQueue->prevPacketPTS;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
422 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
423 bufferQueue->prevPacketWasSynchronized = hasBeenSynchronized;
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
424
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
425 dp->pos = demuxer->filepos;
22759
e6135bdf4f8a Fix filepos calculation
cehoyos
parents: 22519
diff changeset
426 demuxer->filepos += frameSize + headersize;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
427
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
428 // 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
429 bufferQueue->blockingFlag = ~0;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
430 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
431
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
432 static void onSourceClosure(void* clientData) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
433 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
434 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
435
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
436 demuxer->stream->eof = 1;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
437
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
438 // 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
439 bufferQueue->blockingFlag = ~0;
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
440 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
441
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
442 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
443 Boolean mustGetNewData,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
444 float& ptsBehind) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
445 // 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
446 // (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
447 // the demuxer's 'priv' field)
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
448 RTPState* rtpState = (RTPState*)(demuxer->priv);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
449 ReadBufferQueue* bufferQueue = NULL;
22519
5f3a0a712afb cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents: 22463
diff changeset
450 int headersize = 0;
23554
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
451 TaskToken task;
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
452
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
453 if (demuxer->stream->eof) return NULL;
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
454
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
455 if (ds == demuxer->video) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
456 bufferQueue = rtpState->videoBufferQueue;
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
457 if (((sh_video_t*)ds->sh)->format == mmioFOURCC('H','2','6','4'))
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
458 headersize = 3;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
459 } else if (ds == demuxer->audio) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
460 bufferQueue = rtpState->audioBufferQueue;
22463
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
461 if (bufferQueue->readSource()->isAMRAudioSource())
22519
5f3a0a712afb cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents: 22463
diff changeset
462 headersize = 1;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
463 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
464 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
465 return NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
466 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
467
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
468 if (bufferQueue == NULL || bufferQueue->readSource() == NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
469 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
470 return NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
471 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
472
23555
2237e232cc15 Silence three warnings.
cehoyos
parents: 23554
diff changeset
473 demux_packet_t* dp = NULL;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
474 if (!mustGetNewData) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
475 // 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
476 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
477 if (dp != NULL) {
fa45d335a43b Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents: 9904
diff changeset
478 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
479 return dp;
fa45d335a43b Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents: 9904
diff changeset
480 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
481 }
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
482
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
483 // Allocate a new packet buffer, and arrange to read into it:
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
484 if (!bufferQueue->nextpacket) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
485 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
486 bufferQueue->dp = dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
487 if (dp == NULL) return NULL;
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
488 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
489
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
490 #ifdef USE_LIBAVCODEC
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
491 extern AVCodecParserContext * h264parserctx;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
492 int consumed, poutbuf_size = 1;
23224
f2631612f28b Fix compilation after FFmpeg r8921
cehoyos
parents: 22893
diff changeset
493 const uint8_t *poutbuf = NULL;
23555
2237e232cc15 Silence three warnings.
cehoyos
parents: 23554
diff changeset
494 float lastpts = 0.0;
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
495
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
496 do {
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
497 if (!bufferQueue->nextpacket) {
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
498 #endif
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
499 // Schedule the read operation:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
500 bufferQueue->blockingFlag = 0;
22519
5f3a0a712afb cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents: 22463
diff changeset
501 bufferQueue->readSource()->getNextFrame(&dp->buffer[headersize], MAX_RTP_FRAME_SIZE - headersize,
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
502 afterReading, bufferQueue,
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
503 onSourceClosure, bufferQueue);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
504 // Block ourselves until data becomes available:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
505 TaskScheduler& scheduler
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
506 = bufferQueue->readSource()->envir().taskScheduler();
23569
ba3868fbe12c Simplify network timeout calculation.
cehoyos
parents: 23555
diff changeset
507 int delay = 10000000;
ba3868fbe12c Simplify network timeout calculation.
cehoyos
parents: 23555
diff changeset
508 if (bufferQueue->prevPacketPTS * 1.05 > rtpState->mediaSession->playEndTime())
ba3868fbe12c Simplify network timeout calculation.
cehoyos
parents: 23555
diff changeset
509 delay /= 10;
23554
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
510 task = scheduler.scheduleDelayedTask(delay, onSourceClosure, bufferQueue);
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
511 scheduler.doEventLoop(&bufferQueue->blockingFlag);
23554
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
512 scheduler.unscheduleDelayedTask(task);
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
513 if (demuxer->stream->eof) {
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
514 free_demux_packet(dp);
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
515 return NULL;
046d7b14d7f1 Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents: 23224
diff changeset
516 }
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
517
22519
5f3a0a712afb cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents: 22463
diff changeset
518 if (headersize == 1) // amr
22463
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
519 dp->buffer[0] =
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
520 ((AMRAudioSource*)bufferQueue->readSource())->lastFrameHeader();
22852
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
521 #ifdef USE_LIBAVCODEC
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
522 } else {
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
523 bufferQueue->dp = dp = bufferQueue->nextpacket;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
524 bufferQueue->nextpacket = NULL;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
525 }
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
526 if (headersize == 3 && h264parserctx) { // h264
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
527 consumed = h264parserctx->parser->parser_parse(h264parserctx,
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
528 NULL,
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
529 &poutbuf, &poutbuf_size,
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
530 dp->buffer, dp->len);
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
531
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
532 if (!consumed && !poutbuf_size)
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
533 return NULL;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
534
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
535 if (!poutbuf_size) {
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
536 lastpts=dp->pts;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
537 free_demux_packet(dp);
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
538 bufferQueue->dp = dp = new_demux_packet(MAX_RTP_FRAME_SIZE);
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
539 } else {
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
540 bufferQueue->nextpacket = dp;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
541 bufferQueue->dp = dp = new_demux_packet(poutbuf_size);
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
542 memcpy(dp->buffer, poutbuf, poutbuf_size);
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
543 dp->pts=lastpts;
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
544 }
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
545 }
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
546 } while (!poutbuf_size);
d7f4da5e9ee4 Support h264 over rtsp
cehoyos
parents: 22851
diff changeset
547 #endif
22463
979b2aa16e80 support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents: 22454
diff changeset
548
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
549 // 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
550 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
551 && bufferQueue->prevPacketWasSynchronized
384f6a88a31d Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents: 10477
diff changeset
552 && *(bufferQueue->otherQueue) != NULL
384f6a88a31d Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents: 10477
diff changeset
553 && (*(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
554 && (*(bufferQueue->otherQueue))->prevPacketWasSynchronized) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
555 ptsBehind = (*(bufferQueue->otherQueue))->prevPacketPTS
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
556 - bufferQueue->prevPacketPTS;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
557 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
558 ptsBehind = 0.0;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
559 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
560
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
561 if (mustGetNewData) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
562 // Save this buffer for future reads:
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
563 bufferQueue->savePendingBuffer(dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
564 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
566 return dp;
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
567 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
568
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
569 static void teardownRTSPorSIPSession(RTPState* rtpState) {
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
570 MediaSession* mediaSession = rtpState->mediaSession;
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
571 if (mediaSession == NULL) return;
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
572 if (rtpState->rtspClient != NULL) {
22893
777031848801 Use teardownMediaSession() instead of teardownMediaSubsession()
cehoyos
parents: 22852
diff changeset
573 rtpState->rtspClient->teardownMediaSession(*mediaSession);
10054
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
574 } else if (rtpState->sipClient != NULL) {
1342075f81f0 Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents: 9911
diff changeset
575 rtpState->sipClient->sendBYE();
9250
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
576 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
diff changeset
577 }
bb490ffeebf5 Restruct by Ross Finlayson <finlayson@live.com>
bertrand
parents: 8987
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 ////////// "ReadBuffer" and "ReadBufferQueue" implementation:
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
580
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
581 ReadBufferQueue::ReadBufferQueue(MediaSubsession* subsession,
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
582 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
583 : prevPacketWasSynchronized(False), prevPacketPTS(0.0), otherQueue(NULL),
23555
2237e232cc15 Silence three warnings.
cehoyos
parents: 23554
diff changeset
584 dp(NULL), nextpacket(NULL),
2237e232cc15 Silence three warnings.
cehoyos
parents: 23554
diff changeset
585 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
586 fReadSource(subsession == NULL ? NULL : subsession->readSource()),
7534
0a936b10b3d8 passthrough timestamps to demuxer
arpi
parents: 7143
diff changeset
587 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
588 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
589 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
590
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
591 ReadBufferQueue::~ReadBufferQueue() {
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
592 delete fTag;
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
593
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
594 // 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
595 demux_packet_t* dp = pendingDPHead;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
596 while (dp != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
597 demux_packet_t* dpNext = dp->next;
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 free_demux_packet(dp);
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
600 dp = dpNext;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
601 }
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
602 }
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
603
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
604 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
605 // 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
606 if (pendingDPTail == NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
607 pendingDPHead = pendingDPTail = dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
608 } else {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
609 pendingDPTail->next = dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
610 pendingDPTail = dp;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
611 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
612 dp->next = NULL;
6910
1a747aee653b applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff changeset
613 }
9565
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
614
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
615 demux_packet_t* ReadBufferQueue::getPendingBuffer() {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
616 demux_packet_t* dp = pendingDPHead;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
617 if (dp != NULL) {
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
618 pendingDPHead = dp->next;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
619 if (pendingDPHead == NULL) pendingDPTail = NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
620
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
621 dp->next = NULL;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
622 }
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
623
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
624 return dp;
e74916774667 Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents: 9457
diff changeset
625 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
626
22355
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
627 static int demux_rtp_control(struct demuxer_st *demuxer, int cmd, void *arg) {
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
628 double endpts = ((RTPState*)demuxer->priv)->mediaSession->playEndTime();
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
629
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
630 switch(cmd) {
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
631 case DEMUXER_CTRL_GET_TIME_LENGTH:
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
632 if (endpts <= 0)
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
633 return DEMUXER_CTRL_DONTKNOW;
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
634 *((double *)arg) = endpts;
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
635 return DEMUXER_CTRL_OK;
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
636
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
637 case DEMUXER_CTRL_GET_PERCENT_POS:
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
638 if (endpts <= 0)
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
639 return DEMUXER_CTRL_DONTKNOW;
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
640 *((int *)arg) = (int)(((RTPState*)demuxer->priv)->videoBufferQueue->prevPacketPTS*100/endpts);
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
641 return DEMUXER_CTRL_OK;
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
642
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
643 default:
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
644 return DEMUXER_CTRL_NOTIMPL;
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
645 }
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
646 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
647
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
648 demuxer_desc_t demuxer_desc_rtp = {
16572
56a5f69e9b35 "LIVE.COM Streaming Media" is now called "LIVE555 Streaming Media".
rsf
parents: 16175
diff changeset
649 "LIVE555 RTP demuxer",
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
650 "rtp",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
651 "",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
652 "Ross Finlayson",
16572
56a5f69e9b35 "LIVE.COM Streaming Media" is now called "LIVE555 Streaming Media".
rsf
parents: 16175
diff changeset
653 "requires LIVE555 Streaming Media library",
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
654 DEMUXER_TYPE_RTP,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
655 0, // no autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
656 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
657 demux_rtp_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
658 demux_open_rtp,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
659 demux_close_rtp,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
660 NULL,
22355
20be7be45f47 implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents: 22353
diff changeset
661 demux_rtp_control
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15585
diff changeset
662 };