summaryrefslogtreecommitdiff
path: root/src/plugins/previewopus_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/previewopus_extractor.c')
-rw-r--r--src/plugins/previewopus_extractor.c108
1 files changed, 67 insertions, 41 deletions
diff --git a/src/plugins/previewopus_extractor.c b/src/plugins/previewopus_extractor.c
index 45ea420..f137f38 100644
--- a/src/plugins/previewopus_extractor.c
+++ b/src/plugins/previewopus_extractor.c
@@ -44,7 +44,7 @@
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
-#include <libavresample/avresample.h>
+#include <libswresample/swresample.h>
/**
@@ -300,7 +300,7 @@ init_input_frame (AVFrame **frame)
static int
init_resampler (AVCodecContext *input_codec_context,
AVCodecContext *output_codec_context,
- AVAudioResampleContext **resample_context)
+ SwrContext **resample_context)
{
/**
* Only initialize the resampler if it is necessary, i.e.,
@@ -312,7 +312,7 @@ init_resampler (AVCodecContext *input_codec_context,
int error;
/** Create a resampler context for the conversion. */
- if (! (*resample_context = avresample_alloc_context ()))
+ if (! (*resample_context = swr_alloc ()))
{
#if DEBUG
fprintf (stderr, "Could not allocate resample context\n");
@@ -326,28 +326,35 @@ init_resampler (AVCodecContext *input_codec_context,
* Default channel layouts based on the number of channels
* are assumed for simplicity (they are sometimes not detected
* properly by the demuxer and/or decoder).
- */av_opt_set_int (*resample_context, "in_channel_layout",
+ */
+ av_opt_set_int (*resample_context,
+ "in_channel_layout",
av_get_default_channel_layout (
input_codec_context->channels), 0);
- av_opt_set_int (*resample_context, "out_channel_layout",
+ av_opt_set_int (*resample_context,
+ "out_channel_layout",
av_get_default_channel_layout (
output_codec_context->channels), 0);
- av_opt_set_int (*resample_context, "in_sample_rate",
+ av_opt_set_int (*resample_context,
+ "in_sample_rate",
input_codec_context->sample_rate, 0);
- av_opt_set_int (*resample_context, "out_sample_rate",
+ av_opt_set_int (*resample_context,
+ "out_sample_rate",
output_codec_context->sample_rate, 0);
- av_opt_set_int (*resample_context, "in_sample_fmt",
+ av_opt_set_int (*resample_context,
+ "in_sample_fmt",
input_codec_context->sample_fmt, 0);
- av_opt_set_int (*resample_context, "out_sample_fmt",
+ av_opt_set_int (*resample_context,
+ "out_sample_fmt",
output_codec_context->sample_fmt, 0);
/** Open the resampler with the specified parameters. */
- if ((error = avresample_open (*resample_context)) < 0)
+ if ((error = swr_init (*resample_context)) < 0)
{
#if DEBUG
fprintf (stderr, "Could not open resample context\n");
#endif
- avresample_free (resample_context);
+ swr_free (resample_context);
return error;
}
}
@@ -461,7 +468,8 @@ decode_audio_frame (AVFrame *frame,
* The number of audio samples to be allocated is specified in frame_size.
*/
static int
-init_converted_samples (uint8_t ***converted_input_samples, int*out_linesize,
+init_converted_samples (uint8_t ***converted_input_samples,
+ int*out_linesize,
AVCodecContext *output_codec_context,
int frame_size)
{
@@ -484,7 +492,8 @@ init_converted_samples (uint8_t ***converted_input_samples, int*out_linesize,
* Allocate memory for the samples of all channels in one consecutive
* block for convenience.
*/
- if ((error = av_samples_alloc (*converted_input_samples, out_linesize,
+ if ((error = av_samples_alloc (*converted_input_samples,
+ out_linesize,
output_codec_context->channels,
frame_size,
output_codec_context->sample_fmt, 0)) < 0)
@@ -509,19 +518,26 @@ init_converted_samples (uint8_t ***converted_input_samples, int*out_linesize,
*/
static int
convert_samples (uint8_t **input_data,
- uint8_t **converted_data, const int in_sample, const int
- out_sample, const int out_linesize,
- AVAudioResampleContext *resample_context)
+ uint8_t **converted_data,
+ int in_sample,
+ int out_sample,
+ int out_linesize,
+ SwrContext *resample_context)
{
int error;
/** Convert the samples using the resampler. */
- if ((error = avresample_convert (resample_context, converted_data,
- out_linesize,
- out_sample, input_data, 0, in_sample)) < 0)
+ if ((error = swr_convert (resample_context,
+ converted_data,
+ out_linesize,
+ out_sample,
+ input_data,
+ 0,
+ in_sample)) < 0)
{
#if DEBUG
- fprintf (stderr, "Could not convert input samples (error '%s')\n",
+ fprintf (stderr,
+ "Could not convert input samples (error '%s')\n",
get_error_text (error));
#endif
return error;
@@ -532,11 +548,13 @@ convert_samples (uint8_t **input_data,
* Perform a sanity check so that the number of converted samples is
* not greater than the number of samples to be converted.
* If the sample rates differ, this case has to be handled differently
- */if (avresample_available (resample_context))
+ */
+ if (avresample_available (resample_context))
{
#if DEBUG
- fprintf (stderr, "%i Converted samples left over\n",avresample_available (
- resample_context));
+ fprintf (stderr,
+ "%i Converted samples left over\n",
+ avresample_available (resample_context));
#endif
}
@@ -588,7 +606,7 @@ read_decode_convert_and_store (AVAudioFifo *fifo,
AVFormatContext *input_format_context,
AVCodecContext *input_codec_context,
AVCodecContext *output_codec_context,
- AVAudioResampleContext *resampler_context, int
+ SwrContext *resampler_context, int
audio_stream_index,
int *finished)
{
@@ -609,22 +627,25 @@ read_decode_convert_and_store (AVAudioFifo *fifo,
}
/** Decode one frame worth of audio samples. */
- if (decode_audio_frame (input_frame, input_format_context,
- input_codec_context, audio_stream_index,
- &data_present, finished))
+ if (decode_audio_frame (input_frame,
+ input_format_context,
+ input_codec_context,
+ audio_stream_index,
+ &data_present,
+ finished))
{
#if DEBUG
fprintf (stderr, "Failed at decode audio\n");
#endif
goto cleanup;
-
}
/**
* If we are at the end of the file and there are no more samples
* in the decoder which are delayed, we are actually finished.
* This must not be treated as an error.
- */if (*finished && ! data_present)
+ */
+ if (*finished && ! data_present)
{
ret = 0;
#if DEBUG
@@ -636,7 +657,7 @@ read_decode_convert_and_store (AVAudioFifo *fifo,
if (data_present)
{
int out_linesize;
- // FIX ME: I'm losing samples, but can't get it to work.
+ // FIXME: I'm losing samples, but can't get it to work.
int out_samples = avresample_available (resampler_context)
+ avresample_get_delay (resampler_context)
+ input_frame->nb_samples;
@@ -645,7 +666,8 @@ read_decode_convert_and_store (AVAudioFifo *fifo,
// fprintf(stderr, "Input nbsamples %i out_samples: %i \n",input_frame->nb_samples,out_samples);
/** Initialize the temporary storage for the converted input samples. */
- if (init_converted_samples (&converted_input_samples, &out_linesize,
+ if (init_converted_samples (&converted_input_samples,
+ &out_linesize,
output_codec_context,
out_samples))
{
@@ -659,20 +681,23 @@ read_decode_convert_and_store (AVAudioFifo *fifo,
* Convert the input samples to the desired output sample format.
* This requires a temporary storage provided by converted_input_samples.
*/
- if (convert_samples (input_frame->extended_data, converted_input_samples,
- input_frame->nb_samples, out_samples, out_linesize,
+ if (convert_samples (input_frame->extended_data,
+ converted_input_samples,
+ input_frame->nb_samples,
+ out_samples,
+ out_linesize,
resampler_context))
{
-
-
#if DEBUG
- fprintf (stderr, "Failed at convert_samples, input frame %i \n",
+ fprintf (stderr,
+ "Failed at convert_samples, input frame %i \n",
input_frame->nb_samples);
#endif
goto cleanup;
}
/** Add the converted input samples to the FIFO buffer for later processing. */
- if (add_samples_to_fifo (fifo, converted_input_samples,
+ if (add_samples_to_fifo (fifo,
+ converted_input_samples,
out_samples))
{
#if DEBUG
@@ -881,7 +906,7 @@ extract_audio (struct EXTRACTOR_ExtractContext *ec)
AVDictionary *options;
AVFrame *frame;
AVCodecContext*output_codec_context = NULL;
- AVAudioResampleContext *resample_context = NULL;
+ SwrContext *resample_context = NULL;
AVAudioFifo *fifo = NULL;
int audio_stream_index;
@@ -1045,7 +1070,8 @@ extract_audio (struct EXTRACTOR_ExtractContext *ec)
* Since the decoder's and the encoder's frame size may differ, we
* need to FIFO buffer to store as many frames worth of input samples
* that they make up at least one frame worth of output samples.
- */while ((av_audio_fifo_size (fifo) < output_frame_size))
+ */
+ while ((av_audio_fifo_size (fifo) < output_frame_size))
{
/**
* Decode one frame worth of audio samples, convert it to the
@@ -1143,8 +1169,8 @@ cleanup:
av_audio_fifo_free (fifo);
if (resample_context)
{
- avresample_close (resample_context);
- avresample_free (&resample_context);
+ swr_close (resample_context);
+ swr_free (&resample_context);
}
if (output_codec_context)
avcodec_close (output_codec_context);