annotate sub_cc.c @ 31227:ee7beb1a3a6e

backport ass_flush_events() from upstream libass and make use of it This fixes subtitles duplication when seeking back in ass stream formated with the "standard" format FFmpeg uses.
author aurel
date Mon, 31 May 2010 19:10:57 +0000
parents 32725ca88fed
children 68114b6e8311
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
1 /*
28924
d5d66bff938a cosmetics: Remove file names from file header, it only causes trouble.
diego
parents: 25962
diff changeset
2 * decoder for Closed Captions
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
3 *
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
4 * This decoder relies on MPlayer's OSD to display subtitles.
29254
195f6311ba4e Some reformating to avoid two too long lines
reynaldo
parents: 29253
diff changeset
5 * Be warned that decoding is somewhat preliminary, though it basically works.
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
6 *
29254
195f6311ba4e Some reformating to avoid two too long lines
reynaldo
parents: 29253
diff changeset
7 * Most notably, only the text information is decoded as of now, discarding
195f6311ba4e Some reformating to avoid two too long lines
reynaldo
parents: 29253
diff changeset
8 * color, background and position info (see source below).
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
9 *
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
10 * uses source from the xine closed captions decoder
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
11 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
12 * Copyright (C) 2002 Matteo Giani
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
13 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
14 * This file is part of MPlayer.
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
15 *
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
16 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
17 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
18 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
19 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
20 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
21 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
24 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
25 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
26 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
27 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
29 */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
30
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
31 #include <stdio.h>
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
32 #include <stdlib.h>
8123
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 7472
diff changeset
33 #include <string.h>
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
34
17630
7c4eef408b6b include config.h before includes that need it
iive
parents: 17566
diff changeset
35 #include "config.h"
6791
a3b2f80f3a26 codmetics :)
arpi
parents: 6784
diff changeset
36 #include "sub_cc.h"
a3b2f80f3a26 codmetics :)
arpi
parents: 6784
diff changeset
37
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
38 #include "subreader.h"
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
39
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
40 #include "libvo/video_out.h"
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
41 #include "libvo/sub.h"
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
42
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
43
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
44 #define CC_MAX_LINE_LENGTH 64
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
45
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
46 static char chartbl[128];
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
47
6791
a3b2f80f3a26 codmetics :)
arpi
parents: 6784
diff changeset
48 static subtitle buf1,buf2;
a3b2f80f3a26 codmetics :)
arpi
parents: 6784
diff changeset
49 static subtitle *fb,*bb;
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
50
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
51 static unsigned int cursor_pos=0;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
52
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24830
diff changeset
53 static int initialized=0;
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
54
24830
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
55 #define CC_ROLLON 1
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
56 #define CC_ROLLUP 2
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
57
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
58 static int cc_mode=CC_ROLLON;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
59 static int cc_lines=4; ///< number of visible rows in CC roll-up mode, not used in CC roll-on mode
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
60
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
61 static void display_buffer(subtitle * buf);
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
62
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
63 static void build_char_table(void)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
64 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
65 int i;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
66 /* first the normal ASCII codes */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
67 for (i = 0; i < 128; i++)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
68 chartbl[i] = (char) i;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
69 /* now the special codes */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
70 chartbl[0x2a] = 'á';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
71 chartbl[0x5c] = 'é';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
72 chartbl[0x5e] = 'í';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
73 chartbl[0x5f] = 'ó';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
74 chartbl[0x60] = 'ú';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
75 chartbl[0x7b] = 'ç';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
76 chartbl[0x7c] = '÷';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
77 chartbl[0x7d] = 'Ñ';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
78 chartbl[0x7e] = 'ñ';
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
79 chartbl[0x7f] = '¤'; /* FIXME: this should be a solid block */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
80 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
81
6791
a3b2f80f3a26 codmetics :)
arpi
parents: 6784
diff changeset
82 static void clear_buffer(subtitle *buf)
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
83 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
84 int i;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
85 buf->lines=0;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
86 for(i=0;i<SUB_MAX_TEXT;i++) if(buf->text[i]) {free(buf->text[i]);buf->text[i]=NULL;}
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
87 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
88
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
89
24830
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
90 /**
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
91 \brief scroll buffer one line up
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
92 \param buf buffer to scroll
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
93 */
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
94 static void scroll_buffer(subtitle* buf)
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
95 {
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
96 int i;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
97
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
98 while(buf->lines > cc_lines)
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
99 {
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
100 if(buf->text[0]) free(buf->text[0]);
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
101
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
102 for(i = 0; i < (buf->lines - 1); i++) buf->text[i] = buf->text[i+1];
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
103
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
104 buf->text[buf->lines-1] = NULL;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
105 buf->lines--;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
106 }
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
107 }
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
108
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
109
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 8123
diff changeset
110 void subcc_init(void)
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
111 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
112 int i;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
113 //printf("subcc_init(): initing...\n");
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
114 build_char_table();
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
115 for(i=0;i<SUB_MAX_TEXT;i++) {buf1.text[i]=buf2.text[i]=NULL;}
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
116 buf1.lines=buf2.lines=0;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
117 fb=&buf1;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
118 bb=&buf2;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29254
diff changeset
119
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24830
diff changeset
120 initialized=1;
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
121 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
122
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
123 static void append_char(char c)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
124 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
125 if(!bb->lines) {bb->lines++; cursor_pos=0;}
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
126 if(bb->text[bb->lines - 1]==NULL)
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
127 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
128 bb->text[bb->lines - 1]=malloc(CC_MAX_LINE_LENGTH);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
129 memset(bb->text[bb->lines - 1],0,CC_MAX_LINE_LENGTH);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
130 cursor_pos=0;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
131 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29254
diff changeset
132
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
133 if(c=='\n')
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
134 {
21237
530b31f3e60a Sanity-check number of lines in CC subtitle
reimar
parents: 21236
diff changeset
135 if(cursor_pos>0 && bb->lines < SUB_MAX_TEXT)
24830
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
136 {
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
137 bb->lines++;cursor_pos=0;
24830
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
138 if(cc_mode==CC_ROLLUP){ //Carriage return - scroll buffer one line up
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
139 bb->text[bb->lines - 1]=calloc(1, CC_MAX_LINE_LENGTH);
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
140 scroll_buffer(bb);
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
141 }
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
142 }
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
143 }
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
144 else
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
145 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
146 if(cursor_pos==CC_MAX_LINE_LENGTH-1)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
147 {
28924
d5d66bff938a cosmetics: Remove file names from file header, it only causes trouble.
diego
parents: 25962
diff changeset
148 fprintf(stderr,"CC: append_char() reached CC_MAX_LINE_LENGTH!\n");
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
149 return;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
150 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
151 bb->text[bb->lines - 1][cursor_pos++]=c;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
152 }
24830
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
153 //In CC roll-up mode data should be shown immediately
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
154 if(cc_mode==CC_ROLLUP) display_buffer(bb);
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
155 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
156
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
157
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 8123
diff changeset
158 static void swap_buffers(void)
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
159 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
160 subtitle *foo;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
161 foo=fb;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
162 fb=bb;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
163 bb=foo;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
164 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
165
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
166 static void display_buffer(subtitle * buf)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
167 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
168 vo_sub=buf;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
169 vo_osd_changed(OSDTYPE_SUBTITLE);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
170 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
171
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
172
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
173 static void cc_decode_EIA608(unsigned short int data)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
174 {
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
175
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29254
diff changeset
176 static unsigned short int lastcode=0x0000;
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
177 unsigned char c1 = data & 0x7f;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
178 unsigned char c2 = (data >> 8) & 0x7f;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
179
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
180 if (c1 & 0x60) { /* normal character, 0x20 <= c1 <= 0x7f */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
181 append_char(chartbl[c1]);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
182 if(c2 & 0x60) /*c2 might not be a normal char even if c1 is*/
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
183 append_char(chartbl[c2]);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
184 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
185 else if (c1 & 0x10) // control code / special char
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
186 {
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 6791
diff changeset
187 // int channel= (c1 & 0x08) >> 3;
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
188 c1&=~0x08;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
189 if(data!=lastcode)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
190 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
191 if(c2 & 0x40) { /*PAC, Preamble Address Code */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
192 append_char('\n'); /*FIXME properly interpret PACs*/
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
193 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
194 else
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
195 switch(c1)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
196 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
197 case 0x10: break; // ext attribute
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
198 case 0x11:
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
199 if((c2 & 0x30)==0x30)
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
200 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
201 //printf("[debug]:Special char (ignored)\n");
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
202 /*cc_decode_special_char()*/;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
203 }
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
204 else if (c2 & 0x20)
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
205 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
206 //printf("[debug]: midrow_attr (ignored)\n");
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
207 /*cc_decode_midrow_attr()*/;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
208 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
209 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
210 case 0x14:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
211 switch(c2)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
212 {
24830
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
213 case 0x00: //CC roll-on mode
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
214 cc_mode=CC_ROLLON;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
215 break;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
216 case 0x25: //CC roll-up, 2 rows
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
217 case 0x26: //CC roll-up, 3 rows
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
218 case 0x27: //CC roll-up, 4 rows
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
219 cc_lines=c2-0x23;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
220 cc_mode=CC_ROLLUP;
31efcf6a10d0 Basic support for Closed Captioning Roll-up mode.
voroshil
parents: 21237
diff changeset
221 break;
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
222 case 0x2C: display_buffer(NULL); //EDM
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
223 clear_buffer(fb); break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
224 case 0x2d: append_char('\n'); //carriage return
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
225 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
226 case 0x2e: clear_buffer(bb); //ENM
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
227 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
228 case 0x2f: swap_buffers(); //Swap buffers
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
229 display_buffer(fb);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
230 clear_buffer(bb);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
231 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
232 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
233 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
234 case 0x17:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
235 if( c2>=0x21 && c2<=0x23) //TAB
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
236 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
237 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
238 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
239 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
240 }
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
241 }
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
242 lastcode=data;
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
243 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
244
21236
3ec5917cdae2 Cleanup for uselessly complicated closed-caption subtitle handling
reimar
parents: 21234
diff changeset
245 static void subcc_decode(unsigned char *inputbuffer, unsigned int inputlength)
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
246 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
247 /* The first number may denote a channel number. I don't have the
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
248 * EIA-708 standard, so it is hard to say.
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
249 * From what I could figure out so far, the general format seems to be:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
250 *
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
251 * repeat
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
252 *
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
253 * 0xfe starts 2 byte sequence of unknown purpose. It might denote
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
254 * field #2 in line 21 of the VBI. We'll ignore it for the
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
255 * time being.
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
256 *
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
257 * 0xff starts 2 byte EIA-608 sequence, field #1 in line 21 of the VBI.
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
258 * Followed by a 3-code triplet that starts either with 0xff or
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
259 * 0xfe. In either case, the following triplet needs to be ignored
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
260 * for line 21, field 1.
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
261 *
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
262 * 0x00 is padding, followed by 2 more 0x00.
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
263 *
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
264 * 0x01 always seems to appear at the beginning, always seems to
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
265 * be followed by 0xf8, 8-bit number.
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
266 * The lower 7 bits of this 8-bit number seem to denote the
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
267 * number of code triplets that follow.
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
268 * The most significant bit denotes whether the Line 21 field 1
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
269 * captioning information is at odd or even triplet offsets from this
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
270 * beginning triplet. 1 denotes odd offsets, 0 denotes even offsets.
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
271 *
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
272 * Most captions are encoded with odd offsets, so this is what we
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
273 * will assume.
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
274 *
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
275 * until end of packet
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
276 */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
277 unsigned char *current = inputbuffer;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
278 unsigned int curbytes = 0;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
279 unsigned char data1, data2;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
280 unsigned char cc_code;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
281 int odd_offset = 1;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
282
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
283 while (curbytes < inputlength) {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
284 int skip = 2;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
285
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
286 cc_code = *(current);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
287
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
288 if (inputlength - curbytes < 2) {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
289 #ifdef LOG_DEBUG
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
290 fprintf(stderr, "Not enough data for 2-byte CC encoding\n");
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
291 #endif
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
292 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
293 }
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
294
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
295 data1 = *(current+1);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
296 data2 = *(current + 2);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
297 current++; curbytes++;
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
298
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
299 switch (cc_code) {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
300 case 0xfe:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
301 /* expect 2 byte encoding (perhaps CC3, CC4?) */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
302 /* ignore for time being */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
303 skip = 2;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
304 break;
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
305
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
306 case 0xff:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
307 /* expect EIA-608 CC1/CC2 encoding */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
308 // FIXME check parity!
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
309 // Parity check omitted assuming we are reading from a DVD and therefore
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
310 // we should encounter no "transmission errors".
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
311 cc_decode_EIA608(data1 | (data2 << 8));
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
312 skip = 5;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
313 break;
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
314
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
315 case 0x00:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
316 /* This seems to be just padding */
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
317 skip = 2;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
318 break;
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
319
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
320 case 0x01:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
321 odd_offset = data2 & 0x80;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
322 if (odd_offset)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
323 skip = 2;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
324 else
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
325 skip = 5;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
326 break;
29253
f1a9a6fbc051 Get rid of some more trailing whitespace
reynaldo
parents: 28924
diff changeset
327
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
328 default:
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
329 //#ifdef LOG_DEBUG
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
330 fprintf(stderr, "Unknown CC encoding: %x\n", cc_code);
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
331 //#endif
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
332 skip = 2;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
333 break;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
334 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
335 current += skip;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
336 curbytes += skip;
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
337 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
338 }
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
339
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
340
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
341 void subcc_process_data(unsigned char *inputdata,unsigned int len)
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
342 {
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
343 if(!subcc_enabled) return;
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24830
diff changeset
344 if(!initialized) subcc_init();
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29254
diff changeset
345
21236
3ec5917cdae2 Cleanup for uselessly complicated closed-caption subtitle handling
reimar
parents: 21234
diff changeset
346 subcc_decode(inputdata, len);
6784
b38e38b6f88f DVD Closed Captioning support, patch by Matteo Giani <matgiani@ctonet.it>, small changes by me.
atmos4
parents:
diff changeset
347 }