FFmpeg
ac4enc.c
Go to the documentation of this file.
1 /*
2  * Raw AC-4 muxer
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavcodec/codec_id.h"
22 #include "libavcodec/codec_par.h"
23 #include "libavcodec/packet.h"
24 #include "libavutil/crc.h"
25 #include "libavutil/opt.h"
26 #include "avformat.h"
27 #include "mux.h"
28 
29 typedef struct AC4Context {
30  AVClass *class;
31  int write_crc;
32 } AC4Context;
33 
35 {
36  AVCodecParameters *par = s->streams[0]->codecpar;
37 
38  if (s->nb_streams != 1 || par->codec_id != AV_CODEC_ID_AC4) {
39  av_log(s, AV_LOG_ERROR, "Only one AC-4 stream can be muxed by the AC-4 muxer\n");
40  return AVERROR(EINVAL);
41  }
42 
43  return 0;
44 }
45 
47 {
48  AC4Context *ac4 = s->priv_data;
49  AVIOContext *pb = s->pb;
50 
51  if (!pkt->size)
52  return 0;
53 
54  if (ac4->write_crc)
55  avio_wb16(pb, 0xAC41);
56  else
57  avio_wb16(pb, 0xAC40);
58 
59  if (pkt->size >= 0xffff) {
60  avio_wb16(pb, 0xffff);
61  avio_wb24(pb, pkt->size);
62  } else {
63  avio_wb16(pb, pkt->size);
64  }
65 
66  avio_write(pb, pkt->data, pkt->size);
67 
68  if (ac4->write_crc) {
69  uint16_t crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, pkt->data, pkt->size);
70  avio_wl16(pb, crc);
71  }
72 
73  return 0;
74 }
75 
76 #define ENC AV_OPT_FLAG_ENCODING_PARAM
77 #define OFFSET(obj) offsetof(AC4Context, obj)
78 static const AVOption ac4_options[] = {
79  { "write_crc", "enable checksum", OFFSET(write_crc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, ENC},
80  { NULL },
81 };
82 
83 static const AVClass ac4_muxer_class = {
84  .class_name = "AC4 muxer",
85  .item_name = av_default_item_name,
86  .option = ac4_options,
87  .version = LIBAVUTIL_VERSION_INT,
88 };
89 
91  .p.name = "ac4",
92  .p.long_name = NULL_IF_CONFIG_SMALL("raw AC-4"),
93  .p.mime_type = "audio/ac4",
94  .p.extensions = "ac4",
95  .priv_data_size = sizeof(AC4Context),
96  .p.audio_codec = AV_CODEC_ID_AC4,
97  .p.video_codec = AV_CODEC_ID_NONE,
98  .init = ac4_init,
99  .write_packet = ac4_write_packet,
100  .p.priv_class = &ac4_muxer_class,
101  .p.flags = AVFMT_NOTIMESTAMPS,
102 };
ac4_write_packet
static int ac4_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: ac4enc.c:46
AVOutputFormat::name
const char * name
Definition: avformat.h:511
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
opt.h
AC4Context
Definition: ac4enc.c:29
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
ff_ac4_muxer
const FFOutputFormat ff_ac4_muxer
Definition: ac4enc.c:90
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:480
AVPacket::data
uint8_t * data
Definition: packet.h:491
AVOption
AVOption.
Definition: opt.h:251
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:36
crc.h
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:484
AC4Context::write_crc
int write_crc
Definition: ac4enc.c:31
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
codec_id.h
OFFSET
#define OFFSET(obj)
Definition: ac4enc.c:77
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CRC_16_ANSI
@ AV_CRC_16_ANSI
Definition: crc.h:50
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
ENC
#define ENC
Definition: ac4enc.c:76
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
FFOutputFormat
Definition: mux.h:32
ac4_init
static int ac4_init(AVFormatContext *s)
Definition: ac4enc.c:34
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
AVPacket::size
int size
Definition: packet.h:492
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:106
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:248
ac4_options
static const AVOption ac4_options[]
Definition: ac4enc.c:78
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
ac4_muxer_class
static const AVClass ac4_muxer_class
Definition: ac4enc.c:83
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
packet.h
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
avformat.h
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
avio_wb24
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:502
codec_par.h
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:468
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
AV_CODEC_ID_AC4
@ AV_CODEC_ID_AC4
Definition: codec_id.h:545
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:490
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
mux.h