#include "libavutil/md5.h"
#include "libavutil/opt.h"
#include "avcodec.h"
-#include "dsputil.h"
+#include "bswapdsp.h"
#include "get_bits.h"
#include "golomb.h"
#include "internal.h"
enum CodingMode coding_mode;
int porder;
int params[MAX_PARTITIONS];
+ uint32_t udata[FLAC_MAX_BLOCKSIZE];
} RiceContext;
typedef struct FlacSubframe {
struct AVMD5 *md5ctx;
uint8_t *md5_buffer;
unsigned int md5_buffer_size;
- DSPContext dsp;
+ BswapDSPContext bdsp;
FLACDSPContext flac_dsp;
+
+ int flushed;
+ int64_t next_pts;
} FlacEncodeContext;
ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size,
s->options.max_prediction_order, FF_LPC_TYPE_LEVINSON);
- ff_dsputil_init(&s->dsp, avctx);
+ ff_bswapdsp_init(&s->bdsp);
ff_flacdsp_init(&s->flac_dsp, avctx->sample_fmt,
avctx->bits_per_raw_sample);
uint64_t bits[MAX_PARTITION_ORDER+1];
int opt_porder;
RiceContext tmp_rc;
- uint32_t *udata;
- uint64_t sums[MAX_PARTITION_ORDER+1][MAX_PARTITIONS];
+ uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } };
assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);
assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER);
tmp_rc.coding_mode = rc->coding_mode;
- udata = av_malloc(n * sizeof(uint32_t));
for (i = 0; i < n; i++)
- udata[i] = (2*data[i]) ^ (data[i]>>31);
+ rc->udata[i] = (2 * data[i]) ^ (data[i] >> 31);
- calc_sums(pmin, pmax, udata, n, pred_order, sums);
+ calc_sums(pmin, pmax, rc->udata, n, pred_order, sums);
opt_porder = pmin;
bits[pmin] = UINT32_MAX;
}
}
- av_freep(&udata);
return bits[opt_porder];
}
if (s->avctx->bits_per_raw_sample <= 16) {
buf = (const uint8_t *)samples;
#if HAVE_BIGENDIAN
- s->dsp.bswap16_buf((uint16_t *)s->md5_buffer,
- (const uint16_t *)samples, buf_size / 2);
+ s->bdsp.bswap16_buf((uint16_t *) s->md5_buffer,
+ (const uint16_t *) samples, buf_size / 2);
buf = s->md5_buffer;
#endif
} else {
s->max_framesize = s->max_encoded_framesize;
av_md5_final(s->md5ctx, s->md5sum);
write_streaminfo(s, avctx->extradata);
+
+ if (avctx->side_data_only_packets && !s->flushed) {
+ uint8_t *side_data = av_packet_new_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
+ avctx->extradata_size);
+ if (!side_data)
+ return AVERROR(ENOMEM);
+ memcpy(side_data, avctx->extradata, avctx->extradata_size);
+
+ avpkt->pts = s->next_pts;
+
+ *got_packet_ptr = 1;
+ s->flushed = 1;
+ }
+
return 0;
}
frame_bytes = encode_frame(s);
- /* fallback to verbatim mode if the compressed frame is larger than it
+ /* Fall back on verbatim mode if the compressed frame is larger than it
would be if encoded uncompressed. */
if (frame_bytes < 0 || frame_bytes > s->max_framesize) {
s->frame.verbatim_only = 1;
avpkt->pts = frame->pts;
avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
avpkt->size = out_bytes;
+
+ s->next_pts = avpkt->pts + avpkt->duration;
+
*got_packet_ptr = 1;
return 0;
}
AVCodec ff_flac_encoder = {
.name = "flac",
+ .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_FLAC,
.priv_data_size = sizeof(FlacEncodeContext),
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_S32,
AV_SAMPLE_FMT_NONE },
- .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
.priv_class = &flac_encoder_class,
};