FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/ac4enc.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 0 23 0.0%
Functions: 0 2 0.0%
Branches: 0 12 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/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
34 static int ac4_init(AVFormatContext *s)
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
46 static int ac4_write_packet(AVFormatContext *s, AVPacket *pkt)
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
90 const FFOutputFormat ff_ac4_muxer = {
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 };
103