Cloning a MediaStreamTrack does not clone the logger
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jun 2019 17:14:47 +0000 (17:14 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jun 2019 17:14:47 +0000 (17:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198844

Reviewed by Eric Carlson.

Source/WebCore:

Make MediaStream and MediaStreamTrack rely on their private versions for logging.
Move from a RefPtr version to a Ref so as to forbid nullptr crashes.
Make sure that RealtimeIncomingAudioSource and RealtimeIncomingVideoSource check for their logger before logging.
Covered by existing tests and updated test.

* Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:
(WebCore::loggerFromContext):
(WebCore::CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack):
* Modules/mediastream/MediaStream.cpp:
(WebCore::loggerFromContext):
(WebCore::MediaStream::create):
(WebCore::MediaStream::MediaStream):
* Modules/mediastream/MediaStream.h:
* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::MediaStreamTrack):
* Modules/mediastream/MediaStreamTrack.h:
* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::allow):
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::mediaStreamFromRTCStream):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::createReceiverForSource):
* Modules/webaudio/MediaStreamAudioDestinationNode.cpp:
(WebCore::MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode):
* platform/mediastream/MediaStreamPrivate.cpp:
(WebCore::MediaStreamPrivate::create):
(WebCore::MediaStreamPrivate::MediaStreamPrivate):
(WebCore::MediaStreamPrivate::setLogger): Deleted.
* platform/mediastream/MediaStreamPrivate.h:
* platform/mediastream/MediaStreamTrackPrivate.cpp:
(WebCore::MediaStreamTrackPrivate::create):
(WebCore::MediaStreamTrackPrivate::MediaStreamTrackPrivate):
(WebCore::MediaStreamTrackPrivate::clone):
(WebCore::MediaStreamTrackPrivate::setLogger): Deleted.
* platform/mediastream/MediaStreamTrackPrivate.h:
* platform/mediastream/RealtimeMediaSourceCenter.cpp:
(WebCore::RealtimeMediaSourceCenter::createMediaStream):
* platform/mediastream/RealtimeMediaSourceCenter.h:
* platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp:
(WebCore::RealtimeIncomingAudioSourceCocoa::OnData):
* platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
(WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferPool):
(WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferFromVideoFrame):
(WebCore::RealtimeIncomingVideoSourceCocoa::OnFrame):

LayoutTests:

* fast/mediastream/MediaStreamTrack-clone-expected.txt:
* fast/mediastream/MediaStreamTrack-clone.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246436 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/MediaStreamTrack-clone-expected.txt
LayoutTests/fast/mediastream/MediaStreamTrack-clone.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/Modules/mediastream/MediaStream.h
Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrack.h
Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp
Source/WebCore/Modules/webaudio/MediaStreamAudioDestinationNode.cpp
Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp
Source/WebCore/platform/mediastream/MediaStreamPrivate.h
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm

index 82ef0a4..dd38ee0 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-14  Youenn Fablet  <youenn@apple.com>
+
+        Cloning a MediaStreamTrack does not clone the logger
+        https://bugs.webkit.org/show_bug.cgi?id=198844
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/MediaStreamTrack-clone-expected.txt:
+        * fast/mediastream/MediaStreamTrack-clone.html:
+
 2019-06-14  Shawn Roberts  <sroberts@apple.com>
 
         webgpu/compute-squares.html test was deleted in https://trac.webkit.org/changeset/246427
index 9ef68de..7102c65 100644 (file)
@@ -20,6 +20,7 @@ PASS videoTrack.onunmute is not videoTrack2.onunmute
 PASS videoTrack.onended is not videoTrack2.onended
 PASS videoTrack.onoverconstrained is not videoTrack2.onoverconstrained
 PASS videoTrack.readyState is not videoTrack2.readyState
+PASS videoTrack.readyState is videoTrack3.readyState
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 17c6f1d..63e8775 100644 (file)
@@ -7,6 +7,7 @@
             var mediaStream;
             var videoTrack;
             var videoTrack2;
+            var videoTrack3;
             var audioTrack;
 
             function gotStream(stream) {
@@ -40,6 +41,9 @@
                 videoTrack.stop();
                 shouldNotBe('videoTrack.readyState', 'videoTrack2.readyState');
 
+                videoTrack3 = videoTrack.clone();
+                shouldBe('videoTrack.readyState', 'videoTrack3.readyState');
+
                 finishJSTest();
             }
 
index c8f594e..cc383b4 100644 (file)
@@ -1,3 +1,55 @@
+2019-06-14  Youenn Fablet  <youenn@apple.com>
+
+        Cloning a MediaStreamTrack does not clone the logger
+        https://bugs.webkit.org/show_bug.cgi?id=198844
+
+        Reviewed by Eric Carlson.
+
+        Make MediaStream and MediaStreamTrack rely on their private versions for logging.
+        Move from a RefPtr version to a Ref so as to forbid nullptr crashes.
+        Make sure that RealtimeIncomingAudioSource and RealtimeIncomingVideoSource check for their logger before logging.
+        Covered by existing tests and updated test.
+
+        * Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:
+        (WebCore::loggerFromContext):
+        (WebCore::CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack):
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::loggerFromContext):
+        (WebCore::MediaStream::create):
+        (WebCore::MediaStream::MediaStream):
+        * Modules/mediastream/MediaStream.h:
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        (WebCore::MediaStreamTrack::MediaStreamTrack):
+        * Modules/mediastream/MediaStreamTrack.h:
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::allow):
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCMediaEndpoint::mediaStreamFromRTCStream):
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::LibWebRTCPeerConnectionBackend::createReceiverForSource):
+        * Modules/webaudio/MediaStreamAudioDestinationNode.cpp:
+        (WebCore::MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode):
+        * platform/mediastream/MediaStreamPrivate.cpp:
+        (WebCore::MediaStreamPrivate::create):
+        (WebCore::MediaStreamPrivate::MediaStreamPrivate):
+        (WebCore::MediaStreamPrivate::setLogger): Deleted.
+        * platform/mediastream/MediaStreamPrivate.h:
+        * platform/mediastream/MediaStreamTrackPrivate.cpp:
+        (WebCore::MediaStreamTrackPrivate::create):
+        (WebCore::MediaStreamTrackPrivate::MediaStreamTrackPrivate):
+        (WebCore::MediaStreamTrackPrivate::clone):
+        (WebCore::MediaStreamTrackPrivate::setLogger): Deleted.
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+        * platform/mediastream/RealtimeMediaSourceCenter.cpp:
+        (WebCore::RealtimeMediaSourceCenter::createMediaStream):
+        * platform/mediastream/RealtimeMediaSourceCenter.h:
+        * platform/mediastream/mac/RealtimeIncomingAudioSourceCocoa.cpp:
+        (WebCore::RealtimeIncomingAudioSourceCocoa::OnData):
+        * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
+        (WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferPool):
+        (WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferFromVideoFrame):
+        (WebCore::RealtimeIncomingVideoSourceCocoa::OnFrame):
+
 2019-06-14  Ali Juma  <ajuma@chromium.org>
 
         IntersectionObserver rootMargin detection fails when `root` is an element
index 27a9a53..3b66aef 100644 (file)
@@ -42,8 +42,13 @@ Ref<CanvasCaptureMediaStreamTrack> CanvasCaptureMediaStreamTrack::create(ScriptE
     return adoptRef(*new CanvasCaptureMediaStreamTrack(context, WTFMove(canvas), WTFMove(source)));
 }
 
+static inline Ref<const Logger> loggerFromContext(ScriptExecutionContext& context)
+{
+    return downcast<Document>(context).logger();
+}
+
 CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack(ScriptExecutionContext& context, Ref<HTMLCanvasElement>&& canvas, Ref<CanvasCaptureMediaStreamTrack::Source>&& source)
-    : MediaStreamTrack(context, MediaStreamTrackPrivate::create(source.copyRef()))
+    : MediaStreamTrack(context, MediaStreamTrackPrivate::create(loggerFromContext(context), source.copyRef()))
     , m_canvas(WTFMove(canvas))
 {
 }
index 6f3965d..45d8050 100644 (file)
@@ -48,9 +48,14 @@ namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(MediaStream);
 
+static inline Ref<const Logger> loggerFromContext(ScriptExecutionContext& context)
+{
+    return downcast<Document>(context).logger();
+}
+
 Ref<MediaStream> MediaStream::create(ScriptExecutionContext& context)
 {
-    return MediaStream::create(context, MediaStreamPrivate::create({ }));
+    return MediaStream::create(context, MediaStreamPrivate::create(loggerFromContext(context), { }));
 }
 
 Ref<MediaStream> MediaStream::create(ScriptExecutionContext& context, MediaStream& stream)
@@ -79,21 +84,12 @@ static inline MediaStreamTrackPrivateVector createTrackPrivateVector(const Media
 
 MediaStream::MediaStream(ScriptExecutionContext& context, const MediaStreamTrackVector& tracks)
     : ActiveDOMObject(&context)
-    , m_private(MediaStreamPrivate::create(createTrackPrivateVector(tracks)))
+    , m_private(MediaStreamPrivate::create(document()->logger(), createTrackPrivateVector(tracks)))
     , m_mediaSession(PlatformMediaSession::create(*this))
-#if !RELEASE_LOG_DISABLED
-    , m_logger(document()->logger())
-    , m_logIdentifier(uniqueLogIdentifier())
-#endif
 {
     // This constructor preserves MediaStreamTrack instances and must be used by calls originating
     // from the JavaScript MediaStream constructor.
 
-#if !RELEASE_LOG_DISABLED
-    ALWAYS_LOG(LOGIDENTIFIER);
-    m_private->setLogger(logger(), logIdentifier());
-#endif
-
     for (auto& track : tracks) {
         track->addObserver(*this);
         m_trackSet.add(track->id(), track);
@@ -109,15 +105,9 @@ MediaStream::MediaStream(ScriptExecutionContext& context, Ref<MediaStreamPrivate
     : ActiveDOMObject(&context)
     , m_private(WTFMove(streamPrivate))
     , m_mediaSession(PlatformMediaSession::create(*this))
-#if !RELEASE_LOG_DISABLED
-    , m_logger(document()->logger())
-    , m_logIdentifier(uniqueLogIdentifier())
-#endif
 {
-#if !RELEASE_LOG_DISABLED
     ALWAYS_LOG(LOGIDENTIFIER);
-    m_private->setLogger(logger(), logIdentifier());
-#endif
+
     setIsActive(m_private->active());
     m_private->addObserver(*this);
     MediaStreamRegistry::shared().registerStream(*this);
index ffd1c82..5db3bd7 100644 (file)
@@ -125,8 +125,8 @@ protected:
     MediaStream(ScriptExecutionContext&, Ref<MediaStreamPrivate>&&);
 
 #if !RELEASE_LOG_DISABLED
-    const Logger& logger() const final { return m_logger.get(); }
-    const void* logIdentifier() const final { return m_logIdentifier; }
+    const Logger& logger() const final { return m_private->logger(); }
+    const void* logIdentifier() const final { return m_private->logIdentifier(); }
     WTFLogChannel& logChannel() const final;
     const char* logClassName() const final { return "MediaStream"; }
 #endif
@@ -187,11 +187,6 @@ private:
 
     MediaProducer::MediaStateFlags m_state { MediaProducer::IsNotPlaying };
 
-#if !RELEASE_LOG_DISABLED
-    Ref<Logger> m_logger;
-    const void* m_logIdentifier;
-#endif
-
     bool m_isActive { false };
     bool m_isProducingData { false };
     bool m_isWaitingUntilMediaCanStart { false };
index 9bc3cbf..e7a090f 100644 (file)
@@ -58,19 +58,12 @@ Ref<MediaStreamTrack> MediaStreamTrack::create(ScriptExecutionContext& context,
 MediaStreamTrack::MediaStreamTrack(ScriptExecutionContext& context, Ref<MediaStreamTrackPrivate>&& privateTrack)
     : ActiveDOMObject(&context)
     , m_private(WTFMove(privateTrack))
-#if !RELEASE_LOG_DISABLED
-    , m_logger(document()->logger())
-    , m_logIdentifier(uniqueLogIdentifier())
-#endif
     , m_taskQueue(context)
     , m_isCaptureTrack(m_private->isCaptureTrack())
 {
     ALWAYS_LOG(LOGIDENTIFIER);
     suspendIfNeeded();
 
-#if !RELEASE_LOG_DISABLED
-    m_private->setLogger(logger(), logIdentifier());
-#endif
     m_private->addObserver(*this);
 
     if (auto document = this->document()) {
index 155c723..02f1e79 100644 (file)
@@ -151,8 +151,8 @@ public:
     void setIdForTesting(String&& id) { m_private->setIdForTesting(WTFMove(id)); }
 
 #if !RELEASE_LOG_DISABLED
-    const Logger& logger() const final { return m_logger.get(); }
-    const void* logIdentifier() const final { return m_logIdentifier; }
+    const Logger& logger() const final { return m_private->logger(); }
+    const void* logIdentifier() const final { return m_private->logIdentifier(); }
 #endif
 
 protected:
@@ -189,9 +189,6 @@ private:
 #if !RELEASE_LOG_DISABLED
     const char* logClassName() const final { return "MediaStreamTrack"; }
     WTFLogChannel& logChannel() const final;
-    
-    Ref<const Logger> m_logger;
-    const void* m_logIdentifier;
 #endif
 
     Vector<Observer*> m_observers;
index f061bc7..8e136c0 100644 (file)
@@ -246,7 +246,7 @@ void UserMediaRequest::allow(CaptureDevice&& audioDevice, CaptureDevice&& videoD
     auto& document = downcast<Document>(*scriptExecutionContext());
     document.setDeviceIDHashSalt(deviceIdentifierHashSalt);
 
-    RealtimeMediaSourceCenter::singleton().createMediaStream(WTFMove(callback), WTFMove(deviceIdentifierHashSalt), WTFMove(audioDevice), WTFMove(videoDevice), m_request);
+    RealtimeMediaSourceCenter::singleton().createMediaStream(document.logger(), WTFMove(callback), WTFMove(deviceIdentifierHashSalt), WTFMove(audioDevice), WTFMove(videoDevice), m_request);
 
     if (!m_scriptExecutionContext)
         return;
index c7749db..45bf4a9 100644 (file)
@@ -354,7 +354,8 @@ MediaStream& LibWebRTCMediaEndpoint::mediaStreamFromRTCStream(webrtc::MediaStrea
 {
     auto label = fromStdString(rtcStream.id());
     auto mediaStream = m_remoteStreamsById.ensure(label, [label, this]() mutable {
-        return MediaStream::create(*m_peerConnectionBackend.connection().scriptExecutionContext(), MediaStreamPrivate::create({ }, WTFMove(label)));
+        auto& document = downcast<Document>(*m_peerConnectionBackend.connection().scriptExecutionContext());
+        return MediaStream::create(document, MediaStreamPrivate::create(document.logger(), { }, WTFMove(label)));
     });
     return *mediaStream.iterator->value;
 }
index c44e1bc..851fdde 100644 (file)
@@ -269,9 +269,10 @@ void LibWebRTCPeerConnectionBackend::doAddIceCandidate(RTCIceCandidate& candidat
 
 Ref<RTCRtpReceiver> LibWebRTCPeerConnectionBackend::createReceiverForSource(Ref<RealtimeMediaSource>&& source, std::unique_ptr<RTCRtpReceiverBackend>&& backend)
 {
-    String trackID = source->persistentID();
-    auto remoteTrackPrivate = MediaStreamTrackPrivate::create(WTFMove(source), WTFMove(trackID));
-    auto remoteTrack = MediaStreamTrack::create(*m_peerConnection.scriptExecutionContext(), WTFMove(remoteTrackPrivate));
+    auto& document = downcast<Document>(*m_peerConnection.scriptExecutionContext());
+    auto trackID = source->persistentID();
+    auto remoteTrackPrivate = MediaStreamTrackPrivate::create(document.logger(), WTFMove(source), WTFMove(trackID));
+    auto remoteTrack = MediaStreamTrack::create(document, WTFMove(remoteTrackPrivate));
 
     return RTCRtpReceiver::create(*this, WTFMove(remoteTrack), WTFMove(backend));
 }
index c0bb38e..d766293 100644 (file)
@@ -47,7 +47,7 @@ Ref<MediaStreamAudioDestinationNode> MediaStreamAudioDestinationNode::create(Aud
 MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext& context, size_t numberOfChannels)
     : AudioBasicInspectorNode(context, context.sampleRate(), numberOfChannels)
     , m_source(MediaStreamAudioSource::create(context.sampleRate()))
-    , m_stream(MediaStream::create(*context.document(), MediaStreamPrivate::create(m_source.copyRef())))
+    , m_stream(MediaStream::create(*context.document(), MediaStreamPrivate::create(context.document()->logger(), m_source.copyRef())))
 {
     setNodeType(NodeTypeMediaStreamAudioDestination);
     initialize();
index c956f11..ff5abaa 100644 (file)
 
 namespace WebCore {
 
-Ref<MediaStreamPrivate> MediaStreamPrivate::create(Ref<RealtimeMediaSource>&& source)
+Ref<MediaStreamPrivate> MediaStreamPrivate::create(Ref<const Logger>&& logger, Ref<RealtimeMediaSource>&& source)
 {
-    return MediaStreamPrivate::create(MediaStreamTrackPrivateVector::from(MediaStreamTrackPrivate::create(WTFMove(source))));
+    auto loggerCopy = logger.copyRef();
+    return MediaStreamPrivate::create(WTFMove(logger), MediaStreamTrackPrivateVector::from(MediaStreamTrackPrivate::create(WTFMove(loggerCopy), WTFMove(source))));
 }
 
-Ref<MediaStreamPrivate> MediaStreamPrivate::create(const Vector<Ref<RealtimeMediaSource>>& audioSources, const Vector<Ref<RealtimeMediaSource>>& videoSources)
+Ref<MediaStreamPrivate> MediaStreamPrivate::create(Ref<const Logger>&& logger, const Vector<Ref<RealtimeMediaSource>>& audioSources, const Vector<Ref<RealtimeMediaSource>>& videoSources)
 {
     MediaStreamTrackPrivateVector tracks;
     tracks.reserveInitialCapacity(audioSources.size() + videoSources.size());
 
     for (auto& source : audioSources)
-        tracks.uncheckedAppend(MediaStreamTrackPrivate::create(source.copyRef()));
+        tracks.uncheckedAppend(MediaStreamTrackPrivate::create(logger.copyRef(), source.copyRef()));
 
     for (auto& source : videoSources)
-        tracks.uncheckedAppend(MediaStreamTrackPrivate::create(source.copyRef()));
+        tracks.uncheckedAppend(MediaStreamTrackPrivate::create(logger.copyRef(), source.copyRef()));
 
-    return MediaStreamPrivate::create(tracks);
+    return MediaStreamPrivate::create(WTFMove(logger), tracks);
 }
 
-MediaStreamPrivate::MediaStreamPrivate(const MediaStreamTrackPrivateVector& tracks, String&& id)
+MediaStreamPrivate::MediaStreamPrivate(Ref<const Logger>&& logger, const MediaStreamTrackPrivateVector& tracks, String&& id)
     : m_id(WTFMove(id))
+#if !RELEASE_LOG_DISABLED
+    , m_logger(WTFMove(logger))
+    , m_logIdentifier(uniqueLogIdentifier())
+#endif
 {
+    UNUSED_PARAM(logger);
     ASSERT(!m_id.isEmpty());
 
     for (auto& track : tracks) {
@@ -345,13 +351,6 @@ void MediaStreamPrivate::monitorOrientation(OrientationNotifier& notifier)
 }
 
 #if !RELEASE_LOG_DISABLED
-void MediaStreamPrivate::setLogger(const Logger& newLogger, const void* newLogIdentifier)
-{
-    m_logger = &newLogger;
-    m_logIdentifier = newLogIdentifier;
-    ALWAYS_LOG(LOGIDENTIFIER);
-}
-
 WTFLogChannel& MediaStreamPrivate::logChannel() const
 {
     return LogWebRTC;
index 76b4679..9696de2 100644 (file)
@@ -73,9 +73,9 @@ public:
         virtual void didRemoveTrack(MediaStreamTrackPrivate&) { }
     };
 
-    static Ref<MediaStreamPrivate> create(Ref<RealtimeMediaSource>&&);
-    static Ref<MediaStreamPrivate> create(const Vector<Ref<RealtimeMediaSource>>& audioSources, const Vector<Ref<RealtimeMediaSource>>& videoSources);
-    static Ref<MediaStreamPrivate> create(const MediaStreamTrackPrivateVector& tracks, String&& id = createCanonicalUUIDString()) { return adoptRef(*new MediaStreamPrivate(tracks, WTFMove(id))); }
+    static Ref<MediaStreamPrivate> create(Ref<const Logger>&&, Ref<RealtimeMediaSource>&&);
+    static Ref<MediaStreamPrivate> create(Ref<const Logger>&&, const Vector<Ref<RealtimeMediaSource>>& audioSources, const Vector<Ref<RealtimeMediaSource>>& videoSources);
+    static Ref<MediaStreamPrivate> create(Ref<const Logger>&& logger, const MediaStreamTrackPrivateVector& tracks, String&& id = createCanonicalUUIDString()) { return adoptRef(*new MediaStreamPrivate(WTFMove(logger), tracks, WTFMove(id))); }
 
     virtual ~MediaStreamPrivate();
 
@@ -111,11 +111,12 @@ public:
     void monitorOrientation(OrientationNotifier&);
 
 #if !RELEASE_LOG_DISABLED
-    void setLogger(const Logger&, const void*);
+    const Logger& logger() const final { return m_logger; }
+    const void* logIdentifier() const final { return m_logIdentifier; }
 #endif
 
 private:
-    MediaStreamPrivate(const MediaStreamTrackPrivateVector&, String&&);
+    MediaStreamPrivate(Ref<const Logger>&&, const MediaStreamTrackPrivateVector&, String&&);
 
     // MediaStreamTrackPrivate::Observer
     void trackStarted(MediaStreamTrackPrivate&) override;
@@ -131,13 +132,8 @@ private:
     void forEachObserver(const WTF::Function<void(Observer&)>&) const;
 
 #if !RELEASE_LOG_DISABLED
-    const Logger& logger() const final { ASSERT(m_logger); return *m_logger.get(); }
-    const void* logIdentifier() const final { return m_logIdentifier; }
     const char* logClassName() const final { return "MediaStreamPrivate"; }
     WTFLogChannel& logChannel() const final;
-
-    RefPtr<const Logger> m_logger;
-    const void* m_logIdentifier;
 #endif
 
     HashSet<Observer*> m_observers;
@@ -145,6 +141,10 @@ private:
     MediaStreamTrackPrivate* m_activeVideoTrack { nullptr };
     HashMap<String, RefPtr<MediaStreamTrackPrivate>> m_trackSet;
     bool m_isActive { false };
+#if !RELEASE_LOG_DISABLED
+    Ref<const Logger> m_logger;
+    const void* m_logIdentifier;
+#endif
 };
 
 typedef Vector<RefPtr<MediaStreamPrivate>> MediaStreamPrivateVector;
index 4943da3..3c330b9 100644 (file)
 
 namespace WebCore {
 
-Ref<MediaStreamTrackPrivate> MediaStreamTrackPrivate::create(Ref<RealtimeMediaSource>&& source)
+Ref<MediaStreamTrackPrivate> MediaStreamTrackPrivate::create(Ref<const Logger>&& logger, Ref<RealtimeMediaSource>&& source)
 {
-    return create(WTFMove(source), createCanonicalUUIDString());
+    return create(WTFMove(logger), WTFMove(source), createCanonicalUUIDString());
 }
 
-Ref<MediaStreamTrackPrivate> MediaStreamTrackPrivate::create(Ref<RealtimeMediaSource>&& source, String&& id)
+Ref<MediaStreamTrackPrivate> MediaStreamTrackPrivate::create(Ref<const Logger>&& logger, Ref<RealtimeMediaSource>&& source, String&& id)
 {
-    return adoptRef(*new MediaStreamTrackPrivate(WTFMove(source), WTFMove(id)));
+    return adoptRef(*new MediaStreamTrackPrivate(WTFMove(logger), WTFMove(source), WTFMove(id)));
 }
 
-MediaStreamTrackPrivate::MediaStreamTrackPrivate(Ref<RealtimeMediaSource>&& source, String&& id)
+MediaStreamTrackPrivate::MediaStreamTrackPrivate(Ref<const Logger>&& logger, Ref<RealtimeMediaSource>&& source, String&& id)
     : m_source(WTFMove(source))
     , m_id(WTFMove(id))
+    , m_logger(WTFMove(logger))
+#if !RELEASE_LOG_DISABLED
+    , m_logIdentifier(uniqueLogIdentifier())
+#endif
 {
+    UNUSED_PARAM(logger);
+#if !RELEASE_LOG_DISABLED
+    m_source->setLogger(m_logger.copyRef(), m_logIdentifier);
+#endif
     m_source->addObserver(*this);
 }
 
@@ -147,7 +155,8 @@ void MediaStreamTrackPrivate::endTrack()
 
 Ref<MediaStreamTrackPrivate> MediaStreamTrackPrivate::clone()
 {
-    auto clonedMediaStreamTrackPrivate = create(m_source.copyRef());
+    auto clonedMediaStreamTrackPrivate = create(m_logger.copyRef(), m_source.copyRef());
+
     clonedMediaStreamTrackPrivate->m_isEnabled = this->m_isEnabled;
     clonedMediaStreamTrackPrivate->m_isEnded = this->m_isEnded;
     clonedMediaStreamTrackPrivate->m_contentHint = this->m_contentHint;
@@ -279,14 +288,6 @@ void MediaStreamTrackPrivate::updateReadyState()
 }
 
 #if !RELEASE_LOG_DISABLED
-void MediaStreamTrackPrivate::setLogger(const Logger& newLogger, const void* newLogIdentifier)
-{
-    m_logger = &newLogger;
-    m_logIdentifier = newLogIdentifier;
-    ALWAYS_LOG(LOGIDENTIFIER);
-    m_source->setLogger(newLogger, newLogIdentifier);
-}
-
 WTFLogChannel& MediaStreamTrackPrivate::logChannel() const
 {
     return LogWebRTC;
index 5967d45..efa673c 100644 (file)
@@ -64,8 +64,8 @@ public:
         virtual void audioSamplesAvailable(MediaStreamTrackPrivate&, const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) { };
     };
 
-    static Ref<MediaStreamTrackPrivate> create(Ref<RealtimeMediaSource>&&);
-    static Ref<MediaStreamTrackPrivate> create(Ref<RealtimeMediaSource>&&, String&& id);
+    static Ref<MediaStreamTrackPrivate> create(Ref<const Logger>&&, Ref<RealtimeMediaSource>&&);
+    static Ref<MediaStreamTrackPrivate> create(Ref<const Logger>&&, Ref<RealtimeMediaSource>&&, String&& id);
 
     virtual ~MediaStreamTrackPrivate();
 
@@ -117,13 +117,12 @@ public:
     void setIdForTesting(String&& id) { m_id = WTFMove(id); }
 
 #if !RELEASE_LOG_DISABLED
-    void setLogger(const Logger&, const void*);
-    const Logger& logger() const final { ASSERT(m_logger); return *m_logger.get(); }
+    const Logger& logger() const final { return m_logger; }
     const void* logIdentifier() const final { return m_logIdentifier; }
 #endif
-    
+
 private:
-    MediaStreamTrackPrivate(Ref<RealtimeMediaSource>&&, String&& id);
+    MediaStreamTrackPrivate(Ref<const Logger>&&, Ref<RealtimeMediaSource>&&, String&& id);
 
     // RealtimeMediaSourceObserver
     void sourceStarted() final;
@@ -141,9 +140,6 @@ private:
 #if !RELEASE_LOG_DISABLED
     const char* logClassName() const final { return "MediaStreamTrackPrivate"; }
     WTFLogChannel& logChannel() const final;
-
-    RefPtr<const Logger> m_logger;
-    const void* m_logIdentifier;
 #endif
 
     mutable RecursiveLock m_observersLock;
@@ -157,6 +153,10 @@ private:
     bool m_haveProducedData { false };
     HintValue m_contentHint { HintValue::Empty };
     RefPtr<WebAudioSourceProvider> m_audioSourceProvider;
+    Ref<const Logger> m_logger;
+#if !RELEASE_LOG_DISABLED
+    const void* m_logIdentifier;
+#endif
 };
 
 typedef Vector<RefPtr<MediaStreamTrackPrivate>> MediaStreamTrackPrivateVector;
index b53f1f7..cc96cff 100644 (file)
@@ -63,7 +63,7 @@ RealtimeMediaSourceCenter::RealtimeMediaSourceCenter()
 
 RealtimeMediaSourceCenter::~RealtimeMediaSourceCenter() = default;
 
-void RealtimeMediaSourceCenter::createMediaStream(NewMediaStreamHandler&& completionHandler, String&& hashSalt, CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, const MediaStreamRequest& request)
+void RealtimeMediaSourceCenter::createMediaStream(Ref<const Logger>&& logger, NewMediaStreamHandler&& completionHandler, String&& hashSalt, CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, const MediaStreamRequest& request)
 {
     Vector<Ref<RealtimeMediaSource>> audioSources;
     Vector<Ref<RealtimeMediaSource>> videoSources;
@@ -102,7 +102,7 @@ void RealtimeMediaSourceCenter::createMediaStream(NewMediaStreamHandler&& comple
         }
     }
 
-    completionHandler(MediaStreamPrivate::create(audioSources, videoSources));
+    completionHandler(MediaStreamPrivate::create(WTFMove(logger), audioSources, videoSources));
 }
 
 Vector<CaptureDevice> RealtimeMediaSourceCenter::getMediaStreamDevices()
index 3738768..5d19ccb 100644 (file)
@@ -59,12 +59,12 @@ public:
 
     WEBCORE_EXPORT static RealtimeMediaSourceCenter& singleton();
 
-    using ValidConstraintsHandler = WTF::Function<void(Vector<CaptureDevice>&& audioDeviceUIDs, Vector<CaptureDevice>&& videoDeviceUIDs, String&&)>;
-    using InvalidConstraintsHandler = WTF::Function<void(const String& invalidConstraint)>;
+    using ValidConstraintsHandler = Function<void(Vector<CaptureDevice>&& audioDeviceUIDs, Vector<CaptureDevice>&& videoDeviceUIDs, String&&)>;
+    using InvalidConstraintsHandler = Function<void(const String& invalidConstraint)>;
     WEBCORE_EXPORT void validateRequestConstraints(ValidConstraintsHandler&&, InvalidConstraintsHandler&&, const MediaStreamRequest&, String&&);
 
-    using NewMediaStreamHandler = WTF::Function<void(RefPtr<MediaStreamPrivate>&&)>;
-    void createMediaStream(NewMediaStreamHandler&&, String&&, CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, const MediaStreamRequest&);
+    using NewMediaStreamHandler = Function<void(RefPtr<MediaStreamPrivate>&&)>;
+    void createMediaStream(Ref<const Logger>&&, NewMediaStreamHandler&&, String&&, CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, const MediaStreamRequest&);
 
     WEBCORE_EXPORT Vector<CaptureDevice> getMediaStreamDevices();
 
index 632ef0b..af15234 100644 (file)
@@ -88,7 +88,7 @@ void RealtimeIncomingAudioSourceCocoa::OnData(const void* audioData, int bitsPer
 
 #if !RELEASE_LOG_DISABLED
     if (!(++m_chunksReceived % 200))
-        ALWAYS_LOG(LOGIDENTIFIER, "chunk ", m_chunksReceived);
+        ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "chunk ", m_chunksReceived);
 #endif
 
     audioSamplesAvailable(mediaTime, audioBufferList, CAAudioStreamDescription(newDescription), numberOfFrames);
index fe5ebd6..e46d075 100644 (file)
@@ -113,7 +113,7 @@ CVPixelBufferPoolRef RealtimeIncomingVideoSourceCocoa::pixelBufferPool(size_t wi
         auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &pool);
 
         if (status != kCVReturnSuccess) {
-            ERROR_LOG(LOGIDENTIFIER, "Failed creating a pixel buffer pool with error ", status);
+            ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "Failed creating a pixel buffer pool with error ", status);
             return nullptr;
         }
         m_pixelBufferPool = adoptCF(pool);
@@ -144,7 +144,7 @@ RetainPtr<CVPixelBufferRef> RealtimeIncomingVideoSourceCocoa::pixelBufferFromVid
         auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_pixelBufferPool.get(), &pixelBuffer);
 
         if (status != kCVReturnSuccess) {
-            ERROR_LOG(LOGIDENTIFIER, "Failed creating a pixel buffer with error ", status);
+            ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "Failed creating a pixel buffer with error ", status);
             return nullptr;
         }
         newPixelBuffer = adoptCF(pixelBuffer);
@@ -159,12 +159,12 @@ void RealtimeIncomingVideoSourceCocoa::OnFrame(const webrtc::VideoFrame& frame)
 
 #if !RELEASE_LOG_DISABLED
     if (!(++m_numberOfFrames % 60))
-        ALWAYS_LOG(LOGIDENTIFIER, "frame ", m_numberOfFrames);
+        ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "frame ", m_numberOfFrames);
 #endif
 
     auto pixelBuffer = pixelBufferFromVideoFrame(frame);
     if (!pixelBuffer) {
-        ERROR_LOG(LOGIDENTIFIER, "Failed to get a pixel buffer from a frame");
+        ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "Failed to get a pixel buffer from a frame");
         return;
     }
 
@@ -178,7 +178,7 @@ void RealtimeIncomingVideoSourceCocoa::OnFrame(const webrtc::VideoFrame& frame)
     CMVideoFormatDescriptionRef formatDescription;
     OSStatus ostatus = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, &formatDescription);
     if (ostatus != noErr) {
-        ERROR_LOG(LOGIDENTIFIER, "Failed to initialize CMVideoFormatDescription with error ", static_cast<int>(ostatus));
+        ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "Failed to initialize CMVideoFormatDescription with error ", static_cast<int>(ostatus));
         return;
     }
 
@@ -186,7 +186,7 @@ void RealtimeIncomingVideoSourceCocoa::OnFrame(const webrtc::VideoFrame& frame)
     ostatus = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, formatDescription, &timingInfo, &sampleBuffer);
     CFRelease(formatDescription);
     if (ostatus != noErr) {
-        ERROR_LOG(LOGIDENTIFIER, "Failed to create the sample buffer with error ", static_cast<int>(ostatus));
+        ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "Failed to create the sample buffer with error ", static_cast<int>(ostatus));
         return;
     }