[vlc-devel] [PATCH] Fix #8105, #8165 and #8174 (Replaygain)

Anatoliy Anischovich lin.aaa.lin at gmail.com
Thu Mar 7 23:43:42 CET 2013


8105: Vorbis comment's field names are case insensitive, so convert them to uppercase.
8165: If there is no peak data, assume peak is equal 1.0.
8174: Before dictionaries there was a loop, so if-else way was ok, but not now. Also, locale-dependent atof().
---
 include/vlc_input.h       | 18 +++++++++++-------
 modules/codec/vorbis.c    |  9 +++++----
 modules/demux/vorbis.h    | 11 +++++++++++
 src/audio_output/volume.c |  8 ++++----
 4 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index cbd6aab..f9958f2 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -36,6 +36,7 @@
 #include <vlc_epg.h>
 #include <vlc_events.h>
 #include <vlc_input_item.h>
+#include <vlc_charset.h>
 
 #include <string.h>
 
@@ -54,24 +55,27 @@ static inline void vlc_audio_replay_gain_MergeFromMeta( audio_replay_gain_t *p_d
         (psz_value = vlc_meta_GetExtra(p_meta, "RG_RADIO")) )
     {
         p_dst->pb_gain[AUDIO_REPLAY_GAIN_TRACK] = true;
-        p_dst->pf_gain[AUDIO_REPLAY_GAIN_TRACK] = atof( psz_value );
+        p_dst->pf_gain[AUDIO_REPLAY_GAIN_TRACK] = us_atof( psz_value );
     }
-    else if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_TRACK_PEAK" )) ||
+
+    if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_TRACK_PEAK" )) ||
              (psz_value = vlc_meta_GetExtra(p_meta, "RG_PEAK" )) )
     {
         p_dst->pb_peak[AUDIO_REPLAY_GAIN_TRACK] = true;
-        p_dst->pf_peak[AUDIO_REPLAY_GAIN_TRACK] = atof( psz_value );
+        p_dst->pf_peak[AUDIO_REPLAY_GAIN_TRACK] = us_atof( psz_value );
     }
-    else if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_ALBUM_GAIN" )) ||
+
+    if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_ALBUM_GAIN" )) ||
              (psz_value = vlc_meta_GetExtra(p_meta, "RG_AUDIOPHILE" )) )
     {
         p_dst->pb_gain[AUDIO_REPLAY_GAIN_ALBUM] = true;
-        p_dst->pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = atof( psz_value );
+        p_dst->pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = us_atof( psz_value );
     }
-    else if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_ALBUM_PEAK" )) )
+
+    if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_ALBUM_PEAK" )) )
     {
         p_dst->pb_peak[AUDIO_REPLAY_GAIN_ALBUM] = true;
-        p_dst->pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = atof( psz_value );
+        p_dst->pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = us_atof( psz_value );
     }
 }
 
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index 7cc2ec9..9f3bd47 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -34,6 +34,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
+#include <vlc_charset.h>
 #include <vlc_aout.h>
 #include <vlc_input.h>
 #include <vlc_sout.h>
@@ -583,7 +584,7 @@ static void ParseVorbisComments( decoder_t *p_dec )
                 audio_replay_gain_t *r = &p_dec->fmt_out.audio_replay_gain;
 
                 r->pb_gain[AUDIO_REPLAY_GAIN_TRACK] = true;
-                r->pf_gain[AUDIO_REPLAY_GAIN_TRACK] = atof( psz_value );
+                r->pf_gain[AUDIO_REPLAY_GAIN_TRACK] = us_atof( psz_value );
             }
             else if( !strcasecmp( psz_name, "REPLAYGAIN_TRACK_PEAK" ) ||
                      !strcasecmp( psz_name, "RG_PEAK" ) )
@@ -591,7 +592,7 @@ static void ParseVorbisComments( decoder_t *p_dec )
                 audio_replay_gain_t *r = &p_dec->fmt_out.audio_replay_gain;
 
                 r->pb_peak[AUDIO_REPLAY_GAIN_TRACK] = true;
-                r->pf_peak[AUDIO_REPLAY_GAIN_TRACK] = atof( psz_value );
+                r->pf_peak[AUDIO_REPLAY_GAIN_TRACK] = us_atof( psz_value );
             }
             else if( !strcasecmp( psz_name, "REPLAYGAIN_ALBUM_GAIN" ) ||
                      !strcasecmp( psz_name, "RG_AUDIOPHILE" ) )
@@ -599,14 +600,14 @@ static void ParseVorbisComments( decoder_t *p_dec )
                 audio_replay_gain_t *r = &p_dec->fmt_out.audio_replay_gain;
 
                 r->pb_gain[AUDIO_REPLAY_GAIN_ALBUM] = true;
-                r->pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = atof( psz_value );
+                r->pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = us_atof( psz_value );
             }
             else if( !strcasecmp( psz_name, "REPLAYGAIN_ALBUM_PEAK" ) )
             {
                 audio_replay_gain_t *r = &p_dec->fmt_out.audio_replay_gain;
 
                 r->pb_peak[AUDIO_REPLAY_GAIN_ALBUM] = true;
-                r->pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = atof( psz_value );
+                r->pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = us_atof( psz_value );
             }
             else if( !strcasecmp( psz_name, "METADATA_BLOCK_PICTURE" ) )
             { /* Do nothing, for now */ }
diff --git a/modules/demux/vorbis.h b/modules/demux/vorbis.h
index 2642c4b..7cabe6e 100644
--- a/modules/demux/vorbis.h
+++ b/modules/demux/vorbis.h
@@ -221,6 +221,17 @@ static inline void vorbis_ParseComment( vlc_meta_t **pp_meta,
              * undocumented tags and replay gain ) */
             char *p = strchr( psz_comment, '=' );
             *p++ = '\0';
+
+            int i=0;
+            while (psz[i])
+            {
+                /* ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered
+                 * equivalent to ASCII 0x61 through 0x7A inclusive (a-z). */
+                if ( psz[i] >= 'a' && psz[i] <= 'z' )
+                    psz[i] ^= ' ';
+                ++i;
+            }
+
             vlc_meta_AddExtra( p_meta, psz_comment, p );
         }
 #undef IF_EXTRACT
diff --git a/src/audio_output/volume.c b/src/audio_output/volume.c
index 7eb977d..b16cc83 100644
--- a/src/audio_output/volume.c
+++ b/src/audio_output/volume.c
@@ -179,10 +179,10 @@ static float aout_ReplayGainSelect(vlc_object_t *obj, const char *str,
 
         multiplier = pow (10., gain / 20.);
 
-        if (replay_gain->pb_peak[mode]
-         && var_InheritBool (obj, "audio-replay-gain-peak-protection")
-         && replay_gain->pf_peak[mode] * multiplier > 1.f)
-            multiplier = 1.f / replay_gain->pf_peak[mode];
+        if (var_InheritBool (obj, "audio-replay-gain-peak-protection"))
+            multiplier = fminf (multiplier, replay_gain->pb_peak[mode]
+                                            ? 1.f / replay_gain->pf_peak[mode]
+                                            : 1.f);
     }
 
     /* Command line / configuration gain */
-- 
1.8.1.5




More information about the vlc-devel mailing list