aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
[libav.git] / libavcodec / dvdsub_parser.c
blob2ad3b33602b5197b135239772b36523446dac475
1 /*
2 * DVD subtitle decoding
3 * Copyright (c) 2005 Fabrice Bellard
5 * This file is part of Libav.
7 * Libav 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.
12 * Libav 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <string.h>
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
26 #include "avcodec.h"
28 /* parser definition */
29 typedef struct DVDSubParseContext {
30 uint8_t *packet;
31 int packet_len;
32 int packet_index;
33 } DVDSubParseContext;
35 static av_cold int dvdsub_parse_init(AVCodecParserContext *s)
37 return 0;
40 static int dvdsub_parse(AVCodecParserContext *s,
41 AVCodecContext *avctx,
42 const uint8_t **poutbuf, int *poutbuf_size,
43 const uint8_t *buf, int buf_size)
45 DVDSubParseContext *pc = s->priv_data;
47 if (pc->packet_index == 0) {
48 if (buf_size < 2)
49 return 0;
50 pc->packet_len = AV_RB16(buf);
51 if (pc->packet_len == 0) /* HD-DVD subpicture packet */
52 pc->packet_len = AV_RB32(buf+2);
53 av_freep(&pc->packet);
54 pc->packet = av_malloc(pc->packet_len);
56 if (pc->packet) {
57 if (pc->packet_index + buf_size <= pc->packet_len) {
58 memcpy(pc->packet + pc->packet_index, buf, buf_size);
59 pc->packet_index += buf_size;
60 if (pc->packet_index >= pc->packet_len) {
61 *poutbuf = pc->packet;
62 *poutbuf_size = pc->packet_len;
63 pc->packet_index = 0;
64 return buf_size;
66 } else {
67 /* erroneous size */
68 pc->packet_index = 0;
71 *poutbuf = NULL;
72 *poutbuf_size = 0;
73 return buf_size;
76 static av_cold void dvdsub_parse_close(AVCodecParserContext *s)
78 DVDSubParseContext *pc = s->priv_data;
79 av_freep(&pc->packet);
82 AVCodecParser ff_dvdsub_parser = {
83 .codec_ids = { AV_CODEC_ID_DVD_SUBTITLE },
84 .priv_data_size = sizeof(DVDSubParseContext),
85 .parser_init = dvdsub_parse_init,
86 .parser_parse = dvdsub_parse,
87 .parser_close = dvdsub_parse_close,