Created
July 18, 2014 21:41
-
-
Save justinruggles/5626a5ee51ab118b5692 to your computer and use it in GitHub Desktop.
[PATCH] lavr: Do not change the sample format for mono audio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From bbe80480e2a83895d4ba8626cad32e0004d73f1c Mon Sep 17 00:00:00 2001 | |
From: Justin Ruggles <[email protected]> | |
Date: Fri, 18 Jul 2014 17:39:01 -0400 | |
Subject: [PATCH] lavr: Do not change the sample format for mono audio | |
This treats mono as planar internally within libavresample rather | |
than changing the sample format. | |
--- | |
libavresample/audio_convert.c | 4 ++-- | |
libavresample/audio_data.c | 12 ++++++++++-- | |
libavresample/audio_data.h | 2 ++ | |
libavresample/utils.c | 10 ++-------- | |
4 files changed, 16 insertions(+), 12 deletions(-) | |
diff --git a/libavresample/audio_convert.c b/libavresample/audio_convert.c | |
index 27add23..11bbbbe 100644 | |
--- a/libavresample/audio_convert.c | |
+++ b/libavresample/audio_convert.c | |
@@ -288,8 +288,8 @@ AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, | |
return ac; | |
} | |
- in_planar = av_sample_fmt_is_planar(in_fmt); | |
- out_planar = av_sample_fmt_is_planar(out_fmt); | |
+ in_planar = ff_sample_fmt_is_planar(in_fmt, channels); | |
+ out_planar = ff_sample_fmt_is_planar(out_fmt, channels); | |
if (in_planar == out_planar) { | |
ac->func_type = CONV_FUNC_TYPE_FLAT; | |
diff --git a/libavresample/audio_data.c b/libavresample/audio_data.c | |
index c52f518..7a6fe74 100644 | |
--- a/libavresample/audio_data.c | |
+++ b/libavresample/audio_data.c | |
@@ -48,6 +48,14 @@ static void calc_ptr_alignment(AudioData *a) | |
a->ptr_align = min_align; | |
} | |
+int ff_sample_fmt_is_planar(enum AVSampleFormat sample_fmt, int channels) | |
+{ | |
+ if (channels == 1) | |
+ return 1; | |
+ else | |
+ return av_sample_fmt_is_planar(sample_fmt); | |
+} | |
+ | |
int ff_audio_data_set_channels(AudioData *a, int channels) | |
{ | |
if (channels < 1 || channels > AVRESAMPLE_MAX_CHANNELS || | |
@@ -81,7 +89,7 @@ int ff_audio_data_init(AudioData *a, uint8_t **src, int plane_size, int channels | |
av_log(a, AV_LOG_ERROR, "invalid sample format\n"); | |
return AVERROR(EINVAL); | |
} | |
- a->is_planar = av_sample_fmt_is_planar(sample_fmt); | |
+ a->is_planar = ff_sample_fmt_is_planar(sample_fmt, channels); | |
a->planes = a->is_planar ? channels : 1; | |
a->stride = a->sample_size * (a->is_planar ? 1 : channels); | |
@@ -125,7 +133,7 @@ AudioData *ff_audio_data_alloc(int channels, int nb_samples, | |
av_free(a); | |
return NULL; | |
} | |
- a->is_planar = av_sample_fmt_is_planar(sample_fmt); | |
+ a->is_planar = ff_sample_fmt_is_planar(sample_fmt, channels); | |
a->planes = a->is_planar ? channels : 1; | |
a->stride = a->sample_size * (a->is_planar ? 1 : channels); | |
diff --git a/libavresample/audio_data.h b/libavresample/audio_data.h | |
index 97236bb..1541976 100644 | |
--- a/libavresample/audio_data.h | |
+++ b/libavresample/audio_data.h | |
@@ -29,6 +29,8 @@ | |
#include "avresample.h" | |
#include "internal.h" | |
+int ff_sample_fmt_is_planar(enum AVSampleFormat sample_fmt, int channels); | |
+ | |
/** | |
* Audio buffer used for intermediate storage between conversion phases. | |
*/ | |
diff --git a/libavresample/utils.c b/libavresample/utils.c | |
index 8c5a9e2..851cd35 100644 | |
--- a/libavresample/utils.c | |
+++ b/libavresample/utils.c | |
@@ -101,16 +101,10 @@ int avresample_open(AVAudioResampleContext *avr) | |
av_get_sample_fmt_name(avr->internal_sample_fmt)); | |
} | |
- /* treat all mono as planar for easier comparison */ | |
- if (avr->in_channels == 1) | |
- avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt); | |
- if (avr->out_channels == 1) | |
- avr->out_sample_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt); | |
- | |
/* we may need to add an extra conversion in order to remap channels if | |
the output format is not planar */ | |
if (avr->use_channel_map && !avr->mixing_needed && !avr->resample_needed && | |
- !av_sample_fmt_is_planar(avr->out_sample_fmt)) { | |
+ !ff_sample_fmt_is_planar(avr->out_sample_fmt, avr->out_channels)) { | |
avr->internal_sample_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt); | |
} | |
@@ -119,7 +113,7 @@ int avresample_open(AVAudioResampleContext *avr) | |
avr->in_convert_needed = avr->in_sample_fmt != avr->internal_sample_fmt; | |
else | |
avr->in_convert_needed = avr->use_channel_map && | |
- !av_sample_fmt_is_planar(avr->out_sample_fmt); | |
+ !ff_sample_fmt_is_planar(avr->out_sample_fmt, avr->out_channels); | |
if (avr->resample_needed || avr->mixing_needed || avr->in_convert_needed) | |
avr->out_convert_needed = avr->internal_sample_fmt != avr->out_sample_fmt; | |
-- | |
1.8.1.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment