annotate sub/sub_cc.c @ 35070:ff4758e8cfba

Change geometry for corevideo vo to not take dock into account. It makes the % placements behave non-intuitively, particularly with an auto-hide dock where it would depend on whether the dock is visible right when MPlayer starts up.
author reimar
date Tue, 11 Sep 2012 20:03:52 +0000
parents 7abba31768ec
children d206960484fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
1 /*
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
2 * decoder for Closed Captions
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
3 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
4 * This decoder relies on MPlayer's OSD to display subtitles.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
5 * Be warned that decoding is somewhat preliminary, though it basically works.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
6 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
7 * Most notably, only the text information is decoded as of now, discarding
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
8 * color, background and position info (see source below).
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
9 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
10 * uses source from the xine closed captions decoder
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
11 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
12 * Copyright (C) 2002 Matteo Giani
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
13 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
14 * This file is part of MPlayer.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
15 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
16 * MPlayer is free software; you can redistribute it and/or modify
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
17 * it under the terms of the GNU General Public License as published by
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
18 * the Free Software Foundation; either version 2 of the License, or
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
19 * (at your option) any later version.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
20 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
21 * MPlayer is distributed in the hope that it will be useful,
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
24 * GNU General Public License for more details.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
25 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
26 * You should have received a copy of the GNU General Public License along
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
27 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
29 */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
30
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
31 #include <stdio.h>
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
32 #include <stdlib.h>
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
33 #include <string.h>
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
34
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
35 #include "config.h"
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
36 #include "mp_msg.h"
32464
22888a8cb312 Do not use a path for including files in the same directory.
reimar
parents: 32458
diff changeset
37 #include "sub_cc.h"
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
38
32464
22888a8cb312 Do not use a path for including files in the same directory.
reimar
parents: 32458
diff changeset
39 #include "subreader.h"
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
40
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
41 #include "libvo/video_out.h"
32467
fbe5c829c69b Move libvo/sub.[ch] from libvo to sub.
cigaes
parents: 32464
diff changeset
42 #include "sub.h"
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
43
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
44 #include "libavutil/avutil.h"
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
45
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
46
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
47 #define CC_MAX_LINE_LENGTH 64
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
48
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
49 static char chartbl[128];
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
50
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
51 static subtitle buf1,buf2;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
52 static subtitle *fb,*bb;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
53
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
54 static unsigned int cursor_pos=0;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
55
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
56 static int initialized=0;
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
57 static int wtv_format;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
58
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
59 #define CC_ROLLON 1
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
60 #define CC_ROLLUP 2
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
61
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
62 static int cc_mode=CC_ROLLON;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
63 static int cc_lines=4; ///< number of visible rows in CC roll-up mode, not used in CC roll-on mode
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
64
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
65 static void build_char_table(void)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
66 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
67 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
68 /* first the normal ASCII codes */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
69 for (i = 0; i < 128; i++)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
70 chartbl[i] = (char) i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
71 /* now the special codes */
34702
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
72 chartbl[0x2a] = 0xe1; /* Latin Small Letter A with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
73 chartbl[0x5c] = 0xe9; /* Latin Small Letter E with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
74 chartbl[0x5e] = 0xed; /* Latin Small Letter I with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
75 chartbl[0x5f] = 0xf3; /* Latin Small Letter O with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
76 chartbl[0x60] = 0xfa; /* Latin Small Letter U with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
77 chartbl[0x7b] = 0xe7; /* Latin Small Letter C with cedilla */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
78 chartbl[0x7c] = 0xf7; /* Division sign */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
79 chartbl[0x7d] = 0xd1; /* Latin Capital letter N with tilde */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
80 chartbl[0x7e] = 0xf1; /* Latin Small Letter N with tilde */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
81 chartbl[0x7f] = 0xa4; /* Currency sign FIXME: this should be a solid block */
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
82 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
83
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
84 static void clear_buffer(subtitle *buf)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
85 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
86 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
87 buf->lines=0;
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
88 for (i = 0; i < SUB_MAX_TEXT; i++) {
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
89 free(buf->text[i]);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
90 buf->text[i] = NULL;
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
91 }
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
92 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
93
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
94
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
95 /**
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
96 \brief scroll buffer one line up
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
97 \param buf buffer to scroll
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
98 */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
99 static void scroll_buffer(subtitle* buf)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
100 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
101 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
102
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
103 while(buf->lines > cc_lines)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
104 {
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
105 free(buf->text[0]);
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
106
32512
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
107 for(i = 0; i < buf->lines - 1; i++) buf->text[i] = buf->text[i+1];
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
108
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
109 buf->text[buf->lines-1] = NULL;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
110 buf->lines--;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
111 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
112 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
113
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
114 static int channel;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
115
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
116 void subcc_init(void)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
117 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
118 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
119 //printf("subcc_init(): initing...\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
120 build_char_table();
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
121 for(i=0;i<SUB_MAX_TEXT;i++) {buf1.text[i]=buf2.text[i]=NULL;}
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
122 buf1.lines=buf2.lines=0;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
123 fb=&buf1;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
124 bb=&buf2;
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
125 channel = -1;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
126
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
127 initialized=1;
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
128 wtv_format = 0;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
129 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
130
34761
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
131 void subcc_reset(void)
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
132 {
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
133 wtv_format = 0;
34761
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
134 if (!initialized)
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
135 return;
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
136 clear_buffer(&buf1);
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
137 clear_buffer(&buf2);
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
138 }
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
139
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
140 static void display_buffer(subtitle *buf)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
141 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
142 vo_sub = buf;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
143 vo_osd_changed(OSDTYPE_SUBTITLE);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
144 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
145
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
146
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
147 static void append_char(char c)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
148 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
149 if(!bb->lines) {bb->lines++; cursor_pos=0;}
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
150 if(bb->text[bb->lines - 1]==NULL)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
151 {
32513
a150a1bc458d Use calloc instead of malloc+memset.
reimar
parents: 32512
diff changeset
152 bb->text[bb->lines - 1] = calloc(1, CC_MAX_LINE_LENGTH);
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
153 cursor_pos=0;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
154 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
155
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
156 if(c=='\n')
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
157 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
158 if(cursor_pos>0 && bb->lines < SUB_MAX_TEXT)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
159 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
160 bb->lines++;cursor_pos=0;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
161 if(cc_mode==CC_ROLLUP){ //Carriage return - scroll buffer one line up
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
162 bb->text[bb->lines - 1]=calloc(1, CC_MAX_LINE_LENGTH);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
163 scroll_buffer(bb);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
164 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
165 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
166 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
167 else
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
168 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
169 if(cursor_pos==CC_MAX_LINE_LENGTH-1)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
170 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
171 fprintf(stderr,"CC: append_char() reached CC_MAX_LINE_LENGTH!\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
172 return;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
173 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
174 bb->text[bb->lines - 1][cursor_pos++]=c;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
175 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
176 //In CC roll-up mode data should be shown immediately
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
177 if(cc_mode==CC_ROLLUP) display_buffer(bb);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
178 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
179
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
180
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
181 static void swap_buffers(void)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
182 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
183 subtitle *foo;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
184 foo=fb;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
185 fb=bb;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
186 bb=foo;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
187 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
188
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
189 static int selected_channel(void)
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
190 {
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
191 return subcc_enabled - 1;
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
192 }
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
193
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
194 static void cc_decode_EIA608(unsigned short int data)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
195 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
196
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
197 static unsigned short int lastcode=0x0000;
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
198 uint8_t c1 = data & 0x7f;
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
199 uint8_t c2 = (data >> 8) & 0x7f;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
200
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
201 if (c1 & 0x60) { /* normal character, 0x20 <= c1 <= 0x7f */
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
202 if (channel != (selected_channel() & 1))
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
203 return;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
204 append_char(chartbl[c1]);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
205 if(c2 & 0x60) /*c2 might not be a normal char even if c1 is*/
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
206 append_char(chartbl[c2]);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
207 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
208 else if (c1 & 0x10) // control code / special char
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
209 {
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
210 channel = (c1 & 0x08) >> 3;
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
211 if (channel != (selected_channel() & 1))
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
212 return;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
213 c1&=~0x08;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
214 if(data!=lastcode)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
215 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
216 if(c2 & 0x40) { /*PAC, Preamble Address Code */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
217 append_char('\n'); /*FIXME properly interpret PACs*/
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
218 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
219 else
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
220 switch(c1)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
221 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
222 case 0x10: break; // ext attribute
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
223 case 0x11:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
224 if((c2 & 0x30)==0x30)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
225 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
226 //printf("[debug]:Special char (ignored)\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
227 /*cc_decode_special_char()*/;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
228 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
229 else if (c2 & 0x20)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
230 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
231 //printf("[debug]: midrow_attr (ignored)\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
232 /*cc_decode_midrow_attr()*/;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
233 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
234 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
235 case 0x14:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
236 switch(c2)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
237 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
238 case 0x00: //CC roll-on mode
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
239 cc_mode=CC_ROLLON;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
240 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
241 case 0x25: //CC roll-up, 2 rows
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
242 case 0x26: //CC roll-up, 3 rows
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
243 case 0x27: //CC roll-up, 4 rows
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
244 cc_lines=c2-0x23;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
245 cc_mode=CC_ROLLUP;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
246 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
247 case 0x2C: display_buffer(NULL); //EDM
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
248 clear_buffer(fb); break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
249 case 0x2d: append_char('\n'); //carriage return
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
250 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
251 case 0x2e: clear_buffer(bb); //ENM
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
252 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
253 case 0x2f: swap_buffers(); //Swap buffers
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
254 display_buffer(fb);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
255 clear_buffer(bb);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
256 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
257 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
258 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
259 case 0x17:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
260 if( c2>=0x21 && c2<=0x23) //TAB
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
261 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
262 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
263 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
264 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
265 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
266 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
267 lastcode=data;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
268 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
269
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
270 static void subcc_decode(const uint8_t *inputbuffer, unsigned int inputlength)
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
271 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
272 /* The first number may denote a channel number. I don't have the
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
273 * EIA-708 standard, so it is hard to say.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
274 * From what I could figure out so far, the general format seems to be:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
275 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
276 * repeat
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
277 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
278 * 0xfe starts 2 byte sequence of unknown purpose. It might denote
32522
796cd767b024 Fix one -subcc sample.
reimar
parents: 32520
diff changeset
279 * field #2 in line 21 of the VBI.
796cd767b024 Fix one -subcc sample.
reimar
parents: 32520
diff changeset
280 * Treating it identical of 0xff fixes
796cd767b024 Fix one -subcc sample.
reimar
parents: 32520
diff changeset
281 * http://samples.mplayerhq.hu/MPEG-VOB/ClosedCaptions/Starship_Troopers.vob
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
282 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
283 * 0xff starts 2 byte EIA-608 sequence, field #1 in line 21 of the VBI.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
284 * Followed by a 3-code triplet that starts either with 0xff or
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
285 * 0xfe. In either case, the following triplet needs to be ignored
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
286 * for line 21, field 1.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
287 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
288 * 0x00 is padding, followed by 2 more 0x00.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
289 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
290 * 0x01 always seems to appear at the beginning, always seems to
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
291 * be followed by 0xf8, 8-bit number.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
292 * The lower 7 bits of this 8-bit number seem to denote the
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
293 * number of code triplets that follow.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
294 * The most significant bit denotes whether the Line 21 field 1
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
295 * captioning information is at odd or even triplet offsets from this
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
296 * beginning triplet. 1 denotes odd offsets, 0 denotes even offsets.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
297 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
298 * Most captions are encoded with odd offsets, so this is what we
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
299 * will assume.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
300 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
301 * until end of packet
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
302 */
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
303 const uint8_t *current = inputbuffer;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
304 unsigned int curbytes = 0;
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
305 uint8_t data1, data2;
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
306 uint8_t cc_code;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
307 int odd_offset = 1;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
308
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
309 while (curbytes < inputlength) {
32512
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
310 cc_code = current[0];
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
311
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
312 if (inputlength - curbytes < 2) {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
313 #ifdef LOG_DEBUG
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
314 fprintf(stderr, "Not enough data for 2-byte CC encoding\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
315 #endif
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
316 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
317 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
318
32512
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
319 data1 = current[1];
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
320 data2 = current[2];
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
321 current += 3; curbytes += 3;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
322
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
323 // 0xfe/0xff are both used on plain EIA-608 CC and
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
324 // for extended EIA-708 (where 0xfc/0xfd is used for
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
325 // compatibility layer).
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
326 // Allow using channel bit 2 to select between which
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
327 // ones to look in.
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
328 switch (cc_code) {
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
329 case 0xfc:
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
330 case 0xfd:
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
331 case 0xfe:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
332 case 0xff:
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
333 if ((cc_code & 2) == (selected_channel() & 4) >> 1)
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
334 break;
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
335 odd_offset ^= 1;
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
336 if (odd_offset != (selected_channel() & 2) >> 1)
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
337 break;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
338 /* expect EIA-608 CC1/CC2 encoding */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
339 // FIXME check parity!
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
340 // Parity check omitted assuming we are reading from a DVD and therefore
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
341 // we should encounter no "transmission errors".
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
342 cc_decode_EIA608(data1 | (data2 << 8));
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
343 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
344
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
345 case 0xfa:
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
346 case 0x00:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
347 /* This seems to be just padding */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
348 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
349
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
350 case 0x01:
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
351 odd_offset = data2 >> 7;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
352 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
353
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
354 default:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
355 //#ifdef LOG_DEBUG
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
356 fprintf(stderr, "Unknown CC encoding: %x\n", cc_code);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
357 //#endif
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
358 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
359 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
360 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
361 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
362
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
363 static const uint8_t mov_cc_signature_1[] = {0, 0, 0, 0xa, 'c', 'd', 'a', 't'};
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
364 static const uint8_t mov_cc_signature_2[] = {0, 0, 0, 0xa, 'c', 'd', 't', '2'};
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
365 /**
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
366 * MOV uses a vastly more verbose representation for EIA 608 CC data than DVDs.
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
367 * This function handles that case.
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
368 */
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
369 static void mov_subcc_decode(const uint8_t *data, unsigned len)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
370 {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
371 while (len >= 10) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
372 int channel = -1;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
373 if (memcmp(data, mov_cc_signature_1, sizeof(mov_cc_signature_1)) == 0) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
374 channel = 0;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
375 } else if (memcmp(data, mov_cc_signature_2, sizeof(mov_cc_signature_2)) == 0) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
376 channel = 1;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
377 } else {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
378 mp_msg(MSGT_OSD, MSGL_V, "Unknown MOV 608 CC formatting\n");
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
379 data++;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
380 len--;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
381 continue;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
382 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
383 if (channel == selected_channel() >> 1)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
384 cc_decode_EIA608(data[8] | (data[9] << 8));
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
385 data += 10;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
386 len -= 10;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
387 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
388 }
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
389
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
390 void subcc_process_data(const uint8_t *inputdata, unsigned int len)
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
391 {
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
392 int mov_mode = len >= 10 &&
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
393 memcmp(inputdata, mov_cc_signature_1, sizeof(mov_cc_signature_1)) == 0;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
394 if(!subcc_enabled) return;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
395 if(!initialized) subcc_init();
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
396
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
397 if (mov_mode) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
398 mov_subcc_decode(inputdata, len);
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
399 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
400 }
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
401 if (len & 1) wtv_format = 0;
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
402 if (len == 2) {
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
403 // EIA-608 compatibility part.
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
404 // Full EIA-708 parts have length >= 4 (multiple of 2).
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
405 cc_decode_EIA608(inputdata[0] | (inputdata[1] << 8));
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
406 wtv_format = 1;
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
407 }
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
408 if (wtv_format)
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
409 return;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
410 subcc_decode(inputdata, len);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
411 }
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
412
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
413 /**
34759
430e164238d1 Fix misspelling ATSC as ASTC.
reimar
parents: 34756
diff changeset
414 * This processes CC captions in the format as found in ATSC broadcasts.
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
415 * Like DVD CC it is stored inside the MPEG-frame userdata, but with two
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
416 * differences:
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
417 * 1) It starts with "GA" instead of "CC"
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
418 * 2) It _must_ be reordered in the way the decoder reorders the video frames
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
419 * The latter makes things difficult and is the reason why there is no support
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
420 * for this yet beyond this function.
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
421 */
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
422 void subcc_process_eia708(const uint8_t *data, int len)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
423 {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
424 int cc_count;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
425 if (!subcc_enabled)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
426 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
427 if (!initialized)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
428 subcc_init();
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
429 if (len <= 5)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
430 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
431 if (data[0] != '9' || data[1] != '4' || data[2] != 3) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
432 mp_msg(MSGT_OSD, MSGL_ERR, "Unknown ATSC CC type "
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
433 "0x%"PRIx8" 0x%"PRIx8" 0x%"PRIx8"\n",
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
434 data[0], data[1], data[2]);
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
435 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
436 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
437 // process_cc_data_flag
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
438 if (!(data[3] & 0x40))
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
439 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
440 cc_count = data[3] & 0x1f;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
441 data += 5;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
442 len -= 5;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
443 cc_count = FFMIN(cc_count, len / 3);
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
444 while (cc_count--) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
445 // EAI-608 data
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
446 if ((data[0] & 0xfe) == 0xfc && (data[0] & 1) == selected_channel() >> 1)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
447 cc_decode_EIA608(data[1] | (data[2] << 8));
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
448 data += 3;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
449 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
450 }