Shaka Player Embedded
source_buffer.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_SOURCE_BUFFER_H_
16 #define SHAKA_EMBEDDED_JS_MSE_SOURCE_BUFFER_H_
17 
18 #include <string>
19 
20 #include "shaka/media/demuxer.h"
22 #include "shaka/media/streams.h"
23 #include "src/core/member.h"
26 #include "src/mapping/enum.h"
29 #include "src/media/types.h"
30 
31 namespace shaka {
32 namespace js {
33 namespace mse {
34 class MediaSource;
35 class TimeRanges;
36 
37 
38 enum class AppendMode {
39  SEGMENTS,
40  SEQUENCE,
41 };
42 
45 
46  public:
47  SourceBuffer(const std::string& mime, RefPtr<MediaSource> media_source);
48 
49  void Trace(memory::HeapTracer* tracer) const override;
50 
51  bool Attach(const std::string& mime, media::MediaPlayer* player,
52  bool is_video);
53  void Detach();
54 
55  ExceptionOr<void> AppendBuffer(ByteBuffer data);
56  void Abort();
57  ExceptionOr<void> Remove(double start, double end);
58 
59  media::BufferedRanges GetBufferedRanges() const;
60  ExceptionOr<RefPtr<TimeRanges>> GetBuffered() const;
61 
62  double TimestampOffset() const;
63  ExceptionOr<void> SetTimestampOffset(double offset);
64  double AppendWindowStart() const;
65  ExceptionOr<void> SetAppendWindowStart(double window_start);
66  double AppendWindowEnd() const;
67  ExceptionOr<void> SetAppendWindowEnd(double window_end);
68 
70  bool updating;
71 
72  Listener on_update_start;
73  Listener on_update;
74  Listener on_update_end;
75  Listener on_error;
76  Listener on_abort;
77 
78  private:
80  void OnAppendComplete(bool success);
81 
83  media::DemuxerThread demuxer_;
84 
85  Member<MediaSource> media_source_;
86  ByteBuffer append_buffer_;
87  double timestamp_offset_;
88  double append_window_start_;
89  double append_window_end_;
90 };
91 
93  : public BackingObjectFactory<SourceBuffer, events::EventTarget> {
94  public:
96 };
97 
98 } // namespace mse
99 } // namespace js
100 } // namespace shaka
101 
103  AddMapping(Enum::SEGMENTS, "segments");
104  AddMapping(Enum::SEQUENCE, "sequence");
105 }
106 
107 #endif // SHAKA_EMBEDDED_JS_MSE_SOURCE_BUFFER_H_
std::vector< BufferedRange > BufferedRanges
Definition: types.h:26
DEFINE_ENUM_MAPPING(shaka::js::mse, AppendMode)
#define DECLARE_TYPE_INFO(type)