mirror of https://github.com/mpv-player/mpv
Refactor demux_nemesi (from amol)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25025 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
a74197b43f
commit
979c51209f
|
@ -38,6 +38,33 @@ typedef struct {
|
||||||
double seek;
|
double seek;
|
||||||
} Nemesi_DemuxerStreamData;
|
} Nemesi_DemuxerStreamData;
|
||||||
|
|
||||||
|
|
||||||
|
#define STYPE_TO_DS(demuxer, stype) \
|
||||||
|
((stype) == NEMESI_SESSION_VIDEO ? (demuxer)->video : (demuxer)->audio)
|
||||||
|
|
||||||
|
#define DS_TO_STYPE(demuxer, ds) \
|
||||||
|
((ds) == (demuxer)->video ? NEMESI_SESSION_VIDEO : NEMESI_SESSION_AUDIO)
|
||||||
|
|
||||||
|
#define INVERT_STYPE(stype) ((stype + 1) % 2)
|
||||||
|
|
||||||
|
|
||||||
|
static rtp_ssrc *wait_for_packets(Nemesi_DemuxerStreamData * ndsd, Nemesi_SessionType stype)
|
||||||
|
{
|
||||||
|
rtp_ssrc *ssrc = NULL;
|
||||||
|
|
||||||
|
/* Wait for prebuffering (prebuffering must be enabled in nemesi) */
|
||||||
|
int terminated = rtp_fill_buffers(rtsp_get_rtp_th(ndsd->rtsp));
|
||||||
|
|
||||||
|
/* Wait for the ssrc to be registered, if prebuffering is on in nemesi
|
||||||
|
this will just get immediatly the correct ssrc */
|
||||||
|
if (!terminated) {
|
||||||
|
while ( !(ssrc = rtp_session_get_ssrc(ndsd->session[stype], ndsd->rtsp)) )
|
||||||
|
sched_yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ssrc;
|
||||||
|
}
|
||||||
|
|
||||||
static void link_session_and_fetch_conf(Nemesi_DemuxerStreamData * ndsd,
|
static void link_session_and_fetch_conf(Nemesi_DemuxerStreamData * ndsd,
|
||||||
Nemesi_SessionType stype,
|
Nemesi_SessionType stype,
|
||||||
rtp_session * sess,
|
rtp_session * sess,
|
||||||
|
@ -45,28 +72,23 @@ static void link_session_and_fetch_conf(Nemesi_DemuxerStreamData * ndsd,
|
||||||
{
|
{
|
||||||
extern float force_fps;
|
extern float force_fps;
|
||||||
rtp_ssrc *ssrc = NULL;
|
rtp_ssrc *ssrc = NULL;
|
||||||
rtsp_ctrl * ctl = ndsd->rtsp;
|
|
||||||
rtp_frame * fr = &ndsd->first_pkt[stype];
|
rtp_frame * fr = &ndsd->first_pkt[stype];
|
||||||
rtp_buff trash_buff;
|
rtp_buff trash_buff;
|
||||||
|
|
||||||
ndsd->session[stype] = sess;
|
ndsd->session[stype] = sess;
|
||||||
|
|
||||||
if (buff == NULL)
|
ssrc = wait_for_packets(ndsd, stype);
|
||||||
buff = &trash_buff;
|
|
||||||
|
|
||||||
if ( (buff != NULL) || (fps != NULL) ) {
|
if ( (ssrc) && (fps != NULL) ) {
|
||||||
while ( !(ssrc = rtp_session_get_ssrc(sess, ctl)) ) //Wait for the ssrc to be registered
|
if (buff == NULL)
|
||||||
sched_yield();
|
buff = &trash_buff;
|
||||||
|
|
||||||
rtp_fill_buffer(ssrc, fr, buff); //Prefetch the first packet
|
rtp_fill_buffer(ssrc, fr, buff); //Prefetch the first packet
|
||||||
|
while ( !(rtp_get_pkt(ssrc, NULL)) ) //Wait second pkt to calculate FPS
|
||||||
while ( !(rtp_get_pkt(ssrc, NULL)) ) //Wait for the second packet to calculate FPS
|
|
||||||
sched_yield();
|
sched_yield();
|
||||||
|
|
||||||
if ( (force_fps == 0.0) && (fps != NULL) ) {
|
if ( (force_fps == 0.0) && (fps != NULL) )
|
||||||
rtp_fill_buffers(rtsp_get_rtp_th(ctl));
|
|
||||||
*fps = rtp_get_fps(ssrc);
|
*fps = rtp_get_fps(ssrc);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,75 +263,63 @@ demuxer_t* demux_open_rtp(demuxer_t* demuxer)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_data_for_session(Nemesi_DemuxerStreamData * ndsd,
|
static int get_data_for_session(Nemesi_DemuxerStreamData * ndsd,
|
||||||
Nemesi_SessionType stype, rtp_frame * fr)
|
Nemesi_SessionType stype, rtp_ssrc * ssrc,
|
||||||
|
rtp_frame * fr)
|
||||||
{
|
{
|
||||||
rtsp_ctrl * ctl = ndsd->rtsp;
|
if (ndsd->first_pkt[stype].len != 0) {
|
||||||
rtp_ssrc *ssrc = NULL;
|
fr->data = ndsd->first_pkt[stype].data;
|
||||||
|
fr->time_sec = ndsd->first_pkt[stype].time_sec;
|
||||||
for (ssrc = rtp_active_ssrc_queue(rtsp_get_rtp_queue(ctl));
|
fr->len = ndsd->first_pkt[stype].len;
|
||||||
ssrc;
|
ndsd->first_pkt[stype].len = 0;
|
||||||
ssrc = rtp_next_active_ssrc(ssrc)) {
|
return RTP_FILL_OK;
|
||||||
if (ssrc->rtp_sess == ndsd->session[stype]) {
|
} else {
|
||||||
if (ndsd->first_pkt[stype].len != 0) {
|
rtp_buff buff;
|
||||||
fr->data = ndsd->first_pkt[stype].data;
|
return rtp_fill_buffer(ssrc, fr, &buff);
|
||||||
fr->time_sec = ndsd->first_pkt[stype].time_sec;
|
|
||||||
fr->len = ndsd->first_pkt[stype].len;
|
|
||||||
ndsd->first_pkt[stype].len = 0;
|
|
||||||
return RTP_FILL_OK;
|
|
||||||
} else {
|
|
||||||
rtp_buff buff;
|
|
||||||
return rtp_fill_buffer(ssrc, fr, &buff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return RTP_SSRC_NOTVALID;
|
static void stream_add_packet(Nemesi_DemuxerStreamData * ndsd,
|
||||||
|
Nemesi_SessionType stype,
|
||||||
|
demux_stream_t* ds, rtp_frame * fr)
|
||||||
|
{
|
||||||
|
demux_packet_t* dp = new_demux_packet(fr->len);
|
||||||
|
memcpy(dp->buffer, fr->data, fr->len);
|
||||||
|
|
||||||
|
fr->time_sec += ndsd->seek;
|
||||||
|
ndsd->time[stype] = dp->pts = fr->time_sec;
|
||||||
|
|
||||||
|
ds_add_packet(ds, dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int demux_rtp_fill_buffer(demuxer_t* demuxer, demux_stream_t* ds)
|
int demux_rtp_fill_buffer(demuxer_t* demuxer, demux_stream_t* ds)
|
||||||
{
|
{
|
||||||
Nemesi_DemuxerStreamData * ndsd = demuxer->priv;
|
Nemesi_DemuxerStreamData * ndsd = demuxer->priv;
|
||||||
Nemesi_SessionType stype;
|
Nemesi_SessionType stype;
|
||||||
rtsp_ctrl * ctl = ndsd->rtsp;
|
rtp_ssrc * ssrc;
|
||||||
rtp_thread * rtp_th = rtsp_get_rtp_th(ctl);
|
|
||||||
rtp_frame fr;
|
rtp_frame fr;
|
||||||
|
|
||||||
demux_packet_t* dp;
|
if ( (!ndsd->rtsp->rtsp_queue) || (demuxer->stream->eof) ) {
|
||||||
|
|
||||||
if ( (!ctl->rtsp_queue) || (demuxer->stream->eof) || (rtp_fill_buffers(rtp_th)) ) {
|
|
||||||
mp_msg(MSGT_DEMUX, MSGL_INFO, "End of Stream...\n");
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "End of Stream...\n");
|
||||||
demuxer->stream->eof = 1;
|
demuxer->stream->eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ds == demuxer->video)
|
stype = DS_TO_STYPE(demuxer, ds);
|
||||||
stype = NEMESI_SESSION_VIDEO;
|
if ( (ssrc = wait_for_packets(ndsd, stype)) == NULL ) {
|
||||||
else if (ds == demuxer->audio)
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "Bye...\n");
|
||||||
stype = NEMESI_SESSION_AUDIO;
|
demuxer->stream->eof = 1;
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(!get_data_for_session(ndsd, stype, &fr)) {
|
|
||||||
dp = new_demux_packet(fr.len);
|
|
||||||
memcpy(dp->buffer, fr.data, fr.len);
|
|
||||||
fr.time_sec += ndsd->seek;
|
|
||||||
ndsd->time[stype] = dp->pts = fr.time_sec;
|
|
||||||
ds_add_packet(ds, dp);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
stype = (stype + 1) % 2;
|
|
||||||
if (stype == NEMESI_SESSION_VIDEO)
|
|
||||||
ds = demuxer->video;
|
|
||||||
else
|
|
||||||
ds = demuxer->audio;
|
|
||||||
|
|
||||||
if(!get_data_for_session(ndsd, stype, &fr)) {
|
if(!get_data_for_session(ndsd, stype, ssrc, &fr))
|
||||||
dp = new_demux_packet(fr.len);
|
stream_add_packet(ndsd, stype, ds, &fr);
|
||||||
memcpy(dp->buffer, fr.data, fr.len);
|
else {
|
||||||
fr.time_sec += ndsd->seek;
|
stype = INVERT_STYPE(stype);
|
||||||
ndsd->time[stype] = dp->pts = fr.time_sec;
|
ds = STYPE_TO_DS(demuxer, stype);
|
||||||
ds_add_packet(ds, dp);
|
ssrc = wait_for_packets(ndsd, stype);
|
||||||
}
|
|
||||||
|
if(!get_data_for_session(ndsd, stype, ssrc, &fr))
|
||||||
|
stream_add_packet(ndsd, stype, ds, &fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue