--- multiplexer/splice.c 2001/04/03 21:14:33 1.1 +++ multiplexer/splice.c 2001/04/09 15:26:03 1.2 @@ -18,6 +18,15 @@ #include "input.h" #include "pes.h" +/* Connect a stream with a target program. + * programnb denotes the program to connect, + * stream is the stream to connect, + * all further parameters are as with input_openstream. + * If stream is NULL, open a stream first. + * Add the stream to the programs list of streams and vice versa. + * Precondition: f!=NULL + * Return: the changed stream on success, the unchanged "stream" otherwise + */ stream_descr *connect_streamprog (file_descr *f, int programnb, int sourceid, @@ -69,7 +78,13 @@ stream_descr *connect_streamprog (file_d } return (stream); } - + +/* Unlink a stream from a target program. + * If the stream comes out to be in no program then, close it. + * This function may be used only, if the program in question will either + * be non-empty after the call, or will be closed by the calling function. + * Precondition: s!=NULL, p!=NULL + */ void unlink_streamprog (stream_descr *s, prog_descr *p) { @@ -82,24 +97,25 @@ void unlink_streamprog (stream_descr *s, input_closefileifunused (f); } } - + +/* Remove a stream from a target program. + * Close stream and/or program, if not contained in another program or stream. + * Precondition: s!=NULL, p!=NULL, s is stream in target program p + */ void remove_streamprog (stream_descr *s, prog_descr *p) { - int i; - i = s->u.d.progs; - while (--i >= 0) { - if (s->u.d.pdescr[i] == p) { - if (p->streams > 1) { - unlink_streamprog (s,p); - } else { - splice_closeprog (s->u.d.pdescr[i]); - } - break; - } + if (p->streams > 1) { + unlink_streamprog (s,p); + } else { + splice_closeprog (p); } } +/* Find the right stream in a program + * Precondition: p!=NULL + * Return: stream, if found, NULL otherwise + */ stream_descr *get_streamprog (prog_descr *p, int streamid) { @@ -115,38 +131,48 @@ stream_descr *get_streamprog (prog_descr return (NULL); } +/* Find a free stream ID in a program that is equivalent to the given stream id + * Precondition: p!=NULL + * Return: Free ID, if found; given sid otherwise. + */ int splice_findfreestreamid (prog_descr *p, int sid) { - int s, n; + int s0, s, n; + s0 = sid; if ((sid >= PES_CODE_AUDIO) && (sid < (PES_CODE_AUDIO+PES_NUMB_AUDIO))) { s = PES_CODE_AUDIO; - n = PES_NUMB_AUDIO-1; + n = PES_NUMB_AUDIO; } else if ((sid >= PES_CODE_VIDEO) && (sid < (PES_CODE_VIDEO+PES_NUMB_VIDEO))) { s = PES_CODE_VIDEO; - n = PES_NUMB_VIDEO-1; + n = PES_NUMB_VIDEO; } else { s = sid; - n = 0; + n = 1; } while (--n >= 0) { int i; i = p->streams; while ((--i >= 0) - && (p->stream[i]->stream_id != s)) { + && (p->stream[i]->stream_id != s0)) { } if (i < 0) { - warn (LIMP,"Found SID free",EINP,15,sid,s); - return (s); + warn (LIMP,"Found SID free",EINP,15,sid,s0); + return (s0); } + s0 = s; s += 1; } - warn (LIMP,"Found SID",EINP,15,sid,s); - return (s); + warn (LIMP,"Found SID",EINP,15,sid,sid); + return (sid); } +/* Check if there is a source pcr stream in a target program + * Precondition: p!=NULL + * Return: pcr-stream, if found; NULL otherwise. + */ stream_descr *splice_findpcrstream (prog_descr *p) { int i;