22 #include <shine/layer3.h>
31 #define BUFFER_SIZE (4096 * 20)
50 shine_set_config_mpeg_defaults(&
s->config.mpeg);
52 s->config.mpeg.bitr = avctx->
bit_rate / 1000;
55 s->config.wave.channels = avctx->
channels == 2 ? PCM_STEREO : PCM_MONO;
56 if (shine_check_config(
s->config.wave.samplerate,
s->config.mpeg.bitr) < 0) {
60 s->shine = shine_initialise(&
s->config);
63 avctx->
frame_size = shine_samples_per_pass(
s->shine);
78 data = shine_encode_buffer(
s->shine, (int16_t **)
frame->
data, &written);
80 data = shine_flush(
s->shine, &written);
88 memcpy(
s->buffer +
s->buffer_index,
data, written);
89 s->buffer_index += written;
96 if (
s->buffer_index < 4 || !
s->afq.frame_count)
103 len = hdr.frame_size;
104 if (len <= s->buffer_index) {
107 memcpy(avpkt->
data,
s->buffer,
len);
108 s->buffer_index -=
len;
109 memmove(
s->buffer,
s->buffer +
len,
s->buffer_index);
125 shine_close(
s->shine);
130 44100, 48000, 32000, 0
149 .wrapper_name =
"libshine",
static enum AVSampleFormat sample_fmts[]
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int libshine_encode_init(AVCodecContext *avctx)
static const int libshine_sample_rates[]
static av_cold int libshine_encode_close(AVCodecContext *avctx)
static int libshine_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
AVCodec ff_libshine_encoder
mpeg audio declarations for both encoder and decoder.
main external API structure.
int64_t bit_rate
the average bitrate
int sample_rate
samples per second
int channels
number of audio channels
int frame_size
Number of samples per channel in an audio frame.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t buffer[BUFFER_SIZE]