3 * Copyright (c) 2012 Paul B Mahol
5 * This file is part of FFmpeg.
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.
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.
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
22 #include "libavutil/intreadwrite.h"
26 static int lvf_probe(AVProbeData *p)
28 if (AV_RL32(p->buf) == MKTAG('L', 'V', 'F', 'F'))
29 return AVPROBE_SCORE_MAX / 2;
33 static int lvf_read_header(AVFormatContext *s)
37 unsigned size, nb_streams, id;
40 nb_streams = avio_rl32(s->pb);
42 return AVERROR_INVALIDDATA;
44 av_log_ask_for_sample(s, "too many streams\n");
45 return AVERROR_PATCHWELCOME;
48 avio_skip(s->pb, 1012);
50 while (!url_feof(s->pb)) {
51 id = avio_rl32(s->pb);
52 size = avio_rl32(s->pb);
53 next_offset = avio_tell(s->pb) + size;
56 case MKTAG('0', '0', 'f', 'm'):
57 st = avformat_new_stream(s, 0);
59 return AVERROR(ENOMEM);
61 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
63 st->codec->width = avio_rl32(s->pb);
64 st->codec->height = avio_rl32(s->pb);
66 st->codec->codec_tag = avio_rl32(s->pb);
67 st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
68 st->codec->codec_tag);
69 avpriv_set_pts_info(st, 32, 1, 1000);
71 case MKTAG('0', '1', 'f', 'm'):
72 st = avformat_new_stream(s, 0);
74 return AVERROR(ENOMEM);
76 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
77 st->codec->codec_tag = avio_rl16(s->pb);
78 st->codec->channels = avio_rl16(s->pb);
79 st->codec->sample_rate = avio_rl16(s->pb);
81 st->codec->bits_per_coded_sample = avio_r8(s->pb);
82 st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags,
83 st->codec->codec_tag);
84 avpriv_set_pts_info(st, 32, 1, 1000);
87 avio_seek(s->pb, 2048 + 8, SEEK_SET);
90 av_log_ask_for_sample(s, "unknown id\n");
91 return AVERROR_PATCHWELCOME;
94 avio_seek(s->pb, next_offset, SEEK_SET);
100 static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt)
102 unsigned size, flags, timestamp, id;
104 int ret, is_video = 0;
106 pos = avio_tell(s->pb);
107 while (!url_feof(s->pb)) {
108 id = avio_rl32(s->pb);
109 size = avio_rl32(s->pb);
111 if (size == 0xFFFFFFFFu)
115 case MKTAG('0', '0', 'd', 'c'):
117 case MKTAG('0', '1', 'w', 'b'):
119 return AVERROR_INVALIDDATA;
120 timestamp = avio_rl32(s->pb);
121 flags = avio_rl32(s->pb);
122 ret = av_get_packet(s->pb, pkt, size - 8);
123 if (flags & (1 << 12))
124 pkt->flags |= AV_PKT_FLAG_KEY;
125 pkt->stream_index = is_video ? 0 : 1;
126 pkt->pts = timestamp;
130 ret = avio_skip(s->pb, size);
140 AVInputFormat ff_lvf_demuxer = {
142 .long_name = NULL_IF_CONFIG_SMALL("LVF"),
143 .read_probe = lvf_probe,
144 .read_header = lvf_read_header,
145 .read_packet = lvf_read_packet,
147 .flags = AVFMT_GENERIC_INDEX,