]> git.sesse.net Git - ffmpeg/blob - libavformat/mods.c
avformat/argo_asf: fix enforcement of chunk count
[ffmpeg] / libavformat / mods.c
1 /*
2  * MODS demuxer
3  * Copyright (c) 2020 Paul B Mahol
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 "libavutil/intreadwrite.h"
23
24 #include "avformat.h"
25 #include "internal.h"
26
27 static int mods_probe(const AVProbeData *p)
28 {
29     if (memcmp(p->buf, "MODSN3\x0a\x00", 8))
30         return 0;
31     if (AV_RB32(p->buf + 8) == 0)
32         return 0;
33     if (AV_RB32(p->buf + 12) == 0)
34         return 0;
35     if (AV_RB32(p->buf + 16) == 0)
36         return 0;
37     return AVPROBE_SCORE_MAX;
38 }
39
40 static int mods_read_header(AVFormatContext *s)
41 {
42     AVIOContext *pb = s->pb;
43     AVRational fps;
44     int64_t pos;
45
46     AVStream *st = avformat_new_stream(s, NULL);
47     if (!st)
48         return AVERROR(ENOMEM);
49
50     avio_skip(pb, 8);
51
52     st->nb_frames            = avio_rl32(pb);
53     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
54     st->codecpar->codec_id   = AV_CODEC_ID_MOBICLIP;
55     st->codecpar->width      = avio_rl32(pb);
56     st->codecpar->height     = avio_rl32(pb);
57
58     fps.num = avio_rl32(pb);
59     fps.den = 0x1000000;
60     avpriv_set_pts_info(st, 64, fps.den, fps.num);
61
62     avio_skip(pb, 16);
63
64     pos = avio_rl32(pb) + 4;
65     avio_seek(pb, pos, SEEK_SET);
66     pos = avio_rl32(pb);
67     avio_seek(pb, pos, SEEK_SET);
68
69     return 0;
70 }
71
72 static int mods_read_packet(AVFormatContext *s, AVPacket *pkt)
73 {
74     AVIOContext *pb = s->pb;
75     unsigned size;
76     int64_t pos;
77     int ret;
78
79     if (avio_feof(pb))
80         return AVERROR_EOF;
81
82     pos = avio_tell(pb);
83     size = avio_rl32(pb) >> 14;
84     ret = av_get_packet(pb, pkt, size);
85     pkt->pos = pos;
86     pkt->stream_index = 0;
87     pkt->flags |= AV_PKT_FLAG_KEY;
88
89     return ret;
90 }
91
92 AVInputFormat ff_mods_demuxer = {
93     .name           = "mods",
94     .long_name      = NULL_IF_CONFIG_SMALL("MobiClip MODS"),
95     .read_probe     = mods_probe,
96     .read_header    = mods_read_header,
97     .read_packet    = mods_read_packet,
98     .extensions     = "mods",
99     .flags          = AVFMT_GENERIC_INDEX,
100 };