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'))
29  return AVPROBE_SCORE_MAX / 2;
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_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
enum AVCodecID id
Definition: mxfenc.c:89
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
int64_t pos
byte position in stream, -1 if unknown
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.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
Format I/O context.
Definition: avformat.h:944
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static AVPacket pkt
Definition: demuxing.c:56
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static int lvf_read_header(AVFormatContext *s)
Definition: lvfdec.c:33
#define AVERROR_EOF
End of file.
Definition: error.h:55
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.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: lvfdec.c:100
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:579
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:334
int size
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:469
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
static int lvf_probe(AVProbeData *p)
Definition: lvfdec.c:26
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:35
ret
Definition: avfilter.c:821
int width
picture width / height.
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
AVInputFormat ff_lvf_demuxer
Definition: lvfdec.c:140
#define AV_RL32
int url_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:280
Stream structure.
Definition: avformat.h:643
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
enum AVMediaType codec_type
enum AVCodecID codec_id
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:353
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
static int flags
Definition: cpu.c:23
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:563
Main libavformat public API header.
int channels
number of audio channels
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
#define MKTAG(a, b, c, d)
Definition: common.h:282
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...