Changeset 181006 in webkit


Ignore:
Timestamp:
Mar 4, 2015 11:26:22 AM (9 years ago)
Author:
jer.noble@apple.com
Message:

[Mac] YouTube playback at 1.5x speed has audible distortion
https://bugs.webkit.org/show_bug.cgi?id=142280

Reviewed by Eric Carlson.

Use the high-quality AVAudioTimePitchAlgorithmSpectral algorithm for the
AVSampleBufferAudioRenderer rather than its default value of
AVAudioTimePitchAlgorithmTimeDomain.

Drive-by fix:

Might as well add support for MediaPlayer::setPreservesPitch() while we're
changing the audio pitch algorithm. If preservesPitch() is false use the
AVAudioTimePitchAlgorithmVarispeed algorithm in both AVFObjC-based media players
(MediaPlayerPrivateAVFoundationObjC & MediaPlayerPrivateMediaSourceAVFObjC).

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem):
(WebCore::MediaPlayerPrivateAVFoundationObjC::setPreservesPitch):
(WebCore::MediaPlayerPrivateAVFoundationObjC::setRateDouble): Deleted.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
  • platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:

(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setPreservesPitch):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::addAudioRenderer):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181005 r181006  
     12015-03-04  Jer Noble  <jer.noble@apple.com>
     2
     3        [Mac] YouTube playback at 1.5x speed has audible distortion
     4        https://bugs.webkit.org/show_bug.cgi?id=142280
     5
     6        Reviewed by Eric Carlson.
     7
     8        Use the high-quality AVAudioTimePitchAlgorithmSpectral algorithm for the
     9        AVSampleBufferAudioRenderer rather than its default value of
     10        AVAudioTimePitchAlgorithmTimeDomain.
     11
     12        Drive-by fix:
     13
     14        Might as well add support for MediaPlayer::setPreservesPitch() while we're
     15        changing the audio pitch algorithm. If preservesPitch() is false use the
     16        AVAudioTimePitchAlgorithmVarispeed algorithm in both AVFObjC-based media players
     17        (MediaPlayerPrivateAVFoundationObjC & MediaPlayerPrivateMediaSourceAVFObjC).
     18
     19        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
     20        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     21        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem):
     22        (WebCore::MediaPlayerPrivateAVFoundationObjC::setPreservesPitch):
     23        (WebCore::MediaPlayerPrivateAVFoundationObjC::setRateDouble): Deleted.
     24        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
     25        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
     26        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setPreservesPitch):
     27        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::addAudioRenderer):
     28
    1292015-03-04  Jer Noble  <jer.noble@apple.com>
    230
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h

    r180839 r181006  
    179179    virtual void setRateDouble(double) override;
    180180    virtual double rate() const;
     181    void setPreservesPitch(bool) override;
    181182    virtual void seekToTime(const MediaTime&, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance);
    182183    virtual unsigned long long totalBytes() const;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r180839 r181006  
    183183SOFT_LINK_CLASS(CoreImage, CIImage)
    184184
     185SOFT_LINK_POINTER(AVFoundation, AVAudioTimePitchAlgorithmSpectral, NSString*)
     186SOFT_LINK_POINTER(AVFoundation, AVAudioTimePitchAlgorithmVarispeed, NSString*)
    185187SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicVisual, NSString *)
    186188SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicAudible, NSString *)
     
    207209#define AVMetadataItem getAVMetadataItemClass()
    208210
     211#define AVAudioTimePitchAlgorithmSpectral getAVAudioTimePitchAlgorithmSpectral()
     212#define AVAudioTimePitchAlgorithmVarispeed getAVAudioTimePitchAlgorithmVarispeed()
    209213#define AVMediaCharacteristicVisual getAVMediaCharacteristicVisual()
    210214#define AVMediaCharacteristicAudible getAVMediaCharacteristicAudible()
     
    963967        [m_avPlayerItem.get() addObserver:m_objcObserver.get() forKeyPath:keyName options:options context:(void *)MediaPlayerAVFoundationObservationContextPlayerItem];
    964968
     969    [m_avPlayerItem setAudioTimePitchAlgorithm:(player()->preservesPitch() ? AVAudioTimePitchAlgorithmSpectral : AVAudioTimePitchAlgorithmVarispeed)];
     970
    965971    if (m_avPlayer)
    966972        setAVPlayerItem(m_avPlayerItem.get());
     
    970976    if (player()->doesHaveAttribute("data-youtube-id", &value))
    971977        [m_avPlayerItem.get() setDataYouTubeID: value];
    972  #endif
     978#endif
    973979
    974980#if HAVE(AVFOUNDATION_MEDIA_SELECTION_GROUP) && HAVE(AVFOUNDATION_LEGIBLE_OUTPUT_SUPPORT)
     
    13211327
    13221328void MediaPlayerPrivateAVFoundationObjC::setRateDouble(double rate)
    1323 
    13241329{
    13251330    setDelayCallbacks(true);
     
    13351340
    13361341    return m_cachedRate;
     1342}
     1343
     1344void MediaPlayerPrivateAVFoundationObjC::setPreservesPitch(bool preservesPitch)
     1345{
     1346    if (m_avPlayerItem)
     1347        [m_avPlayerItem setAudioTimePitchAlgorithm:(preservesPitch ? AVAudioTimePitchAlgorithmSpectral : AVAudioTimePitchAlgorithmVarispeed)];
    13371348}
    13381349
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h

    r180839 r181006  
    132132    virtual void setRateDouble(double) override;
    133133
     134    void setPreservesPitch(bool) override;
     135
    134136    virtual std::unique_ptr<PlatformTimeRanges> seekable() const override;
    135137    virtual MediaTime maxMediaTimeSeekable() const override;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm

    r180839 r181006  
    6363SOFT_LINK_CLASS_OPTIONAL(AVFoundation, AVVideoPerformanceMetrics)
    6464
     65SOFT_LINK_CONSTANT(AVFoundation, AVAudioTimePitchAlgorithmSpectral, NSString*)
     66SOFT_LINK_CONSTANT(AVFoundation, AVAudioTimePitchAlgorithmVarispeed, NSString*)
    6567SOFT_LINK_CONSTANT(CoreMedia, kCMTimebaseNotification_EffectiveRateChanged, CFStringRef)
     68
     69#define AVAudioTimePitchAlgorithmSpectral getAVAudioTimePitchAlgorithmSpectral()
     70#define AVAudioTimePitchAlgorithmVarispeed getAVAudioTimePitchAlgorithmVarispeed()
    6671#define kCMTimebaseNotification_EffectiveRateChanged getkCMTimebaseNotification_EffectiveRateChanged()
    6772
     
    9297- (void)setVolume:(float)volume;
    9398- (void)setMuted:(BOOL)muted;
     99@property (nonatomic, copy) NSString *audioTimePitchAlgorithm;
    94100@end
    95101
     
    471477}
    472478
     479void MediaPlayerPrivateMediaSourceAVFObjC::setPreservesPitch(bool preservesPitch)
     480{
     481    NSString *algorithm = preservesPitch ? AVAudioTimePitchAlgorithmSpectral : AVAudioTimePitchAlgorithmVarispeed;
     482    for (auto& renderer : m_sampleBufferAudioRenderers)
     483        [renderer setAudioTimePitchAlgorithm:algorithm];
     484}
     485
    473486MediaPlayer::NetworkState MediaPlayerPrivateMediaSourceAVFObjC::networkState() const
    474487{
     
    773786    [audioRenderer setMuted:m_player->muted()];
    774787    [audioRenderer setVolume:m_player->volume()];
     788    [audioRenderer setAudioTimePitchAlgorithm:(m_player->preservesPitch() ? AVAudioTimePitchAlgorithmSpectral : AVAudioTimePitchAlgorithmVarispeed)];
    775789
    776790    [m_synchronizer addRenderer:audioRenderer];
Note: See TracChangeset for help on using the changeset viewer.