FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/dsdenc.c
Date: 2026-09-06 08:50:24
Exec Total Coverage
Lines: 11 12 91.7%
Functions: 2 2 100.0%
Branches: 1 2 50.0%

Line Branch Exec Source
1 /*
2 * Direct Stream Digital (DSD) encoder
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 /**
22 * @file
23 * DSD (Direct Stream Digital) "encoder": AV_SAMPLE_FMT_DSD is
24 * already the bitstream, so packets are a plain copy of the samples.
25 */
26
27 #include <string.h>
28
29 #include "avcodec.h"
30 #include "codec_internal.h"
31 #include "encode.h"
32
33 2 static av_cold int dsd_encode_init(AVCodecContext *avctx)
34 {
35 2 avctx->bits_per_coded_sample = 8;
36 2 avctx->block_align = avctx->ch_layout.nb_channels;
37 2 avctx->bit_rate = 8LL * avctx->block_align * avctx->sample_rate;
38 2 return 0;
39 }
40
41 90 static int dsd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
42 const AVFrame *frame, int *got_packet_ptr)
43 {
44 90 int64_t size = frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels;
45 int ret;
46
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
90 if ((ret = ff_get_encode_buffer(avctx, avpkt, size, 0)) < 0)
48 return ret;
49
50 90 memcpy(avpkt->data, frame->data[0], size);
51
52 90 *got_packet_ptr = 1;
53 90 return 0;
54 }
55
56 const FFCodec ff_dsd_msbf_encoder = {
57 .p.name = "dsd_msbf",
58 CODEC_LONG_NAME("DSD (Direct Stream Digital), most significant bit first"),
59 .p.type = AVMEDIA_TYPE_AUDIO,
60 .p.id = AV_CODEC_ID_DSD_MSBF,
61 .p.capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE,
62 CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_DSD),
63 .init = dsd_encode_init,
64 FF_CODEC_ENCODE_CB(dsd_encode_frame),
65 };
66