434 short int inBytesPerSample = av_get_bytes_per_sample(
pEncoderCtx->sample_fmt);
435 short int outBytesPerSample = av_get_bytes_per_sample(
pCodecCtx->sample_fmt);
457 avpkt.data =
nullptr;
459 av_init_packet(&avpkt);
460 ASSERT(avpkt.data ==
nullptr && avpkt.size == 0);
464 while (avpkt.size > 0) {
465 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0) 467 AVFrame *frame = av_frame_alloc();
469 int decoded = avcodec_decode_audio4(
pCodecCtx, frame, &gotFrame, &avpkt);
471 throw cRuntimeError(
"Error in avcodec_decode_audio4(), err=%d, gotFrame=%d", decoded, gotFrame);
473 avpkt.data += decoded;
474 avpkt.size -= decoded;
479 int dataSize = av_samples_get_buffer_size(
nullptr,
pCodecCtx->channels, frame->nb_samples,
pCodecCtx->sample_fmt, 1);
486 uint8_t **in_data = frame->extended_data;
487 int in_linesize = frame->linesize[0];
488 int in_nb_samples = frame->nb_samples;
490 uint8_t *out_data[AVRESAMPLE_MAX_CHANNELS] = {
496 ret = av_samples_fill_arrays(out_data, &out_linesize, tmpSamples,
500 throw cRuntimeError(
"failed out_data fill arrays");
502 decoded = avresample_convert(
pReSampleCtx, out_data, out_linesize, decoded,
503 in_data, in_linesize, in_nb_samples);
504 if (decoded <= 0 && avresample_get_delay(
pReSampleCtx) == 0) {
505 throw cRuntimeError(
"audio_resample() returns error");
518 av_frame_free(&frame);
519 #else // if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0) 522 int16_t *rbuf, *nbuf;
527 memset(rbuf, 0, frame_size);
528 int decoded = avcodec_decode_audio3(
pCodecCtx, rbuf, &frame_size, &avpkt);
531 throw cRuntimeError(
"Error decoding frame, err=%d", decoded);
533 avpkt.data += decoded;
534 avpkt.size -= decoded;
539 decoded = frame_size / (inBytesPerSample *
pCodecCtx->channels);
540 ASSERT(frame_size == decoded * inBytesPerSample *
pCodecCtx->channels);
543 decoded = audio_resample(
pReSampleCtx, nbuf, rbuf, decoded);
547 #endif // if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0) 548 av_free_packet(&avpkt);
int availableSpace() const
Definition: VoIPStreamSender.h:94
void align()
Definition: VoIPStreamSender.cc:422
int streamIndex
Definition: VoIPStreamSender.h:135
int samplesPerPacket
Definition: VoIPStreamSender.h:137
Definition: VoIPStreamSender.h:78
AVCodecContext * pEncoderCtx
Definition: VoIPStreamSender.h:130
void notifyWrote(int length)
Definition: VoIPStreamSender.h:96
AVFormatContext * pFormatCtx
Definition: VoIPStreamSender.h:120
int length() const
Definition: VoIPStreamSender.h:90
AVPacket packet
Definition: VoIPStreamSender.h:138
char * writePtr()
Definition: VoIPStreamSender.h:93
Buffer sampleBuffer
Definition: VoIPStreamSender.h:139
AVAudioResampleContext * pReSampleCtx
Definition: VoIPStreamSender.h:125
AVCodecContext * pCodecCtx
Definition: VoIPStreamSender.h:121