FFmpeg
Loading...
Searching...
No Matches
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
28typedef struct AC4Context {
29 AVClass *class;
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)
65static 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
70static 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};
static int ac4_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition ac4enc.c:33
static const AVOption ac4_options[]
Definition ac4enc.c:65
static const AVClass ac4_muxer_class
Definition ac4enc.c:70
#define OFFSET(obj)
Definition ac4enc.c:64
const FFOutputFormat ff_ac4_muxer
Definition ac4enc.c:77
Main libavformat public API header.
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:498
void avio_wl16(AVIOContext *s, unsigned int val)
Definition aviobuf.c:440
void avio_wb16(AVIOContext *s, unsigned int val)
Definition aviobuf.c:446
void avio_wb24(AVIOContext *s, unsigned int val)
Definition aviobuf.c:458
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
#define ENC
Definition caca.c:198
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
Public header for CRC hash function implementation.
static AVPacket * pkt
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_AC4
Definition codec_id.h:556
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition crc.c:389
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:421
@ AV_CRC_16_ANSI
Definition crc.h:50
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#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
#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
AVOptions.
int write_crc
Definition ac4enc.c:30
Describe the class of an AVClass context structure.
Definition log.h:76
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580