Shaka Player Embedded
text_track.h
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 #ifndef SHAKA_EMBEDDED_JS_MSE_TEXT_TRACK_H_
16 #define SHAKA_EMBEDDED_JS_MSE_TEXT_TRACK_H_
17 
18 #include <memory>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "shaka/media/text_track.h"
24 #include "shaka/media/vtt_cue.h"
25 #include "src/core/member.h"
26 #include "src/core/ref_ptr.h"
28 #include "src/js/vtt_cue.h"
31 
32 namespace shaka {
33 namespace js {
34 namespace mse {
35 
36 class HTMLMediaElement;
37 
39  DECLARE_TYPE_INFO(TextTrack);
40 
41  public:
42  explicit TextTrack(std::shared_ptr<shaka::media::TextTrack> track);
43 
44  void Trace(memory::HeapTracer* tracer) const override;
45 
47  const std::string label;
48  const std::string language;
49  const std::string id;
50 
51  std::vector<RefPtr<VTTCue>> cues() const;
52 
53  media::TextTrackMode mode() const;
55 
56  // Technically this should accept a TextTrackCue, but we don't distinguish
57  // between the types.
58  void AddCue(RefPtr<VTTCue> cue);
59  void RemoveCue(RefPtr<VTTCue> cue);
60 
61  private:
62  void OnCueAdded(std::shared_ptr<shaka::media::VTTCue> cue) override;
63  void OnCueRemoved(std::shared_ptr<shaka::media::VTTCue> cue) override;
64 
65  mutable Mutex mutex_;
66  std::unordered_map<shaka::media::VTTCue*, Member<VTTCue>> cues_;
67  std::shared_ptr<shaka::media::TextTrack> track_;
68 };
69 
71  : public BackingObjectFactory<TextTrack, events::EventTarget> {
72  public:
74 };
75 
76 } // namespace mse
77 } // namespace js
78 } // namespace shaka
79 
81  AddMapping(Enum::Subtitles, "subtitles");
82  AddMapping(Enum::Captions, "captions");
83  AddMapping(Enum::Descriptions, "descriptions");
84  AddMapping(Enum::Chapters, "chapters");
85  AddMapping(Enum::Metadata, "metadata");
86 }
87 
89  AddMapping(Enum::Disabled, "disabled");
90  AddMapping(Enum::Hidden, "hidden");
91  AddMapping(Enum::Showing, "showing");
92 }
93 
94 #endif // SHAKA_EMBEDDED_JS_MSE_TEXT_TRACK_H_
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
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
DEFINE_ENUM_MAPPING(shaka::media, TextTrackKind)
Definition: text_track.h:80
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