FFmpeg
4.0
libavcodec
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
24
#include "
libavutil/intreadwrite.h
"
25
#include "
libavutil/mem.h
"
26
#include "
avcodec.h
"
27
28
/* parser definition */
29
typedef
struct
DVDSubParseContext
{
30
uint8_t
*
packet
;
31
int
packet_len
;
32
int
packet_index
;
33
}
DVDSubParseContext
;
34
35
static
av_cold
int
dvdsub_parse_init
(
AVCodecParserContext
*
s
)
36
{
37
return
0;
38
}
39
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)
44
{
45
DVDSubParseContext
*pc = s->
priv_data
;
46
47
if
(pc->
packet_index
== 0) {
48
if
(buf_size < 2 ||
AV_RB16
(buf) && buf_size < 6) {
49
if
(buf_size)
50
av_log
(avctx,
AV_LOG_DEBUG
,
"Parser input %d too small\n"
, buf_size);
51
return
buf_size;
52
}
53
pc->
packet_len
=
AV_RB16
(buf);
54
if
(pc->
packet_len
== 0)
/* HD-DVD subpicture packet */
55
pc->
packet_len
=
AV_RB32
(buf+2);
56
av_freep
(&pc->
packet
);
57
pc->
packet
=
av_malloc
(pc->
packet_len
);
58
}
59
if
(pc->
packet
) {
60
if
(pc->
packet_index
+ buf_size <= pc->
packet_len
) {
61
memcpy(pc->
packet
+ pc->
packet_index
, buf, buf_size);
62
pc->
packet_index
+= buf_size;
63
if
(pc->
packet_index
>= pc->
packet_len
) {
64
*poutbuf = pc->
packet
;
65
*poutbuf_size = pc->
packet_len
;
66
pc->
packet_index
= 0;
67
return
buf_size;
68
}
69
}
else
{
70
/* erroneous size */
71
pc->
packet_index
= 0;
72
}
73
}
74
*poutbuf =
NULL
;
75
*poutbuf_size = 0;
76
return
buf_size;
77
}
78
79
static
av_cold
void
dvdsub_parse_close
(
AVCodecParserContext
*
s
)
80
{
81
DVDSubParseContext
*pc = s->
priv_data
;
82
av_freep
(&pc->
packet
);
83
}
84
85
AVCodecParser
ff_dvdsub_parser
= {
86
.
codec_ids
= {
AV_CODEC_ID_DVD_SUBTITLE
},
87
.priv_data_size =
sizeof
(
DVDSubParseContext
),
88
.parser_init =
dvdsub_parse_init
,
89
.parser_parse =
dvdsub_parse
,
90
.parser_close =
dvdsub_parse_close
,
91
};
NULL
#define NULL
Definition:
coverity.c:32
s
const char * s
Definition:
avisynth_c.h:768
mem.h
Memory handling functions.
AVCodecParser::codec_ids
int codec_ids[5]
Definition:
avcodec.h:5200
dvdsub_parse
static int dvdsub_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition:
dvdsub_parser.c:40
dvdsub_parse_init
static av_cold int dvdsub_parse_init(AVCodecParserContext *s)
Definition:
dvdsub_parser.c:35
AV_CODEC_ID_DVD_SUBTITLE
Definition:
avcodec.h:643
uint8_t
uint8_t
Definition:
audio_convert.c:194
av_cold
#define av_cold
Definition:
attributes.h:82
av_malloc
#define av_malloc(s)
Definition:
tableprint_vlc.h:31
AV_RB32
#define AV_RB32
Definition:
intreadwrite.h:130
av_log
#define av_log(a,...)
Definition:
tableprint_vlc.h:28
AV_RB16
#define AV_RB16
Definition:
intreadwrite.h:53
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition:
log.h:197
AVCodecParserContext::priv_data
void * priv_data
Definition:
avcodec.h:5033
AVCodecParser
Definition:
avcodec.h:5199
ff_dvdsub_parser
AVCodecParser ff_dvdsub_parser
Definition:
dvdsub_parser.c:85
intreadwrite.h
DVDSubParseContext::packet_index
int packet_index
Definition:
dvdsub_parser.c:32
AVCodecParserContext
Definition:
avcodec.h:5032
DVDSubParseContext::packet
uint8_t * packet
Definition:
dvdsub_parser.c:30
avcodec.h
Libavcodec external API header.
AVCodecContext
main external API structure.
Definition:
avcodec.h:1518
buf
void * buf
Definition:
avisynth_c.h:690
dvdsub_parse_close
static av_cold void dvdsub_parse_close(AVCodecParserContext *s)
Definition:
dvdsub_parser.c:79
DVDSubParseContext::packet_len
int packet_len
Definition:
dvdsub_parser.c:31
av_freep
#define av_freep(p)
Definition:
tableprint_vlc.h:35
DVDSubParseContext
Definition:
dvdsub_parser.c:29
Generated on Tue May 22 2018 07:06:31 for FFmpeg by
1.8.13