45 if (
ctx->par_in->ch_layout.nb_channels <= 0 ||
ctx->par_in->sample_rate <= 0)
49 s->sample_size =
ctx->par_in->ch_layout.nb_channels *
52 if (
s->frame_rate.num) {
55 min_samples =
s->nb_out_samples;
57 if (min_samples <= 0 || min_samples > INT_MAX /
s->sample_size - 1)
62 if (!
s->in_pkt || !
s->out_pkt)
85 pkt->duration = nb_samples;
92 pkt->size -= drain_data;
93 pkt->data += drain_data;
95 pkt->dts += drain_samples;
97 pkt->pts += drain_samples;
103 if (
s->frame_rate.num) {
107 return s->nb_out_samples;
120 memset(buf,
c,
size);
127 int data_size = nb_samples *
s->sample_size;
131 if (
s->in_pkt->size) {
132 if (
s->out_pkt->size ||
s->in_pkt->size < data_size) {
133 int drain =
FFMIN(
s->in_pkt->size, data_size -
s->out_pkt->size);
134 if (!
s->out_pkt->size) {
143 s->out_pkt->size = 0;
145 memcpy(
s->out_pkt->data +
s->out_pkt->size,
s->in_pkt->data, drain);
146 s->out_pkt->size += drain;
148 if (!
s->in_pkt->size)
150 if (
s->out_pkt->size == data_size) {
155 }
else if (
s->in_pkt->size > data_size) {
159 pkt->size = data_size;
173 set_silence(
ctx->par_in,
s->out_pkt->data +
s->out_pkt->size, data_size -
s->out_pkt->size);
174 s->out_pkt->size = data_size;
176 nb_samples =
s->out_pkt->size /
s->sample_size;
188#define OFFSET(x) offsetof(PCMContext, x)
189#define FLAGS (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM)
191 {
"nb_out_samples",
"set the number of per-packet output samples",
OFFSET(nb_out_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
192 {
"n",
"set the number of per-packet output samples",
OFFSET(nb_out_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
201 .class_name =
"pcm_rechunk_bsf",
233 .p.name =
"pcm_rechunk",
static enum AVCodecID codec_ids[]
static av_cold void close(AVCodecParserContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const FFBitStreamFilter ff_pcm_rechunk_bsf
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
void(* flush)(AVBSFContext *ctx)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_PCM_S24DAUD
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
#define AVERROR_EOF
End of file.
const char * av_default_item_name(void *ptr)
Return the context name.
static AVRational av_make_q(int num, int den)
Create an AVRational.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_DOWN
Round toward -infinity.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int rechunk_filter(AVBSFContext *ctx, AVPacket *pkt)
static const AVClass pcm_rechunk_class
static int send_packet(PCMContext *s, int nb_samples, AVPacket *pkt)
static void uninit(AVBSFContext *ctx)
static void drain_packet(AVPacket *pkt, int drain_data, int drain_samples)
static void set_silence(AVCodecParameters *par, uint8_t *buf, size_t size)
static int get_next_nb_samples(AVBSFContext *ctx)
The bitstream filter state.
Describe the class of an AVClass context structure.
This struct describes the properties of an encoded stream.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
Rational number (pair of numerator and denominator).
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static AVFormatContext * ctx