diff options
Diffstat (limited to 'teletext.c')
-rw-r--r-- | teletext.c | 415 |
1 files changed, 0 insertions, 415 deletions
@@ -330,418 +330,3 @@ void print_line(char *p) dprint("\n"); } - - -#if 0 -void -show_page(struct ttxt_page *p) -{ - static cOsdBase *o = NULL; - static tWindowHandle w1 = 0; - static tWindowHandle w2 = 0; - static int open1 = 0, open2 = 0; - char *s1 = NULL, *s2 = NULL; - int i, j; - - for(i = 1; i < TTXT_ROWS; i++) { - char *s = NULL; - if(p->data[i][0]) { - int do_incr = 0; - dprint("Checking row %d\n", i); - for(j = 0; j < 40; j++) { - p->data[i][j] = p->data[i][j] & 0x7f; - switch(p->data[i][j]) { - case 0x0d: // double height - case 0x0f: // double size - do_incr = 1; - break; - case 0x0a: // box end - p->data[i][j] = '\0'; - break; - case 0x0b: // box begin - s = (char *) &(p->data[i][j+1]); - dprint("Using row %d\n", i); - break; - case '[': - p->data[i][j] = 'Ä'; - break; - case ']': - p->data[i][j] = 'Å'; - break; - case '\\': - p->data[i][j] = 'Ö'; - break; - case '{': - p->data[i][j] = 'ä'; - break; - case '}': - p->data[i][j] = 'å'; - break; - case '|': - p->data[i][j] = 'ö'; - break; - } - } - if(do_incr) - i++; - dprint("\n"); - } - - if(s) - if(!s1) - s1 = s; - else if(!s2) - s2 = s; - } - - if(s1 && !s2) { - s2 = s1; - s1 = NULL; - } - - if(s1) - dprint("S1: %s\n", s1); - else - dprint("S1: <none>\n"); - if(s2) - dprint("S2: %s\n", s2); - else - dprint("S2: <none>\n"); - - if(o != NULL) { - if(open1) { - o->Clear(w1); - open1 = 0; - } - if(open2) { - o->Clear(w2); - open2 = 0; - } - - o->Clear(); - delete o; - o = NULL; - } - - if(!s1 && !s2) - return; - - o = cOsd::OpenRaw(125, 450); - - if(o == NULL) - return; - - o->SetFont(fontOsd); - - if(s1) { - int w = o->Width((char *) s1); - dprint("w1: %d\n", w); - w = 450; - int h = 36; - w1 = o->Create(0, 0, w, h, 2); -#if 0 - o->AddColor(clrBackground, w1); - o->AddColor(clrWhite, w1); -#endif - o->Fill(0, 0, w, h, clrBackground, w1); - o->Text(15, 4, (char *) s1, clrWhite, clrBackground, w1); - open1 = 1; - } - - if(s2) { - int w = o->Width((char *) s2); - dprint("w2: %d\n", w); - w = 452; - int h = 36; - w2 = o->Create(0, 45, w, h, 2); -#if 0 - o->AddColor(clrBackground, w2); - o->AddColor(clrWhite, w2); -#endif - o->Fill(0, 45, w, 45 + h, clrBackground, w2); - o->Text(15, 45 + 4, (char *) s2, clrWhite, clrBackground, w2); - open2 = 1; - } - - o->Flush(); -} -#endif - -#if 0 -void -ttxt_packet_in(int data_unit_id, int mag, int pack, uint8_t *data) -{ - static int valid = 0; - static struct ttxt_page p; - int i; - - if(pack == 0) { - if(valid) - if(p.mag == TTXT_MAG && p.no == TTXT_PAGE) - if(p.subtitle) - //print_page(&p); - /* if(p.mag == 1) */{ - show_page(&p); - print_page(&p); - } - - memset(&p, 0, sizeof(p)); - p.data_unit_id = data_unit_id; - p.mag = mag; - p.no = unham(data[0], data[1]); - - if(data[3] & 0x80) { // Erase Page - memset(p.data, 0, sizeof(p.data)); - p.erasepage = 1; - } - if(data[5] & 0x20) // Newsflash - p.newsflash = 1; - if(data[5] & 0x80) // Subtitle - p.subtitle = 1; - if(data[6] & 0x02) // Suppress Header - p.suppress_header = 1; - //if(data[6] & 0x08) // Update Indicator - //if(data[6] & 0x20) // Interrupted Sequence - if(data[6] & 0x80) // Inhibit Display - p.inhibit_display = 1; - //if(data[7] & 0x02) // Magazine Serial - - p.national_charset = - ((data[7] & 0x80) >> 7) + ((data[7] & 0x20) >> 4) + ((data[7] & 0x08) >> 1); - - valid = 1; - - for(i = 0; i < 32; i++) - p.data[0][i] = data[i+8]; - } else if(pack < 26) { - for(i = 0; i < 42; i++) - p.data[pack][i] = data[i]; - } else { - if((valid && p.mag == TTXT_MAG && p.no == TTXT_PAGE) || - pack == 28) - dprint("mag: %d, pack: %d, page: %02x\n", p.mag, pack, p.no); - } -} -#endif - -#if 0 -void -ttxt_pes_data_in(struct ttxt_pes_data_field *t, int len) -{ - int i; - - if(len < 1) - return; - - if(t->data_identifier < 0x10 || t->data_identifier > 0x1F) { - dprint("Unknown data identifier: %02x\n", t->data_identifier); - return; - } - - for(i = 0; (uint8_t *) (&(t->d[i+1])) < (((uint8_t *) t) + len); i++) { - struct ttxt_data_field *d = &(t->d[i]); - int i; - uint8_t *p; - int uh; - int mag; - int pack; - - // if(d->data_unit_id != ttxt_subtitle) - // continue; - - p = (uint8_t *) &(d->mag_addr_ham); - for(i = 0; i < 42; i++) { - p[i] = invtab[p[i]]; - } - - uh = unham(d->mag_addr_ham[0], d->mag_addr_ham[1]); - mag = uh & 0x7; - pack = (uh >> 3) & 0x1f; - - // dump_hex("line", (uint8_t *) d, 20); - // dprint("id: %d, line: %d, mag %d, pack: %d\n", d->data_unit_id, TTXT_LINE_NO(*d), mag, pack); - - ttxt_packet_in(d->data_unit_id, mag, pack, d->data); - } -} - - -void -set_filt(int fd,uint16_t tt_pid, dmx_pes_type_t t) -{ - struct dmx_pes_filter_params pesFilterParams; - - memset(&pesFilterParams, 0, sizeof(pesFilterParams)); - - pesFilterParams.pid = tt_pid; - pesFilterParams.input = DMX_IN_FRONTEND; - pesFilterParams.output = DMX_OUT_TAP; - pesFilterParams.pes_type = t; - pesFilterParams.flags = DMX_IMMEDIATE_START; - - if (ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams) < 0) - perror("DMX SET PES FILTER:"); - - // XXX set buffer size too? -} -#endif - -#if 0 -#define BUFSIZE 2000 - -// external entry point -void ttxt_decode(int fd, int tpid, int *doRun) -{ - uint8_t buf[BUFSIZE]; - int n; - int hunt = 1; - - set_filt(fd, tpid, DMX_PES_OTHER); - - while (*doRun) { - restart: - if(hunt) { - int i; - - dprint("hunting...\n"); - n = read(fd, buf, 199); - if(n < 0) { - perror("ttxt_decode:read: "); - goto restart; - } - - for(i = 0; i < (n - 3); i++) { - if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1 && buf[i+3] == 0xbd) { - struct ttxt_pes_header *p = (struct ttxt_pes_header *) (buf + i); - size_t skip = ntohs(p->len) + 6 - (n - i); - - if(skip > 0) { - read(fd, buf, skip < sizeof(buf) ? skip : sizeof(buf)); - if(n < 0) { - perror("ttxt_decode:read: "); - goto restart; - } - hunt = 0; - break; - } - } - } - } else { - struct ttxt_pes_header *p = (struct ttxt_pes_header *) buf; - - n = read(fd, buf, 6); - if(n < 0) { - perror("ttxt_decode:read: "); - goto restart; - } - - if(p->start[0] != 0 || p->start[1] != 0 || p->start[2] != 1 || - p->stream_id != 0xbd || // private_stream_1 - ntohs(p->len) > (sizeof(buf) - 6)) { - dprint("Lost PES packet sync, hunting...\n"); - hunt = 1; - continue; - } - - n = read(fd, buf + 6, ntohs(p->len)); - if(n < 0) { - perror("ttxt_decode:read: "); - goto restart; - } - - // dprint("len: %d\n", n); - - if(n != ntohs(p->len) || - p->header_len != 0x24) { // header should allways be 0x24 long (EN 300 472) - dprint("Error reading PES packet, hunting...\n"); - hunt = 1; - continue; - } - - ttxt_pes_data_in((struct ttxt_pes_data_field *) (buf + 45), n + 6 - 45); - } - - // fwrite(buf,1,n,stdout); - } - - dprint("ttxt_decode DONE!\n"); -} -#endif - - -#if 0 -int -main(int argc, char **argv) -{ - int fd; - int pid; - uint8_t buf[BUFSIZE]; - int n; - int hunt = 1; - - if (argc!=2) { - fprintf(stderr,"USAGE: %s PID\n", argv[0]); - return -1; - } - - pid = atoi(argv[1]); - - if((fd = open("/dev/dvb/adapter0/demux0", O_RDWR)) < 0){ - perror("Error opening demux device: "); - return -1; - } - - set_filt(fd, pid, DMX_PES_OTHER); - - for (;;) { - if(hunt) { - int i; - - dprint("hunting...\n"); - n = read(fd, buf, 199); - - for(i = 0; i < (n - 3); i++) { - if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1 && buf[i+3] == 0xbd) { - struct ttxt_pes_header *p = (struct ttxt_pes_header *) (buf + i); - int skip = ntohs(p->len) + 6 - (n - i); - - if(skip > 0) { - read(fd, buf, skip < sizeof(buf) ? skip : sizeof(buf)); - hunt = 0; - break; - } - } - } - } else { - struct ttxt_pes_header *p = (struct ttxt_pes_header *) buf; - - n = read(fd, buf, 6); - - if(p->start[0] != 0 || p->start[1] != 0 || p->start[2] != 1 || - p->stream_id != 0xbd || // private_stream_1 - ntohs(p->len) > (sizeof(buf) - 6)) { - dprint("Lost PES packet sync, hunting...\n"); - hunt = 1; - continue; - } - - n = read(fd, buf + 6, ntohs(p->len)); - - // dprint("len: %d\n", n); - - if(n != ntohs(p->len) || - p->header_len != 0x24) { // header should allways be 0x24 long (EN 300 472) - dprint("Error reading PES packet, hunting...\n"); - hunt = 1; - continue; - } - - ttxt_pes_data_in((struct ttxt_pes_data_field *) (buf + 45), n + 6 - 45); - } - - // fwrite(buf,1,n,stdout); - } - - return 0; -} -#endif |