/src/ffmpeg/libavformat/dvbsub.c
Line | Count | Source |
1 | | /* |
2 | | * RAW dvbsub demuxer |
3 | | * Copyright (c) 2015 Michael Niedermayer <michaelni@gmx.at> |
4 | | * |
5 | | * This file is part of FFmpeg. |
6 | | * |
7 | | * FFmpeg is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * FFmpeg is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public |
18 | | * License along with FFmpeg; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | | */ |
21 | | |
22 | | #include "libavutil/intreadwrite.h" |
23 | | |
24 | | #include "avformat.h" |
25 | | #include "rawdec.h" |
26 | | |
27 | | |
28 | | static int dvbsub_probe(const AVProbeData *p) |
29 | 964k | { |
30 | 964k | int i, j, k; |
31 | 964k | const uint8_t *end = p->buf + p->buf_size; |
32 | 964k | int type, len; |
33 | 964k | int max_score = 0; |
34 | | |
35 | 3.33G | for(i=0; i<p->buf_size; i++){ |
36 | 3.33G | if (p->buf[i] == 0x0f) { |
37 | 10.8M | const uint8_t *ptr = p->buf + i; |
38 | 10.8M | uint8_t histogram[6] = {0}; |
39 | 10.8M | int min = 255; |
40 | 11.2M | for(j=0; 6 < end - ptr; j++) { |
41 | 11.1M | if (*ptr != 0x0f) |
42 | 282k | break; |
43 | 10.9M | type = ptr[1]; |
44 | | //page_id = AV_RB16(ptr + 2); |
45 | 10.9M | len = AV_RB16(ptr + 4); |
46 | 10.9M | if (type == 0x80) { |
47 | 167k | ; |
48 | 10.7M | } else if (type >= 0x10 && type <= 0x14) { |
49 | 320k | histogram[type - 0x10] ++; |
50 | 320k | } else |
51 | 10.4M | break; |
52 | 487k | if (6 + len > end - ptr) |
53 | 110k | break; |
54 | 377k | ptr += 6 + len; |
55 | 377k | } |
56 | 54.2M | for (k=0; k < 4; k++) { |
57 | 43.3M | min = FFMIN(min, histogram[k]); |
58 | 43.3M | } |
59 | 10.8M | if (min && j > max_score) |
60 | 431 | max_score = j; |
61 | 10.8M | } |
62 | 3.33G | } |
63 | | |
64 | 964k | if (max_score > 5) |
65 | 177 | return AVPROBE_SCORE_EXTENSION; |
66 | | |
67 | 964k | return 0; |
68 | 964k | } |
69 | | |
70 | | FF_DEF_RAWSUB_DEMUXER(dvbsub, "raw dvbsub", dvbsub_probe, NULL, AV_CODEC_ID_DVB_SUBTITLE, AVFMT_GENERIC_INDEX) |