Title: [182555] trunk/Source/WebCore
- Revision
- 182555
- Author
- [email protected]
- Date
- 2015-04-08 11:12:56 -0700 (Wed, 08 Apr 2015)
Log Message
[Mac][WebAudio] Update the AVAudioMix in the AudioSourceProviderAVFObjC when the list of enabled audio tracks change.
https://bugs.webkit.org/show_bug.cgi?id=143332
Reviewed by Eric Carlson.
Some media assets (notably, mp3s) will not have an enabled audio track when the AVAsset is
first loaded, so the AVAudioMix will have no trackID in it's parameters. Whenever the list
of enabled tracks change, recreate the AVAudioMix with the new first enabled audio trackID.
To facilitate this, add a new setter to AudioSourceProviderAVFObjC taking an AVAssetTrack to
use with the AVAudioMix. Whenever this parameter changes, the AVAudioMix is destroyed and
recreated.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerEngineUpdated): Drive-by fix: when the media
player switches engines, re-associate the audio source node with its provider.
* platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h:
* platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
(WebCore::AudioSourceProviderAVFObjC::setPlayerItem): Only create the mix if there is a valid AVPlayerItem and AVAssetTrack
(WebCore::AudioSourceProviderAVFObjC::setAudioTrack): Ditto.
(WebCore::AudioSourceProviderAVFObjC::createMix): Don't iterate over the AVPlayerItem's tracks,
just use the one passed in through setAudioTrack().
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::cancelLoad): Clear the provider's track.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem): Set the provider's track.
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::audioSourceProvider): Ditto.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (182554 => 182555)
--- trunk/Source/WebCore/ChangeLog 2015-04-08 18:06:58 UTC (rev 182554)
+++ trunk/Source/WebCore/ChangeLog 2015-04-08 18:12:56 UTC (rev 182555)
@@ -1,3 +1,33 @@
+2015-04-08 Jer Noble <[email protected]>
+
+ [Mac][WebAudio] Update the AVAudioMix in the AudioSourceProviderAVFObjC when the list of enabled audio tracks change.
+ https://bugs.webkit.org/show_bug.cgi?id=143332
+
+ Reviewed by Eric Carlson.
+
+ Some media assets (notably, mp3s) will not have an enabled audio track when the AVAsset is
+ first loaded, so the AVAudioMix will have no trackID in it's parameters. Whenever the list
+ of enabled tracks change, recreate the AVAudioMix with the new first enabled audio trackID.
+
+ To facilitate this, add a new setter to AudioSourceProviderAVFObjC taking an AVAssetTrack to
+ use with the AVAudioMix. Whenever this parameter changes, the AVAudioMix is destroyed and
+ recreated.
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::mediaPlayerEngineUpdated): Drive-by fix: when the media
+ player switches engines, re-associate the audio source node with its provider.
+ * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h:
+ * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
+ (WebCore::AudioSourceProviderAVFObjC::setPlayerItem): Only create the mix if there is a valid AVPlayerItem and AVAssetTrack
+ (WebCore::AudioSourceProviderAVFObjC::setAudioTrack): Ditto.
+ (WebCore::AudioSourceProviderAVFObjC::createMix): Don't iterate over the AVPlayerItem's tracks,
+ just use the one passed in through setAudioTrack().
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::cancelLoad): Clear the provider's track.
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem): Set the provider's track.
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Ditto.
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::audioSourceProvider): Ditto.
+
2015-04-08 Anders Carlsson <[email protected]>
Move some ApplicationCache static member functions to ApplicationCacheStorage
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (182554 => 182555)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2015-04-08 18:06:58 UTC (rev 182554)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2015-04-08 18:12:56 UTC (rev 182555)
@@ -4273,6 +4273,14 @@
m_mediaSession->applyMediaPlayerRestrictions(*this);
+#if ENABLE(WEB_AUDIO)
+ if (m_audioSourceNode && audioSourceProvider()) {
+ m_audioSourceNode->lock();
+ audioSourceProvider()->setClient(m_audioSourceNode);
+ m_audioSourceNode->unlock();
+ }
+#endif
+
#if PLATFORM(IOS)
if (!m_player)
return;
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h (182554 => 182555)
--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h 2015-04-08 18:06:58 UTC (rev 182554)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h 2015-04-08 18:12:56 UTC (rev 182555)
@@ -34,6 +34,7 @@
#include <wtf/RefPtr.h>
#include <wtf/RetainPtr.h>
+OBJC_CLASS AVAssetTrack;
OBJC_CLASS AVPlayerItem;
OBJC_CLASS AVMutableAudioMix;
@@ -54,6 +55,7 @@
virtual ~AudioSourceProviderAVFObjC();
void setPlayerItem(AVPlayerItem *);
+ void setAudioTrack(AVAssetTrack *);
private:
AudioSourceProviderAVFObjC(AVPlayerItem *);
@@ -78,6 +80,7 @@
void process(CMItemCount numberFrames, MTAudioProcessingTapFlags flagsIn, AudioBufferList *bufferListInOut, CMItemCount *numberFramesOut, MTAudioProcessingTapFlags *flagsOut);
RetainPtr<AVPlayerItem> m_avPlayerItem;
+ RetainPtr<AVAssetTrack> m_avAssetTrack;
RetainPtr<AVMutableAudioMix> m_avAudioMix;
RetainPtr<MTAudioProcessingTapRef> m_tap;
RetainPtr<AudioConverterRef> m_converter;
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm (182554 => 182555)
--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm 2015-04-08 18:06:58 UTC (rev 182554)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm 2015-04-08 18:12:56 UTC (rev 182555)
@@ -38,7 +38,6 @@
#import <AVFoundation/AVAudioMix.h>
#import <AVFoundation/AVMediaFormat.h>
#import <AVFoundation/AVPlayerItem.h>
-#import <AVFoundation/AVPlayerItemTrack.h>
#import <objc/runtime.h>
#import <wtf/MainThread.h>
@@ -151,10 +150,24 @@
m_avPlayerItem = avPlayerItem;
- if (m_client && m_avPlayerItem)
+ if (m_client && m_avPlayerItem && m_avAssetTrack)
createMix();
}
+void AudioSourceProviderAVFObjC::setAudioTrack(AVAssetTrack *avAssetTrack)
+{
+ if (m_avAssetTrack == avAssetTrack)
+ return;
+
+ if (m_avAudioMix)
+ destroyMix();
+
+ m_avAssetTrack = avAssetTrack;
+
+ if (m_client && m_avPlayerItem && m_avAssetTrack)
+ createMix();
+}
+
void AudioSourceProviderAVFObjC::destroyMix()
{
if (m_avPlayerItem)
@@ -190,15 +203,8 @@
RetainPtr<AVMutableAudioMixInputParameters> parameters = adoptNS([allocAVMutableAudioMixInputParametersInstance() init]);
[parameters setAudioTapProcessor:m_tap.get()];
- CMPersistentTrackID firstEnabledAudioTrackID = kCMPersistentTrackID_Invalid;
- NSArray* tracks = [m_avPlayerItem tracks];
- for (AVPlayerItemTrack* track in tracks) {
- if ([track.assetTrack hasMediaCharacteristic:AVMediaCharacteristicAudible] && track.enabled) {
- firstEnabledAudioTrackID = track.assetTrack.trackID;
- break;
- }
- }
- [parameters setTrackID:firstEnabledAudioTrackID];
+ CMPersistentTrackID trackID = m_avAssetTrack.get().trackID;
+ [parameters setTrackID:trackID];
[m_avAudioMix setInputParameters:@[parameters.get()]];
[m_avPlayerItem setAudioMix:m_avAudioMix.get()];
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (182554 => 182555)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2015-04-08 18:06:58 UTC (rev 182554)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2015-04-08 18:12:56 UTC (rev 182555)
@@ -349,6 +349,7 @@
static NSArray *itemKVOProperties();
static NSArray *assetTrackMetadataKeyNames();
static NSArray *playerKVOProperties();
+static AVAssetTrack* firstEnabledTrack(NSArray* tracks);
#if !LOG_DISABLED
static const char *boolString(bool val)
@@ -566,8 +567,10 @@
m_cachedTracks = nullptr;
#if ENABLE(WEB_AUDIO) && USE(MEDIATOOLBOX)
- if (m_provider)
+ if (m_provider) {
m_provider->setPlayerItem(nullptr);
+ m_provider->setAudioTrack(nullptr);
+ }
#endif
setIgnoreLoadStateChanges(false);
@@ -998,8 +1001,10 @@
#endif
#if ENABLE(WEB_AUDIO) && USE(MEDIATOOLBOX)
- if (m_provider)
+ if (m_provider) {
m_provider->setPlayerItem(m_avPlayerItem.get());
+ m_provider->setAudioTrack(firstEnabledTrack([m_avAsset tracksWithMediaCharacteristic:AVMediaCharacteristicAudible]));
+ }
#endif
setDelayCallbacks(false);
@@ -1917,6 +1922,11 @@
if (primaryAudioTrackLanguage != languageOfPrimaryAudioTrack())
characteristicsChanged();
+#if ENABLE(WEB_AUDIO) && USE(MEDIATOOLBOX)
+ if (m_provider)
+ m_provider->setAudioTrack(firstEnabledTrack([m_avAsset tracksWithMediaCharacteristic:AVMediaCharacteristicAudible]));
+#endif
+
setDelayCharacteristicsChangedNotification(false);
}
@@ -2127,8 +2137,11 @@
#if ENABLE(WEB_AUDIO) && USE(MEDIATOOLBOX)
AudioSourceProvider* MediaPlayerPrivateAVFoundationObjC::audioSourceProvider()
{
- if (!m_provider)
+ if (!m_provider) {
m_provider = AudioSourceProviderAVFObjC::create(m_avPlayerItem.get());
+ m_provider->setAudioTrack(firstEnabledTrack([m_avAsset tracksWithMediaCharacteristic:AVMediaCharacteristicAudible]));
+ }
+
return m_provider.get();
}
#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes