⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 271270 in webkit


Ignore:
Timestamp:
Jan 7, 2021, 4:18:32 PM (6 years ago)
Author:
eric.carlson@apple.com
Message:

[Mac] Add runtime logging to format reader and WebM parser
https://bugs.webkit.org/show_bug.cgi?id=220423
<rdar://problem/72896655>

Reviewed by Andy Estes.

Source/WebCore:

Add a shared Logger to Document that can be used by singletons or objects that don't
have access to a Document. To ensure that the shared logger doesn't log activity
from a private session, it is disabled if *any* Document in the process doesn't
allow logging.

  • WebCore.xcodeproj/project.pbxproj:
  • dom/Document.cpp:

(WebCore::sharedLoggerOwner):
(WebCore::staticSharedLogger):
(WebCore::Document::sharedLogger):
(WebCore::Document::configureSharedLogger):
(WebCore::Document::addToDocumentsMap):
(WebCore::Document::removeFromDocumentsMap):
(WebCore::m_selection):
(WebCore::Document::~Document):

  • dom/Document.h:
  • platform/graphics/cocoa/SourceBufferParserWebM.cpp:

(WTF::LogArgument<webm::TrackType>::toString):
(WebCore::logChannel):
(WebCore::logClassName):
(WebCore::SourceBufferParserWebM::appendData):
(WebCore::SourceBufferParserWebM::setLogger):
(WebCore::SourceBufferParserWebM::OnElementBegin):
(WebCore::SourceBufferParserWebM::OnElementEnd):
(WebCore::SourceBufferParserWebM::OnEbml):
(WebCore::SourceBufferParserWebM::OnSegmentBegin):
(WebCore::SourceBufferParserWebM::OnInfo):
(WebCore::SourceBufferParserWebM::OnClusterBegin):
(WebCore::SourceBufferParserWebM::OnTrackEntry):
(WebCore::SourceBufferParserWebM::OnBlockBegin):
(WebCore::SourceBufferParserWebM::OnBlockEnd):
(WebCore::SourceBufferParserWebM::OnSimpleBlockBegin):
(WebCore::SourceBufferParserWebM::OnSimpleBlockEnd):
(WebCore::SourceBufferParserWebM::OnBlockGroupBegin):
(WebCore::SourceBufferParserWebM::OnBlockGroupEnd):
(WebCore::SourceBufferParserWebM::OnFrame):

  • platform/graphics/cocoa/SourceBufferParserWebM.h:

Source/WebKit:

Use the Document::sharedLogger to log format and track reader state changes
and errors.

  • Shared/mac/MediaFormatReader/MediaFormatReader.cpp:

(WebKit::nextLogIdentifier):
(WebKit::logChannel):
(WebKit::logClassName):
(WebKit::MediaFormatReader::parseByteSource):
(WebKit::MediaFormatReader::didParseTracks):
(WebKit::MediaFormatReader::copyProperty):
(WebKit::MediaFormatReader::nextTrackReaderLogIdentifier const):

  • Shared/mac/MediaFormatReader/MediaFormatReader.h:
  • Shared/mac/MediaFormatReader/WebKit::MediaTrackReader.cpp:

(WebKit::MediaTrackReader::MediaTrackReader):
(WebKit::MediaTrackReader::finishParsing):
(WebKit::MediaTrackReader::mediaTypeString const):
(WebKit::MediaTrackReader::copyProperty):
(WebKit::MediaTrackReader::finalize):
(WebKit::MediaTrackReader::logChannel const):

  • Shared/mac/MediaFormatReader/WebKit::MediaTrackReader.h:
Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r271269 r271270  
     12021-01-07  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Mac] Add runtime logging to format reader and WebM parser
     4        https://bugs.webkit.org/show_bug.cgi?id=220423
     5        <rdar://problem/72896655>
     6
     7        Reviewed by Andy Estes.
     8
     9        Add a shared Logger to Document that can be used by singletons or objects that don't
     10        have access to a Document. To ensure that the shared logger doesn't log activity
     11        from a private session, it is disabled if *any* Document in the process doesn't
     12        allow logging.
     13
     14        * WebCore.xcodeproj/project.pbxproj:
     15        * dom/Document.cpp:
     16        (WebCore::sharedLoggerOwner):
     17        (WebCore::staticSharedLogger):
     18        (WebCore::Document::sharedLogger):
     19        (WebCore::Document::configureSharedLogger):
     20        (WebCore::Document::addToDocumentsMap):
     21        (WebCore::Document::removeFromDocumentsMap):
     22        (WebCore::m_selection):
     23        (WebCore::Document::~Document):
     24        * dom/Document.h:
     25        * platform/graphics/cocoa/SourceBufferParserWebM.cpp:
     26        (WTF::LogArgument<webm::TrackType>::toString):
     27        (WebCore::logChannel):
     28        (WebCore::logClassName):
     29        (WebCore::SourceBufferParserWebM::appendData):
     30        (WebCore::SourceBufferParserWebM::setLogger):
     31        (WebCore::SourceBufferParserWebM::OnElementBegin):
     32        (WebCore::SourceBufferParserWebM::OnElementEnd):
     33        (WebCore::SourceBufferParserWebM::OnEbml):
     34        (WebCore::SourceBufferParserWebM::OnSegmentBegin):
     35        (WebCore::SourceBufferParserWebM::OnInfo):
     36        (WebCore::SourceBufferParserWebM::OnClusterBegin):
     37        (WebCore::SourceBufferParserWebM::OnTrackEntry):
     38        (WebCore::SourceBufferParserWebM::OnBlockBegin):
     39        (WebCore::SourceBufferParserWebM::OnBlockEnd):
     40        (WebCore::SourceBufferParserWebM::OnSimpleBlockBegin):
     41        (WebCore::SourceBufferParserWebM::OnSimpleBlockEnd):
     42        (WebCore::SourceBufferParserWebM::OnBlockGroupBegin):
     43        (WebCore::SourceBufferParserWebM::OnBlockGroupEnd):
     44        (WebCore::SourceBufferParserWebM::OnFrame):
     45        * platform/graphics/cocoa/SourceBufferParserWebM.h:
     46
    1472021-01-07  Alexey Shvayka  <shvaikalesh@gmail.com>
    248
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r271188 r271270  
    34283428                A81872200977D3C0005826D9 /* ChildNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = A81872150977D3C0005826D9 /* ChildNodeList.h */; };
    34293429                A81872230977D3C0005826D9 /* NamedNodeMap.h in Headers */ = {isa = PBXBuildFile; fileRef = A81872180977D3C0005826D9 /* NamedNodeMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
    3430                 A8239E0109B3CF8A00B60641 /* Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = A8239DFF09B3CF8A00B60641 /* Logging.h */; };
     3430                A8239E0109B3CF8A00B60641 /* Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = A8239DFF09B3CF8A00B60641 /* Logging.h */; settings = {ATTRIBUTES = (Private, ); }; };
    34313431                A824B4650E2EF2EA0081A7B7 /* TextRun.h in Headers */ = {isa = PBXBuildFile; fileRef = A824B4640E2EF2EA0081A7B7 /* TextRun.h */; settings = {ATTRIBUTES = (Private, ); }; };
    34323432                A833C7CA0A2CF06B00D57664 /* SVGNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 656581E809D1508D000E61D7 /* SVGNames.cpp */; };
  • trunk/Source/WebCore/dom/Document.cpp

    r271146 r271270  
    516516uint64_t Document::s_globalTreeVersion = 0;
    517517
     518static const void* sharedLoggerOwner()
     519{
     520    static uint64_t owner = cryptographicallyRandomNumber();
     521    return reinterpret_cast<const void*>(owner);
     522}
     523
     524static Logger*& staticSharedLogger()
     525{
     526    static Logger* logger;
     527    return logger;
     528}
     529
     530const Logger& Document::sharedLogger()
     531{
     532    if (!staticSharedLogger()) {
     533        staticSharedLogger() = &Logger::create(sharedLoggerOwner()).leakRef();
     534        configureSharedLogger();
     535    }
     536   
     537    return *staticSharedLogger();
     538}
     539
     540void Document::configureSharedLogger()
     541{
     542    auto logger = staticSharedLogger();
     543    if (!logger)
     544        return;
     545
     546    bool alwaysOnLoggingAllowed = !allDocumentsMap().isEmpty() && WTF::allOf(allDocumentsMap().values(), [](auto* document) {
     547        auto* page = document->page();
     548        return !page || page->sessionID().isAlwaysOnLoggingAllowed();
     549    });
     550    logger->setEnabled(sharedLoggerOwner(), alwaysOnLoggingAllowed);
     551}
     552
     553auto Document::addToDocumentsMap() -> DocumentsMap::AddResult
     554{
     555    auto addResult = allDocumentsMap().add(m_identifier, this);
     556    configureSharedLogger();
     557   
     558    return addResult;
     559}
     560
     561void Document::removeFromDocumentsMap()
     562{
     563    ASSERT(allDocumentsMap().contains(m_identifier));
     564    allDocumentsMap().remove(m_identifier);
     565    configureSharedLogger();
     566}
     567
    518568auto Document::allDocumentsMap() -> DocumentsMap&
    519569{
     
    590640    , m_selection(makeUniqueRef<FrameSelection>(this))
    591641{
    592     auto addResult = allDocumentsMap().add(m_identifier, this);
     642    auto addResult = addToDocumentsMap();
    593643    ASSERT_UNUSED(addResult, addResult.isNewEntry);
    594644
     
    650700#endif
    651701
    652     ASSERT(allDocumentsMap().contains(m_identifier));
    653     allDocumentsMap().remove(m_identifier);
     702    removeFromDocumentsMap();
     703
    654704    // We need to remove from the contexts map very early in the destructor so that calling postTask() on this Document from another thread is safe.
    655705    removeFromContextsMap();
  • trunk/Source/WebCore/dom/Document.h

    r270974 r271270  
    14931493
    14941494    Logger& logger();
     1495    WEBCORE_EXPORT static const Logger& sharedLogger();
    14951496
    14961497    WEBCORE_EXPORT void setConsoleMessageListener(RefPtr<StringCallback>&&); // For testing.
     
    17191720
    17201721    void didLogMessage(const WTFLogChannel&, WTFLogLevel, Vector<JSONLogValue>&&) final;
     1722    static void configureSharedLogger();
     1723
     1724    DocumentsMap::AddResult addToDocumentsMap();
     1725    void removeFromDocumentsMap();
    17211726
    17221727    const Ref<const Settings> m_settings;
  • trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp

    r271214 r271270  
    6161
    6262template<typename> struct LogArgument;
     63
     64template<> struct LogArgument<webm::TrackType> {
     65    static String toString(webm::TrackType type)
     66    {
     67        switch (type) {
     68        case webm::TrackType::kVideo: return "Video"_s;
     69        case webm::TrackType::kAudio: return "Audio"_s;
     70        case webm::TrackType::kComplex: return "Complex"_s;
     71        case webm::TrackType::kLogo: return "Logo"_s;
     72        case webm::TrackType::kSubtitle: return "Subtitle"_s;
     73        case webm::TrackType::kButtons: return "Buttons"_s;
     74        case webm::TrackType::kControl: return "Control"_s;
     75        }
     76        return "Unknown"_s;
     77    }
     78};
    6379
    6480template<> struct LogArgument<webm::Id> {
     
    244260using namespace PAL;
    245261
    246 #if !RELEASE_LOG_DISABLED
    247 static WTFLogChannel& logChannel() { return LogMediaSource; }
     262static WTFLogChannel& logChannel() { return LogMedia; }
    248263static const char* logClassName() { return "SourceBufferParserWebM"; }
    249 #endif
    250264
    251265// FIXME: Remove this once kCMVideoCodecType_VP9 is added to CMFormatDescription.h
     
    628642        // parsed as a top-level element, rather than as a child of the Segment.
    629643        if (!m_reader->rewindTo(*m_rewindToPosition)) {
    630             ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "failed to rewind reader, bailing");
     644            ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "failed to rewind reader");
    631645            break;
    632646        }
     
    689703}
    690704
    691 #if !RELEASE_LOG_DISABLED
    692705void SourceBufferParserWebM::setLogger(const Logger& logger, const void* logIdentifier)
    693706{
     
    695708    m_logIdentifier = logIdentifier;
    696709}
    697 #endif
    698710
    699711auto SourceBufferParserWebM::trackDataForTrackNumber(uint64_t trackNumber) -> TrackData*
     
    721733    if ((m_state == State::None && metadata.id != Id::kEbml && metadata.id != Id::kSegment)
    722734        || (m_state == State::ReadingSegment && metadata.id != Id::kInfo && metadata.id != Id::kTracks && metadata.id != Id::kCluster)) {
    723         DEBUG_LOG_IF_POSSIBLE(LOGIDENTIFIER, "state(", m_state, "), id(", metadata.id, "), position(", metadata.position, "), headerSize(", metadata.header_size, "), size(", metadata.size, "), skipping");
     735        INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER, "state(", m_state, "), id(", metadata.id, "), position(", metadata.position, "), headerSize(", metadata.header_size, "), size(", metadata.size, "), skipping");
    724736
    725737        *action = Action::kSkip;
     
    727739    }
    728740
    729 #if !RELEASE_LOG_DISABLED
    730741    auto oldState = m_state;
    731 #endif
    732742
    733743    if (metadata.id == Id::kEbml)
     
    744754        m_state = State::ReadingCluster;
    745755
    746     DEBUG_LOG_IF_POSSIBLE(LOGIDENTIFIER, "state(", oldState, "->", m_state, "), id(", metadata.id, "), position(", metadata.position, "), headerSize(", metadata.header_size, "), size(", metadata.size, ")");
     756    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER, "state(", oldState, "->", m_state, "), id(", metadata.id, "), position(", metadata.position, "), headerSize(", metadata.header_size, "), size(", metadata.size, ")");
    747757
    748758    return Status(Status::kOkCompleted);
     
    752762{
    753763    UNUSED_PARAM(metadata);
    754 
    755 #if !RELEASE_LOG_DISABLED
     764    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     765
    756766    auto oldState = m_state;
    757 #endif
    758767
    759768    if (metadata.id == Id::kEbml || metadata.id == Id::kSegment)
     
    764773        m_state = State::ReadingTracks;
    765774
    766     DEBUG_LOG_IF_POSSIBLE(LOGIDENTIFIER, "state(", oldState, "->", m_state, "), id(", metadata.id, "), size(", metadata.size, ")");
     775    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER, "state(", oldState, "->", m_state, "), id(", metadata.id, "), size(", metadata.size, ")");
    767776
    768777    return Status(Status::kOkCompleted);
     
    772781{
    773782    UNUSED_PARAM(metadata);
     783    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     784
    774785    if (ebml.doc_type.is_present() && ebml.doc_type.value().compare("webm"))
    775786        return Status(Status::Code(ErrorCode::InvalidDocType));
     
    784795{
    785796    UNUSED_PARAM(metadata);
     797    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     798
    786799    if (!m_initializationSegmentEncountered) {
    787         ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered Segment before Embl, bailing");
     800        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered Segment before Embl");
    788801        return Status(Status::Code(ErrorCode::InvalidInitSegment));
    789802    }
     
    800813{
    801814    UNUSED_PARAM(metadata);
     815    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     816
    802817    if (!m_initializationSegmentEncountered || !m_initializationSegment) {
    803         ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered Info outside Segment, bailing");
     818        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered Info outside Segment");
    804819        return Status(Status::Code(ErrorCode::InvalidInitSegment));
    805820    }
     
    815830{
    816831    UNUSED_PARAM(metadata);
    817     UNUSED_PARAM(cluster);
     832    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     833
    818834    ASSERT(action);
    819835    if (!action)
     
    850866    String codecId { trackEntry.codec_id.value().data(), (unsigned)trackEntry.codec_id.value().length() };
    851867
     868    ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER, trackType, ", codec ", codecId);
     869
    852870    if (trackType == TrackType::kVideo && !supportedVideoCodecs().contains(codecId)) {
    853         ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered unsupported video codec ID \"", codecId, "\", bailing");
     871        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered unsupported video codec ID ", codecId);
    854872        return Status(Status::Code(ErrorCode::UnsupportedVideoCodec));
    855873    }
    856874
    857875    if (trackType == TrackType::kAudio && !supportedAudioCodecs().contains(codecId)) {
    858         ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered unsupported audio codec ID \"", codecId, "\", bailing");
     876        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered unsupported audio codec ID ", codecId);
    859877        return Status(Status::Code(ErrorCode::UnsupportedAudioCodec));
    860878    }
    861879
    862     if (trackType == TrackType::kVideo)
    863         m_initializationSegment->videoTracks.append({ MediaDescriptionWebM::create(TrackEntry(trackEntry)), VideoTrackPrivateWebM::create(TrackEntry(trackEntry)) });
    864     else if (trackType == TrackType::kAudio)
    865         m_initializationSegment->audioTracks.append({ MediaDescriptionWebM::create(TrackEntry(trackEntry)), AudioTrackPrivateWebM::create(TrackEntry(trackEntry)) });
     880    if (trackType == TrackType::kVideo) {
     881        auto track = VideoTrackPrivateWebM::create(TrackEntry(trackEntry));
     882        if (m_logger)
     883            track->setLogger(*m_logger, LoggerHelper::childLogIdentifier(m_logIdentifier, ++m_nextChildIdentifier));
     884        m_initializationSegment->videoTracks.append({ MediaDescriptionWebM::create(TrackEntry(trackEntry)), WTFMove(track) });
     885    } else if (trackType == TrackType::kAudio) {
     886        auto track = AudioTrackPrivateWebM::create(TrackEntry(trackEntry));
     887        if (m_logger)
     888            track->setLogger(*m_logger, LoggerHelper::childLogIdentifier(m_logIdentifier, ++m_nextChildIdentifier));
     889        m_initializationSegment->audioTracks.append({ MediaDescriptionWebM::create(TrackEntry(trackEntry)), WTFMove(track) });
     890    }
    866891
    867892    StringView codecString { trackEntry.codec_id.value().data(), (unsigned)trackEntry.codec_id.value().length() };
     
    898923{
    899924    UNUSED_PARAM(metadata);
     925    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     926
    900927    ASSERT(action);
    901928    if (!action)
     
    913940    UNUSED_PARAM(metadata);
    914941    UNUSED_PARAM(block);
     942    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
    915943
    916944    m_currentBlock = WTF::nullopt;
     
    922950{
    923951    UNUSED_PARAM(metadata);
     952    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     953
    924954    ASSERT(action);
    925955    if (!action)
     
    936966{
    937967    UNUSED_PARAM(metadata);
     968    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     969
    938970    UNUSED_PARAM(block);
    939971
     
    946978{
    947979    UNUSED_PARAM(metadata);
     980    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
     981
    948982    ASSERT(action);
    949983    if (!action)
     
    958992    UNUSED_PARAM(metadata);
    959993    UNUSED_PARAM(blockGroup);
     994    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER);
    960995    return Status(Status::kOkCompleted);
    961996}
     
    9671002        return Status(Status::kNotEnoughMemory);
    9681003
    969     if (!m_currentBlock)
     1004    if (!m_currentBlock) {
     1005        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "no current block!");
    9701006        return Status(Status::kInvalidElementId);
     1007    }
    9711008
    9721009    auto* block = WTF::switchOn(*m_currentBlock, [](Block& block) {
  • trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h

    r271253 r271270  
    271271    RefPtr<const WTF::Logger> m_logger;
    272272    const void* m_logIdentifier { nullptr };
     273    uint64_t m_nextChildIdentifier { 0 };
    273274};
    274275
  • trunk/Source/WebKit/ChangeLog

    r271269 r271270  
     12021-01-07  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Mac] Add runtime logging to format reader and WebM parser
     4        https://bugs.webkit.org/show_bug.cgi?id=220423
     5        <rdar://problem/72896655>
     6
     7        Reviewed by Andy Estes.
     8
     9        Use the Document::sharedLogger to log format and track reader state changes
     10        and errors.
     11
     12        * Shared/mac/MediaFormatReader/MediaFormatReader.cpp:
     13        (WebKit::nextLogIdentifier):
     14        (WebKit::logChannel):
     15        (WebKit::logClassName):
     16        (WebKit::MediaFormatReader::parseByteSource):
     17        (WebKit::MediaFormatReader::didParseTracks):
     18        (WebKit::MediaFormatReader::copyProperty):
     19        (WebKit::MediaFormatReader::nextTrackReaderLogIdentifier const):
     20        * Shared/mac/MediaFormatReader/MediaFormatReader.h:
     21        * Shared/mac/MediaFormatReader/WebKit::MediaTrackReader.cpp:
     22        (WebKit::MediaTrackReader::MediaTrackReader):
     23        (WebKit::MediaTrackReader::finishParsing):
     24        (WebKit::MediaTrackReader::mediaTypeString const):
     25        (WebKit::MediaTrackReader::copyProperty):
     26        (WebKit::MediaTrackReader::finalize):
     27        (WebKit::MediaTrackReader::logChannel const):
     28        * Shared/mac/MediaFormatReader/WebKit::MediaTrackReader.h:
     29
    1302021-01-07  Alexey Shvayka  <shvaikalesh@gmail.com>
    231
  • trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaFormatReader.cpp

    r271253 r271270  
    3232#include <WebCore/AudioTrackPrivate.h>
    3333#include <WebCore/ContentType.h>
     34#include <WebCore/Document.h>
    3435#include <WebCore/InbandTextTrackPrivate.h>
     36#include <WebCore/Logging.h>
    3537#include <WebCore/MediaSample.h>
    3638#include <WebCore/SourceBufferParserWebM.h>
    3739#include <WebCore/VideoTrackPrivate.h>
    3840#include <pal/avfoundation/MediaTimeAVFoundation.h>
     41#include <wtf/LoggerHelper.h>
    3942#include <wtf/WorkQueue.h>
    4043
     
    4750using namespace PAL;
    4851using namespace WebCore;
     52
     53static const void* nextLogIdentifier()
     54{
     55    static uint64_t logIdentifier = cryptographicallyRandomNumber();
     56    return reinterpret_cast<const void*>(++logIdentifier);
     57}
     58
     59static WTFLogChannel& logChannel() { return WebCore::LogMedia; }
     60static const char* logClassName() { return "MediaFormatReader"; }
    4961
    5062CMBaseClassID MediaFormatReader::wrapperClassID()
     
    98110    }
    99111
     112    if (!m_logger) {
     113        m_logger = makeRefPtr(Document::sharedLogger());
     114        m_logIdentifier = nextLogIdentifier();
     115    }
     116
     117    ALWAYS_LOG(LOGIDENTIFIER);
     118    parser->setLogger(*m_logger, m_logIdentifier);
     119
    100120    // Set a minimum audio sample duration of 0 so the parser creates indivisible samples with byte source ranges.
    101121    parser->setMinimumAudioSampleDuration(0);
     
    141161    ASSERT(m_trackReaders.isEmpty());
    142162
     163    ALWAYS_LOG(LOGIDENTIFIER);
     164    if (errorCode)
     165        ERROR_LOG(LOGIDENTIFIER, errorCode);
     166
    143167    m_parseTracksStatus = errorCode ? kMTPluginFormatReaderError_ParsingFailure : noErr;
    144168    m_duration = WTFMove(segment.duration);
     
    187211{
    188212    ASSERT(!isMainThread());
     213    ALWAYS_LOG(LOGIDENTIFIER);
    189214
    190215    auto locker = holdLock(m_parseTracksLock);
     
    214239    }
    215240
     241    ERROR_LOG(LOGIDENTIFIER, "asked for unsupported property ", String(key));
    216242    return kCMBaseObjectError_ValueNotAvailable;
    217243}
     
    235261}
    236262
     263const void* MediaFormatReader::nextTrackReaderLogIdentifier(uint64_t trackID) const
     264{
     265    return LoggerHelper::childLogIdentifier(m_logIdentifier, trackID);
     266}
     267
    237268} // namespace WebKit
    238269
  • trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaFormatReader.h

    r271253 r271270  
    3232#include <wtf/Condition.h>
    3333#include <wtf/Lock.h>
     34#include <wtf/Logger.h>
    3435
    3536DECLARE_CORE_MEDIA_TRAITS(FormatReader);
     
    5657    const MediaTime& duration() const { return m_duration; }
    5758
     59    const Logger& logger() const { ASSERT(m_logger); return *m_logger.get(); }
     60    const void* nextTrackReaderLogIdentifier(uint64_t) const;
     61
    5862private:
    5963    explicit MediaFormatReader(Allocator&&);
     
    7276    // WrapperClass
    7377    OSStatus copyTrackArray(CFArrayRef*);
     78   
     79    const void* logIdentifier() const { return m_logIdentifier; }
    7480
    7581    RetainPtr<MTPluginByteSourceRef> m_byteSource;
     
    7985    Optional<OSStatus> m_parseTracksStatus;
    8086    Vector<Ref<MediaTrackReader>> m_trackReaders;
     87    RefPtr<const Logger> m_logger;
     88    const void* m_logIdentifier;
    8189};
    8290
  • trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaTrackReader.cpp

    r271253 r271270  
    3434#include <WebCore/AudioTrackPrivate.h>
    3535#include <WebCore/InbandTextTrackPrivate.h>
     36#include <WebCore/Logging.h>
    3637#include <WebCore/MediaDescription.h>
    3738#include <WebCore/SampleMap.h>
     
    7475    , m_mediaType(mediaType)
    7576    , m_duration(formatReader.duration())
     77    , m_logger(formatReader.logger())
     78    , m_logIdentifier(formatReader.nextTrackReaderLogIdentifier(trackID))
    7679{
    7780    ASSERT(!isMainThread());
    7881
     82    ALWAYS_LOG(LOGIDENTIFIER, mediaTypeString(), " ", trackID);
    7983    if (enabled)
    8084        m_isEnabled = enabled.value() ? Enabled::True : Enabled::False;
     
    113117{
    114118    ASSERT(!isMainThread());
     119
     120    ALWAYS_LOG(LOGIDENTIFIER);
    115121    auto locker = holdLock(m_sampleStorageLock);
    116122    if (!m_sampleStorage)
    117123        m_sampleStorage = makeUnique<SampleStorage>();
    118124    m_sampleStorage->hasAllSamples = true;
    119     if (m_isEnabled == Enabled::Unknown)
     125    if (m_isEnabled == Enabled::Unknown) {
    120126        m_isEnabled = m_sampleStorage->sampleMap.empty() ? Enabled::False : Enabled::True;
     127        if (m_isEnabled == Enabled::False)
     128            ERROR_LOG(LOGIDENTIFIER, "ignoring empty ", mediaTypeString(), " track");
     129    }
    121130    m_sampleStorageCondition.notifyAll();
     131}
     132
     133const char* MediaTrackReader::mediaTypeString() const
     134{
     135    switch (m_mediaType) {
     136    case kCMMediaType_Video:
     137        return "video";
     138        break;
     139    case kCMMediaType_Audio:
     140        return "audio";
     141        break;
     142    case kCMMediaType_Text:
     143        return "text";
     144        break;
     145    }
     146    ASSERT_NOT_REACHED();
     147    return "unknown";
    122148}
    123149
     
    138164
    139165    if (CFEqual(key, PAL::get_MediaToolbox_kMTPluginTrackReaderProperty_Enabled())) {
    140         if (m_isEnabled == Enabled::Unknown)
     166        if (m_isEnabled == Enabled::Unknown) {
    141167            m_isEnabled = sampleMap.empty() ? Enabled::False : Enabled::True;
     168            if (m_isEnabled == Enabled::False)
     169                ERROR_LOG(LOGIDENTIFIER, "ignoring empty ", mediaTypeString(), " track");
     170        }
    142171
    143172        *reinterpret_cast<CFBooleanRef*>(copiedValue) = retainPtr(m_isEnabled == Enabled::True ? kCFBooleanTrue : kCFBooleanFalse).leakRef();
     
    145174    }
    146175
    147     if (sampleMap.empty())
     176    if (sampleMap.empty()) {
     177        ERROR_LOG(LOGIDENTIFIER, "sample table empty when asked for ", String(key));
    148178        return kCMBaseObjectError_ValueNotAvailable;
     179    }
    149180
    150181    auto& lastSample = *sampleMap.decodeOrder().rbegin()->second;
     
    163194    }
    164195
     196    ERROR_LOG(LOGIDENTIFIER, "asked for unsupported property ", String(key));
    165197    return kCMBaseObjectError_ValueNotAvailable;
    166198}
     
    200232}
    201233
     234WTFLogChannel& MediaTrackReader::logChannel() const
     235{
     236    return WebCore::LogMedia;
     237}
     238
    202239} // namespace WebKit
    203240
  • trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaTrackReader.h

    r271253 r271270  
    9191    };
    9292
     93    const char* mediaTypeString() const;
     94    const WTF::Logger& logger() const { return m_logger; }
     95    const char* logClassName() const { return "MediaTrackReader"; }
     96    const void* logIdentifier() const { return m_logIdentifier; }
     97    WTFLogChannel& logChannel() const;
     98
    9399    enum Enabled : uint8_t { Unknown, False, True };
    94100
     
    100106    mutable Lock m_sampleStorageLock;
    101107    mutable std::unique_ptr<SampleStorage> m_sampleStorage;
     108    Ref<const Logger> m_logger;
     109    const void* m_logIdentifier;
    102110};
    103111
Note: See TracChangeset for help on using the changeset viewer.