1 ////////// Routines (with C-linkage) that interface between "MPlayer"
2 ////////// and the "LIVE555 Streaming Media" libraries:
5 // on MinGW, we must include windows.h before the things it conflicts
6 #ifdef __MINGW32__ // with. they are each protected from
7 #include <windows.h> // windows.h, but not the other way around.
12 #include "demux_rtp_internal.h"
14 #include "BasicUsageEnvironment.hh"
15 #include "liveMedia.hh"
16 #include "GroupsockHelper.hh"
19 // A data structure representing input data for each stream:
20 class ReadBufferQueue
{
22 ReadBufferQueue(MediaSubsession
* subsession
, demuxer_t
* demuxer
,
24 virtual ~ReadBufferQueue();
26 FramedSource
* readSource() const { return fReadSource
; }
27 RTPSource
* rtpSource() const { return fRTPSource
; }
28 demuxer_t
* ourDemuxer() const { return fOurDemuxer
; }
29 char const* tag() const { return fTag
; }
31 char blockingFlag
; // used to implement synchronous reads
33 // For A/V synchronization:
34 Boolean prevPacketWasSynchronized
;
36 ReadBufferQueue
** otherQueue
;
38 // The 'queue' actually consists of just a single "demux_packet_t"
39 // (because the underlying OS does the actual queueing/buffering):
42 // However, we sometimes inspect buffers before delivering them.
43 // For this, we maintain a queue of pending buffers:
44 void savePendingBuffer(demux_packet_t
* dp
);
45 demux_packet_t
* getPendingBuffer();
47 // For H264 over rtsp using AVParser, the next packet has to be saved
48 demux_packet_t
* nextpacket
;
51 demux_packet_t
* pendingDPHead
;
52 demux_packet_t
* pendingDPTail
;
54 FramedSource
* fReadSource
;
55 RTPSource
* fRTPSource
;
56 demuxer_t
* fOurDemuxer
;
57 char const* fTag
; // used for debugging
60 // A structure of RTP-specific state, kept so that we can cleanly
62 typedef struct RTPState
{
63 char const* sdpDescription
;
64 RTSPClient
* rtspClient
;
66 MediaSession
* mediaSession
;
67 ReadBufferQueue
* audioBufferQueue
;
68 ReadBufferQueue
* videoBufferQueue
;
70 struct timeval firstSyncTime
;
73 extern "C" char* network_username
;
74 extern "C" char* network_password
;
75 static char* openURL_rtsp(RTSPClient
* client
, char const* url
) {
76 // If we were given a user name (and optional password), then use them:
77 if (network_username
!= NULL
) {
78 char const* password
= network_password
== NULL
? "" : network_password
;
79 return client
->describeWithPassword(url
, network_username
, password
);
81 return client
->describeURL(url
);
85 static char* openURL_sip(SIPClient
* client
, char const* url
) {
86 // If we were given a user name (and optional password), then use them:
87 if (network_username
!= NULL
) {
88 char const* password
= network_password
== NULL
? "" : network_password
;
89 return client
->inviteWithPassword(url
, network_username
, password
);
91 return client
->invite(url
);
95 int rtspStreamOverTCP
= 0;
98 extern "C" int audio_id
, video_id
, dvdsub_id
;
99 extern "C" demuxer_t
* demux_open_rtp(demuxer_t
* demuxer
) {
100 Boolean success
= False
;
102 TaskScheduler
* scheduler
= BasicTaskScheduler::createNew();
103 if (scheduler
== NULL
) break;
104 UsageEnvironment
* env
= BasicUsageEnvironment::createNew(*scheduler
);
105 if (env
== NULL
) break;
107 RTSPClient
* rtspClient
= NULL
;
108 SIPClient
* sipClient
= NULL
;
110 if (demuxer
== NULL
|| demuxer
->stream
== NULL
) break; // shouldn't happen
111 demuxer
->stream
->eof
= 0; // just in case
113 // Look at the stream's 'priv' field to see if we were initiated
114 // via a SDP description:
115 char* sdpDescription
= (char*)(demuxer
->stream
->priv
);
116 if (sdpDescription
== NULL
) {
117 // We weren't given a SDP description directly, so assume that
118 // we were given a RTSP or SIP URL:
119 char const* protocol
= demuxer
->stream
->streaming_ctrl
->url
->protocol
;
120 char const* url
= demuxer
->stream
->streaming_ctrl
->url
->url
;
122 if (strcmp(protocol
, "rtsp") == 0) {
123 rtspClient
= RTSPClient::createNew(*env
, verbose
, "MPlayer");
124 if (rtspClient
== NULL
) {
125 fprintf(stderr
, "Failed to create RTSP client: %s\n",
126 env
->getResultMsg());
129 sdpDescription
= openURL_rtsp(rtspClient
, url
);
131 unsigned char desiredAudioType
= 0; // PCMU (use 3 for GSM)
132 sipClient
= SIPClient::createNew(*env
, desiredAudioType
, NULL
,
134 if (sipClient
== NULL
) {
135 fprintf(stderr
, "Failed to create SIP client: %s\n",
136 env
->getResultMsg());
139 sipClient
->setClientStartPortNum(8000);
140 sdpDescription
= openURL_sip(sipClient
, url
);
143 if (sdpDescription
== NULL
) {
144 fprintf(stderr
, "Failed to get a SDP description from URL \"%s\": %s\n",
145 url
, env
->getResultMsg());
150 // Now that we have a SDP description, create a MediaSession from it:
151 MediaSession
* mediaSession
= MediaSession::createNew(*env
, sdpDescription
);
152 if (mediaSession
== NULL
) break;
155 // Create a 'RTPState' structure containing the state that we just created,
156 // and store it in the demuxer's 'priv' field, for future reference:
157 RTPState
* rtpState
= new RTPState
;
158 rtpState
->sdpDescription
= sdpDescription
;
159 rtpState
->rtspClient
= rtspClient
;
160 rtpState
->sipClient
= sipClient
;
161 rtpState
->mediaSession
= mediaSession
;
162 rtpState
->audioBufferQueue
= rtpState
->videoBufferQueue
= NULL
;
164 rtpState
->firstSyncTime
.tv_sec
= rtpState
->firstSyncTime
.tv_usec
= 0;
165 demuxer
->priv
= rtpState
;
167 int audiofound
= 0, videofound
= 0;
168 // Create RTP receivers (sources) for each subsession:
169 MediaSubsessionIterator
iter(*mediaSession
);
170 MediaSubsession
* subsession
;
171 unsigned desiredReceiveBufferSize
;
172 while ((subsession
= iter
.next()) != NULL
) {
173 // Ignore any subsession that's not audio or video:
174 if (strcmp(subsession
->mediumName(), "audio") == 0) {
176 fprintf(stderr
, "Additional subsession \"audio/%s\" skipped\n", subsession
->codecName());
179 desiredReceiveBufferSize
= 100000;
180 } else if (strcmp(subsession
->mediumName(), "video") == 0) {
182 fprintf(stderr
, "Additional subsession \"video/%s\" skipped\n", subsession
->codecName());
185 desiredReceiveBufferSize
= 2000000;
191 subsession
->setClientPortNum (rtsp_port
);
193 if (!subsession
->initiate()) {
194 fprintf(stderr
, "Failed to initiate \"%s/%s\" RTP subsession: %s\n", subsession
->mediumName(), subsession
->codecName(), env
->getResultMsg());
196 fprintf(stderr
, "Initiated \"%s/%s\" RTP subsession on port %d\n", subsession
->mediumName(), subsession
->codecName(), subsession
->clientPortNum());
198 // Set the OS's socket receive buffer sufficiently large to avoid
199 // incoming packets getting dropped between successive reads from this
200 // subsession's demuxer. Depending on the bitrate(s) that you expect,
201 // you may wish to tweak the "desiredReceiveBufferSize" values above.
202 int rtpSocketNum
= subsession
->rtpSource()->RTPgs()->socketNum();
203 int receiveBufferSize
204 = increaseReceiveBufferTo(*env
, rtpSocketNum
,
205 desiredReceiveBufferSize
);
207 fprintf(stderr
, "Increased %s socket receive buffer to %d bytes \n",
208 subsession
->mediumName(), receiveBufferSize
);
211 if (rtspClient
!= NULL
) {
212 // Issue a RTSP "SETUP" command on the chosen subsession:
213 if (!rtspClient
->setupMediaSubsession(*subsession
, False
,
214 rtspStreamOverTCP
)) break;
215 if (!strcmp(subsession
->mediumName(), "audio"))
217 if (!strcmp(subsession
->mediumName(), "video"))
223 if (rtspClient
!= NULL
) {
224 // Issue a RTSP aggregate "PLAY" command on the whole session:
225 if (!rtspClient
->playMediaSession(*mediaSession
)) break;
226 } else if (sipClient
!= NULL
) {
227 sipClient
->sendACK(); // to start the stream flowing
230 // Now that the session is ready to be read, do additional
231 // MPlayer codec-specific initialization on each subsession:
233 while ((subsession
= iter
.next()) != NULL
) {
234 if (subsession
->readSource() == NULL
) continue; // not reading this
237 if (strcmp(subsession
->mediumName(), "audio") == 0) {
238 rtpState
->audioBufferQueue
239 = new ReadBufferQueue(subsession
, demuxer
, "audio");
240 rtpState
->audioBufferQueue
->otherQueue
= &(rtpState
->videoBufferQueue
);
241 rtpCodecInitialize_audio(demuxer
, subsession
, flags
);
242 } else if (strcmp(subsession
->mediumName(), "video") == 0) {
243 rtpState
->videoBufferQueue
244 = new ReadBufferQueue(subsession
, demuxer
, "video");
245 rtpState
->videoBufferQueue
->otherQueue
= &(rtpState
->audioBufferQueue
);
246 rtpCodecInitialize_video(demuxer
, subsession
, flags
);
248 rtpState
->flags
|= flags
;
252 if (!success
) return NULL
; // an error occurred
254 // Hack: If audio and video are demuxed together on a single RTP stream,
255 // then create a new "demuxer_t" structure to allow the higher-level
256 // code to recognize this:
257 if (demux_is_multiplexed_rtp_stream(demuxer
)) {
258 stream_t
* s
= new_ds_stream(demuxer
->video
);
259 demuxer_t
* od
= demux_open(s
, DEMUXER_TYPE_UNKNOWN
,
260 audio_id
, video_id
, dvdsub_id
, NULL
);
261 demuxer
= new_demuxers_demuxer(od
, od
, od
);
267 extern "C" int demux_is_mpeg_rtp_stream(demuxer_t
* demuxer
) {
268 // Get the RTP state that was stored in the demuxer's 'priv' field:
269 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
271 return (rtpState
->flags
&RTPSTATE_IS_MPEG12_VIDEO
) != 0;
274 extern "C" int demux_is_multiplexed_rtp_stream(demuxer_t
* demuxer
) {
275 // Get the RTP state that was stored in the demuxer's 'priv' field:
276 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
278 return (rtpState
->flags
&RTPSTATE_IS_MULTIPLEXED
) != 0;
281 static demux_packet_t
* getBuffer(demuxer_t
* demuxer
, demux_stream_t
* ds
,
282 Boolean mustGetNewData
,
283 float& ptsBehind
); // forward
285 extern "C" int demux_rtp_fill_buffer(demuxer_t
* demuxer
, demux_stream_t
* ds
) {
286 // Get a filled-in "demux_packet" from the RTP source, and deliver it.
287 // Note that this is called as a synchronous read operation, so it needs
288 // to block in the (hopefully infrequent) case where no packet is
289 // immediately available.
293 demux_packet_t
* dp
= getBuffer(demuxer
, ds
, False
, ptsBehind
); // blocking
294 if (dp
== NULL
) return 0;
296 if (demuxer
->stream
->eof
) return 0; // source stream has closed down
298 // Before using this packet, check to make sure that its presentation
299 // time is not far behind the other stream (if any). If it is,
300 // then we discard this packet, and get another instead. (The rest of
301 // MPlayer doesn't always do a good job of synchronizing when the
302 // audio and video streams get this far apart.)
303 // (We don't do this when streaming over TCP, because then the audio and
304 // video streams are interleaved.)
305 // (Also, if the stream is *excessively* far behind, then we allow
306 // the packet, because in this case it probably means that there was
307 // an error in the source's timestamp synchronization.)
308 const float ptsBehindThreshold
= 1.0; // seconds
309 const float ptsBehindLimit
= 60.0; // seconds
310 if (ptsBehind
< ptsBehindThreshold
||
311 ptsBehind
> ptsBehindLimit
||
312 rtspStreamOverTCP
) { // packet's OK
313 ds_add_packet(ds
, dp
);
317 #ifdef DEBUG_PRINT_DISCARDED_PACKETS
318 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
319 ReadBufferQueue
* bufferQueue
= ds
== demuxer
->video
? rtpState
->videoBufferQueue
: rtpState
->audioBufferQueue
;
320 fprintf(stderr
, "Discarding %s packet (%fs behind)\n", bufferQueue
->tag(), ptsBehind
);
322 free_demux_packet(dp
); // give back this packet, and get another one
328 Boolean
awaitRTPPacket(demuxer_t
* demuxer
, demux_stream_t
* ds
,
329 unsigned char*& packetData
, unsigned& packetDataLen
,
331 // Similar to "demux_rtp_fill_buffer()", except that the "demux_packet"
332 // is not delivered to the "demux_stream".
334 demux_packet_t
* dp
= getBuffer(demuxer
, ds
, True
, ptsBehind
); // blocking
335 if (dp
== NULL
) return False
;
337 packetData
= dp
->buffer
;
338 packetDataLen
= dp
->len
;
344 static void teardownRTSPorSIPSession(RTPState
* rtpState
); // forward
346 extern "C" void demux_close_rtp(demuxer_t
* demuxer
) {
347 // Reclaim all RTP-related state:
349 // Get the RTP state that was stored in the demuxer's 'priv' field:
350 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
351 if (rtpState
== NULL
) return;
353 teardownRTSPorSIPSession(rtpState
);
355 UsageEnvironment
* env
= NULL
;
356 TaskScheduler
* scheduler
= NULL
;
357 if (rtpState
->mediaSession
!= NULL
) {
358 env
= &(rtpState
->mediaSession
->envir());
359 scheduler
= &(env
->taskScheduler());
361 Medium::close(rtpState
->mediaSession
);
362 Medium::close(rtpState
->rtspClient
);
363 Medium::close(rtpState
->sipClient
);
364 delete rtpState
->audioBufferQueue
;
365 delete rtpState
->videoBufferQueue
;
366 delete rtpState
->sdpDescription
;
369 env
->reclaim(); delete scheduler
;
372 ////////// Extra routines that help implement the above interface functions:
374 #define MAX_RTP_FRAME_SIZE 50000
375 // >= the largest conceivable frame composed from one or more RTP packets
377 static void afterReading(void* clientData
, unsigned frameSize
,
378 unsigned /*numTruncatedBytes*/,
379 struct timeval presentationTime
,
380 unsigned /*durationInMicroseconds*/) {
382 if (frameSize
>= MAX_RTP_FRAME_SIZE
) {
383 fprintf(stderr
, "Saw an input frame too large (>=%d). Increase MAX_RTP_FRAME_SIZE in \"demux_rtp.cpp\".\n",
386 ReadBufferQueue
* bufferQueue
= (ReadBufferQueue
*)clientData
;
387 demuxer_t
* demuxer
= bufferQueue
->ourDemuxer();
388 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
390 if (frameSize
> 0) demuxer
->stream
->eof
= 0;
392 demux_packet_t
* dp
= bufferQueue
->dp
;
394 if (bufferQueue
->readSource()->isAMRAudioSource())
396 else if (bufferQueue
== rtpState
->videoBufferQueue
&&
397 ((sh_video_t
*)demuxer
->video
->sh
)->format
== mmioFOURCC('H','2','6','4')) {
404 resize_demux_packet(dp
, frameSize
+ headersize
);
406 // Set the packet's presentation time stamp, depending on whether or
407 // not our RTP source's timestamps have been synchronized yet:
408 Boolean hasBeenSynchronized
409 = bufferQueue
->rtpSource()->hasBeenSynchronizedUsingRTCP();
410 if (hasBeenSynchronized
) {
411 if (verbose
> 0 && !bufferQueue
->prevPacketWasSynchronized
) {
412 fprintf(stderr
, "%s stream has been synchronized using RTCP \n",
416 struct timeval
* fst
= &(rtpState
->firstSyncTime
); // abbrev
417 if (fst
->tv_sec
== 0 && fst
->tv_usec
== 0) {
418 *fst
= presentationTime
;
421 // For the "pts" field, use the time differential from the first
422 // synchronized time, rather than absolute time, in order to avoid
423 // round-off errors when converting to a float:
424 dp
->pts
= presentationTime
.tv_sec
- fst
->tv_sec
425 + (presentationTime
.tv_usec
- fst
->tv_usec
)/1000000.0;
426 bufferQueue
->prevPacketPTS
= dp
->pts
;
428 if (verbose
> 0 && bufferQueue
->prevPacketWasSynchronized
) {
429 fprintf(stderr
, "%s stream is no longer RTCP-synchronized \n",
433 // use the previous packet's "pts" once again:
434 dp
->pts
= bufferQueue
->prevPacketPTS
;
436 bufferQueue
->prevPacketWasSynchronized
= hasBeenSynchronized
;
438 dp
->pos
= demuxer
->filepos
;
439 demuxer
->filepos
+= frameSize
+ headersize
;
441 // Signal any pending 'doEventLoop()' call on this queue:
442 bufferQueue
->blockingFlag
= ~0;
445 static void onSourceClosure(void* clientData
) {
446 ReadBufferQueue
* bufferQueue
= (ReadBufferQueue
*)clientData
;
447 demuxer_t
* demuxer
= bufferQueue
->ourDemuxer();
449 demuxer
->stream
->eof
= 1;
451 // Signal any pending 'doEventLoop()' call on this queue:
452 bufferQueue
->blockingFlag
= ~0;
455 static demux_packet_t
* getBuffer(demuxer_t
* demuxer
, demux_stream_t
* ds
,
456 Boolean mustGetNewData
,
458 // Begin by finding the buffer queue that we want to read from:
459 // (Get this from the RTP state, which we stored in
460 // the demuxer's 'priv' field)
461 RTPState
* rtpState
= (RTPState
*)(demuxer
->priv
);
462 ReadBufferQueue
* bufferQueue
= NULL
;
466 if (demuxer
->stream
->eof
) return NULL
;
468 if (ds
== demuxer
->video
) {
469 bufferQueue
= rtpState
->videoBufferQueue
;
470 if (((sh_video_t
*)ds
->sh
)->format
== mmioFOURCC('H','2','6','4'))
472 } else if (ds
== demuxer
->audio
) {
473 bufferQueue
= rtpState
->audioBufferQueue
;
474 if (bufferQueue
->readSource()->isAMRAudioSource())
477 fprintf(stderr
, "(demux_rtp)getBuffer: internal error: unknown stream\n");
481 if (bufferQueue
== NULL
|| bufferQueue
->readSource() == NULL
) {
482 fprintf(stderr
, "(demux_rtp)getBuffer failed: no appropriate RTP subsession has been set up\n");
486 demux_packet_t
* dp
= NULL
;
487 if (!mustGetNewData
) {
488 // Check whether we have a previously-saved buffer that we can use:
489 dp
= bufferQueue
->getPendingBuffer();
491 ptsBehind
= 0.0; // so that we always accept this data
496 // Allocate a new packet buffer, and arrange to read into it:
497 if (!bufferQueue
->nextpacket
) {
498 dp
= new_demux_packet(MAX_RTP_FRAME_SIZE
);
499 bufferQueue
->dp
= dp
;
500 if (dp
== NULL
) return NULL
;
503 #ifdef USE_LIBAVCODEC
504 extern AVCodecParserContext
* h264parserctx
;
505 int consumed
, poutbuf_size
= 1;
506 const uint8_t *poutbuf
= NULL
;
510 if (!bufferQueue
->nextpacket
) {
512 // Schedule the read operation:
513 bufferQueue
->blockingFlag
= 0;
514 bufferQueue
->readSource()->getNextFrame(&dp
->buffer
[headersize
], MAX_RTP_FRAME_SIZE
- headersize
,
515 afterReading
, bufferQueue
,
516 onSourceClosure
, bufferQueue
);
517 // Block ourselves until data becomes available:
518 TaskScheduler
& scheduler
519 = bufferQueue
->readSource()->envir().taskScheduler();
520 int delay
= 10000000;
521 if (bufferQueue
->prevPacketPTS
* 1.05 > rtpState
->mediaSession
->playEndTime())
523 task
= scheduler
.scheduleDelayedTask(delay
, onSourceClosure
, bufferQueue
);
524 scheduler
.doEventLoop(&bufferQueue
->blockingFlag
);
525 scheduler
.unscheduleDelayedTask(task
);
526 if (demuxer
->stream
->eof
) {
527 free_demux_packet(dp
);
531 if (headersize
== 1) // amr
533 ((AMRAudioSource
*)bufferQueue
->readSource())->lastFrameHeader();
534 #ifdef USE_LIBAVCODEC
536 bufferQueue
->dp
= dp
= bufferQueue
->nextpacket
;
537 bufferQueue
->nextpacket
= NULL
;
539 if (headersize
== 3 && h264parserctx
) { // h264
540 consumed
= h264parserctx
->parser
->parser_parse(h264parserctx
,
542 &poutbuf
, &poutbuf_size
,
543 dp
->buffer
, dp
->len
);
545 if (!consumed
&& !poutbuf_size
)
550 free_demux_packet(dp
);
551 bufferQueue
->dp
= dp
= new_demux_packet(MAX_RTP_FRAME_SIZE
);
553 bufferQueue
->nextpacket
= dp
;
554 bufferQueue
->dp
= dp
= new_demux_packet(poutbuf_size
);
555 memcpy(dp
->buffer
, poutbuf
, poutbuf_size
);
559 } while (!poutbuf_size
);
562 // Set the "ptsBehind" result parameter:
563 if (bufferQueue
->prevPacketPTS
!= 0.0
564 && bufferQueue
->prevPacketWasSynchronized
565 && *(bufferQueue
->otherQueue
) != NULL
566 && (*(bufferQueue
->otherQueue
))->prevPacketPTS
!= 0.0
567 && (*(bufferQueue
->otherQueue
))->prevPacketWasSynchronized
) {
568 ptsBehind
= (*(bufferQueue
->otherQueue
))->prevPacketPTS
569 - bufferQueue
->prevPacketPTS
;
574 if (mustGetNewData
) {
575 // Save this buffer for future reads:
576 bufferQueue
->savePendingBuffer(dp
);
582 static void teardownRTSPorSIPSession(RTPState
* rtpState
) {
583 MediaSession
* mediaSession
= rtpState
->mediaSession
;
584 if (mediaSession
== NULL
) return;
585 if (rtpState
->rtspClient
!= NULL
) {
586 rtpState
->rtspClient
->teardownMediaSession(*mediaSession
);
587 } else if (rtpState
->sipClient
!= NULL
) {
588 rtpState
->sipClient
->sendBYE();
592 ////////// "ReadBuffer" and "ReadBufferQueue" implementation:
594 ReadBufferQueue::ReadBufferQueue(MediaSubsession
* subsession
,
595 demuxer_t
* demuxer
, char const* tag
)
596 : prevPacketWasSynchronized(False
), prevPacketPTS(0.0), otherQueue(NULL
),
597 dp(NULL
), nextpacket(NULL
),
598 pendingDPHead(NULL
), pendingDPTail(NULL
),
599 fReadSource(subsession
== NULL
? NULL
: subsession
->readSource()),
600 fRTPSource(subsession
== NULL
? NULL
: subsession
->rtpSource()),
601 fOurDemuxer(demuxer
), fTag(strdup(tag
)) {
604 ReadBufferQueue::~ReadBufferQueue() {
607 // Free any pending buffers (that never got delivered):
608 demux_packet_t
* dp
= pendingDPHead
;
610 demux_packet_t
* dpNext
= dp
->next
;
612 free_demux_packet(dp
);
617 void ReadBufferQueue::savePendingBuffer(demux_packet_t
* dp
) {
618 // Keep this buffer around, until MPlayer asks for it later:
619 if (pendingDPTail
== NULL
) {
620 pendingDPHead
= pendingDPTail
= dp
;
622 pendingDPTail
->next
= dp
;
628 demux_packet_t
* ReadBufferQueue::getPendingBuffer() {
629 demux_packet_t
* dp
= pendingDPHead
;
631 pendingDPHead
= dp
->next
;
632 if (pendingDPHead
== NULL
) pendingDPTail
= NULL
;
640 static int demux_rtp_control(struct demuxer_st
*demuxer
, int cmd
, void *arg
) {
641 double endpts
= ((RTPState
*)demuxer
->priv
)->mediaSession
->playEndTime();
644 case DEMUXER_CTRL_GET_TIME_LENGTH
:
646 return DEMUXER_CTRL_DONTKNOW
;
647 *((double *)arg
) = endpts
;
648 return DEMUXER_CTRL_OK
;
650 case DEMUXER_CTRL_GET_PERCENT_POS
:
652 return DEMUXER_CTRL_DONTKNOW
;
653 *((int *)arg
) = (int)(((RTPState
*)demuxer
->priv
)->videoBufferQueue
->prevPacketPTS
*100/endpts
);
654 return DEMUXER_CTRL_OK
;
657 return DEMUXER_CTRL_NOTIMPL
;
661 demuxer_desc_t demuxer_desc_rtp
= {
662 "LIVE555 RTP demuxer",
666 "requires LIVE555 Streaming Media library",
670 demux_rtp_fill_buffer
,