| | 1 | /* |
| | 2 | * probe function for PGS subtitles |
| | 3 | * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at> |
| | 4 | * Copyright (c) 2011 Carl Eugen Hoyos for FFmpeg |
| | 5 | * |
| | 6 | * This file is part of FFmpeg. |
| | 7 | * |
| | 8 | * FFmpeg is free software; you can redistribute it and/or |
| | 9 | * modify it under the terms of the GNU Lesser General Public |
| | 10 | * License as published by the Free Software Foundation; either |
| | 11 | * version 2.1 of the License, or (at your option) any later version. |
| | 12 | * |
| | 13 | * FFmpeg is distributed in the hope that it will be useful, |
| | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| | 16 | * Lesser General Public License for more details. |
| | 17 | * |
| | 18 | * You should have received a copy of the GNU Lesser General Public |
| | 19 | * License along with FFmpeg; if not, write to the Free Software |
| | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| | 21 | */ |
| | 22 | |
| | 23 | #include "libavutil/intreadwrite.h" |
| | 24 | #include "avformat.h" |
| | 25 | |
| | 26 | static int pgs_subtitle_probe(AVProbeData *p) |
| | 27 | { |
| | 28 | int frames, max_frames = 0, first_frames = 0; |
| | 29 | uint8_t *buf0 = p->buf; |
| | 30 | uint8_t *buf, *buf2; |
| | 31 | uint8_t *end = buf0 + p->buf_size - 3; |
| | 32 | |
| | 33 | buf = buf0; |
| | 34 | |
| | 35 | for(; buf < end; buf= buf2+1) { |
| | 36 | buf2 = buf; |
| | 37 | |
| | 38 | for(frames = 0; buf2 < end; frames++) { |
| | 39 | uint16_t size = AV_RB16(buf2 + 1) + 3; |
| | 40 | if (*buf2 != 0x80 && (*buf2 | 3) != 0x17 || |
| | 41 | buf2 + size > end || |
| | 42 | buf2[size] != 0x80 && (buf2[size] | 3) != 0x17) |
| | 43 | break; |
| | 44 | buf2 += size; |
| | 45 | } |
| | 46 | max_frames = FFMAX(max_frames, frames); |
| | 47 | if(buf == buf0) |
| | 48 | first_frames= frames; |
| | 49 | } |
| | 50 | if (first_frames>=10) return AVPROBE_SCORE_MAX/2+1; |
| | 51 | else if(max_frames>50) return AVPROBE_SCORE_MAX/2; |
| | 52 | else if(max_frames>=5) return AVPROBE_SCORE_MAX/4; |
| | 53 | else if(max_frames>=3) return 1; |
| | 54 | else return 0; |
| | 55 | } |
| | 56 | |
| | 57 | AVInputFormat ff_pgs_demuxer = { |
| | 58 | .name = "pgs", |
| | 59 | .long_name = NULL_IF_CONFIG_SMALL("raw PGS subtitles"), |
| | 60 | .read_probe = pgs_subtitle_probe, |
| | 61 | .value = CODEC_ID_HDMV_PGS_SUBTITLE, |
| | 62 | }; |