Shaka Player Embedded
demuxer_thread.h
Go to the documentation of this file.
1 // Copyright 2017 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_MEDIA_DEMUXER_THREAD_H_
16 #define SHAKA_EMBEDDED_MEDIA_DEMUXER_THREAD_H_
17 
18 #include <atomic>
19 #include <functional>
20 #include <memory>
21 #include <string>
22 
23 #include "shaka/media/demuxer.h"
24 #include "shaka/media/streams.h"
25 #include "src/debug/mutex.h"
26 #include "src/debug/thread.h"
27 #include "src/debug/thread_event.h"
28 #include "src/media/types.h"
29 #include "src/util/buffer_reader.h"
30 #include "src/util/macros.h"
31 
32 namespace shaka {
33 namespace media {
34 
42  public:
49  DemuxerThread(const std::string& mime, Demuxer::Client* client,
50  ElementaryStream* stream);
52 
54 
56  void Stop();
57 
71  void AppendData(double timestamp_offset, double window_start,
72  double window_end, const uint8_t* data, size_t data_size,
73  std::function<void(bool)> on_complete);
74 
75  private:
76  void ThreadMain();
77  void CallOnComplete(bool success);
78 
79  Mutex mutex_;
80  std::unique_ptr<Demuxer> demuxer_;
81  ThreadEvent<void> new_data_;
82  std::function<void(bool)> on_complete_;
83  Demuxer::Client* client_;
84  std::string mime_;
85  std::atomic<bool> shutdown_;
86  const uint8_t* data_;
87  size_t data_size_;
88  double timestamp_offset_;
89  double window_start_;
90  double window_end_;
91  bool need_key_frame_;
92 
93  ElementaryStream* stream_;
94 
95  // Should be last so the thread starts after all the fields are initialized.
96  Thread thread_;
97 };
98 
99 } // namespace media
100 } // namespace shaka
101 
102 #endif // SHAKA_EMBEDDED_MEDIA_DEMUXER_THREAD_H_
DemuxerThread(const std::string &mime, Demuxer::Client *client, ElementaryStream *stream)
SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE(DemuxerThread)
void AppendData(double timestamp_offset, double window_start, double window_end, const uint8_t *data, size_t data_size, std::function< void(bool)> on_complete)