FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/ac4enc.c
Date: 2024-05-04 02:01:39
Exec Total Coverage
Lines: 0 17 0.0%
Functions: 0 1 0.0%
Branches: 0 8 0.0%

Line Branch Exec Source
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
33 static int ac4_write_packet(AVFormatContext *s, AVPacket *pkt)
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
77 const FFOutputFormat ff_ac4_muxer = {
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 |
87 FF_OFMT_FLAG_ONLY_DEFAULT_CODECS,
88 .write_packet = ac4_write_packet,
89 .p.priv_class = &ac4_muxer_class,
90 .p.flags = AVFMT_NOTIMESTAMPS,
91 };
92