FFmpeg
Loading...
Searching...
No Matches
dvdsub_parser.c
Go to the documentation of this file.
1/*
2 * DVD subtitle decoding
3 * Copyright (c) 2005 Fabrice Bellard
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 <string.h>
23
25#include "libavutil/mem.h"
26#include "avcodec.h"
27#include "parser_internal.h"
28
29/* parser definition */
35
37 AVCodecContext *avctx,
38 const uint8_t **poutbuf, int *poutbuf_size,
39 const uint8_t *buf, int buf_size)
40{
41 DVDSubParseContext *pc = s->priv_data;
42
43 *poutbuf = buf;
44 *poutbuf_size = buf_size;
45
46 if (pc->packet_index == 0) {
47 if (buf_size < 2 || (AV_RB16(buf) == 0 && buf_size < 6)) {
48 if (buf_size)
49 av_log(avctx, AV_LOG_DEBUG, "Parser input %d too small\n", buf_size);
50 return buf_size;
51 }
52 pc->packet_len = AV_RB16(buf);
53 if (pc->packet_len == 0) /* HD-DVD subpicture packet */
54 pc->packet_len = AV_RB32(buf+2);
55 av_freep(&pc->packet);
56 if ((unsigned)pc->packet_len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
57 av_log(avctx, AV_LOG_ERROR, "packet length %d is invalid\n", pc->packet_len);
58 return buf_size;
59 }
61 }
62 if (pc->packet) {
63 if (buf_size <= pc->packet_len - pc->packet_index) {
64 memcpy(pc->packet + pc->packet_index, buf, buf_size);
65 pc->packet_index += buf_size;
66 if (pc->packet_index >= pc->packet_len) {
67 *poutbuf = pc->packet;
68 *poutbuf_size = pc->packet_len;
69 pc->packet_index = 0;
70 return buf_size;
71 }
72 } else {
73 /* erroneous size */
74 pc->packet_index = 0;
75 }
76 }
77 *poutbuf = NULL;
78 *poutbuf_size = 0;
79 return buf_size;
80}
81
83{
84 DVDSubParseContext *pc = s->priv_data;
85 av_freep(&pc->packet);
86}
87
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition apv_parser.c:92
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
Libavcodec external API header.
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static int dvdsub_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
static av_cold void dvdsub_parse_close(AVCodecParserContext *s)
const FFCodecParser ff_dvdsub_parser
@ AV_CODEC_ID_DVD_SUBTITLE
Definition codec_id.h:566
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define AV_RB32(p)
#define AV_RB16(p)
#define av_cold
Definition attributes.h:117
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
#define PARSER_CODEC_LIST(...)
main external API structure.
Definition avcodec.h:443
#define av_freep(p)
#define av_log(a,...)