Shaka Player Embedded
text_track.cc
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/js/mse/text_track.h"
16 
17 #include "src/js/js_error.h"
18 
19 namespace shaka {
20 namespace js {
21 namespace mse {
22 
23 TextTrack::TextTrack(std::shared_ptr<shaka::media::TextTrack> track)
24  : kind(track->kind),
25  label(track->label),
26  language(track->language),
27  id(track->id),
28  mutex_("TextTrack"),
29  track_(track) {
30  track->AddClient(this);
31 }
32 
33 TextTrack::~TextTrack() {
34  track_->RemoveClient(this);
35 }
36 
37 void TextTrack::Trace(memory::HeapTracer* tracer) const {
39 
40  std::unique_lock<Mutex> lock(mutex_);
41  for (auto& pair : cues_)
42  tracer->Trace(&pair.second);
43 }
44 
45 std::vector<RefPtr<VTTCue>> TextTrack::cues() const {
46  std::unique_lock<Mutex> lock(mutex_);
47  std::vector<RefPtr<VTTCue>> ret;
48  ret.reserve(cues_.size());
49  for (auto& pair : cues_)
50  ret.emplace_back(pair.second);
51 
52  return ret;
53 }
54 
56  return track_->mode();
57 }
58 
60  track_->SetMode(mode);
61 }
62 
63 
65  // Don't add to |cues_| since we'll get an event for it anyway.
66  track_->AddCue(cue->GetPublic());
67 }
68 
70  // Don't change to |cues_| since we'll get an event for it anyway.
71  track_->RemoveCue(cue->GetPublic());
72 }
73 
74 void TextTrack::OnCueAdded(std::shared_ptr<shaka::media::VTTCue> cue) {
75  std::unique_lock<Mutex> lock(mutex_);
76  cues_.emplace(cue.get(), new VTTCue(cue));
77 }
78 
79 void TextTrack::OnCueRemoved(std::shared_ptr<shaka::media::VTTCue> cue) {
80  std::unique_lock<Mutex> lock(mutex_);
81  cues_.erase(cue.get());
82 }
83 
84 
86  AddReadOnlyProperty("kind", &TextTrack::kind);
87  AddReadOnlyProperty("label", &TextTrack::label);
88  AddReadOnlyProperty("language", &TextTrack::language);
89  AddReadOnlyProperty("id", &TextTrack::id);
90 
91  AddGenericProperty("cues", &TextTrack::cues);
92  AddGenericProperty("mode", &TextTrack::mode, &TextTrack::SetMode);
93 
94  AddMemberFunction("addCue", &TextTrack::AddCue);
95  AddMemberFunction("removeCue", &TextTrack::RemoveCue);
96 
97  NotImplemented("activeCues");
98  NotImplemented("oncuechange");
99 }
100 
101 } // namespace mse
102 } // namespace js
103 } // namespace shaka
void AddCue(RefPtr< VTTCue > cue)
Definition: text_track.cc:64
std::vector< RefPtr< VTTCue > > cues() const
Definition: text_track.cc:45
TextTrack(std::shared_ptr< shaka::media::TextTrack > track)
Definition: text_track.cc:23
void SetMode(media::TextTrackMode mode)
Definition: text_track.cc:59
const std::string id
Definition: text_track.h:49
void Trace(const Traceable *ptr)
Definition: heap_tracer.cc:43
void Trace(memory::HeapTracer *tracer) const override
Definition: event_target.cc:31
const std::string label
Definition: text_track.h:47
void RemoveCue(RefPtr< VTTCue > cue)
Definition: text_track.cc:69
void Trace(memory::HeapTracer *tracer) const override
Definition: text_track.cc:37
const std::string language
Definition: text_track.h:48
const media::TextTrackKind kind
Definition: text_track.h:46
media::TextTrackMode mode() const
Definition: text_track.cc:55