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/packet.h"
23 #include "libavutil/crc.h"
24 #include "libavutil/opt.h"
25 #include "avformat.h"
26 #include "mux.h"
27 
28 typedef struct AC4Context {
29  AVClass *class;
30  int write_crc;
31 } AC4Context;
32 
34 {
35  AC4Context *ac4 = s->priv_data;
36  AVIOContext *pb = s->pb;
37 
38  if (!pkt->size)
39  return 0;
40 
41  if (ac4->write_crc)
42  avio_wb16(pb, 0xAC41);
43  else
44  avio_wb16(pb, 0xAC40);
45 
46  if (pkt->size >= 0xffff) {
47  avio_wb16(pb, 0xffff);
48  avio_wb24(pb, pkt->size);
49  } else {
50  avio_wb16(pb, pkt->size);
51  }
52 
53  avio_write(pb, pkt->data, pkt->size);
54 
55  if (ac4->write_crc) {
56  uint16_t crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, pkt->data, pkt->size);
57  avio_wl16(pb, crc);
58  }
59 
60  return 0;
61 }
62 
63 #define ENC AV_OPT_FLAG_ENCODING_PARAM
64 #define OFFSET(obj) offsetof(AC4Context, obj)
65 static const AVOption ac4_options[] = {
66  { "write_crc", "enable checksum", OFFSET(write_crc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, ENC},
67  { NULL },
68 };
69 
70 static const AVClass ac4_muxer_class = {
71  .class_name = "AC4 muxer",
72  .item_name = av_default_item_name,
73  .option = ac4_options,
74  .version = LIBAVUTIL_VERSION_INT,
75 };
76 
78  .p.name = "ac4",
79  .p.long_name = NULL_IF_CONFIG_SMALL("raw AC-4"),
80  .p.mime_type = "audio/ac4",
81  .p.extensions = "ac4",
82  .priv_data_size = sizeof(AC4Context),
83  .p.audio_codec = AV_CODEC_ID_AC4,
84  .p.video_codec = AV_CODEC_ID_NONE,
85  .p.subtitle_codec = AV_CODEC_ID_NONE,
86  .flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH |
88  .write_packet = ac4_write_packet,
89  .p.priv_class = &ac4_muxer_class,
90  .p.flags = AVFMT_NOTIMESTAMPS,
91 };
ac4_write_packet
static int ac4_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: ac4enc.c:33
AVOutputFormat::name
const char * name
Definition: avformat.h:510
opt.h
AC4Context
Definition: ac4enc.c:28
ff_ac4_muxer
const FFOutputFormat ff_ac4_muxer
Definition: ac4enc.c:77
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:479
AVPacket::data
uint8_t * data
Definition: packet.h:539
AVOption
AVOption.
Definition: opt.h:429
FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
#define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
If this flag is set, then the only permitted audio/video/subtitle codec ids are AVOutputFormat....
Definition: mux.h:59
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:65
crc.h
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:437
AC4Context::write_crc
int write_crc
Definition: ac4enc.c:30
pkt
AVPacket * pkt
Definition: movenc.c:60
codec_id.h
OFFSET
#define OFFSET(obj)
Definition: ac4enc.c:64
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:1300
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
ENC
#define ENC
Definition: ac4enc.c:63
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
FFOutputFormat
Definition: mux.h:61
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
AVPacket::size
int size
Definition: packet.h:540
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
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
ac4_options
static const AVOption ac4_options[]
Definition: ac4enc.c:65
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:70
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
packet.h
FF_OFMT_FLAG_MAX_ONE_OF_EACH
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
Definition: mux.h:50
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:80
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:455
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
AV_CODEC_ID_AC4
@ AV_CODEC_ID_AC4
Definition: codec_id.h:548
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:443
mux.h