annotate sub/sub_cc.c @ 36843:1078b8dd7625

Cast appropriately.
author ib
date Tue, 25 Feb 2014 17:10:39 +0000
parents d206960484fe
children
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"
35712
d206960484fe Add a number of missing libavutil header #includes.
diego
parents: 35029
diff changeset
45 #include "libavutil/common.h"
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
46
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
47
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
48 #define CC_MAX_LINE_LENGTH 64
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
49
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
50 static char chartbl[128];
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
51
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
52 static subtitle buf1,buf2;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
53 static subtitle *fb,*bb;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
54
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
55 static unsigned int cursor_pos=0;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
56
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
57 static int initialized=0;
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
58 static int wtv_format;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
59
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
60 #define CC_ROLLON 1
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
61 #define CC_ROLLUP 2
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
62
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
63 static int cc_mode=CC_ROLLON;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
64 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
65
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
66 static void build_char_table(void)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
67 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
68 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
69 /* first the normal ASCII codes */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
70 for (i = 0; i < 128; i++)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
71 chartbl[i] = (char) i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
72 /* now the special codes */
34702
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
73 chartbl[0x2a] = 0xe1; /* Latin Small Letter A with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
74 chartbl[0x5c] = 0xe9; /* Latin Small Letter E with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
75 chartbl[0x5e] = 0xed; /* Latin Small Letter I with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
76 chartbl[0x5f] = 0xf3; /* Latin Small Letter O with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
77 chartbl[0x60] = 0xfa; /* Latin Small Letter U with acute */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
78 chartbl[0x7b] = 0xe7; /* Latin Small Letter C with cedilla */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
79 chartbl[0x7c] = 0xf7; /* Division sign */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
80 chartbl[0x7d] = 0xd1; /* Latin Capital letter N with tilde */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
81 chartbl[0x7e] = 0xf1; /* Latin Small Letter N with tilde */
788175a8c14a Do not use single quotes around hex literals
al
parents: 34693
diff changeset
82 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
83 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
84
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
85 static void clear_buffer(subtitle *buf)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
86 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
87 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
88 buf->lines=0;
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
89 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
90 free(buf->text[i]);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
91 buf->text[i] = NULL;
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
92 }
32458
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 /**
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
97 \brief scroll buffer one line up
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
98 \param buf buffer to scroll
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
99 */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
100 static void scroll_buffer(subtitle* buf)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
101 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
102 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
103
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
104 while(buf->lines > cc_lines)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
105 {
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32467
diff changeset
106 free(buf->text[0]);
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
107
32512
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
108 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
109
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
110 buf->text[buf->lines-1] = NULL;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
111 buf->lines--;
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 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
114
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
115 static int channel;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
116
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
117 void subcc_init(void)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
118 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
119 int i;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
120 //printf("subcc_init(): initing...\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
121 build_char_table();
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
122 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
123 buf1.lines=buf2.lines=0;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
124 fb=&buf1;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
125 bb=&buf2;
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
126 channel = -1;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
127
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
128 initialized=1;
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
129 wtv_format = 0;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
130 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
131
34761
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
132 void subcc_reset(void)
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
133 {
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
134 wtv_format = 0;
34761
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
135 if (!initialized)
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
136 return;
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
137 clear_buffer(&buf1);
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
138 clear_buffer(&buf2);
02a03e00341e Support EIA-608 captions in MOV.
reimar
parents: 34759
diff changeset
139 }
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
140
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
141 static void display_buffer(subtitle *buf)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
142 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
143 vo_sub = buf;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
144 vo_osd_changed(OSDTYPE_SUBTITLE);
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
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
148 static void append_char(char c)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
149 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
150 if(!bb->lines) {bb->lines++; cursor_pos=0;}
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
151 if(bb->text[bb->lines - 1]==NULL)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
152 {
32513
a150a1bc458d Use calloc instead of malloc+memset.
reimar
parents: 32512
diff changeset
153 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
154 cursor_pos=0;
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
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
157 if(c=='\n')
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
158 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
159 if(cursor_pos>0 && bb->lines < SUB_MAX_TEXT)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
160 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
161 bb->lines++;cursor_pos=0;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
162 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
163 bb->text[bb->lines - 1]=calloc(1, CC_MAX_LINE_LENGTH);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
164 scroll_buffer(bb);
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 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
168 else
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
169 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
170 if(cursor_pos==CC_MAX_LINE_LENGTH-1)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
171 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
172 fprintf(stderr,"CC: append_char() reached CC_MAX_LINE_LENGTH!\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
173 return;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
174 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
175 bb->text[bb->lines - 1][cursor_pos++]=c;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
176 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
177 //In CC roll-up mode data should be shown immediately
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
178 if(cc_mode==CC_ROLLUP) display_buffer(bb);
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
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
182 static void swap_buffers(void)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
183 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
184 subtitle *foo;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
185 foo=fb;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
186 fb=bb;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
187 bb=foo;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
188 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
189
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
190 static int selected_channel(void)
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
191 {
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
192 return subcc_enabled - 1;
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
193 }
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
194
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
195 static void cc_decode_EIA608(unsigned short int data)
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
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
198 static unsigned short int lastcode=0x0000;
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
199 uint8_t c1 = data & 0x7f;
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
200 uint8_t c2 = (data >> 8) & 0x7f;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
201
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
202 if (c1 & 0x60) { /* normal character, 0x20 <= c1 <= 0x7f */
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
203 if (channel != (selected_channel() & 1))
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
204 return;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
205 append_char(chartbl[c1]);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
206 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
207 append_char(chartbl[c2]);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
208 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
209 else if (c1 & 0x10) // control code / special char
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
210 {
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
211 channel = (c1 & 0x08) >> 3;
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
212 if (channel != (selected_channel() & 1))
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
213 return;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
214 c1&=~0x08;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
215 if(data!=lastcode)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
216 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
217 if(c2 & 0x40) { /*PAC, Preamble Address Code */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
218 append_char('\n'); /*FIXME properly interpret PACs*/
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
219 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
220 else
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
221 switch(c1)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
222 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
223 case 0x10: break; // ext attribute
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
224 case 0x11:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
225 if((c2 & 0x30)==0x30)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
226 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
227 //printf("[debug]:Special char (ignored)\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
228 /*cc_decode_special_char()*/;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
229 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
230 else if (c2 & 0x20)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
231 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
232 //printf("[debug]: midrow_attr (ignored)\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
233 /*cc_decode_midrow_attr()*/;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
234 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
235 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
236 case 0x14:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
237 switch(c2)
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
238 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
239 case 0x00: //CC roll-on mode
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
240 cc_mode=CC_ROLLON;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
241 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
242 case 0x25: //CC roll-up, 2 rows
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
243 case 0x26: //CC roll-up, 3 rows
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
244 case 0x27: //CC roll-up, 4 rows
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
245 cc_lines=c2-0x23;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
246 cc_mode=CC_ROLLUP;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
247 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
248 case 0x2C: display_buffer(NULL); //EDM
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
249 clear_buffer(fb); break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
250 case 0x2d: append_char('\n'); //carriage return
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
251 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
252 case 0x2e: clear_buffer(bb); //ENM
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
253 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
254 case 0x2f: swap_buffers(); //Swap buffers
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
255 display_buffer(fb);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
256 clear_buffer(bb);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
257 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
258 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
259 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
260 case 0x17:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
261 if( c2>=0x21 && c2<=0x23) //TAB
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
262 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
263 break;
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 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
268 lastcode=data;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
269 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
270
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
271 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
272 {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
273 /* 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
274 * EIA-708 standard, so it is hard to say.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
275 * 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
276 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
277 * repeat
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
278 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
279 * 0xfe starts 2 byte sequence of unknown purpose. It might denote
32522
796cd767b024 Fix one -subcc sample.
reimar
parents: 32520
diff changeset
280 * field #2 in line 21 of the VBI.
796cd767b024 Fix one -subcc sample.
reimar
parents: 32520
diff changeset
281 * Treating it identical of 0xff fixes
796cd767b024 Fix one -subcc sample.
reimar
parents: 32520
diff changeset
282 * http://samples.mplayerhq.hu/MPEG-VOB/ClosedCaptions/Starship_Troopers.vob
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
283 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
284 * 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
285 * 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
286 * 0xfe. In either case, the following triplet needs to be ignored
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
287 * for line 21, field 1.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
288 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
289 * 0x00 is padding, followed by 2 more 0x00.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
290 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
291 * 0x01 always seems to appear at the beginning, always seems to
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
292 * be followed by 0xf8, 8-bit number.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
293 * 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
294 * number of code triplets that follow.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
295 * The most significant bit denotes whether the Line 21 field 1
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
296 * captioning information is at odd or even triplet offsets from this
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
297 * beginning triplet. 1 denotes odd offsets, 0 denotes even offsets.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
298 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
299 * 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
300 * will assume.
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
301 *
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
302 * until end of packet
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
303 */
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
304 const uint8_t *current = inputbuffer;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
305 unsigned int curbytes = 0;
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
306 uint8_t data1, data2;
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
307 uint8_t cc_code;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
308 int odd_offset = 1;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
309
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
310 while (curbytes < inputlength) {
32512
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
311 cc_code = current[0];
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
312
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
313 if (inputlength - curbytes < 2) {
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
314 #ifdef LOG_DEBUG
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
315 fprintf(stderr, "Not enough data for 2-byte CC encoding\n");
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
316 #endif
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
317 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
318 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
319
32512
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
320 data1 = current[1];
024358659ebd Avoid unnecessary ().
reimar
parents: 32511
diff changeset
321 data2 = current[2];
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
322 current += 3; curbytes += 3;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
323
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
324 // 0xfe/0xff are both used on plain EIA-608 CC and
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
325 // for extended EIA-708 (where 0xfc/0xfd is used for
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
326 // compatibility layer).
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
327 // Allow using channel bit 2 to select between which
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
328 // ones to look in.
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
329 switch (cc_code) {
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
330 case 0xfc:
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
331 case 0xfd:
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
332 case 0xfe:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
333 case 0xff:
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
334 if ((cc_code & 2) == (selected_channel() & 4) >> 1)
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
335 break;
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
336 odd_offset ^= 1;
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
337 if (odd_offset != (selected_channel() & 2) >> 1)
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
338 break;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
339 /* expect EIA-608 CC1/CC2 encoding */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
340 // FIXME check parity!
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
341 // 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
342 // we should encounter no "transmission errors".
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
343 cc_decode_EIA608(data1 | (data2 << 8));
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
344 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
345
35029
7abba31768ec Add new -subcc values.
reimar
parents: 35028
diff changeset
346 case 0xfa:
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
347 case 0x00:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
348 /* This seems to be just padding */
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
349 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
350
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
351 case 0x01:
32520
5e062dc4a04d Add code to allow selecting the Close Captioning channel.
reimar
parents: 32513
diff changeset
352 odd_offset = data2 >> 7;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
353 break;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
354
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
355 default:
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
356 //#ifdef LOG_DEBUG
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
357 fprintf(stderr, "Unknown CC encoding: %x\n", cc_code);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
358 //#endif
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
359 break;
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 }
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
363
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
364 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
365 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
366 /**
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
367 * 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
368 * This function handles that case.
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
369 */
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
370 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
371 {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
372 while (len >= 10) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
373 int channel = -1;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
374 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
375 channel = 0;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
376 } 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
377 channel = 1;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
378 } else {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
379 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
380 data++;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
381 len--;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
382 continue;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
383 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
384 if (channel == selected_channel() >> 1)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
385 cc_decode_EIA608(data[8] | (data[9] << 8));
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
386 data += 10;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
387 len -= 10;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
388 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
389 }
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
390
32566
da2dc11d8436 Use uint8_t type instead of unsigned char.
reimar
parents: 32565
diff changeset
391 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
392 {
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
393 int mov_mode = len >= 10 &&
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
394 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
395 if(!subcc_enabled) return;
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
396 if(!initialized) subcc_init();
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
397
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
398 if (mov_mode) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
399 mov_subcc_decode(inputdata, len);
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
400 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
401 }
35028
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
402 if (len & 1) wtv_format = 0;
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
403 if (len == 2) {
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
404 // EIA-608 compatibility part.
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
405 // 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
406 cc_decode_EIA608(inputdata[0] | (inputdata[1] << 8));
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
407 wtv_format = 1;
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
408 }
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
409 if (wtv_format)
dd77d5a292df Support closed-caption format as used in wtv format.
reimar
parents: 34761
diff changeset
410 return;
32458
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
411 subcc_decode(inputdata, len);
ab8fb38f28b1 Move sub_cc.[ch] to the sub directory.
cigaes
parents:
diff changeset
412 }
34756
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
413
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
414 /**
34759
430e164238d1 Fix misspelling ATSC as ASTC.
reimar
parents: 34756
diff changeset
415 * 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
416 * 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
417 * differences:
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
418 * 1) It starts with "GA" instead of "CC"
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
419 * 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
420 * 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
421 * for this yet beyond this function.
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
422 */
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
423 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
424 {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
425 int cc_count;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
426 if (!subcc_enabled)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
427 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
428 if (!initialized)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
429 subcc_init();
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
430 if (len <= 5)
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
431 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
432 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
433 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
434 "0x%"PRIx8" 0x%"PRIx8" 0x%"PRIx8"\n",
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
435 data[0], data[1], data[2]);
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
436 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
437 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
438 // process_cc_data_flag
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
439 if (!(data[3] & 0x40))
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
440 return;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
441 cc_count = data[3] & 0x1f;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
442 data += 5;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
443 len -= 5;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
444 cc_count = FFMIN(cc_count, len / 3);
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
445 while (cc_count--) {
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
446 // EAI-608 data
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
447 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
448 cc_decode_EIA608(data[1] | (data[2] << 8));
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
449 data += 3;
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
450 }
df3ff52039fe Add code to support CC subtitles in ASTC and MOV.
reimar
parents: 34702
diff changeset
451 }