Annotation of multiplexer/splice.c, revision 1.1
1.1 ! oskar 1: /*
! 2: * ISO 13818 stream multiplexer
! 3: * Copyright (C) 2001 Convergence Integrated Media GmbH Berlin
! 4: * Author: Oskar Schirmer (oskar@convergence.de)
! 5: */
! 6:
! 7: /*
! 8: * Module: Splice
! 9: * Purpose: Service functions for specific Splice* modules
! 10: *
! 11: * This module provides functions needed for splicing
! 12: * which are independent from the splice type.
! 13: */
! 14:
! 15: #include "global.h"
! 16: #include "error.h"
! 17: #include "splice.h"
! 18: #include "input.h"
! 19: #include "pes.h"
! 20:
! 21: stream_descr *connect_streamprog (file_descr *f,
! 22: int programnb,
! 23: int sourceid,
! 24: int streamid,
! 25: int streamtype,
! 26: stream_descr *stream,
! 27: stream_descr *mapstream,
! 28: boolean mention)
! 29: {
! 30: stream_descr *s;
! 31: prog_descr *p;
! 32: if (stream == NULL) {
! 33: s = input_openstream (f,sourceid,streamid<0?-streamid:streamid,
! 34: streamtype,FALSE,mapstream);
! 35: } else {
! 36: if (streamid < 0) {
! 37: streamid = -streamid;
! 38: warn (LWAR,"Cannot refind sid",EINP,14,1,streamid);
! 39: }
! 40: s = stream;
! 41: }
! 42: if (s != NULL) {
! 43: p = splice_openprog (programnb);
! 44: if (p != NULL) {
! 45: if (input_addprog (s,p)) {
! 46: if (splice_addstream (p,s,streamid>=0) > 0) {
! 47: /*
! 48: if (p->pcr_pid < 0) {
! 49: if (xxx) {
! 50: p->pcr_pid = s->u.d.pid;
! 51: s->u.d.has_clockref = TRUE;
! 52: s->u.d.next_clockref = msec_now () - MAX_MSEC_PCRDIST;
! 53: }
! 54: }
! 55: */
! 56: s->endaction = ENDSTR_WAIT;
! 57: s->u.d.mention = mention;
! 58: return (s);
! 59: }
! 60: input_delprog (s,p);
! 61: }
! 62: if (p->streams <= 0) {
! 63: splice_closeprog (p);
! 64: }
! 65: }
! 66: if (stream == NULL) {
! 67: input_closestream (s);
! 68: }
! 69: }
! 70: return (stream);
! 71: }
! 72:
! 73: void unlink_streamprog (stream_descr *s,
! 74: prog_descr *p)
! 75: {
! 76: splice_delstream (p,s);
! 77: input_delprog (s,p);
! 78: if (s->u.d.progs <= 0) {
! 79: file_descr *f;
! 80: f = s->fdescr;
! 81: input_closestream (s);
! 82: input_closefileifunused (f);
! 83: }
! 84: }
! 85:
! 86: void remove_streamprog (stream_descr *s,
! 87: prog_descr *p)
! 88: {
! 89: int i;
! 90: i = s->u.d.progs;
! 91: while (--i >= 0) {
! 92: if (s->u.d.pdescr[i] == p) {
! 93: if (p->streams > 1) {
! 94: unlink_streamprog (s,p);
! 95: } else {
! 96: splice_closeprog (s->u.d.pdescr[i]);
! 97: }
! 98: break;
! 99: }
! 100: }
! 101: }
! 102:
! 103: stream_descr *get_streamprog (prog_descr *p,
! 104: int streamid)
! 105: {
! 106: int i;
! 107: i = p->streams;
! 108: while (--i >= 0) {
! 109: stream_descr *s;
! 110: s = p->stream[i];
! 111: if (s->stream_id == streamid) {
! 112: return (s);
! 113: }
! 114: }
! 115: return (NULL);
! 116: }
! 117:
! 118: int splice_findfreestreamid (prog_descr *p,
! 119: int sid)
! 120: {
! 121: int s, n;
! 122: if ((sid >= PES_CODE_AUDIO)
! 123: && (sid < (PES_CODE_AUDIO+PES_NUMB_AUDIO))) {
! 124: s = PES_CODE_AUDIO;
! 125: n = PES_NUMB_AUDIO-1;
! 126: } else if ((sid >= PES_CODE_VIDEO)
! 127: && (sid < (PES_CODE_VIDEO+PES_NUMB_VIDEO))) {
! 128: s = PES_CODE_VIDEO;
! 129: n = PES_NUMB_VIDEO-1;
! 130: } else {
! 131: s = sid;
! 132: n = 0;
! 133: }
! 134: while (--n >= 0) {
! 135: int i;
! 136: i = p->streams;
! 137: while ((--i >= 0)
! 138: && (p->stream[i]->stream_id != s)) {
! 139: }
! 140: if (i < 0) {
! 141: warn (LIMP,"Found SID free",EINP,15,sid,s);
! 142: return (s);
! 143: }
! 144: s += 1;
! 145: }
! 146: warn (LIMP,"Found SID",EINP,15,sid,s);
! 147: return (s);
! 148: }
! 149:
! 150: stream_descr *splice_findpcrstream (prog_descr *p)
! 151: {
! 152: int i;
! 153: pmt_descr *pmt;
! 154: warn (LIMP,"Find PCR Stream",EINP,13,0,p->program_number);
! 155: i = p->streams;
! 156: while (--i >= 0) {
! 157: if (p->stream[i]->fdescr->content == ct_transport) {
! 158: pmt = p->stream[i]->fdescr->u.ts.pat;
! 159: while (pmt != NULL) {
! 160: if (pmt->pcr_pid == p->stream[i]->sourceid) {
! 161: warn (LIMP,"Found PCR Stream",EINP,13,1,p->stream[i]->sourceid);
! 162: return (p->stream[i]);
! 163: }
! 164: pmt = pmt->next;
! 165: }
! 166: }
! 167: }
! 168: return (NULL);
! 169: }
! 170:
LinuxTV legacy CVS <linuxtv.org/cvs>