FFmpeg
Loading...
Searching...
No Matches
supdec.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "avformat.h"
20#include "demux.h"
21#include "internal.h"
23
24#define SUP_PGS_MAGIC 0x5047 /* "PG", big endian */
25
27{
29 if (!st)
30 return AVERROR(ENOMEM);
33 avpriv_set_pts_info(st, 32, 1, 90000);
34
35 return 0;
36}
37
39{
40 int64_t pts, dts, pos;
41 int ret;
42
43 pos = avio_tell(s->pb);
44
45 if (avio_rb16(s->pb) != SUP_PGS_MAGIC)
47
48 pts = avio_rb32(s->pb);
49 dts = avio_rb32(s->pb);
50
51 if ((ret = av_get_packet(s->pb, pkt, 3)) < 0)
52 return ret;
53
54 pkt->stream_index = 0;
55 pkt->flags |= AV_PKT_FLAG_KEY;
56 pkt->pos = pos;
57 pkt->pts = pts;
58 // Many files have DTS set to 0 for all packets, so assume 0 means unset.
59 pkt->dts = dts ? dts : AV_NOPTS_VALUE;
60
61 if (pkt->size >= 3) {
62 // The full packet size is stored as part of the packet.
63 size_t len = AV_RB16(pkt->data + 1);
64
65 if ((ret = av_append_packet(s->pb, pkt, len)) < 0)
66 return ret;
67 }
68
69 return 0;
70}
71
72static int sup_probe(const AVProbeData *p)
73{
74 unsigned char *buf = p->buf;
75 size_t buf_size = p->buf_size;
76 int nb_packets;
77
78 for (nb_packets = 0; nb_packets < 10; nb_packets++) {
79 size_t full_packet_size;
80 if (buf_size < 10 + 3)
81 break;
82 if (AV_RB16(buf) != SUP_PGS_MAGIC)
83 return 0;
84 full_packet_size = AV_RB16(buf + 10 + 1) + 10 + 3;
85 if (buf_size < full_packet_size)
86 break;
87 buf += full_packet_size;
88 buf_size -= full_packet_size;
89 }
90 if (!nb_packets)
91 return 0;
92 if (nb_packets < 2)
93 return AVPROBE_SCORE_RETRY / 2;
94 if (nb_packets < 4)
96 if (nb_packets < 10)
98 return AVPROBE_SCORE_MAX;
99}
100
102 .p.name = "sup",
103 .p.long_name = NULL_IF_CONFIG_SMALL("raw HDMV Presentation Graphic Stream subtitles"),
104 .p.extensions = "sup",
105 .p.mime_type = "application/x-pgs",
106 .p.flags = AVFMT_GENERIC_INDEX,
107 .read_probe = sup_probe,
108 .read_header = sup_read_header,
109 .read_packet = sup_read_packet,
110};
const FFInputFormat ff_sup_demuxer
Definition supdec.c:101
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
int av_append_packet(AVIOContext *s, AVPacket *pkt, int size)
Read data and append it to the current content of the AVPacket.
Definition utils.c:114
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition avformat.h:481
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
#define AVPROBE_SCORE_RETRY
Definition avformat.h:478
unsigned int avio_rb16(AVIOContext *s)
Definition aviobuf.c:749
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
unsigned int avio_rb32(AVIOContext *s)
Definition aviobuf.c:764
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
Definition codec_id.h:572
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_RB16(p)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
unsigned int pos
Definition spdifenc.c:431
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1333
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
static int sup_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition supdec.c:38
static int sup_probe(const AVProbeData *p)
Definition supdec.c:72
#define SUP_PGS_MAGIC
Definition supdec.c:24
static int sup_read_header(AVFormatContext *s)
Definition supdec.c:26
static int64_t pts
int len