| 1 | /* |
| 2 | * Copyright (C) 2012-2017 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "InbandWebVTTTextTrack.h" |
| 28 | |
| 29 | #if ENABLE(VIDEO_TRACK) |
| 30 | |
| 31 | #include "InbandTextTrackPrivate.h" |
| 32 | #include "Logging.h" |
| 33 | #include "VTTCue.h" |
| 34 | #include "VTTRegionList.h" |
| 35 | #include <wtf/IsoMallocInlines.h> |
| 36 | #include <wtf/text/CString.h> |
| 37 | |
| 38 | namespace WebCore { |
| 39 | |
| 40 | WTF_MAKE_ISO_ALLOCATED_IMPL(InbandWebVTTTextTrack); |
| 41 | |
| 42 | inline InbandWebVTTTextTrack::InbandWebVTTTextTrack(ScriptExecutionContext& context, TextTrackClient& client, InbandTextTrackPrivate& trackPrivate) |
| 43 | : InbandTextTrack(context, client, trackPrivate) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | Ref<InbandTextTrack> InbandWebVTTTextTrack::create(ScriptExecutionContext& context, TextTrackClient& client, InbandTextTrackPrivate& trackPrivate) |
| 48 | { |
| 49 | return adoptRef(*new InbandWebVTTTextTrack(context, client, trackPrivate)); |
| 50 | } |
| 51 | |
| 52 | InbandWebVTTTextTrack::~InbandWebVTTTextTrack() = default; |
| 53 | |
| 54 | WebVTTParser& InbandWebVTTTextTrack::parser() |
| 55 | { |
| 56 | if (!m_webVTTParser) |
| 57 | m_webVTTParser = std::make_unique<WebVTTParser>(static_cast<WebVTTParserClient*>(this), scriptExecutionContext()); |
| 58 | return *m_webVTTParser; |
| 59 | } |
| 60 | |
| 61 | void InbandWebVTTTextTrack::parseWebVTTCueData(const char* data, unsigned length) |
| 62 | { |
| 63 | parser().parseBytes(data, length); |
| 64 | } |
| 65 | |
| 66 | void InbandWebVTTTextTrack::parseWebVTTCueData(const ISOWebVTTCue& cueData) |
| 67 | { |
| 68 | parser().parseCueData(cueData); |
| 69 | } |
| 70 | |
| 71 | void InbandWebVTTTextTrack::newCuesParsed() |
| 72 | { |
| 73 | Vector<RefPtr<WebVTTCueData>> cues; |
| 74 | parser().getNewCues(cues); |
| 75 | for (auto& cueData : cues) { |
| 76 | auto vttCue = VTTCue::create(*scriptExecutionContext(), *cueData); |
| 77 | if (hasCue(vttCue.ptr(), TextTrackCue::IgnoreDuration)) { |
| 78 | INFO_LOG(LOGIDENTIFIER, "ignoring already added cue: " , vttCue.get()); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | INFO_LOG(LOGIDENTIFIER, vttCue.get()); |
| 83 | |
| 84 | addCue(WTFMove(vttCue)); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | void InbandWebVTTTextTrack::newRegionsParsed() |
| 89 | { |
| 90 | Vector<RefPtr<VTTRegion>> newRegions; |
| 91 | parser().getNewRegions(newRegions); |
| 92 | for (auto& region : newRegions) { |
| 93 | region->setTrack(this); |
| 94 | regions()->add(region.releaseNonNull()); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void InbandWebVTTTextTrack::newStyleSheetsParsed() |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | void InbandWebVTTTextTrack::fileFailedToParse() |
| 103 | { |
| 104 | ERROR_LOG(LOGIDENTIFIER, "Error parsing WebVTT stream." ); |
| 105 | } |
| 106 | |
| 107 | } // namespace WebCore |
| 108 | |
| 109 | #endif |
| 110 | |