Mercurial > mplayer.hg
annotate libmpdemux/demux_rtp.cpp @ 34645:0bce77ccae9a
Fix compiling with osdep setenv
Since we have -Werror-implicit-function-declaration in CFLAGS,
we need a prototype for the osdep setenv() implementation.
Reported-by: redxii (in #mplayer IRC channel)
author | al |
---|---|
date | Sat, 18 Feb 2012 00:08:30 +0000 |
parents | a5d8b198c214 |
children | 6e0aeeb6cdc4 |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
2 * routines (with C-linkage) that interface between MPlayer |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
3 * and the "LIVE555 Streaming Media" libraries |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
4 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
5 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
6 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
10 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
11 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
15 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
16 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27776
diff
changeset
|
20 */ |
9250 | 21 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
22 extern "C" { |
12531
834e7844ab3b
MinGW compilation fix from a patch by Joey Parrish, approved by Sascha
diego
parents:
12521
diff
changeset
|
23 // 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
|
24 #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
|
25 #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
|
26 #endif |
34173
a5d8b198c214
demux_rtp: Replace extern declarations by proper header #includes.
diego
parents:
33705
diff
changeset
|
27 #include "mp_msg.h" |
31483 | 28 #include "demuxer.h" |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
29 #include "demux_rtp.h" |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
30 #include "stheader.h" |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
31 } |
9250 | 32 #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
|
33 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
34 #include "BasicUsageEnvironment.hh" |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
35 #include "liveMedia.hh" |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
36 #include "GroupsockHelper.hh" |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
37 #include <unistd.h> |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
38 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
39 // 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
|
40 class ReadBufferQueue { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
41 public: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
42 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
|
43 char const* tag); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
44 virtual ~ReadBufferQueue(); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
45 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
46 FramedSource* readSource() const { return fReadSource; } |
7534 | 47 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
|
48 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
|
49 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
|
50 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
51 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
|
52 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
53 // For A/V synchronization: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
54 Boolean prevPacketWasSynchronized; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
55 float prevPacketPTS; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
56 ReadBufferQueue** otherQueue; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
57 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
58 // 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
|
59 // (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
|
60 demux_packet_t* dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
61 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
62 // 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
|
63 // 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
|
64 void savePendingBuffer(demux_packet_t* dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
65 demux_packet_t* getPendingBuffer(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
66 |
22852 | 67 // For H264 over rtsp using AVParser, the next packet has to be saved |
68 demux_packet_t* nextpacket; | |
69 | |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
70 private: |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
71 demux_packet_t* pendingDPHead; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
72 demux_packet_t* pendingDPTail; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
73 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
74 FramedSource* fReadSource; |
7534 | 75 RTPSource* fRTPSource; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
76 demuxer_t* fOurDemuxer; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
77 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
|
78 }; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
79 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
80 // 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
|
81 // reclaim it: |
32086
048d9fffd740
Remove pointless typedef keyword from struct RTPState declaration; fixes:
diego
parents:
31483
diff
changeset
|
82 struct RTPState { |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
83 char const* sdpDescription; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
84 RTSPClient* rtspClient; |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
85 SIPClient* sipClient; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
86 MediaSession* mediaSession; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
87 ReadBufferQueue* audioBufferQueue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
88 ReadBufferQueue* videoBufferQueue; |
9250 | 89 unsigned flags; |
7534 | 90 struct timeval firstSyncTime; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
91 }; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
92 |
9904
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
93 extern "C" char* network_username; |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
94 extern "C" char* network_password; |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
95 static char* openURL_rtsp(RTSPClient* client, char const* url) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
96 // If we were given a user name (and optional password), then use them: |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
97 if (network_username != NULL) { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
98 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
|
99 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
|
100 } else { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
101 return client->describeURL(url); |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
102 } |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
103 } |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
104 |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
105 static char* openURL_sip(SIPClient* client, char const* url) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
106 // If we were given a user name (and optional password), then use them: |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
107 if (network_username != NULL) { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
108 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
|
109 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
|
110 } else { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
111 return client->invite(url); |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
112 } |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
113 } |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
114 |
29280
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
115 #ifdef CONFIG_LIBNEMESI |
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
116 extern int rtsp_transport_tcp; |
31281 | 117 extern int rtsp_transport_http; |
29280
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
118 #else |
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
119 int rtsp_transport_tcp = 0; |
31281 | 120 int rtsp_transport_http = 0; |
29280
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
121 #endif |
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
122 |
32208
4cd07921bec2
Rename preprocessor directives: CONFIG_LIBAVCODEC --> CONFIG_FFMPEG
diego
parents:
32086
diff
changeset
|
123 #ifdef CONFIG_FFMPEG |
29453 | 124 extern AVCodecContext *avcctx; |
125 #endif | |
7664 | 126 |
12521
27ed4672c619
Added "audio_id", "video_id", "dvdsub_id" to the call to "demux_open()".
rsf
parents:
12043
diff
changeset
|
127 extern "C" int audio_id, video_id, dvdsub_id; |
11984
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
128 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
|
129 Boolean success = False; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
130 do { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
131 TaskScheduler* scheduler = BasicTaskScheduler::createNew(); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
132 if (scheduler == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
133 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
|
134 if (env == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
135 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
136 RTSPClient* rtspClient = NULL; |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
137 SIPClient* sipClient = NULL; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
138 |
9457
ea1c0a4520bf
Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents:
9370
diff
changeset
|
139 if (demuxer == NULL || demuxer->stream == NULL) break; // shouldn't happen |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
140 demuxer->stream->eof = 0; // just in case |
9457
ea1c0a4520bf
Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents:
9370
diff
changeset
|
141 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
142 // 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
|
143 // via a SDP description: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
144 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
|
145 if (sdpDescription == NULL) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
146 // 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
|
147 // 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
|
148 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
|
149 char const* url = demuxer->stream->streaming_ctrl->url->url; |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
150 if (strcmp(protocol, "rtsp") == 0) { |
31281 | 151 if (rtsp_transport_http == 1) { |
152 rtsp_transport_http = demuxer->stream->streaming_ctrl->url->port; | |
153 rtsp_transport_tcp = 1; | |
154 } | |
155 rtspClient = RTSPClient::createNew(*env, verbose, "MPlayer", rtsp_transport_http); | |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
156 if (rtspClient == NULL) { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
157 fprintf(stderr, "Failed to create RTSP client: %s\n", |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
158 env->getResultMsg()); |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
159 break; |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
160 } |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
161 sdpDescription = openURL_rtsp(rtspClient, url); |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
162 } else { // SIP |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
163 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
|
164 sipClient = SIPClient::createNew(*env, desiredAudioType, NULL, |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
165 verbose, "MPlayer"); |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
166 if (sipClient == NULL) { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
167 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
|
168 env->getResultMsg()); |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
169 break; |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
170 } |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
171 sipClient->setClientStartPortNum(8000); |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
172 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
|
173 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
174 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
175 if (sdpDescription == NULL) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
176 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
|
177 url, env->getResultMsg()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
178 break; |
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 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
181 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
182 // 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
|
183 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
|
184 if (mediaSession == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
185 |
9250 | 186 |
187 // Create a 'RTPState' structure containing the state that we just created, | |
188 // and store it in the demuxer's 'priv' field, for future reference: | |
189 RTPState* rtpState = new RTPState; | |
190 rtpState->sdpDescription = sdpDescription; | |
191 rtpState->rtspClient = rtspClient; | |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
192 rtpState->sipClient = sipClient; |
9250 | 193 rtpState->mediaSession = mediaSession; |
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
194 rtpState->audioBufferQueue = rtpState->videoBufferQueue = NULL; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
195 rtpState->flags = 0; |
9250 | 196 rtpState->firstSyncTime.tv_sec = rtpState->firstSyncTime.tv_usec = 0; |
197 demuxer->priv = rtpState; | |
198 | |
25237
963cd0542cec
Fix playback of streams with more than one video track (only one supported).
cehoyos
parents:
24598
diff
changeset
|
199 int audiofound = 0, videofound = 0; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
200 // 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
|
201 MediaSubsessionIterator iter(*mediaSession); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
202 MediaSubsession* subsession; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
203 unsigned desiredReceiveBufferSize; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
204 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
|
205 // 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
|
206 if (strcmp(subsession->mediumName(), "audio") == 0) { |
24598
5411b440eb24
Fix playback of streams with more than one audio track (only one supported).
cehoyos
parents:
23569
diff
changeset
|
207 if (audiofound) { |
5411b440eb24
Fix playback of streams with more than one audio track (only one supported).
cehoyos
parents:
23569
diff
changeset
|
208 fprintf(stderr, "Additional subsession \"audio/%s\" skipped\n", subsession->codecName()); |
5411b440eb24
Fix playback of streams with more than one audio track (only one supported).
cehoyos
parents:
23569
diff
changeset
|
209 continue; |
5411b440eb24
Fix playback of streams with more than one audio track (only one supported).
cehoyos
parents:
23569
diff
changeset
|
210 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
211 desiredReceiveBufferSize = 100000; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
212 } else if (strcmp(subsession->mediumName(), "video") == 0) { |
25237
963cd0542cec
Fix playback of streams with more than one video track (only one supported).
cehoyos
parents:
24598
diff
changeset
|
213 if (videofound) { |
963cd0542cec
Fix playback of streams with more than one video track (only one supported).
cehoyos
parents:
24598
diff
changeset
|
214 fprintf(stderr, "Additional subsession \"video/%s\" skipped\n", subsession->codecName()); |
963cd0542cec
Fix playback of streams with more than one video track (only one supported).
cehoyos
parents:
24598
diff
changeset
|
215 continue; |
963cd0542cec
Fix playback of streams with more than one video track (only one supported).
cehoyos
parents:
24598
diff
changeset
|
216 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
217 desiredReceiveBufferSize = 2000000; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
218 } else { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
219 continue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
220 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
221 |
17650
d6e575c86bb8
Allows the LIVE555 library to forces the client's port to be used
bertrand
parents:
16572
diff
changeset
|
222 if (rtsp_port) |
d6e575c86bb8
Allows the LIVE555 library to forces the client's port to be used
bertrand
parents:
16572
diff
changeset
|
223 subsession->setClientPortNum (rtsp_port); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
224 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
225 if (!subsession->initiate()) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
226 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
|
227 } else { |
17650
d6e575c86bb8
Allows the LIVE555 library to forces the client's port to be used
bertrand
parents:
16572
diff
changeset
|
228 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
|
229 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
230 // 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
|
231 // 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
|
232 // 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
|
233 // 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
|
234 int rtpSocketNum = subsession->rtpSource()->RTPgs()->socketNum(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
235 int receiveBufferSize |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
236 = increaseReceiveBufferTo(*env, rtpSocketNum, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
237 desiredReceiveBufferSize); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
238 if (verbose > 0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
239 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
|
240 subsession->mediumName(), receiveBufferSize); |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
241 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
242 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
243 if (rtspClient != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
244 // 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
|
245 if (!rtspClient->setupMediaSubsession(*subsession, False, |
29280
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
246 rtsp_transport_tcp)) break; |
24598
5411b440eb24
Fix playback of streams with more than one audio track (only one supported).
cehoyos
parents:
23569
diff
changeset
|
247 if (!strcmp(subsession->mediumName(), "audio")) |
5411b440eb24
Fix playback of streams with more than one audio track (only one supported).
cehoyos
parents:
23569
diff
changeset
|
248 audiofound = 1; |
25237
963cd0542cec
Fix playback of streams with more than one video track (only one supported).
cehoyos
parents:
24598
diff
changeset
|
249 if (!strcmp(subsession->mediumName(), "video")) |
963cd0542cec
Fix playback of streams with more than one video track (only one supported).
cehoyos
parents:
24598
diff
changeset
|
250 videofound = 1; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
251 } |
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 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
254 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
255 if (rtspClient != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
256 // 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
|
257 if (!rtspClient->playMediaSession(*mediaSession)) break; |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
258 } else if (sipClient != NULL) { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
259 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
|
260 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
261 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
262 // 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
|
263 // 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
|
264 iter.reset(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
265 while ((subsession = iter.next()) != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
266 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
|
267 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
268 unsigned flags = 0; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
269 if (strcmp(subsession->mediumName(), "audio") == 0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
270 rtpState->audioBufferQueue |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
271 = new ReadBufferQueue(subsession, demuxer, "audio"); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
272 rtpState->audioBufferQueue->otherQueue = &(rtpState->videoBufferQueue); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
273 rtpCodecInitialize_audio(demuxer, subsession, flags); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
274 } 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
|
275 rtpState->videoBufferQueue |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
276 = new ReadBufferQueue(subsession, demuxer, "video"); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
277 rtpState->videoBufferQueue->otherQueue = &(rtpState->audioBufferQueue); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
278 rtpCodecInitialize_video(demuxer, subsession, flags); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
279 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
280 rtpState->flags |= flags; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
281 } |
12043
8d45dcfc016f
Fixed a bug that was accidentally introduced by the addition of MPEG Transport
rsf
parents:
12007
diff
changeset
|
282 success = True; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
283 } while (0); |
12043
8d45dcfc016f
Fixed a bug that was accidentally introduced by the addition of MPEG Transport
rsf
parents:
12007
diff
changeset
|
284 if (!success) return NULL; // an error occurred |
11984
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
285 |
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
286 // 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
|
287 // 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
|
288 // code to recognize this: |
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
289 if (demux_is_multiplexed_rtp_stream(demuxer)) { |
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
290 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
|
291 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
|
292 audio_id, video_id, dvdsub_id, NULL); |
11984
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
293 demuxer = new_demuxers_demuxer(od, od, od); |
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
294 } |
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
295 |
94e1953fbe8e
Added support for multiplexed audio+video RTP streams.
rsf
parents:
11755
diff
changeset
|
296 return demuxer; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
297 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
298 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
299 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
|
300 // 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
|
301 RTPState* rtpState = (RTPState*)(demuxer->priv); |
9250 | 302 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
303 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
|
304 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
305 |
10477
c34185f47b62
Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents:
10054
diff
changeset
|
306 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
|
307 // 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
|
308 RTPState* rtpState = (RTPState*)(demuxer->priv); |
c34185f47b62
Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents:
10054
diff
changeset
|
309 |
c34185f47b62
Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents:
10054
diff
changeset
|
310 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
|
311 } |
c34185f47b62
Added support for checking whether a RTP demuxer contains combined audio_video data.
rsf
parents:
10054
diff
changeset
|
312 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
313 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
|
314 Boolean mustGetNewData, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
315 float& ptsBehind); // forward |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
316 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
317 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
|
318 // 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
|
319 // 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
|
320 // 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
|
321 // immediately available. |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
322 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
323 while (1) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
324 float ptsBehind; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
325 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
|
326 if (dp == NULL) return 0; |
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 if (demuxer->stream->eof) return 0; // source stream has closed down |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
329 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
330 // 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
|
331 // 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
|
332 // 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
|
333 // 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
|
334 // 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
|
335 // (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
|
336 // video streams are interleaved.) |
12007
b41cc72bb8ad
We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents:
11984
diff
changeset
|
337 // (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
|
338 // 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
|
339 // 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
|
340 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
|
341 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
|
342 if (ptsBehind < ptsBehindThreshold || |
b41cc72bb8ad
We now allow for the possibility of the RTCP audio/video synchronization being
rsf
parents:
11984
diff
changeset
|
343 ptsBehind > ptsBehindLimit || |
29280
99063eff7512
Unify over rtsp_transport_tcp as var to hold the -rtsp-stream-over-tcp flag and make sure libnemesi only builds are fine
lu_zero
parents:
29263
diff
changeset
|
344 rtsp_transport_tcp) { // packet's OK |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
345 ds_add_packet(ds, dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
346 break; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
347 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
348 |
9786
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
349 #ifdef DEBUG_PRINT_DISCARDED_PACKETS |
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
350 RTPState* rtpState = (RTPState*)(demuxer->priv); |
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
351 ReadBufferQueue* bufferQueue = ds == demuxer->video ? rtpState->videoBufferQueue : rtpState->audioBufferQueue; |
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
352 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
|
353 #endif |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
354 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
|
355 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
356 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
357 return 1; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
358 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
359 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
360 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
|
361 unsigned char*& packetData, unsigned& packetDataLen, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
362 float& pts) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
363 // 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
|
364 // 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
|
365 float ptsBehind; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
366 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
|
367 if (dp == NULL) return False; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
368 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
369 packetData = dp->buffer; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
370 packetDataLen = dp->len; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
371 pts = dp->pts; |
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 return True; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
374 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
375 |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
376 static void teardownRTSPorSIPSession(RTPState* rtpState); // forward |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
377 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
378 extern "C" void demux_close_rtp(demuxer_t* demuxer) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
379 // Reclaim all RTP-related state: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
380 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
381 // Get the RTP state that was stored in the demuxer's 'priv' field: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
382 RTPState* rtpState = (RTPState*)(demuxer->priv); |
7143
fdfc10c2e2d2
- Tell the RTSP client code to use the string "mplayer" in RTSP
arpi
parents:
7008
diff
changeset
|
383 if (rtpState == NULL) return; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
384 |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
385 teardownRTSPorSIPSession(rtpState); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
386 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
387 UsageEnvironment* env = NULL; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
388 TaskScheduler* scheduler = NULL; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
389 if (rtpState->mediaSession != NULL) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
390 env = &(rtpState->mediaSession->envir()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
391 scheduler = &(env->taskScheduler()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
392 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
393 Medium::close(rtpState->mediaSession); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
394 Medium::close(rtpState->rtspClient); |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
395 Medium::close(rtpState->sipClient); |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
396 delete rtpState->audioBufferQueue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
397 delete rtpState->videoBufferQueue; |
29585
a17d4f8040f1
free(), delete and delete[] are all different and can't just be used at random,
reimar
parents:
29460
diff
changeset
|
398 delete[] rtpState->sdpDescription; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
399 delete rtpState; |
32208
4cd07921bec2
Rename preprocessor directives: CONFIG_LIBAVCODEC --> CONFIG_FFMPEG
diego
parents:
32086
diff
changeset
|
400 #ifdef CONFIG_FFMPEG |
29460 | 401 av_freep(&avcctx); |
29451
6aca83f5ba73
Fix a crash when playing some H264 over rtsp streams: Do pass an
cehoyos
parents:
29280
diff
changeset
|
402 #endif |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
403 |
12866
332f24a1dd5c
Updated to conform to a small change in the LIVE.COM API.
rsf
parents:
12531
diff
changeset
|
404 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
|
405 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
406 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
407 ////////// 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
|
408 |
27776
ef0b0f9291a2
increase the max RTP packet size to 5MB as modern Elphel
attila
parents:
27341
diff
changeset
|
409 #define MAX_RTP_FRAME_SIZE 5000000 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
410 // >= 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
|
411 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
412 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
|
413 unsigned /*numTruncatedBytes*/, |
a79a318585ce
Changed to conform to recent changes to the "LIVE.COM Streaming Media" code.
rsf
parents:
10937
diff
changeset
|
414 struct timeval presentationTime, |
a79a318585ce
Changed to conform to recent changes to the "LIVE.COM Streaming Media" code.
rsf
parents:
10937
diff
changeset
|
415 unsigned /*durationInMicroseconds*/) { |
22463
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
416 int headersize = 0; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
417 if (frameSize >= MAX_RTP_FRAME_SIZE) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
418 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
|
419 MAX_RTP_FRAME_SIZE); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
420 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
421 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
|
422 demuxer_t* demuxer = bufferQueue->ourDemuxer(); |
7534 | 423 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
|
424 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
425 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
|
426 |
22851
e878a71cb27f
Cosmetics: Move variable declaration and initialization up.
cehoyos
parents:
22759
diff
changeset
|
427 demux_packet_t* dp = bufferQueue->dp; |
e878a71cb27f
Cosmetics: Move variable declaration and initialization up.
cehoyos
parents:
22759
diff
changeset
|
428 |
22463
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
429 if (bufferQueue->readSource()->isAMRAudioSource()) |
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
430 headersize = 1; |
22852 | 431 else if (bufferQueue == rtpState->videoBufferQueue && |
432 ((sh_video_t*)demuxer->video->sh)->format == mmioFOURCC('H','2','6','4')) { | |
433 dp->buffer[0]=0x00; | |
434 dp->buffer[1]=0x00; | |
435 dp->buffer[2]=0x01; | |
436 headersize = 3; | |
437 } | |
22463
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
438 |
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
439 resize_demux_packet(dp, frameSize + headersize); |
7534 | 440 |
441 // Set the packet's presentation time stamp, depending on whether or | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
442 // 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
|
443 Boolean hasBeenSynchronized |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
444 = bufferQueue->rtpSource()->hasBeenSynchronizedUsingRTCP(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
445 if (hasBeenSynchronized) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
446 if (verbose > 0 && !bufferQueue->prevPacketWasSynchronized) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
447 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
|
448 bufferQueue->tag()); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
449 } |
7534 | 450 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
451 struct timeval* fst = &(rtpState->firstSyncTime); // abbrev |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
452 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
|
453 *fst = presentationTime; |
7534 | 454 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
455 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
456 // 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
|
457 // 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
|
458 // 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
|
459 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
|
460 + (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
|
461 bufferQueue->prevPacketPTS = dp->pts; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
462 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
463 if (verbose > 0 && bufferQueue->prevPacketWasSynchronized) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
464 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
|
465 bufferQueue->tag()); |
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 // 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
|
469 dp->pts = bufferQueue->prevPacketPTS; |
7534 | 470 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
471 bufferQueue->prevPacketWasSynchronized = hasBeenSynchronized; |
7534 | 472 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
473 dp->pos = demuxer->filepos; |
22759 | 474 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
|
475 |
9250 | 476 // 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
|
477 bufferQueue->blockingFlag = ~0; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
478 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
479 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
480 static void onSourceClosure(void* clientData) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
481 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
|
482 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
|
483 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
484 demuxer->stream->eof = 1; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
485 |
9250 | 486 // 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
|
487 bufferQueue->blockingFlag = ~0; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
488 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
489 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
490 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
|
491 Boolean mustGetNewData, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
492 float& ptsBehind) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
493 // 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
|
494 // (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
|
495 // the demuxer's 'priv' field) |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
496 RTPState* rtpState = (RTPState*)(demuxer->priv); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
497 ReadBufferQueue* bufferQueue = NULL; |
22519
5f3a0a712afb
cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents:
22463
diff
changeset
|
498 int headersize = 0; |
33705
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
499 int waitboth = 0; |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
500 TaskToken task, task2; |
23554
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
501 |
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
502 if (demuxer->stream->eof) return NULL; |
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
503 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
504 if (ds == demuxer->video) { |
33705
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
505 bufferQueue = rtpState->audioBufferQueue; |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
506 // HACK: for the latest versions we must also receive audio |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
507 // when probing for video FPS, otherwise the stream just hangs |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
508 // and times out |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
509 if (mustGetNewData && |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
510 bufferQueue && |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
511 bufferQueue->readSource() && |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
512 !bufferQueue->nextpacket) { |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
513 headersize = bufferQueue->readSource()->isAMRAudioSource() ? 1 : 0; |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
514 demux_packet_t *dp = new_demux_packet(MAX_RTP_FRAME_SIZE); |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
515 bufferQueue->dp = dp; |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
516 bufferQueue->blockingFlag = 0; |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
517 bufferQueue->readSource()->getNextFrame( |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
518 &dp->buffer[headersize], MAX_RTP_FRAME_SIZE - headersize, |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
519 afterReading, bufferQueue, |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
520 onSourceClosure, bufferQueue); |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
521 task2 = bufferQueue->readSource()->envir().taskScheduler(). |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
522 scheduleDelayedTask(10000000, onSourceClosure, bufferQueue); |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
523 waitboth = 1; |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
524 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
525 bufferQueue = rtpState->videoBufferQueue; |
22852 | 526 if (((sh_video_t*)ds->sh)->format == mmioFOURCC('H','2','6','4')) |
527 headersize = 3; | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
528 } else if (ds == demuxer->audio) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
529 bufferQueue = rtpState->audioBufferQueue; |
22463
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
530 if (bufferQueue->readSource()->isAMRAudioSource()) |
22519
5f3a0a712afb
cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents:
22463
diff
changeset
|
531 headersize = 1; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
532 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
533 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
|
534 return NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
535 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
536 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
537 if (bufferQueue == NULL || bufferQueue->readSource() == NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
538 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
|
539 return NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
540 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
541 |
23555 | 542 demux_packet_t* dp = NULL; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
543 if (!mustGetNewData) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
544 // 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
|
545 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
|
546 if (dp != NULL) { |
fa45d335a43b
Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents:
9904
diff
changeset
|
547 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
|
548 return dp; |
fa45d335a43b
Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents:
9904
diff
changeset
|
549 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
550 } |
9250 | 551 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
552 // Allocate a new packet buffer, and arrange to read into it: |
22852 | 553 if (!bufferQueue->nextpacket) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
554 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
|
555 bufferQueue->dp = dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
556 if (dp == NULL) return NULL; |
22852 | 557 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
558 |
32208
4cd07921bec2
Rename preprocessor directives: CONFIG_LIBAVCODEC --> CONFIG_FFMPEG
diego
parents:
32086
diff
changeset
|
559 #ifdef CONFIG_FFMPEG |
22852 | 560 extern AVCodecParserContext * h264parserctx; |
561 int consumed, poutbuf_size = 1; | |
23224 | 562 const uint8_t *poutbuf = NULL; |
23555 | 563 float lastpts = 0.0; |
22852 | 564 |
565 do { | |
566 if (!bufferQueue->nextpacket) { | |
567 #endif | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
568 // Schedule the read operation: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
569 bufferQueue->blockingFlag = 0; |
22519
5f3a0a712afb
cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents:
22463
diff
changeset
|
570 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
|
571 afterReading, bufferQueue, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
572 onSourceClosure, bufferQueue); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
573 // Block ourselves until data becomes available: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
574 TaskScheduler& scheduler |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
575 = bufferQueue->readSource()->envir().taskScheduler(); |
23569 | 576 int delay = 10000000; |
577 if (bufferQueue->prevPacketPTS * 1.05 > rtpState->mediaSession->playEndTime()) | |
578 delay /= 10; | |
23554
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
579 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
|
580 scheduler.doEventLoop(&bufferQueue->blockingFlag); |
23554
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
581 scheduler.unscheduleDelayedTask(task); |
33705
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
582 if (waitboth) { |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
583 scheduler.doEventLoop(&rtpState->audioBufferQueue->blockingFlag); |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
584 scheduler.unscheduleDelayedTask(task2); |
db1b1a1ecba8
Add a hack to receive audio while probing video FPS.
reimar
parents:
32208
diff
changeset
|
585 } |
23554
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
586 if (demuxer->stream->eof) { |
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
587 free_demux_packet(dp); |
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
588 return NULL; |
046d7b14d7f1
Stop playing at eof or if no data arrives for ten seconds.
cehoyos
parents:
23224
diff
changeset
|
589 } |
9250 | 590 |
22519
5f3a0a712afb
cosmetics: renamed variable amr as headersize, more meaningful; patch by Carl Eugen Hoyos
nicodvb
parents:
22463
diff
changeset
|
591 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
|
592 dp->buffer[0] = |
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
593 ((AMRAudioSource*)bufferQueue->readSource())->lastFrameHeader(); |
32208
4cd07921bec2
Rename preprocessor directives: CONFIG_LIBAVCODEC --> CONFIG_FFMPEG
diego
parents:
32086
diff
changeset
|
594 #ifdef CONFIG_FFMPEG |
22852 | 595 } else { |
596 bufferQueue->dp = dp = bufferQueue->nextpacket; | |
597 bufferQueue->nextpacket = NULL; | |
598 } | |
599 if (headersize == 3 && h264parserctx) { // h264 | |
600 consumed = h264parserctx->parser->parser_parse(h264parserctx, | |
29453 | 601 avcctx, |
22852 | 602 &poutbuf, &poutbuf_size, |
603 dp->buffer, dp->len); | |
604 | |
605 if (!consumed && !poutbuf_size) | |
606 return NULL; | |
607 | |
608 if (!poutbuf_size) { | |
609 lastpts=dp->pts; | |
610 free_demux_packet(dp); | |
611 bufferQueue->dp = dp = new_demux_packet(MAX_RTP_FRAME_SIZE); | |
612 } else { | |
613 bufferQueue->nextpacket = dp; | |
614 bufferQueue->dp = dp = new_demux_packet(poutbuf_size); | |
615 memcpy(dp->buffer, poutbuf, poutbuf_size); | |
616 dp->pts=lastpts; | |
617 } | |
618 } | |
619 } while (!poutbuf_size); | |
620 #endif | |
22463
979b2aa16e80
support for AMR; it works inserting in the first byte of the demux_packet
nicodvb
parents:
22454
diff
changeset
|
621 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
622 // 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
|
623 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
|
624 && bufferQueue->prevPacketWasSynchronized |
384f6a88a31d
Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents:
10477
diff
changeset
|
625 && *(bufferQueue->otherQueue) != NULL |
384f6a88a31d
Changed the criteria for when to drop RTP packets whose timestamp is too far
rsf
parents:
10477
diff
changeset
|
626 && (*(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
|
627 && (*(bufferQueue->otherQueue))->prevPacketWasSynchronized) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
628 ptsBehind = (*(bufferQueue->otherQueue))->prevPacketPTS |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
629 - bufferQueue->prevPacketPTS; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
630 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
631 ptsBehind = 0.0; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
632 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
633 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
634 if (mustGetNewData) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
635 // Save this buffer for future reads: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
636 bufferQueue->savePendingBuffer(dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
637 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
638 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
639 return dp; |
9250 | 640 } |
641 | |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
642 static void teardownRTSPorSIPSession(RTPState* rtpState) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
643 MediaSession* mediaSession = rtpState->mediaSession; |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
644 if (mediaSession == NULL) return; |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
645 if (rtpState->rtspClient != NULL) { |
22893
777031848801
Use teardownMediaSession() instead of teardownMediaSubsession()
cehoyos
parents:
22852
diff
changeset
|
646 rtpState->rtspClient->teardownMediaSession(*mediaSession); |
10054
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
647 } else if (rtpState->sipClient != NULL) { |
1342075f81f0
Added SIP (IP telephony) client support. (This was already supported in the
rsf
parents:
9911
diff
changeset
|
648 rtpState->sipClient->sendBYE(); |
9250 | 649 } |
650 } | |
651 | |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
652 ////////// "ReadBuffer" and "ReadBufferQueue" implementation: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
653 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
654 ReadBufferQueue::ReadBufferQueue(MediaSubsession* subsession, |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
655 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
|
656 : prevPacketWasSynchronized(False), prevPacketPTS(0.0), otherQueue(NULL), |
23555 | 657 dp(NULL), nextpacket(NULL), |
658 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
|
659 fReadSource(subsession == NULL ? NULL : subsession->readSource()), |
7534 | 660 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
|
661 fOurDemuxer(demuxer), fTag(strdup(tag)) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
662 } |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
663 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
664 ReadBufferQueue::~ReadBufferQueue() { |
29585
a17d4f8040f1
free(), delete and delete[] are all different and can't just be used at random,
reimar
parents:
29460
diff
changeset
|
665 free((void *)fTag); |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
666 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
667 // 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
|
668 demux_packet_t* dp = pendingDPHead; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
669 while (dp != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
670 demux_packet_t* dpNext = dp->next; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
671 dp->next = NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
672 free_demux_packet(dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
673 dp = dpNext; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
674 } |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
675 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
676 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
677 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
|
678 // 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
|
679 if (pendingDPTail == NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
680 pendingDPHead = pendingDPTail = dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
681 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
682 pendingDPTail->next = dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
683 pendingDPTail = dp; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
684 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
685 dp->next = NULL; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
686 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
687 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
688 demux_packet_t* ReadBufferQueue::getPendingBuffer() { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
689 demux_packet_t* dp = pendingDPHead; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
690 if (dp != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
691 pendingDPHead = dp->next; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
692 if (pendingDPHead == NULL) pendingDPTail = NULL; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
693 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
694 dp->next = NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
695 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
696 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
697 return dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
698 } |
16175 | 699 |
30644
390c8d36d463
Drop weird and unnecessary _s/_st suffixes from demuxer struct names.
diego
parents:
29585
diff
changeset
|
700 static int demux_rtp_control(struct demuxer *demuxer, int cmd, void *arg) { |
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
|
701 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
|
702 |
20be7be45f47
implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents:
22353
diff
changeset
|
703 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
|
704 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
|
705 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
|
706 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
|
707 *((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
|
708 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
|
709 |
20be7be45f47
implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents:
22353
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 *((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
|
714 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
|
715 |
20be7be45f47
implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents:
22353
diff
changeset
|
716 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
|
717 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
|
718 } |
20be7be45f47
implementation of DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS; patch by the usual Hoyos
nicodvb
parents:
22353
diff
changeset
|
719 } |
16175 | 720 |
721 demuxer_desc_t demuxer_desc_rtp = { | |
16572
56a5f69e9b35
"LIVE.COM Streaming Media" is now called "LIVE555 Streaming Media".
rsf
parents:
16175
diff
changeset
|
722 "LIVE555 RTP demuxer", |
25270 | 723 "live555", |
16175 | 724 "", |
725 "Ross Finlayson", | |
16572
56a5f69e9b35
"LIVE.COM Streaming Media" is now called "LIVE555 Streaming Media".
rsf
parents:
16175
diff
changeset
|
726 "requires LIVE555 Streaming Media library", |
16175 | 727 DEMUXER_TYPE_RTP, |
728 0, // no autodetect | |
729 NULL, | |
730 demux_rtp_fill_buffer, | |
731 demux_open_rtp, | |
732 demux_close_rtp, | |
733 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
|
734 demux_rtp_control |
16175 | 735 }; |