FFmpeg  2.1.1
lvfdec.c
Go to the documentation of this file.
1 /*
2  * LVF demuxer
3  * Copyright (c) 2012 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 #include "avformat.h"
24 #include "riff.h"
25 
26 static int lvf_probe(AVProbeData *p)
27 {
28  if (AV_RL32(p->buf) == MKTAG('L', 'V', 'F', 'F'))
30  return 0;
31 }
32 
34 {
35  AVStream *st;
36  int64_t next_offset;
37  unsigned size, nb_streams, id;
38 
39  avio_skip(s->pb, 16);
40  nb_streams = avio_rl32(s->pb);
41  if (!nb_streams)
42  return AVERROR_INVALIDDATA;
43  if (nb_streams > 2) {
44  avpriv_request_sample(s, "%d streams", nb_streams);
45  return AVERROR_PATCHWELCOME;
46  }
47 
48  avio_skip(s->pb, 1012);
49 
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;
54 
55  switch (id) {
56  case MKTAG('0', '0', 'f', 'm'):
57  st = avformat_new_stream(s, 0);
58  if (!st)
59  return AVERROR(ENOMEM);
60 
62  avio_skip(s->pb, 4);
63  st->codec->width = avio_rl32(s->pb);
64  st->codec->height = avio_rl32(s->pb);
65  avio_skip(s->pb, 4);
66  st->codec->codec_tag = avio_rl32(s->pb);
68  st->codec->codec_tag);
69  avpriv_set_pts_info(st, 32, 1, 1000);
70  break;
71  case MKTAG('0', '1', 'f', 'm'):
72  st = avformat_new_stream(s, 0);
73  if (!st)
74  return AVERROR(ENOMEM);
75 
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);
80  avio_skip(s->pb, 8);
83  st->codec->codec_tag);
84  avpriv_set_pts_info(st, 32, 1, 1000);
85  break;
86  case 0:
87  avio_seek(s->pb, 2048 + 8, SEEK_SET);
88  return 0;
89  default:
90  avpriv_request_sample(s, "id %d", id);
91  return AVERROR_PATCHWELCOME;
92  }
93 
94  avio_seek(s->pb, next_offset, SEEK_SET);
95  }
96 
97  return AVERROR_EOF;
98 }
99 
101 {
102  unsigned size, flags, timestamp, id;
103  int64_t pos;
104  int ret, is_video = 0;
105 
106  pos = avio_tell(s->pb);
107  while (!url_feof(s->pb)) {
108  id = avio_rl32(s->pb);
109  size = avio_rl32(s->pb);
110 
111  if (size == 0xFFFFFFFFu)
112  return AVERROR_EOF;
113 
114  switch (id) {
115  case MKTAG('0', '0', 'd', 'c'):
116  is_video = 1;
117  case MKTAG('0', '1', 'w', 'b'):
118  if (size < 8)
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;
127  pkt->pos = pos;
128  return ret;
129  default:
130  ret = avio_skip(s->pb, size);
131  }
132 
133  if (ret < 0)
134  return ret;
135  }
136 
137  return AVERROR_EOF;
138 }
139 
141  .name = "lvf",
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,
146  .extensions = "lvf",
147  .flags = AVFMT_GENERIC_INDEX,
148 };
const char * s
Definition: avisynth_c.h:668
#define AVERROR_PATCHWELCOME
int size
enum AVCodecID id
Definition: mxfenc.c:90
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:2556
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:478
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1092
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:3922
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:686
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:593
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:471
Format I/O context.
Definition: avformat.h:968
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
static int lvf_read_header(AVFormatContext *s)
Definition: lvfdec.c:33
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2563
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3348
static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: lvfdec.c:100
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:200
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1113
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:577
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:358
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:355
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1069
static int lvf_probe(AVProbeData *p)
Definition: lvfdec.c:26
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:32
ret
Definition: avfilter.c:961
int width
picture width / height.
Definition: avcodec.h:1314
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:341
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
AVInputFormat ff_lvf_demuxer
Definition: lvfdec.c:140
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
Stream structure.
Definition: avformat.h:667
enum AVMediaType codec_type
Definition: avcodec.h:1154
enum AVCodecID codec_id
Definition: avcodec.h:1157
int sample_rate
samples per second
Definition: avcodec.h:1873
unsigned int codec_tag
fourcc (LSB first, so &quot;ABCD&quot; -&gt; (&#39;D&#39;&lt;&lt;24) + (&#39;C&#39;&lt;&lt;16) + (&#39;B&#39;&lt;&lt;8) + &#39;A&#39;).
Definition: avcodec.h:1172
AVIOContext * pb
I/O context.
Definition: avformat.h:1001
#define MKTAG(a, b, c, d)
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
static int flags
Definition: cpu.c:45
#define AVERROR_EOF
int url_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:280
Main libavformat public API header.
#define AVERROR_INVALIDDATA
#define AV_RL32(x)
Definition: intreadwrite.h:275
int channels
number of audio channels
Definition: avcodec.h:1874
#define AVERROR(e)
static AVPacket pkt
Definition: demuxing.c:52
int stream_index
Definition: avcodec.h:1065
This structure stores compressed data.
Definition: avcodec.h:1040
int64_t pts
Presentation timestamp in AVStream-&gt;time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1056