FFmpeg
aixdec.c
Go to the documentation of this file.
1 /*
2  * AIX demuxer
3  * Copyright (c) 2016 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 "internal.h"
25 
26 static int aix_probe(const AVProbeData *p)
27 {
28  if (AV_RL32(p->buf) != MKTAG('A','I','X','F') ||
29  AV_RB32(p->buf + 8) != 0x01000014 ||
30  AV_RB32(p->buf + 12) != 0x00000800)
31  return 0;
32 
33  return AVPROBE_SCORE_MAX;
34 }
35 
37 {
38  unsigned nb_streams, first_offset, nb_segments;
39  unsigned stream_list_offset;
40  unsigned segment_list_offset = 0x20;
41  unsigned segment_list_entry_size = 0x10;
42  unsigned size;
43  int i;
44 
45  avio_skip(s->pb, 4);
46  first_offset = avio_rb32(s->pb) + 8;
47  avio_skip(s->pb, 16);
48  nb_segments = avio_rb16(s->pb);
49  if (nb_segments == 0)
50  return AVERROR_INVALIDDATA;
51  stream_list_offset = segment_list_offset + segment_list_entry_size * nb_segments + 0x10;
52  if (stream_list_offset >= first_offset)
53  return AVERROR_INVALIDDATA;
54  avio_seek(s->pb, stream_list_offset, SEEK_SET);
55  nb_streams = avio_r8(s->pb);
56  if (nb_streams == 0)
57  return AVERROR_INVALIDDATA;
58  avio_skip(s->pb, 7);
59  for (i = 0; i < nb_streams; i++) {
61 
62  if (!st)
63  return AVERROR(ENOMEM);
66  st->codecpar->sample_rate = avio_rb32(s->pb);
67  st->codecpar->channels = avio_r8(s->pb);
68  avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
69  avio_skip(s->pb, 3);
70  }
71 
72  avio_seek(s->pb, first_offset, SEEK_SET);
73  for (i = 0; i < nb_streams; i++) {
74  if (avio_rl32(s->pb) != MKTAG('A','I','X','P'))
75  return AVERROR_INVALIDDATA;
76  size = avio_rb32(s->pb);
77  if (size <= 8)
78  return AVERROR_INVALIDDATA;
79  avio_skip(s->pb, 8);
80  ff_get_extradata(s, s->streams[i]->codecpar, s->pb, size - 8);
81  }
82 
83  return 0;
84 }
85 
87 {
88  unsigned size, index, duration, chunk;
89  int64_t pos;
90  int sequence, ret, i;
91 
92  pos = avio_tell(s->pb);
93  if (avio_feof(s->pb))
94  return AVERROR_EOF;
95  chunk = avio_rl32(s->pb);
96  size = avio_rb32(s->pb);
97  if (chunk == MKTAG('A','I','X','E')) {
98  avio_skip(s->pb, size);
99  for (i = 0; i < s->nb_streams; i++) {
100  if (avio_feof(s->pb))
101  return AVERROR_EOF;
102  chunk = avio_rl32(s->pb);
103  size = avio_rb32(s->pb);
104  avio_skip(s->pb, size);
105  }
106  pos = avio_tell(s->pb);
107  chunk = avio_rl32(s->pb);
108  size = avio_rb32(s->pb);
109  }
110 
111  if (chunk != MKTAG('A','I','X','P'))
112  return AVERROR_INVALIDDATA;
113  if (size <= 8)
114  return AVERROR_INVALIDDATA;
115  index = avio_r8(s->pb);
116  if (avio_r8(s->pb) != s->nb_streams || index >= s->nb_streams)
117  return AVERROR_INVALIDDATA;
118  duration = avio_rb16(s->pb);
119  sequence = avio_rb32(s->pb);
120  if (sequence < 0) {
121  avio_skip(s->pb, size - 8);
122  return 0;
123  }
124 
125  ret = av_get_packet(s->pb, pkt, size - 8);
127  pkt->duration = duration;
128  pkt->pos = pos;
129  return ret;
130 }
131 
133  .name = "aix",
134  .long_name = NULL_IF_CONFIG_SMALL("CRI AIX"),
135  .read_probe = aix_probe,
136  .read_header = aix_read_header,
137  .read_packet = aix_read_packet,
138  .extensions = "aix",
139  .flags = AVFMT_GENERIC_INDEX,
140 };
aix_probe
static int aix_probe(const AVProbeData *p)
Definition: aixdec.c:26
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
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:768
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
ff_get_extradata
int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
Definition: utils.c:469
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
index
fg index
Definition: ffmpeg_filter.c:167
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:391
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:459
AVCodecParameters::channels
int channels
Audio only.
Definition: codec_par.h:166
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:504
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:476
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:790
pkt
AVPacket * pkt
Definition: movenc.c:59
AVInputFormat
Definition: avformat.h:650
duration
int64_t duration
Definition: movenc.c:64
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:655
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:449
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
nb_streams
static int nb_streams
Definition: ffprobe.c:297
AVFormatContext
Format I/O context.
Definition: avformat.h:1200
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1095
NULL
#define NULL
Definition: coverity.c:32
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:447
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:170
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:759
AV_CODEC_ID_ADPCM_ADX
@ AV_CODEC_ID_ADPCM_ADX
Definition: codec_id.h:362
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:117
aix_read_header
static int aix_read_header(AVFormatContext *s)
Definition: aixdec.c:36
size
int size
Definition: twinvq_data.h:10344
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
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:632
aix_read_packet
static int aix_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: aixdec.c:86
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
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:197
ff_aix_demuxer
const AVInputFormat ff_aix_demuxer
Definition: aixdec.c:132
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:935
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:775
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
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: utils.c:1196
AVPacket::stream_index
int stream_index
Definition: packet.h:375
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:347
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:393
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:375