Mercurial > mplayer.hg
annotate libmpdemux/demux_rtp.cpp @ 9952:fb4d0658b1b9
xvidix now supports -geometry.
author | diego |
---|---|
date | Sun, 20 Apr 2003 23:43:25 +0000 |
parents | fa45d335a43b |
children | 1342075f81f0 |
rev | line source |
---|---|
9250 | 1 ////////// Routines (with C-linkage) that interface between "MPlayer" |
2 ////////// and the "LIVE.COM Streaming Media" libraries: | |
3 | |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
4 extern "C" { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
5 #include "demux_rtp.h" |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
6 #include "stheader.h" |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
7 } |
9250 | 8 #include "demux_rtp_internal.h" |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
9 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
10 #include "BasicUsageEnvironment.hh" |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
11 #include "liveMedia.hh" |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
12 #include "GroupsockHelper.hh" |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
13 #include <unistd.h> |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
14 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
15 extern "C" stream_t* stream_open_sdp(int fd, off_t fileSize, |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
16 int* file_format) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
17 *file_format = DEMUXER_TYPE_RTP; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
18 stream_t* newStream = NULL; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
19 do { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
20 char* sdpDescription = (char*)malloc(fileSize+1); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
21 if (sdpDescription == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
22 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
23 ssize_t numBytesRead = read(fd, sdpDescription, fileSize); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
24 if (numBytesRead != fileSize) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
25 sdpDescription[fileSize] = '\0'; // to be safe |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
26 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
27 newStream = (stream_t*)calloc(sizeof (stream_t), 1); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
28 if (newStream == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
29 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
30 // Store the SDP description in the 'priv' field, for later use: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
31 newStream->priv = sdpDescription; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
32 } while (0); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
33 return newStream; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
34 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
35 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
36 extern "C" int _rtsp_streaming_seek(int /*fd*/, off_t /*pos*/, |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
37 streaming_ctrl_t* /*streaming_ctrl*/) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
38 return -1; // For now, we don't handle RTSP stream seeking |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
39 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
40 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
41 extern "C" int rtsp_streaming_start(stream_t* stream) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
42 stream->streaming_ctrl->streaming_seek = _rtsp_streaming_seek; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
43 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
44 return 0; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
45 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
46 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
47 // A data structure representing input data for each stream: |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
48 class ReadBufferQueue { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
49 public: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
50 ReadBufferQueue(MediaSubsession* subsession, demuxer_t* demuxer, |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
51 char const* tag); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
52 virtual ~ReadBufferQueue(); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
53 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
54 FramedSource* readSource() const { return fReadSource; } |
7534 | 55 RTPSource* rtpSource() const { return fRTPSource; } |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
56 demuxer_t* ourDemuxer() const { return fOurDemuxer; } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
57 char const* tag() const { return fTag; } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
58 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
59 char blockingFlag; // used to implement synchronous reads |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
60 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
61 // For A/V synchronization: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
62 Boolean prevPacketWasSynchronized; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
63 float prevPacketPTS; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
64 ReadBufferQueue** otherQueue; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
65 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
66 // The 'queue' actually consists of just a single "demux_packet_t" |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
67 // (because the underlying OS does the actual queueing/buffering): |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
68 demux_packet_t* dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
69 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
70 // However, we sometimes inspect buffers before delivering them. |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
71 // For this, we maintain a queue of pending buffers: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
72 void savePendingBuffer(demux_packet_t* dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
73 demux_packet_t* getPendingBuffer(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
74 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
75 private: |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
76 demux_packet_t* pendingDPHead; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
77 demux_packet_t* pendingDPTail; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
78 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
79 FramedSource* fReadSource; |
7534 | 80 RTPSource* fRTPSource; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
81 demuxer_t* fOurDemuxer; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
82 char const* fTag; // used for debugging |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
83 }; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
84 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
85 // A structure of RTP-specific state, kept so that we can cleanly |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
86 // reclaim it: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
87 typedef struct RTPState { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
88 char const* sdpDescription; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
89 RTSPClient* rtspClient; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
90 MediaSession* mediaSession; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
91 ReadBufferQueue* audioBufferQueue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
92 ReadBufferQueue* videoBufferQueue; |
9250 | 93 unsigned flags; |
7534 | 94 struct timeval firstSyncTime; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
95 }; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
96 |
9904
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
97 extern "C" char* network_username; |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
98 extern "C" char* network_password; |
7664 | 99 int rtspStreamOverTCP = 0; |
100 | |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
101 extern "C" void demux_open_rtp(demuxer_t* demuxer) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
102 do { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
103 TaskScheduler* scheduler = BasicTaskScheduler::createNew(); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
104 if (scheduler == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
105 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
|
106 if (env == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
107 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
108 RTSPClient* rtspClient = NULL; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
109 |
9457
ea1c0a4520bf
Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents:
9370
diff
changeset
|
110 if (demuxer == NULL || demuxer->stream == NULL) break; // shouldn't happen |
ea1c0a4520bf
Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents:
9370
diff
changeset
|
111 demuxer->stream->eof = 0; // just in case |
ea1c0a4520bf
Repairing breakage to RTP streaming. Patch by Ross Finlayson <finlayson@live.com>
bertrand
parents:
9370
diff
changeset
|
112 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
113 // Look at the stream's 'priv' field to see if we were initiated |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
114 // via a SDP description: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
115 char* sdpDescription = (char*)(demuxer->stream->priv); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
116 if (sdpDescription == NULL) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
117 // We weren't given a SDP description directly, so assume that |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
118 // we were given a RTSP URL: |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
119 char const* url = demuxer->stream->streaming_ctrl->url->url; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
120 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
121 extern int verbose; |
9250 | 122 rtspClient = RTSPClient::createNew(*env, verbose, "MPlayer"); |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
123 if (rtspClient == NULL) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
124 fprintf(stderr, "Failed to create RTSP client: %s\n", |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
125 env->getResultMsg()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
126 break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
127 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
128 |
9904
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
129 // If we were given a user name (and optional password), then use them: |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
130 if (network_username != NULL) { |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
131 char const* password |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
132 = network_password == NULL ? "" : network_password; |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
133 sdpDescription |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
134 = rtspClient->describeWithPassword(url, network_username, password); |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
135 } else { |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
136 sdpDescription = rtspClient->describeURL(url); |
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
137 } |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
138 if (sdpDescription == NULL) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
139 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
|
140 url, env->getResultMsg()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
141 break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
142 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
143 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
144 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
145 // 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
|
146 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
|
147 if (mediaSession == NULL) break; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
148 |
9250 | 149 |
150 // Create a 'RTPState' structure containing the state that we just created, | |
151 // and store it in the demuxer's 'priv' field, for future reference: | |
152 RTPState* rtpState = new RTPState; | |
153 rtpState->sdpDescription = sdpDescription; | |
154 rtpState->rtspClient = rtspClient; | |
155 rtpState->mediaSession = mediaSession; | |
9370
88bd19564b64
Motion-JPEG RTP streams can now be played. Some MPEG-4 ES video RTP
arpi
parents:
9250
diff
changeset
|
156 rtpState->audioBufferQueue = rtpState->videoBufferQueue = NULL; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
157 rtpState->flags = 0; |
9250 | 158 rtpState->firstSyncTime.tv_sec = rtpState->firstSyncTime.tv_usec = 0; |
159 demuxer->priv = rtpState; | |
160 | |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
161 // 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
|
162 MediaSubsessionIterator iter(*mediaSession); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
163 MediaSubsession* subsession; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
164 unsigned desiredReceiveBufferSize; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
165 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
|
166 // 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
|
167 if (strcmp(subsession->mediumName(), "audio") == 0) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
168 desiredReceiveBufferSize = 100000; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
169 } else if (strcmp(subsession->mediumName(), "video") == 0) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
170 desiredReceiveBufferSize = 2000000; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
171 } else { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
172 continue; |
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 (!subsession->initiate()) { |
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 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
|
177 } else { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
178 fprintf(stderr, "Initiated \"%s/%s\" RTP subsession\n", subsession->mediumName(), subsession->codecName()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
179 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
180 // 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
|
181 // 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
|
182 // 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
|
183 // 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
|
184 int rtpSocketNum = subsession->rtpSource()->RTPgs()->socketNum(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
185 int receiveBufferSize |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
186 = increaseReceiveBufferTo(*env, rtpSocketNum, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
187 desiredReceiveBufferSize); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
188 if (verbose > 0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
189 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
|
190 subsession->mediumName(), receiveBufferSize); |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
191 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
192 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
193 if (rtspClient != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
194 // 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
|
195 if (!rtspClient->setupMediaSubsession(*subsession, False, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
196 rtspStreamOverTCP)) break; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
197 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
198 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
199 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
200 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
201 if (rtspClient != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
202 // 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
|
203 if (!rtspClient->playMediaSession(*mediaSession)) break; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
204 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
205 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
206 // 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
|
207 // 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
|
208 iter.reset(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
209 while ((subsession = iter.next()) != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
210 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
|
211 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
212 unsigned flags = 0; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
213 if (strcmp(subsession->mediumName(), "audio") == 0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
214 rtpState->audioBufferQueue |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
215 = new ReadBufferQueue(subsession, demuxer, "audio"); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
216 rtpState->audioBufferQueue->otherQueue = &(rtpState->videoBufferQueue); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
217 rtpCodecInitialize_audio(demuxer, subsession, flags); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
218 } 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
|
219 rtpState->videoBufferQueue |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
220 = new ReadBufferQueue(subsession, demuxer, "video"); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
221 rtpState->videoBufferQueue->otherQueue = &(rtpState->audioBufferQueue); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
222 rtpCodecInitialize_video(demuxer, subsession, flags); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
223 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
224 rtpState->flags |= flags; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
225 } |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
226 } while (0); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
227 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
228 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
229 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
|
230 // 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
|
231 RTPState* rtpState = (RTPState*)(demuxer->priv); |
9250 | 232 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
233 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
|
234 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
235 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
236 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
|
237 Boolean mustGetNewData, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
238 float& ptsBehind); // forward |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
239 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
240 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
|
241 // 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
|
242 // 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
|
243 // 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
|
244 // immediately available. |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
245 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
246 while (1) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
247 float ptsBehind; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
248 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
|
249 if (dp == NULL) return 0; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
250 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
251 if (demuxer->stream->eof) return 0; // source stream has closed down |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
252 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
253 // 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
|
254 // 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
|
255 // 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
|
256 // 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
|
257 // 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
|
258 // (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
|
259 // video streams are interleaved.) |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
260 const float ptsBehindThreshold = 1.0; // seconds |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
261 if (ptsBehind < ptsBehindThreshold || rtspStreamOverTCP) { // packet's OK |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
262 ds_add_packet(ds, dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
263 break; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
264 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
265 |
9786
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
266 #ifdef DEBUG_PRINT_DISCARDED_PACKETS |
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
267 RTPState* rtpState = (RTPState*)(demuxer->priv); |
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
268 ReadBufferQueue* bufferQueue = ds == demuxer->video ? rtpState->videoBufferQueue : rtpState->audioBufferQueue; |
177a3393057c
Added some optional debugging printfs (disabled by default)
rsf
parents:
9565
diff
changeset
|
269 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
|
270 #endif |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
271 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
|
272 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
273 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
274 return 1; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
275 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
276 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
277 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
|
278 unsigned char*& packetData, unsigned& packetDataLen, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
279 float& pts) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
280 // 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
|
281 // 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
|
282 float ptsBehind; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
283 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
|
284 if (dp == NULL) return False; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
285 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
286 packetData = dp->buffer; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
287 packetDataLen = dp->len; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
288 pts = dp->pts; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
289 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
290 return True; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
291 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
292 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
293 Boolean insertRTPData(demuxer_t* demuxer, demux_stream_t* ds, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
294 unsigned char* data, unsigned dataLen) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
295 // Begin by finding the buffer queue that we want to add data to. |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
296 // (Get this from the RTP state, which we stored in |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
297 // 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
|
298 RTPState* rtpState = (RTPState*)(demuxer->priv); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
299 ReadBufferQueue* bufferQueue = NULL; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
300 if (ds == demuxer->video) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
301 bufferQueue = rtpState->videoBufferQueue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
302 } else if (ds == demuxer->audio) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
303 bufferQueue = rtpState->audioBufferQueue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
304 } else { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
305 fprintf(stderr, "(demux_rtp)insertRTPData: internal error: unknown stream\n"); |
9250 | 306 return False; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
307 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
308 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
309 if (data == NULL || dataLen == 0) return False; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
310 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
311 demux_packet_t* dp = new_demux_packet(dataLen); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
312 if (dp == NULL) return False; |
9250 | 313 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
314 // Copy our data into the buffer, and save it: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
315 memmove(dp->buffer, data, dataLen); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
316 dp->len = dataLen; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
317 dp->pts = 0; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
318 bufferQueue->savePendingBuffer(dp); |
9904
afbbf103a662
Access-controlled RTSP sessions can now be played, if the user uses the
rsf
parents:
9786
diff
changeset
|
319 return True; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
320 } |
9250 | 321 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
322 static void teardownRTSPSession(RTPState* rtpState); // forward |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
323 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
324 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
|
325 // 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
|
326 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
327 // 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
|
328 RTPState* rtpState = (RTPState*)(demuxer->priv); |
7143
fdfc10c2e2d2
- Tell the RTSP client code to use the string "mplayer" in RTSP
arpi
parents:
7008
diff
changeset
|
329 if (rtpState == NULL) return; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
330 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
331 teardownRTSPSession(rtpState); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
332 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
333 UsageEnvironment* env = NULL; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
334 TaskScheduler* scheduler = NULL; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
335 if (rtpState->mediaSession != NULL) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
336 env = &(rtpState->mediaSession->envir()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
337 scheduler = &(env->taskScheduler()); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
338 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
339 Medium::close(rtpState->mediaSession); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
340 Medium::close(rtpState->rtspClient); |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
341 delete rtpState->audioBufferQueue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
342 delete rtpState->videoBufferQueue; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
343 delete rtpState->sdpDescription; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
344 delete rtpState; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
345 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
346 delete env; delete scheduler; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
347 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
348 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
349 ////////// 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
|
350 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
351 #define MAX_RTP_FRAME_SIZE 50000 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
352 // >= 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
|
353 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
354 static void afterReading(void* clientData, unsigned frameSize, |
7534 | 355 struct timeval presentationTime) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
356 if (frameSize >= MAX_RTP_FRAME_SIZE) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
357 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
|
358 MAX_RTP_FRAME_SIZE); |
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 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
|
361 demuxer_t* demuxer = bufferQueue->ourDemuxer(); |
7534 | 362 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
|
363 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
364 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
|
365 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
366 demux_packet_t* dp = bufferQueue->dp; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
367 dp->len = frameSize; |
7534 | 368 |
369 // Set the packet's presentation time stamp, depending on whether or | |
370 // 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
|
371 Boolean hasBeenSynchronized |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
372 = bufferQueue->rtpSource()->hasBeenSynchronizedUsingRTCP(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
373 if (hasBeenSynchronized) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
374 if (verbose > 0 && !bufferQueue->prevPacketWasSynchronized) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
375 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
|
376 bufferQueue->tag()); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
377 } |
7534 | 378 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
379 struct timeval* fst = &(rtpState->firstSyncTime); // abbrev |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
380 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
|
381 *fst = presentationTime; |
7534 | 382 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
383 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
384 // 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
|
385 // 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
|
386 // 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
|
387 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
|
388 + (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
|
389 bufferQueue->prevPacketPTS = dp->pts; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
390 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
391 if (verbose > 0 && bufferQueue->prevPacketWasSynchronized) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
392 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
|
393 bufferQueue->tag()); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
394 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
395 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
396 // 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
|
397 dp->pts = bufferQueue->prevPacketPTS; |
7534 | 398 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
399 bufferQueue->prevPacketWasSynchronized = hasBeenSynchronized; |
7534 | 400 |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
401 dp->pos = demuxer->filepos; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
402 demuxer->filepos += frameSize; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
403 |
9250 | 404 // 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
|
405 bufferQueue->blockingFlag = ~0; |
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 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
408 static void onSourceClosure(void* clientData) { |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
409 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
|
410 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
|
411 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
412 demuxer->stream->eof = 1; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
413 |
9250 | 414 // 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
|
415 bufferQueue->blockingFlag = ~0; |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
416 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
417 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
418 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
|
419 Boolean mustGetNewData, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
420 float& ptsBehind) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
421 // 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
|
422 // (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
|
423 // the demuxer's 'priv' field) |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
424 RTPState* rtpState = (RTPState*)(demuxer->priv); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
425 ReadBufferQueue* bufferQueue = NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
426 if (ds == demuxer->video) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
427 bufferQueue = rtpState->videoBufferQueue; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
428 } else if (ds == demuxer->audio) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
429 bufferQueue = rtpState->audioBufferQueue; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
430 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
431 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
|
432 return NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
433 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
434 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
435 if (bufferQueue == NULL || bufferQueue->readSource() == NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
436 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
|
437 return NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
438 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
439 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
440 demux_packet_t* dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
441 if (!mustGetNewData) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
442 // 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
|
443 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
|
444 if (dp != NULL) { |
fa45d335a43b
Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents:
9904
diff
changeset
|
445 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
|
446 return dp; |
fa45d335a43b
Fixed a bug that could sometimes cause the first video packet in a RTP stream
rsf
parents:
9904
diff
changeset
|
447 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
448 } |
9250 | 449 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
450 // Allocate a new packet buffer, and arrange to read into it: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
451 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
|
452 bufferQueue->dp = dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
453 if (dp == NULL) return NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
454 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
455 // Schedule the read operation: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
456 bufferQueue->blockingFlag = 0; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
457 bufferQueue->readSource()->getNextFrame(dp->buffer, MAX_RTP_FRAME_SIZE, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
458 afterReading, bufferQueue, |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
459 onSourceClosure, bufferQueue); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
460 // Block ourselves until data becomes available: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
461 TaskScheduler& scheduler |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
462 = bufferQueue->readSource()->envir().taskScheduler(); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
463 scheduler.doEventLoop(&bufferQueue->blockingFlag); |
9250 | 464 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
465 // Set the "ptsBehind" result parameter: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
466 if (bufferQueue->prevPacketPTS != 0.0 && *(bufferQueue->otherQueue) != NULL |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
467 && (*(bufferQueue->otherQueue))->prevPacketPTS != 0.0) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
468 ptsBehind = (*(bufferQueue->otherQueue))->prevPacketPTS |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
469 - bufferQueue->prevPacketPTS; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
470 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
471 ptsBehind = 0.0; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
472 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
473 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
474 if (mustGetNewData) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
475 // Save this buffer for future reads: |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
476 bufferQueue->savePendingBuffer(dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
477 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
478 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
479 return dp; |
9250 | 480 } |
481 | |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
482 static void teardownRTSPSession(RTPState* rtpState) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
483 RTSPClient* rtspClient = rtpState->rtspClient; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
484 MediaSession* mediaSession = rtpState->mediaSession; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
485 if (rtspClient == NULL || mediaSession == NULL) return; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
486 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
487 MediaSubsessionIterator iter(*mediaSession); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
488 MediaSubsession* subsession; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
489 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
490 while ((subsession = iter.next()) != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
491 rtspClient->teardownMediaSubsession(*subsession); |
9250 | 492 } |
493 } | |
494 | |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
495 ////////// "ReadBuffer" and "ReadBufferQueue" implementation: |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
496 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
497 ReadBufferQueue::ReadBufferQueue(MediaSubsession* subsession, |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
498 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
|
499 : prevPacketWasSynchronized(False), prevPacketPTS(0.0), otherQueue(NULL), |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
500 dp(NULL), pendingDPHead(NULL), pendingDPTail(NULL), |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
501 fReadSource(subsession == NULL ? NULL : subsession->readSource()), |
7534 | 502 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
|
503 fOurDemuxer(demuxer), fTag(strdup(tag)) { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
504 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
505 |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
506 ReadBufferQueue::~ReadBufferQueue() { |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
507 delete fTag; |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
508 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
509 // 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
|
510 demux_packet_t* dp = pendingDPHead; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
511 while (dp != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
512 demux_packet_t* dpNext = dp->next; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
513 dp->next = NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
514 free_demux_packet(dp); |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
515 dp = dpNext; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
516 } |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
517 } |
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
518 |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
519 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
|
520 // 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
|
521 if (pendingDPTail == NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
522 pendingDPHead = pendingDPTail = dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
523 } else { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
524 pendingDPTail->next = dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
525 pendingDPTail = dp; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
526 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
527 dp->next = NULL; |
6910
1a747aee653b
applied live.com streaming patch (-sdp and rtsp:// support) by Ross Finlayson <finlayson@live.com>
arpi
parents:
diff
changeset
|
528 } |
9565
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
529 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
530 demux_packet_t* ReadBufferQueue::getPendingBuffer() { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
531 demux_packet_t* dp = pendingDPHead; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
532 if (dp != NULL) { |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
533 pendingDPHead = dp->next; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
534 if (pendingDPHead == NULL) pendingDPTail = 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 dp->next = NULL; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
537 } |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
538 |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
539 return dp; |
e74916774667
Improved RTP packet buffering, by relying on the underlying OS's UDP
rsf
parents:
9457
diff
changeset
|
540 } |