2 * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, 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 COMPUTER, 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.
28 #if ENABLE(VIDEO_TRACK)
30 #include "InbandWebVTTTextTrack.h"
32 #include "InbandTextTrackPrivate.h"
34 #include "NotImplemented.h"
35 #include <wtf/text/CString.h>
39 PassRefPtr<InbandTextTrack> InbandWebVTTTextTrack::create(ScriptExecutionContext* context, TextTrackClient* client, PassRefPtr<InbandTextTrackPrivate> playerPrivate)
41 return adoptRef(new InbandWebVTTTextTrack(context, client, playerPrivate));
44 InbandWebVTTTextTrack::InbandWebVTTTextTrack(ScriptExecutionContext* context, TextTrackClient* client, PassRefPtr<InbandTextTrackPrivate> trackPrivate)
45 : InbandTextTrack(context, client, trackPrivate)
49 InbandWebVTTTextTrack::~InbandWebVTTTextTrack()
53 void InbandWebVTTTextTrack::parseWebVTTCueData(InbandTextTrackPrivate* trackPrivate, const char* data, unsigned length)
55 ASSERT_UNUSED(trackPrivate, trackPrivate == m_private);
57 m_webVTTParser = std::make_unique<WebVTTParser>(static_cast<WebVTTParserClient*>(this), scriptExecutionContext());
58 m_webVTTParser->parseBytes(data, length);
61 void InbandWebVTTTextTrack::newCuesParsed()
63 Vector<RefPtr<WebVTTCueData>> cues;
64 m_webVTTParser->getNewCues(cues);
65 for (size_t i = 0; i < cues.size(); ++i) {
66 RefPtr<WebVTTCueData> cueData = cues[i];
67 RefPtr<VTTCue> cue = VTTCue::create(*scriptExecutionContext(), cueData->startTime(), cueData->endTime(), cueData->content());
68 cue->setId(cueData->id());
69 cue->setCueSettings(cueData->settings());
71 if (hasCue(cue.get(), VTTCue::IgnoreDuration)) {
72 LOG(Media, "InbandWebVTTTextTrack::newCuesParsed ignoring already added cue: start=%.2f, end=%.2f, content=\"%s\"\n", cueData->startTime(), cueData->endTime(), cueData->content().utf8().data());
75 addCue(cue.release(), ASSERT_NO_EXCEPTION);
79 #if ENABLE(WEBVTT_REGIONS)
80 void InbandWebVTTTextTrack::newRegionsParsed()
86 void InbandWebVTTTextTrack::fileFailedToParse()
88 LOG(Media, "Unable to parse WebVTT stream.");
91 } // namespace WebCore