<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>199559</bug_id>
          
          <creation_ts>2019-07-07 02:58:49 -0700</creation_ts>
          <short_desc>[GStreamer] Ensure that  “volume = foo; assert(volume == foo)” always succeeds</short_desc>
          <delta_ts>2019-07-10 08:42:41 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Media</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=199505</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Charlie Turner">cturner</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>calvaris</cc>
    
    <cc>pnormand</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1550698</commentid>
    <comment_count>0</comment_count>
    <who name="Charlie Turner">cturner</who>
    <bug_when>2019-07-07 02:58:49 -0700</bug_when>
    <thetext>See https://bugs.webkit.org/show_bug.cgi?id=199505. It would be nice if for any media element E, E.volume = x does not undergo and transformations that cannot be reversed when reading the volume back. Currently in the pulseaudio backend, this is not the case due to the following PA code,


// converting to PA integer volume code
uint32_t pa_sw_volume_from_linear(double v) {
 
  if (v &lt;= 0.0)
    return PA_VOLUME_MUTED;
 
  /*
   * We use a cubic mapping here, as suggested and discussed here:
   *
   * http://www.robotplanet.dk/audio/audio_gui_design/
   * http://lists.linuxaudio.org/pipermail/linux-audio-dev/2009-May/thread.html#23151
   *
   * We make sure that the conversion to linear and back yields the
   * same volume value! That&apos;s why we need the lround() below!
   */
 
// clamps between 0 and UINT32_MAX/2
  return (uint32_t) PA_CLAMP_VOLUME((uint64_t) lround(cbrt(v) * PA_VOLUME_NORM));
}

// converting back to double from PA integer volume code
double pa_sw_volume_to_linear(uint32_t v) {
  double f;
 
  if (v &lt;= PA_VOLUME_MUTED)
    return 0.0;
 
  if (v == PA_VOLUME_NORM)
    return 1.0;
 
  f = ((double) v / PA_VOLUME_NORM);

  return (f*f*f);
}



The lround there means it&apos;s lossy. I&apos;m not sure how to fix that when the PA devs do not consider it a bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1550699</commentid>
    <comment_count>1</comment_count>
    <who name="Charlie Turner">cturner</who>
    <bug_when>2019-07-07 02:59:52 -0700</bug_when>
    <thetext>The upstream PA bug is at https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/697</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1550764</commentid>
    <comment_count>2</comment_count>
    <who name="Xabier Rodríguez Calvar">calvaris</who>
    <bug_when>2019-07-08 00:09:22 -0700</bug_when>
    <thetext>If PA devs don&apos;t fix this, which is unlikely, I think we should cache the volume we set somehow and use this unless we get a volume change signal from GStreamer, which would invalidate that cache.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1551269</commentid>
    <comment_count>3</comment_count>
    <who name="Philippe Normand">pnormand</who>
    <bug_when>2019-07-09 09:56:08 -0700</bug_when>
    <thetext>In MediaPlayerPrivateGStreamerBase::notifyPlayerOfVolumeChange() why do we cast the value to float? m_player-&gt;volumeChanged() expects a double.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1551272</commentid>
    <comment_count>4</comment_count>
    <who name="Philippe Normand">pnormand</who>
    <bug_when>2019-07-09 09:58:17 -0700</bug_when>
    <thetext>Also, I wonder if we should override MediaPlayerPrivate::setVolumeDouble(double) instead of MediaPlayer::setVolume(float).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1551667</commentid>
    <comment_count>5</comment_count>
    <who name="Charlie Turner">cturner</who>
    <bug_when>2019-07-10 08:42:41 -0700</bug_when>
    <thetext>(In reply to Philippe Normand from comment #3)
&gt; In MediaPlayerPrivateGStreamerBase::notifyPlayerOfVolumeChange() why do we
&gt; cast the value to float? m_player-&gt;volumeChanged() expects a double.

It&apos;s old code, perhaps the MediaPlayer class changed since it was written. Regardless, it doesn&apos;t matter since the error from PA has already crept in before we start casting. Same goes for the setVolumeDouble, PA behavior still introduces this issue.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>