FFmpeg
Loading...
Searching...
No Matches
dsdenc.c
Go to the documentation of this file.
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
34{
35 avctx->bits_per_coded_sample = 8;
36 avctx->block_align = avctx->ch_layout.nb_channels;
37 avctx->bit_rate = 8LL * avctx->block_align * avctx->sample_rate;
38 return 0;
39}
40
41static int dsd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
42 const AVFrame *frame, int *got_packet_ptr)
43{
44 int64_t size = frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels;
45 int ret;
46
47 if ((ret = ff_get_encode_buffer(avctx, avpkt, size, 0)) < 0)
48 return ret;
49
50 memcpy(avpkt->data, frame->data[0], size);
51
52 *got_packet_ptr = 1;
53 return 0;
54}
55
57 .p.name = "dsd_msbf",
58 CODEC_LONG_NAME("DSD (Direct Stream Digital), most significant bit first"),
59 .p.type = AVMEDIA_TYPE_AUDIO,
61 .p.capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE,
63 .init = dsd_encode_init,
65};
const FFCodec ff_dsd_msbf_encoder
Definition dsdenc.c:56
Libavcodec external API header.
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
long long int64_t
Definition coverity.c:34
static AVFrame * frame
static av_cold int dsd_encode_init(AVCodecContext *avctx)
Definition dsdenc.c:33
static int dsd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition dsdenc.c:41
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:106
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition codec.h:116
@ AV_CODEC_ID_DSD_MSBF
Definition codec_id.h:527
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AV_SAMPLE_FMT_DSD
DSD (Direct Stream Digital) bitstream, interleaved.
Definition samplefmt.h:77
#define av_cold
Definition attributes.h:117
int nb_channels
Number of channels in this layout.
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1055
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition avcodec.h:1565
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int sample_rate
samples per second
Definition avcodec.h:1040
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition avcodec.h:1075
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
uint8_t * data
Definition packet.h:603
int size