FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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(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);
126  pkt->stream_index = index;
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 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1621
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:4560
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3980
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:230
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:304
static AVPacket pkt
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:742
Format I/O context.
Definition: avformat.h:1338
static int nb_streams
Definition: ffprobe.c:254
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:757
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1619
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4193
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:87
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1406
int64_t duration
Definition: movenc.c:63
static int aix_probe(AVProbeData *p)
Definition: aixdec.c:26
static int aix_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: aixdec.c:86
#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.
Definition: utils.c:289
ptrdiff_t size
Definition: opengl_enc.c:101
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:511
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:726
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3976
AVInputFormat ff_aix_demuxer
Definition: aixdec.c:132
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:595
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:463
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1394
Stream structure.
Definition: avformat.h:889
AVIOContext * pb
I/O context.
Definition: avformat.h:1380
int index
Definition: gxfenc.c:89
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:487
This structure contains the data a format has to probe a file.
Definition: avformat.h:461
int sample_rate
Audio only.
Definition: avcodec.h:4090
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:473
Main libavformat public API header.
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:3196
static int aix_read_header(AVFormatContext *s)
Definition: aixdec.c:36
int channels
Audio only.
Definition: avcodec.h:4086
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:664
AVCodecParameters * codecpar
Definition: avformat.h:1241
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:328
int stream_index
Definition: avcodec.h:1603
#define MKTAG(a, b, c, d)
Definition: common.h:342
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1578