Shaka Player Embedded
decoder_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_DECODER_THREAD_H_
16 #define SHAKA_EMBEDDED_MEDIA_DECODER_THREAD_H_
17 
18 #include <string>
19 
20 #include "shaka/media/decoder.h"
21 #include "shaka/media/streams.h"
22 #include "src/debug/mutex.h"
23 #include "src/debug/thread.h"
24 #include "src/debug/thread_event.h"
25 #include "src/util/macros.h"
26 
27 namespace shaka {
28 
29 namespace eme {
30 class Implementation;
31 } // namespace eme
32 
33 namespace media {
34 
40  public:
41  class Client {
42  public:
43  virtual ~Client() {}
44 
45  // These should have the same names as MediaPlayer to ensure we can subclass
46  // both.
47  virtual double CurrentTime() const = 0;
48  virtual double Duration() const = 0;
49  virtual void OnWaitingForKey() = 0;
50 
51  virtual void OnError(const std::string& error) = 0;
52  };
53 
58  DecoderThread(Client* client, DecodedStream* output);
59  ~DecoderThread();
60 
62 
64  void Attach(const ElementaryStream* input);
65 
67  void Detach();
68 
73  void OnSeek();
74 
75  void SetCdm(eme::Implementation* cdm);
76 
78  void SetDecoder(Decoder* decoder);
79 
80  private:
81  void ThreadMain();
82 
83  Mutex mutex_;
84  ThreadEvent<void> signal_;
85 
86  Client* const client_;
87  const ElementaryStream* input_;
88  DecodedStream* const output_;
89  Decoder* decoder_;
90 
91  eme::Implementation* cdm_;
92  double last_frame_time_;
93  bool shutdown_;
94  bool did_flush_;
95  bool raised_waiting_event_;
96 
97  Thread thread_;
98 };
99 
100 } // namespace media
101 } // namespace shaka
102 
103 #endif // SHAKA_EMBEDDED_MEDIA_DECODER_THREAD_H_
#define SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE(Type)
Definition: macros.h:51