kodi
DVDMessage.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "FileItem.h"
12 #include "cores/IPlayer.h"
13 
14 #include <atomic>
15 #include <string.h>
16 #include <string>
17 
18 struct DemuxPacket;
19 
20 class CDVDMsg
21 {
22 public:
23  // clang-format off
24  enum Message
25  {
26  NONE = 1000,
27 
28  // messages used in the whole system
29  GENERAL_RESYNC, //
30  GENERAL_FLUSH, // flush all buffers
31  GENERAL_RESET, // reset codecs for new data
32  GENERAL_PAUSE,
33  GENERAL_STREAMCHANGE, //
34  GENERAL_SYNCHRONIZE, //
35  GENERAL_GUI_ACTION, // gui action of some sort
36  GENERAL_EOF, // eof of stream
37 
38  // player core related messages (cVideoPlayer.cpp)
39  PLAYER_SET_AUDIOSTREAM, //
40  PLAYER_SET_VIDEOSTREAM, //
41  PLAYER_SET_SUBTITLESTREAM, //
42  PLAYER_SET_SUBTITLESTREAM_VISIBLE, //
43  PLAYER_SET_STATE, // restore the VideoPlayer to a certain state
44  PLAYER_SET_PROGRAM,
45  PLAYER_SET_UPDATE_STREAM_DETAILS, // player should update file item stream details with its current streams
46  PLAYER_SEEK, //
47  PLAYER_SEEK_CHAPTER, //
48  PLAYER_SETSPEED, // set the playback speed
49  PLAYER_REQUEST_STATE,
50  PLAYER_OPENFILE,
51  PLAYER_STARTED, // sent whenever a sub player has finished it's first frame after open
52  PLAYER_AVCHANGE, // signal a change in audio, video or subtitle parameters
53  PLAYER_ABORT,
54  PLAYER_REPORT_STATE,
55  PLAYER_FRAME_ADVANCE,
56  PLAYER_DISPLAY_RESET, // report display reset event
57 
58  // demuxer related messages
59  DEMUXER_PACKET, // data packet
60  DEMUXER_RESET, // reset the demuxer
61 
62  // video related messages
63  VIDEO_SET_ASPECT, // set aspectratio of video
64  VIDEO_DRAIN, // wait for decoder to output last frame
65 
66  // subtitle related messages
67  SUBTITLE_CLUTCHANGE,
68  SUBTITLE_ADDFILE
69  };
70  // clang-format on
71 
72  explicit CDVDMsg(Message msg)
73  {
74  m_message = msg;
75  }
76 
77  virtual ~CDVDMsg() = default;
78 
82  inline bool IsType(Message msg)
83  {
84  return (m_message == msg);
85  }
86 
87  inline Message GetMessageType()
88  {
89  return m_message;
90  }
91 
92 private:
93  Message m_message;
94 };
95 
101 
102 #define SYNCSOURCE_AUDIO 0x01
103 #define SYNCSOURCE_VIDEO 0x02
104 #define SYNCSOURCE_PLAYER 0x04
105 #define SYNCSOURCE_ANY 0x08
106 
109 {
110 public:
111  CDVDMsgGeneralSynchronize(std::chrono::milliseconds timeout, unsigned int sources);
112  ~CDVDMsgGeneralSynchronize() override;
113 
114  // waits until all threads waiting, released the object
115  // if abort is set somehow
116  bool Wait(std::chrono::milliseconds ms, unsigned int source);
117  void Wait(std::atomic<bool>& abort, unsigned int source);
118 
119 private:
121 };
122 
123 template <typename T>
124 class CDVDMsgType : public CDVDMsg
125 {
126 public:
127  CDVDMsgType(Message type, const T &value)
128  : CDVDMsg(type)
129  , m_value(value)
130  {}
131 
132  ~CDVDMsgType() override = default;
133 
134  operator T() { return m_value; }
135  T m_value;
136 };
137 
141 
147 
149 {
150 public:
151  explicit CDVDMsgPlayerSetAudioStream(int streamId) : CDVDMsg(PLAYER_SET_AUDIOSTREAM) { m_streamId = streamId; }
152  ~CDVDMsgPlayerSetAudioStream() override = default;
153 
154  int GetStreamId() { return m_streamId; }
155 private:
156  int m_streamId;
157 };
158 
160 {
161 public:
162  explicit CDVDMsgPlayerSetVideoStream(int streamId) : CDVDMsg(PLAYER_SET_VIDEOSTREAM) { m_streamId = streamId; }
163  ~CDVDMsgPlayerSetVideoStream() override = default;
164 
165  int GetStreamId() const { return m_streamId; }
166 private:
167  int m_streamId;
168 };
169 
171 {
172 public:
173  explicit CDVDMsgPlayerSetSubtitleStream(int streamId) : CDVDMsg(PLAYER_SET_SUBTITLESTREAM) { m_streamId = streamId; }
174  ~CDVDMsgPlayerSetSubtitleStream() override = default;
175 
176  int GetStreamId() { return m_streamId; }
177 private:
178  int m_streamId;
179 };
180 
182 {
183 public:
184  explicit CDVDMsgPlayerSetState(const std::string& state) : CDVDMsg(PLAYER_SET_STATE), m_state(state) {}
185  ~CDVDMsgPlayerSetState() override = default;
186 
187  std::string GetState() { return m_state; }
188 private:
189  std::string m_state;
190 };
191 
193 {
194 public:
195  struct CMode
196  {
197  double time = 0;
198  bool relative = false;
199  bool backward = false;
200  bool accurate = true;
201  bool sync = true;
202  bool restore = true;
203  bool trickplay = false;
204  };
205 
206  explicit CDVDMsgPlayerSeek(CDVDMsgPlayerSeek::CMode mode) : CDVDMsg(PLAYER_SEEK),
207  m_mode(mode)
208  {}
209  ~CDVDMsgPlayerSeek() override = default;
210 
211  double GetTime() { return m_mode.time; }
212  bool GetRelative() { return m_mode.relative; }
213  bool GetBackward() { return m_mode.backward; }
214  bool GetAccurate() { return m_mode.accurate; }
215  bool GetRestore() { return m_mode.restore; }
216  bool GetTrickPlay() { return m_mode.trickplay; }
217  bool GetSync() { return m_mode.sync; }
218 
219 private:
220  CMode m_mode;
221 };
222 
224 {
225  public:
226  explicit CDVDMsgPlayerSeekChapter(int iChapter)
227  : CDVDMsg(PLAYER_SEEK_CHAPTER)
228  , m_iChapter(iChapter)
229  {}
230  ~CDVDMsgPlayerSeekChapter() override = default;
231 
232  int GetChapter() const { return m_iChapter; }
233 
234  private:
235 
236  int m_iChapter;
237 };
238 
240 {
241 public:
242  struct SpeedParams
243  {
244  int m_speed;
245  bool m_isTempo;
246  };
247 
248  explicit CDVDMsgPlayerSetSpeed(SpeedParams params)
249  : CDVDMsg(PLAYER_SETSPEED)
250  , m_params(params)
251  {}
252  ~CDVDMsgPlayerSetSpeed() override = default;
253 
254  int GetSpeed() const { return m_params.m_speed; }
255  bool IsTempo() const { return m_params.m_isTempo; }
256 
257 private:
258 
259  SpeedParams m_params;
260 
261 };
262 
263 class CDVDMsgOpenFile : public CDVDMsg
264 {
265 public:
266  struct FileParams
267  {
268  CFileItem m_item;
269  CPlayerOptions m_options;
270  };
271 
272  explicit CDVDMsgOpenFile(const FileParams &params)
273  : CDVDMsg(PLAYER_OPENFILE)
274  , m_params(params)
275  {}
276  ~CDVDMsgOpenFile() override = default;
277 
278  CFileItem& GetItem() { return m_params.m_item; }
279  CPlayerOptions& GetOptions() { return m_params.m_options; }
280 
281 private:
282 
283  FileParams m_params;
284 };
285 
291 
293 {
294 public:
295  CDVDMsgDemuxerPacket(DemuxPacket* packet, bool drop = false);
296  ~CDVDMsgDemuxerPacket() override;
297  DemuxPacket* GetPacket() { return m_packet; }
298  unsigned int GetPacketSize();
299  bool GetPacketDrop() { return m_drop; }
300  DemuxPacket* m_packet;
301  bool m_drop;
302 };
303 
305 {
306 public:
307  CDVDMsgDemuxerReset() : CDVDMsg(DEMUXER_RESET) {}
308  ~CDVDMsgDemuxerReset() override = default;
309 };
310 
311 
312 
318 
319 
325 
327 {
328 public:
329  explicit CDVDMsgSubtitleClutChange(uint8_t* data) : CDVDMsg(SUBTITLE_CLUTCHANGE) { memcpy(m_data, data, 16*4); }
330  ~CDVDMsgSubtitleClutChange() override = default;
331 
332  uint8_t m_data[16][4];
333 };
Definition: DVDMessage.h:292
Definition: DVDMessage.h:20
bool IsType(Message msg)
checks for message type
Definition: DVDMessage.h:82
Definition: DVDMessage.h:192
Definition: DVDMessage.h:170
Definition: DVDMessage.h:181
Definition: DVDMessage.h:223
Definition: DVDMessage.cpp:23
Definition: DVDMessage.h:304
Definition: DVDMessage.h:239
Definition: DVDMessage.h:326
Definition: DVDMessage.h:242
Definition: DVDMessage.h:124
Definition: DVDMessage.h:159
Definition: DemuxPacket.h:22
Definition: DVDMessage.h:266
Definition: DVDMessage.h:195
Definition: DVDMessage.h:108
Definition: DVDMessage.h:263
Definition: IPlayer.h:31
Definition: DVDMessage.h:148
Represents a file on a share.
Definition: FileItem.h:102