FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/wvenc.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 17 19 89.5%
Functions: 2 2 100.0%
Branches: 5 10 50.0%

Line Branch Exec Source
1 /*
2 * WavPack muxer
3 * Copyright (c) 2013 Konstantin Shishkov <kostya.shishkov@gmail.com>
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/attributes.h"
24
25 #include "apetag.h"
26 #include "avformat.h"
27 #include "mux.h"
28 #include "wv.h"
29
30 typedef struct WvMuxContext {
31 int64_t samples;
32 } WvMuxContext;
33
34 13 static int wv_write_packet(AVFormatContext *ctx, AVPacket *pkt)
35 {
36 13 WvMuxContext *s = ctx->priv_data;
37 WvHeader header;
38 int ret;
39
40
2/4
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
26 if (pkt->size < WV_HEADER_SIZE ||
41 13 (ret = ff_wv_parse_header(&header, pkt->data)) < 0) {
42 av_log(ctx, AV_LOG_ERROR, "Invalid WavPack packet.\n");
43 return AVERROR(EINVAL);
44 }
45 13 s->samples += header.samples;
46
47 13 avio_write(ctx->pb, pkt->data, pkt->size);
48
49 13 return 0;
50 }
51
52 2 static av_cold int wv_write_trailer(AVFormatContext *ctx)
53 {
54 2 WvMuxContext *s = ctx->priv_data;
55
56 /* update total number of samples in the first block */
57
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if ((ctx->pb->seekable & AVIO_SEEKABLE_NORMAL) && s->samples &&
58
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 s->samples < UINT32_MAX) {
59 2 int64_t pos = avio_tell(ctx->pb);
60 2 avio_seek(ctx->pb, 12, SEEK_SET);
61 2 avio_wl32(ctx->pb, s->samples);
62 2 avio_seek(ctx->pb, pos, SEEK_SET);
63 }
64
65 2 ff_ape_write_tag(ctx);
66 2 return 0;
67 }
68
69 const FFOutputFormat ff_wv_muxer = {
70 .p.name = "wv",
71 .p.long_name = NULL_IF_CONFIG_SMALL("raw WavPack"),
72 .p.mime_type = "audio/x-wavpack",
73 .p.extensions = "wv",
74 .priv_data_size = sizeof(WvMuxContext),
75 .p.audio_codec = AV_CODEC_ID_WAVPACK,
76 .p.video_codec = AV_CODEC_ID_NONE,
77 .p.subtitle_codec = AV_CODEC_ID_NONE,
78 .write_packet = wv_write_packet,
79 .write_trailer = wv_write_trailer,
80 .p.flags = AVFMT_NOTIMESTAMPS,
81 .flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH |
82 FF_OFMT_FLAG_ONLY_DEFAULT_CODECS,
83 };
84