FFmpeg
lmlm4.c
Go to the documentation of this file.
1 /*
2  * Linux Media Labs MPEG-4 demuxer
3  * Copyright (c) 2008 Ivo van Poorten
4  *
5  * Due to a lack of sample files, only files with one channel are supported.
6  * u-law and ADPCM audio are unsupported for the same reason.
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 #include "libavutil/intreadwrite.h"
26 
27 #include "avformat.h"
28 #include "demux.h"
29 #include "internal.h"
30 
31 #define LMLM4_I_FRAME 0x00
32 #define LMLM4_P_FRAME 0x01
33 #define LMLM4_B_FRAME 0x02
34 #define LMLM4_INVALID 0x03
35 #define LMLM4_MPEG1L2 0x04
36 
37 #define LMLM4_MAX_PACKET_SIZE 1024 * 1024
38 
39 static int lmlm4_probe(const AVProbeData *pd)
40 {
41  const unsigned char *buf = pd->buf;
42  unsigned int frame_type, packet_size;
43 
44  frame_type = AV_RB16(buf + 2);
45  packet_size = AV_RB32(buf + 4);
46 
47  if (!AV_RB16(buf) && frame_type <= LMLM4_MPEG1L2 && packet_size &&
48  frame_type != LMLM4_INVALID && packet_size <= LMLM4_MAX_PACKET_SIZE) {
49  if (frame_type == LMLM4_MPEG1L2) {
50  if ((AV_RB16(buf + 8) & 0xfffe) != 0xfffc)
51  return 0;
52  /* I could calculate the audio framesize and compare with
53  * packet_size-8, but that seems overkill */
54  return AVPROBE_SCORE_MAX / 3;
55  } else if (AV_RB24(buf + 8) == 0x000001) { /* PES Signal */
56  return AVPROBE_SCORE_MAX / 5;
57  }
58  }
59 
60  return 0;
61 }
62 
64 {
65  AVStream *st;
66 
67  if (!(st = avformat_new_stream(s, NULL)))
68  return AVERROR(ENOMEM);
72  avpriv_set_pts_info(st, 64, 1001, 30000);
73 
74  if (!(st = avformat_new_stream(s, NULL)))
75  return AVERROR(ENOMEM);
79 
80  /* the parameters will be extracted from the compressed bitstream */
81  return 0;
82 }
83 
85 {
86  AVIOContext *pb = s->pb;
87  int ret;
88  unsigned int frame_type, packet_size, padding, frame_size;
89 
90  avio_rb16(pb); /* channel number */
91  frame_type = avio_rb16(pb);
92  packet_size = avio_rb32(pb);
93  padding = -packet_size & 511;
94 
96  av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n");
97  return AVERROR_INVALIDDATA;
98  }
99  if (packet_size > LMLM4_MAX_PACKET_SIZE || packet_size<=8) {
100  av_log(s, AV_LOG_ERROR, "packet size %d is invalid\n", packet_size);
101  return AVERROR_INVALIDDATA;
102  }
103 
104  frame_size = packet_size - 8;
105  if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0)
106  return ret < 0 ? ret : AVERROR(EIO);
107 
108  avio_skip(pb, padding);
109 
110  switch (frame_type) {
111  case LMLM4_I_FRAME:
113  case LMLM4_P_FRAME:
114  case LMLM4_B_FRAME:
115  pkt->stream_index = 0;
116  break;
117  case LMLM4_MPEG1L2:
118  pkt->stream_index = 1;
119  break;
120  }
121 
122  return ret;
123 }
124 
126  .p.name = "lmlm4",
127  .p.long_name = NULL_IF_CONFIG_SMALL("raw lmlm4"),
128  .read_probe = lmlm4_probe,
129  .read_header = lmlm4_read_header,
130  .read_packet = lmlm4_read_packet,
131 };
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
LMLM4_P_FRAME
#define LMLM4_P_FRAME
Definition: lmlm4.c:32
LMLM4_I_FRAME
#define LMLM4_I_FRAME
Definition: lmlm4.c:31
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:594
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:463
avpriv_set_pts_info
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:867
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:358
LMLM4_MPEG1L2
#define LMLM4_MPEG1L2
Definition: lmlm4.c:35
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:761
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
frame_size
int frame_size
Definition: mxfenc.c:2429
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:446
lmlm4_read_header
static int lmlm4_read_header(AVFormatContext *s)
Definition: lmlm4.c:63
lmlm4_probe
static int lmlm4_probe(const AVProbeData *pd)
Definition: lmlm4.c:39
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:325
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
NULL
#define NULL
Definition: coverity.c:32
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
ff_lmlm4_demuxer
const FFInputFormat ff_lmlm4_demuxer
Definition: lmlm4.c:125
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
LMLM4_INVALID
#define LMLM4_INVALID
Definition: lmlm4.c:34
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:46
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
LMLM4_B_FRAME
#define LMLM4_B_FRAME
Definition: lmlm4.c:33
frame_type
frame_type
Definition: jpeg2000_parser.c:31
demux.h
av_get_packet
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:91
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:746
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:594
avformat.h
lmlm4_read_packet
static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: lmlm4.c:84
LMLM4_MAX_PACKET_SIZE
#define LMLM4_MAX_PACKET_SIZE
Definition: lmlm4.c:37
AVPacket::stream_index
int stream_index
Definition: packet.h:541
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:318
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:516
FFInputFormat
Definition: demux.h:42
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_RB24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:97
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98