2 * routines (with C-linkage) that interface between MPlayer
3 * and the "LIVE555 Streaming Media" libraries
5 * This file is part of MPlayer.
7 * MPlayer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * MPlayer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // on MinGW, we must include windows.h before the things it conflicts
24 #ifdef __MINGW32__ // with. they are each protected from
25 #include <windows.h> // windows.h, but not the other way around.
27 #include "demux_rtp.h"
30 #include "demux_rtp_internal.h"
32 #include "BasicUsageEnvironment.hh"
33 #include "liveMedia.hh"
34 #include "GroupsockHelper.hh"
37 // A data structure representing input data for each stream:
38 class ReadBufferQueue
{
40 ReadBufferQueue(MediaSubsession
* subsession
, demuxer_t
* demuxer
,
42 virtual ~ReadBufferQueue();
44 FramedSource
* readSource() const { return fReadSource
; }
45 RTPSource
* rtpSource() const { return fRTPSource
; }
46 demuxer_t
* ourDemuxer() const { return fOurDemuxer
; }
47 char const* tag() const { return fTag
; }
49 char blockingFlag
; // used to implement synchronous reads
51 // For A/V synchronization:
52 Boolean prevPacketWasSynchronized
;
54 ReadBufferQueue
** otherQueue
;
56 // The 'queue' actually consists of just a single "demux_packet_t"
57 // (because the underlying OS does the actual queueing/buffering):
60 // However, we sometimes inspect buffers before delivering them.
61 // For this, we maintain a queue of pending buffers:
62 void savePendingBuffer(demux_packet_t
* dp
);
63 demux_packet_t
* getPendingBuffer();
65 // For H264 over rtsp using AVParser, the next packet has to be saved
66 demux_packet_t
* nextpacket
;
69 demux_packet_t
* pendingDPHead
;
70 demux_packet_t
* pendingDPTail
;
72 FramedSource
* fReadSource
;
73 RTPSource
* fRTPSource
;
74 demuxer_t
* fOurDemuxer
;
75 char const* fTag
; // used for debugging
78 // A structure of RTP-specific state, kept so that we can cleanly
80 typedef struct RTPState
{
81 char const* sdpDescription
;
82 RTSPClient
* rtspClient
;
84 MediaSession
* mediaSession
;
85 ReadBufferQueue
* audioBufferQueue
;
86 ReadBufferQueue
* videoBufferQueue
;
88 struct timeval firstSyncTime
;
91 extern "C" char* network_username
;
92 extern "C" char* network_password
;
93 static char* openURL_rtsp(RTSPClient
* client
, char const* url
) {
94 // If we were given a user name (and optional password), then use them:
95 if (network_username
!= NULL
) {
96 char const* password
= network_password
== NULL
? "" : network_password
;
97 return client
->describeWithPassword(url
, network_username
, password
);
99 return client
->describeURL(url
);
103 static char* openURL_sip(SIPClient
* client
, char const* url
) {
104 // If we were given a user name (and optional password), then use them:
105 if (network_username
!= NULL
) {
106 char const* password
= network_password
== NULL
? "" : network_password
;
107 return client
->inviteWithPassword(url
, network_username
, password
);
109 return client
->invite(url
);
113 #ifdef CONFIG_LIBNEMESI
114 extern int rtsp_transport_tcp
;
116 int rtsp_transport_tcp
= 0;
119 extern int rtsp_port
;
121 extern "C" int audio_id
, video_id
, dvdsub_id
;
122 extern "C" demuxer_t
* demux_open_rtp(demuxer_t
* demuxer
) {
123 Boolean success
= False
;
125 TaskScheduler
* scheduler
= BasicTaskScheduler::createNew();
126 if (scheduler
== NULL
) break;
127 UsageEnvironment
* env
= BasicUsageEnvironment::createNew(*scheduler
);
128 if (env
== NULL
) break;
130 RTSPClient
* rtspClient
= NULL
;
131 SIPClient
* sipClient
= NULL
;
133 if (demuxer
== NULL
|| demuxer
->stream
== NULL
) break; // shouldn't happen
134 demuxer
->stream
->eof
= 0; // just in case
136 // Look at the stream's 'priv' field to see if we were initiated
137 // via a SDP description:
138 char* sdpDescription
= (char*)(demuxer
->stream
->priv
);
139 if (sdpDescription
== NULL
) {
140 // We weren't given a SDP description directly, so assume that
141 // we were given a RTSP or SIP URL:
142 char const* protocol
= demuxer
->stream
->streaming_ctrl
->url
->protocol
;
143 char const* url
= demuxer
->stream
->streaming_ctrl
->url
->url
;
145 if (strcmp(protocol
, "rtsp") == 0) {
146 rtspClient
= RTSPClient::createNew(*env
, verbose
, "MPlayer");
147 if (rtspClient
== NULL
) {
148 fprintf(stderr
, "Failed to create RTSP client: %s\n",
149 env
->getResultMsg());
152 sdpDescription
= openURL_rtsp(rtspClient
, url
);
154 unsigned char desiredAudioType
= 0; // PCMU (use 3 for GSM)
155 sipClient
= SIPClient::createNew(*env
, desiredAudioType
, NULL
,
157 if (sipClient
== NULL
) {
158 fprintf(stderr
, "Failed to create SIP client: %s\n",
159 env
->getResultMsg());
162 sipClient
->setClientStartPortNum(8000);
163 sdpDescription
= openURL_sip(sipClient
, url
);
166 if (sdpDescription
== NULL
) {
167 fprintf(stderr
, "Failed to get a SDP description from URL \"%s\": %s\n",
168 url
, env
->getResultMsg());
173 // Now that we have a SDP description, create a MediaSession from it:
174 MediaSession
* mediaSession
= MediaSession::createNew(*env
, sdpDescription
);
175 if (mediaSession
== NULL
) break;
178 // Create a 'RTPState' structure containing the state that we just created,
179 // and store it in the demuxer's 'priv' field, for future reference:
180 RTPState
* rtpState
= new RTPState
;
181 rtpState
->sdpDescription
= sdpDescription
;
182 rtpState
->rtspClient
= rtspClient
;
183 rtpState
->sipClient
= sipClient
;
184 rtpState
->mediaSession
= mediaSession
;
185 rtpState
->audioBufferQueue
= rtpState
->videoBufferQueue
= NULL
;
187 rtpState
->firstSyncTime
.tv_sec
= rtpState
->firstSyncTime
.tv_usec
= 0;
188 demuxer
->priv
= rtpState
;
190 int audiofound
= 0, videofound
= 0;
191 // Create RTP receivers (sources) for each subsession:
192 MediaSubsessionIterator
iter(*mediaSession
);
193 MediaSubsession
* subsession
;
194 unsigned desiredReceiveBufferSize
;
195 while ((subsession
= iter
.next()) != NULL
) {
196 // Ignore any subsession that's not audio or video:
197 if (strcmp(subsession
->mediumName(), "audio") == 0) {
199 fprintf(stderr
, "Additional subsession \"audio/%s\" skipped\n", subsession
->codecName());
202 desiredReceiveBufferSize
= 100000;
203 } else if (strcmp(subsession
->mediumName(), "video") == 0) {
205 fprintf(stderr
, "Additional subsession \"video/%s\" skipped\n", subsession
->codecName());
208 desiredReceiveBufferSize
= 2000000;
214 subsession
->setClientPortNum (rtsp_port
);
216 if (!subsession
->initiate()) {
217 fprintf(stderr
, "Failed to initiate \"%s/%s\" RTP subsession: %s\n", subsession
->mediumName(), subsession
->codecName(), env
->getResultMsg());
219 fprintf(stderr
, "Initiated \"%s/%s\" RTP subsession on port %d\n", subsession
->mediumName(), subsession
->codecName(), subsession
->clientPortNum());
221 // Set the OS's socket receive buffer sufficiently large to avoid
222 // incoming packets getting dropped between successive reads from this
223 // subsession's demuxer. Depending on the bitrate(s) that you expect,
224 // you may wish to tweak the "desiredReceiveBufferSize" values above.
225 int rtpSocketNum
= subsession
->rtpSource()->RTPgs()->socketNum();
226 int receiveBufferSize
227 = increaseReceiveBufferTo(*env
, rtpSocketNum
,
228 desiredReceiveBufferSize
);
230 fprintf(stderr
, "Increased %s socket receive buffer to %d bytes \n",
231 subsession
->mediumName(), receiveBufferSize
);
234 if (rtspClient
!= NULL
) {
235 // Issue a RTSP "SETUP" command on the chosen subsession:
236 if (!rtspClient
->setupMediaSubsession(*subsession
, False
,
237 rtsp_transport_tcp
)) break;
238 if (!strcmp(subsession
->mediumName(), "audio"))
240 if (!strcmp(subsession
->mediumName(), "video"))
246 if (rtspClient
!= NULL
) {
247 // Issue a RTSP aggregate "PLAY" command on the whole session:
248 if (!rtspClient
->playMediaSession(*mediaSession
)) break;
249 } else if (sipClient
!= NULL
) {
250 sipClient
->sendACK(); // to start the stream flowing
253 // Now that the session is ready to be read, do additional
254 // MPlayer codec-specific initialization on each subsession:
256 while ((subsession
= iter
.next()) != NULL
) {
257 if (subsession
->readSource() == NULL
) continue; // not reading this
260 if (strcmp(subsession
->mediumName(), "audio") == 0) {
261 rtpState
->audioBufferQueue
262 = new ReadBufferQueue(subsession
, demuxer
, "audio");
263 rtpState
->audioBufferQueue
->otherQueue
= &(rtpState
->videoBufferQueue
);
264 rtpCodecInitialize_audio(demuxer
, subsession
, flags
);
265 } else if (strcmp(subsession
->mediumName(), "video") == 0) {
266 rtpState
->videoBufferQueue
267 = new ReadBufferQueue(subsession
, demuxer
, "video");
268 rtpState
->videoBufferQueue
->otherQueue
= &(rtpState
->audioBufferQueue
);
269 rtpCodecInitialize_video(demuxer
, subsession
, flags
);
271 rtpState
->flags
|= flags
;
275 if (!success
) return NULL
; // an error occurred
277 // Hack: If audio and video are demuxed together on a single RTP stream,
278 // then create a new "demuxer_t" structure to allow the higher-level
279 // code to recognize this:
280 if (demux_is_multiplexed_rtp_stream(demuxer
)) {
281 stream_t
* s
= new_ds_stream(demuxer
->video
);
282 demuxer_t
* od
= demux_open(s
, DEMUXER_TYPE_UNKNOWN
,
283 audio_id
, video_id
, dvdsub_id
, NULL
);
284 demuxer
= new_demuxers_demuxer(od
, od
, od
);
290 extern "C" int demux_is_mpeg_rtp_stream(demuxer_t
* demuxer
) {
291 // Get the RTP state that was stored in the demuxer's 'priv' field:
292 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
294 return (rtpState
->flags
&RTPSTATE_IS_MPEG12_VIDEO
) != 0;
297 extern "C" int demux_is_multiplexed_rtp_stream(demuxer_t
* demuxer
) {
298 // Get the RTP state that was stored in the demuxer's 'priv' field:
299 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
301 return (rtpState
->flags
&RTPSTATE_IS_MULTIPLEXED
) != 0;
304 static demux_packet_t
* getBuffer(demuxer_t
* demuxer
, demux_stream_t
* ds
,
305 Boolean mustGetNewData
,
306 float& ptsBehind
); // forward
308 extern "C" int demux_rtp_fill_buffer(demuxer_t
* demuxer
, demux_stream_t
* ds
) {
309 // Get a filled-in "demux_packet" from the RTP source, and deliver it.
310 // Note that this is called as a synchronous read operation, so it needs
311 // to block in the (hopefully infrequent) case where no packet is
312 // immediately available.
316 demux_packet_t
* dp
= getBuffer(demuxer
, ds
, False
, ptsBehind
); // blocking
317 if (dp
== NULL
) return 0;
319 if (demuxer
->stream
->eof
) return 0; // source stream has closed down
321 // Before using this packet, check to make sure that its presentation
322 // time is not far behind the other stream (if any). If it is,
323 // then we discard this packet, and get another instead. (The rest of
324 // MPlayer doesn't always do a good job of synchronizing when the
325 // audio and video streams get this far apart.)
326 // (We don't do this when streaming over TCP, because then the audio and
327 // video streams are interleaved.)
328 // (Also, if the stream is *excessively* far behind, then we allow
329 // the packet, because in this case it probably means that there was
330 // an error in the source's timestamp synchronization.)
331 const float ptsBehindThreshold
= 1.0; // seconds
332 const float ptsBehindLimit
= 60.0; // seconds
333 if (ptsBehind
< ptsBehindThreshold
||
334 ptsBehind
> ptsBehindLimit
||
335 rtsp_transport_tcp
) { // packet's OK
336 ds_add_packet(ds
, dp
);
340 #ifdef DEBUG_PRINT_DISCARDED_PACKETS
341 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
342 ReadBufferQueue
* bufferQueue
= ds
== demuxer
->video
? rtpState
->videoBufferQueue
: rtpState
->audioBufferQueue
;
343 fprintf(stderr
, "Discarding %s packet (%fs behind)\n", bufferQueue
->tag(), ptsBehind
);
345 free_demux_packet(dp
); // give back this packet, and get another one
351 Boolean
awaitRTPPacket(demuxer_t
* demuxer
, demux_stream_t
* ds
,
352 unsigned char*& packetData
, unsigned& packetDataLen
,
354 // Similar to "demux_rtp_fill_buffer()", except that the "demux_packet"
355 // is not delivered to the "demux_stream".
357 demux_packet_t
* dp
= getBuffer(demuxer
, ds
, True
, ptsBehind
); // blocking
358 if (dp
== NULL
) return False
;
360 packetData
= dp
->buffer
;
361 packetDataLen
= dp
->len
;
367 static void teardownRTSPorSIPSession(RTPState
* rtpState
); // forward
369 extern "C" void demux_close_rtp(demuxer_t
* demuxer
) {
370 // Reclaim all RTP-related state:
372 // Get the RTP state that was stored in the demuxer's 'priv' field:
373 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
374 if (rtpState
== NULL
) return;
376 teardownRTSPorSIPSession(rtpState
);
378 UsageEnvironment
* env
= NULL
;
379 TaskScheduler
* scheduler
= NULL
;
380 if (rtpState
->mediaSession
!= NULL
) {
381 env
= &(rtpState
->mediaSession
->envir());
382 scheduler
= &(env
->taskScheduler());
384 Medium::close(rtpState
->mediaSession
);
385 Medium::close(rtpState
->rtspClient
);
386 Medium::close(rtpState
->sipClient
);
387 delete rtpState
->audioBufferQueue
;
388 delete rtpState
->videoBufferQueue
;
389 delete rtpState
->sdpDescription
;
392 env
->reclaim(); delete scheduler
;
395 ////////// Extra routines that help implement the above interface functions:
397 #define MAX_RTP_FRAME_SIZE 5000000
398 // >= the largest conceivable frame composed from one or more RTP packets
400 static void afterReading(void* clientData
, unsigned frameSize
,
401 unsigned /*numTruncatedBytes*/,
402 struct timeval presentationTime
,
403 unsigned /*durationInMicroseconds*/) {
405 if (frameSize
>= MAX_RTP_FRAME_SIZE
) {
406 fprintf(stderr
, "Saw an input frame too large (>=%d). Increase MAX_RTP_FRAME_SIZE in \"demux_rtp.cpp\".\n",
409 ReadBufferQueue
* bufferQueue
= (ReadBufferQueue
*)clientData
;
410 demuxer_t
* demuxer
= bufferQueue
->ourDemuxer();
411 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
413 if (frameSize
> 0) demuxer
->stream
->eof
= 0;
415 demux_packet_t
* dp
= bufferQueue
->dp
;
417 if (bufferQueue
->readSource()->isAMRAudioSource())
419 else if (bufferQueue
== rtpState
->videoBufferQueue
&&
420 ((sh_video_t
*)demuxer
->video
->sh
)->format
== mmioFOURCC('H','2','6','4')) {
427 resize_demux_packet(dp
, frameSize
+ headersize
);
429 // Set the packet's presentation time stamp, depending on whether or
430 // not our RTP source's timestamps have been synchronized yet:
431 Boolean hasBeenSynchronized
432 = bufferQueue
->rtpSource()->hasBeenSynchronizedUsingRTCP();
433 if (hasBeenSynchronized
) {
434 if (verbose
> 0 && !bufferQueue
->prevPacketWasSynchronized
) {
435 fprintf(stderr
, "%s stream has been synchronized using RTCP \n",
439 struct timeval
* fst
= &(rtpState
->firstSyncTime
); // abbrev
440 if (fst
->tv_sec
== 0 && fst
->tv_usec
== 0) {
441 *fst
= presentationTime
;
444 // For the "pts" field, use the time differential from the first
445 // synchronized time, rather than absolute time, in order to avoid
446 // round-off errors when converting to a float:
447 dp
->pts
= presentationTime
.tv_sec
- fst
->tv_sec
448 + (presentationTime
.tv_usec
- fst
->tv_usec
)/1000000.0;
449 bufferQueue
->prevPacketPTS
= dp
->pts
;
451 if (verbose
> 0 && bufferQueue
->prevPacketWasSynchronized
) {
452 fprintf(stderr
, "%s stream is no longer RTCP-synchronized \n",
456 // use the previous packet's "pts" once again:
457 dp
->pts
= bufferQueue
->prevPacketPTS
;
459 bufferQueue
->prevPacketWasSynchronized
= hasBeenSynchronized
;
461 dp
->pos
= demuxer
->filepos
;
462 demuxer
->filepos
+= frameSize
+ headersize
;
464 // Signal any pending 'doEventLoop()' call on this queue:
465 bufferQueue
->blockingFlag
= ~0;
468 static void onSourceClosure(void* clientData
) {
469 ReadBufferQueue
* bufferQueue
= (ReadBufferQueue
*)clientData
;
470 demuxer_t
* demuxer
= bufferQueue
->ourDemuxer();
472 demuxer
->stream
->eof
= 1;
474 // Signal any pending 'doEventLoop()' call on this queue:
475 bufferQueue
->blockingFlag
= ~0;
478 static demux_packet_t
* getBuffer(demuxer_t
* demuxer
, demux_stream_t
* ds
,
479 Boolean mustGetNewData
,
481 // Begin by finding the buffer queue that we want to read from:
482 // (Get this from the RTP state, which we stored in
483 // the demuxer's 'priv' field)
484 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
485 ReadBufferQueue
* bufferQueue
= NULL
;
489 if (demuxer
->stream
->eof
) return NULL
;
491 if (ds
== demuxer
->video
) {
492 bufferQueue
= rtpState
->videoBufferQueue
;
493 if (((sh_video_t
*)ds
->sh
)->format
== mmioFOURCC('H','2','6','4'))
495 } else if (ds
== demuxer
->audio
) {
496 bufferQueue
= rtpState
->audioBufferQueue
;
497 if (bufferQueue
->readSource()->isAMRAudioSource())
500 fprintf(stderr
, "(demux_rtp)getBuffer: internal error: unknown stream\n");
504 if (bufferQueue
== NULL
|| bufferQueue
->readSource() == NULL
) {
505 fprintf(stderr
, "(demux_rtp)getBuffer failed: no appropriate RTP subsession has been set up\n");
509 demux_packet_t
* dp
= NULL
;
510 if (!mustGetNewData
) {
511 // Check whether we have a previously-saved buffer that we can use:
512 dp
= bufferQueue
->getPendingBuffer();
514 ptsBehind
= 0.0; // so that we always accept this data
519 // Allocate a new packet buffer, and arrange to read into it:
520 if (!bufferQueue
->nextpacket
) {
521 dp
= new_demux_packet(MAX_RTP_FRAME_SIZE
);
522 bufferQueue
->dp
= dp
;
523 if (dp
== NULL
) return NULL
;
526 #ifdef CONFIG_LIBAVCODEC
527 extern AVCodecParserContext
* h264parserctx
;
528 int consumed
, poutbuf_size
= 1;
529 const uint8_t *poutbuf
= NULL
;
533 if (!bufferQueue
->nextpacket
) {
535 // Schedule the read operation:
536 bufferQueue
->blockingFlag
= 0;
537 bufferQueue
->readSource()->getNextFrame(&dp
->buffer
[headersize
], MAX_RTP_FRAME_SIZE
- headersize
,
538 afterReading
, bufferQueue
,
539 onSourceClosure
, bufferQueue
);
540 // Block ourselves until data becomes available:
541 TaskScheduler
& scheduler
542 = bufferQueue
->readSource()->envir().taskScheduler();
543 int delay
= 10000000;
544 if (bufferQueue
->prevPacketPTS
* 1.05 > rtpState
->mediaSession
->playEndTime())
546 task
= scheduler
.scheduleDelayedTask(delay
, onSourceClosure
, bufferQueue
);
547 scheduler
.doEventLoop(&bufferQueue
->blockingFlag
);
548 scheduler
.unscheduleDelayedTask(task
);
549 if (demuxer
->stream
->eof
) {
550 free_demux_packet(dp
);
554 if (headersize
== 1) // amr
556 ((AMRAudioSource
*)bufferQueue
->readSource())->lastFrameHeader();
557 #ifdef CONFIG_LIBAVCODEC
559 bufferQueue
->dp
= dp
= bufferQueue
->nextpacket
;
560 bufferQueue
->nextpacket
= NULL
;
562 if (headersize
== 3 && h264parserctx
) { // h264
563 consumed
= h264parserctx
->parser
->parser_parse(h264parserctx
,
565 &poutbuf
, &poutbuf_size
,
566 dp
->buffer
, dp
->len
);
568 if (!consumed
&& !poutbuf_size
)
573 free_demux_packet(dp
);
574 bufferQueue
->dp
= dp
= new_demux_packet(MAX_RTP_FRAME_SIZE
);
576 bufferQueue
->nextpacket
= dp
;
577 bufferQueue
->dp
= dp
= new_demux_packet(poutbuf_size
);
578 memcpy(dp
->buffer
, poutbuf
, poutbuf_size
);
582 } while (!poutbuf_size
);
585 // Set the "ptsBehind" result parameter:
586 if (bufferQueue
->prevPacketPTS
!= 0.0
587 && bufferQueue
->prevPacketWasSynchronized
588 && *(bufferQueue
->otherQueue
) != NULL
589 && (*(bufferQueue
->otherQueue
))->prevPacketPTS
!= 0.0
590 && (*(bufferQueue
->otherQueue
))->prevPacketWasSynchronized
) {
591 ptsBehind
= (*(bufferQueue
->otherQueue
))->prevPacketPTS
592 - bufferQueue
->prevPacketPTS
;
597 if (mustGetNewData
) {
598 // Save this buffer for future reads:
599 bufferQueue
->savePendingBuffer(dp
);
605 static void teardownRTSPorSIPSession(RTPState
* rtpState
) {
606 MediaSession
* mediaSession
= rtpState
->mediaSession
;
607 if (mediaSession
== NULL
) return;
608 if (rtpState
->rtspClient
!= NULL
) {
609 rtpState
->rtspClient
->teardownMediaSession(*mediaSession
);
610 } else if (rtpState
->sipClient
!= NULL
) {
611 rtpState
->sipClient
->sendBYE();
615 ////////// "ReadBuffer" and "ReadBufferQueue" implementation:
617 ReadBufferQueue::ReadBufferQueue(MediaSubsession
* subsession
,
618 demuxer_t
* demuxer
, char const* tag
)
619 : prevPacketWasSynchronized(False
), prevPacketPTS(0.0), otherQueue(NULL
),
620 dp(NULL
), nextpacket(NULL
),
621 pendingDPHead(NULL
), pendingDPTail(NULL
),
622 fReadSource(subsession
== NULL
? NULL
: subsession
->readSource()),
623 fRTPSource(subsession
== NULL
? NULL
: subsession
->rtpSource()),
624 fOurDemuxer(demuxer
), fTag(strdup(tag
)) {
627 ReadBufferQueue::~ReadBufferQueue() {
630 // Free any pending buffers (that never got delivered):
631 demux_packet_t
* dp
= pendingDPHead
;
633 demux_packet_t
* dpNext
= dp
->next
;
635 free_demux_packet(dp
);
640 void ReadBufferQueue::savePendingBuffer(demux_packet_t
* dp
) {
641 // Keep this buffer around, until MPlayer asks for it later:
642 if (pendingDPTail
== NULL
) {
643 pendingDPHead
= pendingDPTail
= dp
;
645 pendingDPTail
->next
= dp
;
651 demux_packet_t
* ReadBufferQueue::getPendingBuffer() {
652 demux_packet_t
* dp
= pendingDPHead
;
654 pendingDPHead
= dp
->next
;
655 if (pendingDPHead
== NULL
) pendingDPTail
= NULL
;
663 static int demux_rtp_control(struct demuxer_st
*demuxer
, int cmd
, void *arg
) {
664 double endpts
= ((RTPState
*)demuxer
->priv
)->mediaSession
->playEndTime();
667 case DEMUXER_CTRL_GET_TIME_LENGTH
:
669 return DEMUXER_CTRL_DONTKNOW
;
670 *((double *)arg
) = endpts
;
671 return DEMUXER_CTRL_OK
;
673 case DEMUXER_CTRL_GET_PERCENT_POS
:
675 return DEMUXER_CTRL_DONTKNOW
;
676 *((int *)arg
) = (int)(((RTPState
*)demuxer
->priv
)->videoBufferQueue
->prevPacketPTS
*100/endpts
);
677 return DEMUXER_CTRL_OK
;
680 return DEMUXER_CTRL_NOTIMPL
;
684 demuxer_desc_t demuxer_desc_rtp
= {
685 "LIVE555 RTP demuxer",
689 "requires LIVE555 Streaming Media library",
693 demux_rtp_fill_buffer
,