FFmpeg
Loading...
Searching...
No Matches
cdg.c
Go to the documentation of this file.
1/*
2 * CD Graphics Demuxer
3 * Copyright (c) 2009 Michael Tison
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 "avformat.h"
23#include "demux.h"
24#include "internal.h"
25
26#define CDG_PACKET_SIZE 24
27#define CDG_COMMAND 0x09
28#define CDG_MASK 0x3F
29
30static int read_probe(const AVProbeData *p)
31{
32 const int cnt = p->buf_size / CDG_PACKET_SIZE;
33 int score = 0;
34
35 for (int i = 0; i < cnt; i++) {
36 const int x = p->buf[i * CDG_PACKET_SIZE] & CDG_MASK;
37
38 score += x == CDG_COMMAND;
39 if (x != CDG_COMMAND && x != 0)
40 return 0;
41 }
42
43 return FFMIN(score, AVPROBE_SCORE_MAX);
44}
45
47{
48 AVStream *vst;
49 int64_t ret;
50
52 if (!vst)
53 return AVERROR(ENOMEM);
54
57
58 /// 75 sectors/sec * 4 packets/sector = 300 packets/sec
59 avpriv_set_pts_info(vst, 32, 1, 300);
60
61 ret = avio_size(s->pb);
62 if (ret < 0) {
63 av_log(s, AV_LOG_WARNING, "Cannot calculate duration as file size cannot be determined\n");
64 } else
65 vst->duration = (ret * (int64_t)vst->time_base.den) / (CDG_PACKET_SIZE * 300);
66
67 return 0;
68}
69
71{
72 int ret;
73
75 pkt->stream_index = 0;
76 pkt->dts=
77 pkt->pts= pkt->pos / CDG_PACKET_SIZE;
78
79 if (!pkt->pos || (ret > 5 &&
80 (pkt->data[0] & CDG_MASK) == CDG_COMMAND &&
81 (pkt->data[1] & CDG_MASK) == 1 && !(pkt->data[2+2+1] & 0x0F))) {
82 pkt->flags = AV_PKT_FLAG_KEY;
83 }
84 return ret;
85}
86
88 .p.name = "cdg",
89 .p.long_name = NULL_IF_CONFIG_SMALL("CD Graphics"),
90 .p.flags = AVFMT_GENERIC_INDEX,
91 .p.extensions = "cdg",
92 .read_probe = read_probe,
93 .read_header = read_header,
94 .read_packet = read_packet,
95};
const FFInputFormat ff_cdg_demuxer
Definition cdg.c:87
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.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
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
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition aviobuf.c:326
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_packet(AVFormatContext *s, AVPacket *pkt)
Definition cdg.c:70
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
static int read_header(AVFormatContext *s)
Definition cdg.c:46
#define CDG_COMMAND
masks
Definition cdgraphics.c:46
#define CDG_PACKET_SIZE
data sizes
Definition cdgraphics.c:61
#define CDG_MASK
Definition cdgraphics.c:47
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_CDGRAPHICS
Definition codec_id.h:182
#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(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define FFMIN(a, b)
Definition macros.h:49
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
int den
Denominator.
Definition rational.h:60
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:825
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:805
#define av_log(a,...)