FFmpeg
Loading...
Searching...
No Matches
ac4dec.c
Go to the documentation of this file.
1/*
2 * RAW AC-4 demuxer
3 * Copyright (c) 2019 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/avassert.h"
23#include "libavutil/crc.h"
24#include "avformat.h"
25#include "demux.h"
26#include "rawdec.h"
27
28static int ac4_probe(const AVProbeData *p)
29{
30 const uint8_t *buf = p->buf;
31 int left = p->buf_size;
32 int max_frames = 0;
33
34 while (left > 7) {
35 int size;
36
37 if (buf[0] == 0xAC &&
38 (buf[1] == 0x40 ||
39 buf[1] == 0x41)) {
40 size = (buf[2] << 8) | buf[3];
41 if (size == 0xFFFF)
42 size = 3 + ((buf[4] << 16) | (buf[5] << 8) | buf[6]);
43 size += 4;
44 if (buf[1] == 0x41)
45 size += 2;
46 if (left < size)
47 break;
48 max_frames++;
49 left -= size;
50 buf += size;
51 } else {
52 break;
53 }
54 }
55
56 return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
57}
58
60{
61 AVStream *st;
62
64 if (!st)
65 return AVERROR(ENOMEM);
66
69
70 return 0;
71}
72
74{
75 AVIOContext *pb = s->pb;
77 uint16_t sync;
78 int ret, size;
79
80 if (avio_feof(s->pb))
81 return AVERROR_EOF;
82
83 pos = avio_tell(s->pb);
84 sync = avio_rb16(pb);
85 size = avio_rb16(pb);
86 if (size == 0xffff)
87 size = avio_rb24(pb);
88
89 ret = av_get_packet(pb, pkt, size);
90 pkt->pos = pos;
91 pkt->stream_index = 0;
92
93 if (sync == 0xAC41)
94 avio_skip(pb, 2);
95
96 return ret;
97}
98
100 .p.name = "ac4",
101 .p.long_name = NULL_IF_CONFIG_SMALL("raw AC-4"),
102 .p.flags = AVFMT_GENERIC_INDEX,
103 .p.extensions = "ac4",
104 .read_probe = ac4_probe,
105 .read_header = ac4_read_header,
106 .read_packet = ac4_read_packet,
107};
static int ac4_probe(const AVProbeData *p)
Definition ac4dec.c:28
const FFInputFormat ff_ac4_demuxer
Definition ac4dec.c:99
static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition ac4dec.c:73
static int ac4_read_header(AVFormatContext *s)
Definition ac4dec.c:59
simple assert() macros that are a bit more flexible than ISO C assert().
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
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:98
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
unsigned int avio_rb16(AVIOContext *s)
Definition aviobuf.c:749
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rb24(AVIOContext *s)
Definition aviobuf.c:757
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
Public header for CRC hash function implementation.
static AVPacket * pkt
@ AV_CODEC_ID_AC4
Definition codec_id.h:556
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define FFMIN(a, b)
Definition macros.h:49
unsigned int pos
Definition spdifenc.c:431
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int size