summaryrefslogtreecommitdiffstats
path: root/libmpdemux/demux_ts.c
diff options
context:
space:
mode:
authornicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-11-18 14:32:14 +0000
committernicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-11-18 14:32:14 +0000
commitbdc75c29ae1380b86783b0c7f82a4ade472fff39 (patch)
tree90d6da6e5da97a68c37aca86e8342a9b4b1e5e2a /libmpdemux/demux_ts.c
parentc97dc5061d8379090e1a3d88156c6fb229d573f6 (diff)
downloadmpv-bdc75c29ae1380b86783b0c7f82a4ade472fff39.tar.bz2
mpv-bdc75c29ae1380b86783b0c7f82a4ade472fff39.tar.xz
implemented DEMUXER_CTRL_IDENTIFY_PROGRAM
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@21022 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux/demux_ts.c')
-rw-r--r--libmpdemux/demux_ts.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/libmpdemux/demux_ts.c b/libmpdemux/demux_ts.c
index 72a678fb6c..54812d7f15 100644
--- a/libmpdemux/demux_ts.c
+++ b/libmpdemux/demux_ts.c
@@ -3163,6 +3163,24 @@ static int ts_check_file_dmx(demuxer_t *demuxer)
return ts_check_file(demuxer) ? DEMUXER_TYPE_MPEG_TS : 0;
}
+static int is_usable_program(ts_priv_t *priv, pmt_t *pmt)
+{
+ int j;
+
+ for(j = 0; j < pmt->es_cnt; j++)
+ {
+ if(priv->ts.pids[pmt->es[j].pid] == NULL || priv->ts.streams[pmt->es[j].pid].sh == NULL)
+ continue;
+ if(
+ priv->ts.streams[pmt->es[j].pid].type == TYPE_VIDEO ||
+ priv->ts.streams[pmt->es[j].pid].type == TYPE_AUDIO
+ )
+ return 1;
+ }
+
+ return 0;
+}
+
static int demux_ts_control(demuxer_t *demuxer, int cmd, void *arg)
{
ts_priv_t* priv = (ts_priv_t *)demuxer->priv;
@@ -3277,6 +3295,73 @@ static int demux_ts_control(demuxer_t *demuxer, int cmd, void *arg)
return DEMUXER_CTRL_OK;
}
+ case DEMUXER_CTRL_IDENTIFY_PROGRAM: //returns in prog->{aid,vid} the new ids that comprise a program
+ {
+ int i, j, cnt=0;
+ int vid_done=0, aid_done=0;
+ pmt_t *pmt = NULL;
+ demux_program_t *prog = arg;
+
+ if(priv->pmt_cnt < 2)
+ return DEMUXER_CTRL_NOTIMPL;
+
+ if(prog->progid == -1)
+ {
+ int cur_pmt_idx = 0;
+
+ for(i = 0; i < priv->pmt_cnt; i++)
+ if(priv->pmt[i].progid == priv->prog)
+ {
+ cur_pmt_idx = i;
+ break;
+ }
+
+ i = (cur_pmt_idx + 1) % priv->pmt_cnt;
+ while(i != cur_pmt_idx)
+ {
+ pmt = &priv->pmt[i];
+ cnt = is_usable_program(priv, pmt);
+ if(cnt)
+ break;
+ i = (i + 1) % priv->pmt_cnt;
+ }
+ }
+ else
+ {
+ for(i = 0; i < priv->pmt_cnt; i++)
+ if(priv->pmt[i].progid == prog->progid)
+ {
+ pmt = &priv->pmt[i]; //required program
+ cnt = is_usable_program(priv, pmt);
+ }
+ }
+
+ if(!cnt)
+ return DEMUXER_CTRL_NOTIMPL;
+
+ //finally some food
+ prog->aid = prog->vid = -2; //no audio and no video by default
+ for(j = 0; j < pmt->es_cnt; j++)
+ {
+ if(priv->ts.pids[pmt->es[j].pid] == NULL || priv->ts.streams[pmt->es[j].pid].sh == NULL)
+ continue;
+
+ if(!vid_done && priv->ts.streams[pmt->es[j].pid].type == TYPE_VIDEO)
+ {
+ vid_done = 1;
+ prog->vid = priv->ts.streams[pmt->es[j].pid].id;
+ }
+ else if(!aid_done && priv->ts.streams[pmt->es[j].pid].type == TYPE_AUDIO)
+ {
+ aid_done = 1;
+ prog->aid = priv->ts.streams[pmt->es[j].pid].id;
+ }
+ }
+
+ priv->prog = prog->progid = pmt->progid;
+ return DEMUXER_CTRL_OK;
+ }
+
default:
return DEMUXER_CTRL_NOTIMPL;
}