Shaka Player Embedded
media_source.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_MEDIA_SOURCE_H_
16 #define SHAKA_EMBEDDED_JS_MSE_MEDIA_SOURCE_H_
17 
18 #include <string>
19 #include <unordered_map>
20 
21 #include "shaka/media/demuxer.h"
23 #include "shaka/optional.h"
24 #include "src/core/member.h"
25 #include "src/core/ref_ptr.h"
28 #include "src/mapping/enum.h"
30 #include "src/media/types.h"
31 
32 namespace shaka {
33 namespace js {
34 namespace mse {
35 
36 class HTMLMediaElement;
37 class SourceBuffer;
38 
39 
41  CLOSED,
42  OPEN,
43  ENDED,
44 };
45 
48 
49  public:
50  MediaSource();
51 
52  static MediaSource* Create() {
53  return new MediaSource();
54  }
55 
56  static bool IsTypeSupported(const std::string& mime_type);
57  static RefPtr<MediaSource> FindMediaSource(const std::string& url);
58 
59  void Trace(memory::HeapTracer* tracer) const override;
60 
61  ExceptionOr<RefPtr<SourceBuffer>> AddSourceBuffer(const std::string& type);
62  ExceptionOr<void> EndOfStream(optional<std::string> error);
63 
64  double GetDuration() const;
65  ExceptionOr<void> SetDuration(double duration);
66 
67 
69  void OpenMediaSource(RefPtr<HTMLMediaElement> video,
70  media::MediaPlayer* player);
72  void CloseMediaSource();
73 
74 
78 
80  const std::string url;
81 
82  private:
83  void OnLoadedMetaData(double duration) override;
84  void OnEncrypted(::shaka::eme::MediaKeyInitDataType type, const uint8_t* data,
85  size_t size) override;
86 
87  Member<SourceBuffer> audio_buffer_;
88  Member<SourceBuffer> video_buffer_;
90  media::MediaPlayer* player_;
91  bool got_loaded_metadata_;
92 
93  // A map of every MediaSource object created. These are not traced so they
94  // are weak pointers. Once a MediaSource gets destroyed, it will be removed
95  // from this map by its destructor.
96  static std::unordered_map<std::string, Member<MediaSource>> media_sources_;
97 };
98 
100  : public BackingObjectFactory<MediaSource, events::EventTarget> {
101  public:
103 };
104 
105 } // namespace mse
106 } // namespace js
107 } // namespace shaka
108 
110  AddMapping(Enum::CLOSED, "closed");
111  AddMapping(Enum::OPEN, "open");
112  AddMapping(Enum::ENDED, "ended");
113 }
114 
115 #endif // SHAKA_EMBEDDED_JS_MSE_MEDIA_SOURCE_H_
static MediaSource * Create()
Definition: media_source.h:52
MediaSourceReadyState ready_state
Definition: media_source.h:79
ExceptionCode type
#define DECLARE_TYPE_INFO(type)
DEFINE_ENUM_MAPPING(shaka::js::mse, MediaSourceReadyState)
Definition: media_source.h:109
const std::string url
Definition: media_source.h:80