FFmpeg
Loading...
Searching...
No Matches
dfa.c
Go to the documentation of this file.
1/*
2 * Chronomaster DFA Format Demuxer
3 * Copyright (c) 2011 Konstantin Shishkov
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 <inttypes.h>
23
25#include "avformat.h"
26#include "demux.h"
27#include "internal.h"
28
29static int dfa_probe(const AVProbeData *p)
30{
31 if (p->buf_size < 4 || AV_RL32(p->buf) != MKTAG('D', 'F', 'I', 'A'))
32 return 0;
33
34 if (AV_RL32(p->buf + 16) != 0x80)
35 return AVPROBE_SCORE_MAX / 4;
36
37 return AVPROBE_SCORE_MAX;
38}
39
41{
42 AVIOContext *pb = s->pb;
43 AVStream *st;
44 int frames, ret;
45 int version;
46 uint32_t mspf;
47
48 if (avio_rl32(pb) != MKTAG('D', 'F', 'I', 'A')) {
49 av_log(s, AV_LOG_ERROR, "Invalid magic for DFA\n");
51 }
52
53 version = avio_rl16(pb);
54 frames = avio_rl16(pb);
55
57 if (!st)
58 return AVERROR(ENOMEM);
59
62 st->codecpar->width = avio_rl16(pb);
63 st->codecpar->height = avio_rl16(pb);
64 mspf = avio_rl32(pb);
65 if (!mspf) {
66 av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n");
67 mspf = 100;
68 }
69 avpriv_set_pts_info(st, 24, mspf, 1000);
70 avio_skip(pb, 128 - 16); // padding
71 st->duration = frames;
72
73 if ((ret = ff_alloc_extradata(st->codecpar, 2)) < 0)
74 return ret;
76 if (version == 0x100)
77 st->sample_aspect_ratio = (AVRational){2, 1};
78
79 return 0;
80}
81
83{
84 AVIOContext *pb = s->pb;
85 uint32_t frame_size;
86 int ret, first = 1;
87
88 if (avio_feof(pb))
89 return AVERROR_EOF;
90
91 if (av_get_packet(pb, pkt, 12) != 12)
93 while (!avio_feof(pb)) {
94 if (!first) {
95 ret = av_append_packet(pb, pkt, 12);
96 if (ret < 0) {
97 return ret;
98 }
99 } else
100 first = 0;
101 frame_size = AV_RL32(pkt->data + pkt->size - 8);
102 if (frame_size > INT_MAX - 4) {
103 av_log(s, AV_LOG_ERROR, "Too large chunk size: %"PRIu32"\n", frame_size);
104 return AVERROR_INVALIDDATA;
105 }
106 if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) {
107 if (frame_size) {
109 "skipping %"PRIu32" bytes of end-of-frame marker chunk\n",
110 frame_size);
112 }
113 return 0;
114 }
115 ret = av_append_packet(pb, pkt, frame_size);
116 if (ret < 0) {
117 return ret;
118 }
119 }
120
121 return 0;
122}
123
125 .p.name = "dfa",
126 .p.long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
127 .p.flags = AVFMT_GENERIC_INDEX,
128 .read_probe = dfa_probe,
129 .read_header = dfa_read_header,
130 .read_packet = dfa_read_packet,
131};
const FFInputFormat ff_dfa_demuxer
Definition dfa.c:124
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
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
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static const uint8_t frame_size[4]
Definition g723_1.h:222
@ AV_CODEC_ID_DFA
Definition codec_id.h:200
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
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_RL32(p)
#define AV_WL16(p, v)
static int dfa_read_header(AVFormatContext *s)
Definition dfa.c:40
static int dfa_probe(const AVProbeData *p)
Definition dfa.c:29
static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition dfa.c:82
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition utils.c:237
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
version
Definition libkvazaar.c:313
#define MKTAG(a, b, c, d)
Definition macros.h:55
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
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
Bytestream IO Context.
Definition avio.h:160
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
Rational number (pair of numerator and denominator).
Definition rational.h:58
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition avformat.h:844
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:825
#define av_log(a,...)
static int frames
Definition movenc.c:67