summaryrefslogtreecommitdiffstats
path: root/xbmc/cores/VideoPlayer/DVDMessage.h
blob: 5b1dcf760271ea3a1f7b54f5a4d3b5f04a7ee993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "FileItem.h"
#include "cores/IPlayer.h"

#include <atomic>
#include <string.h>
#include <string>

struct DemuxPacket;

class CDVDMsg
{
public:
  // clang-format off
  enum Message
  {
    NONE = 1000,

    // messages used in the whole system
    GENERAL_RESYNC,                 //
    GENERAL_FLUSH,                  // flush all buffers
    GENERAL_RESET,                  // reset codecs for new data
    GENERAL_PAUSE,
    GENERAL_STREAMCHANGE,           //
    GENERAL_SYNCHRONIZE,            //
    GENERAL_GUI_ACTION,             // gui action of some sort
    GENERAL_EOF,                    // eof of stream

    // player core related messages (cVideoPlayer.cpp)
    PLAYER_SET_AUDIOSTREAM,         //
    PLAYER_SET_VIDEOSTREAM,         //
    PLAYER_SET_SUBTITLESTREAM,      //
    PLAYER_SET_SUBTITLESTREAM_VISIBLE, //
    PLAYER_SET_STATE,               // restore the VideoPlayer to a certain state
    PLAYER_SET_PROGRAM,
    PLAYER_SET_UPDATE_STREAM_DETAILS, // player should update file item stream details with its current streams
    PLAYER_SEEK,                    //
    PLAYER_SEEK_CHAPTER,            //
    PLAYER_SETSPEED,                // set the playback speed
    PLAYER_REQUEST_STATE,
    PLAYER_OPENFILE,
    PLAYER_STARTED,                 // sent whenever a sub player has finished it's first frame after open
    PLAYER_AVCHANGE,                // signal a change in audio, video or subtitle parameters
    PLAYER_ABORT,
    PLAYER_REPORT_STATE,
    PLAYER_FRAME_ADVANCE,
    PLAYER_DISPLAY_RESET,           // report display reset event

    // demuxer related messages
    DEMUXER_PACKET,                 // data packet
    DEMUXER_RESET,                  // reset the demuxer

    // video related messages
    VIDEO_SET_ASPECT,               // set aspectratio of video
    VIDEO_DRAIN,                    // wait for decoder to output last frame

    // subtitle related messages
    SUBTITLE_CLUTCHANGE,
    SUBTITLE_ADDFILE
  };
  // clang-format on

  explicit CDVDMsg(Message msg)
  {
    m_message = msg;
  }

  virtual ~CDVDMsg() = default;

  /**
   * checks for message type
   */
  inline bool IsType(Message msg)
  {
    return (m_message == msg);
  }

  inline Message GetMessageType()
  {
    return m_message;
  }

private:
  Message m_message;
};

////////////////////////////////////////////////////////////////////////////////
//////
////// GENERAL_ Messages
//////
////////////////////////////////////////////////////////////////////////////////

#define SYNCSOURCE_AUDIO  0x01
#define SYNCSOURCE_VIDEO  0x02
#define SYNCSOURCE_PLAYER 0x04
#define SYNCSOURCE_ANY    0x08

class CDVDMsgGeneralSynchronizePriv;
class CDVDMsgGeneralSynchronize : public CDVDMsg
{
public:
  CDVDMsgGeneralSynchronize(std::chrono::milliseconds timeout, unsigned int sources);
  ~CDVDMsgGeneralSynchronize() override;

  // waits until all threads waiting, released the object
  // if abort is set somehow
  bool Wait(std::chrono::milliseconds ms, unsigned int source);
  void Wait(std::atomic<bool>& abort, unsigned int source);

private:
  class CDVDMsgGeneralSynchronizePriv* m_p;
};

template <typename T>
class CDVDMsgType : public CDVDMsg
{
public:
  CDVDMsgType(Message type, const T &value)
    : CDVDMsg(type)
    , m_value(value)
  {}

  ~CDVDMsgType() override = default;

  operator T() { return m_value; }
  T m_value;
};

typedef CDVDMsgType<bool> CDVDMsgBool;
typedef CDVDMsgType<int> CDVDMsgInt;
typedef CDVDMsgType<double> CDVDMsgDouble;

////////////////////////////////////////////////////////////////////////////////
//////
////// PLAYER_ Messages
//////
////////////////////////////////////////////////////////////////////////////////

class CDVDMsgPlayerSetAudioStream : public CDVDMsg
{
public:
  explicit CDVDMsgPlayerSetAudioStream(int streamId) : CDVDMsg(PLAYER_SET_AUDIOSTREAM) { m_streamId = streamId; }
  ~CDVDMsgPlayerSetAudioStream() override = default;

  int GetStreamId() { return m_streamId; }
private:
  int m_streamId;
};

class CDVDMsgPlayerSetVideoStream : public CDVDMsg
{
public:
  explicit CDVDMsgPlayerSetVideoStream(int streamId) : CDVDMsg(PLAYER_SET_VIDEOSTREAM) { m_streamId = streamId; }
  ~CDVDMsgPlayerSetVideoStream() override = default;

  int GetStreamId() const { return m_streamId; }
private:
  int m_streamId;
};

class CDVDMsgPlayerSetSubtitleStream : public CDVDMsg
{
public:
  explicit CDVDMsgPlayerSetSubtitleStream(int streamId) : CDVDMsg(PLAYER_SET_SUBTITLESTREAM) { m_streamId = streamId; }
  ~CDVDMsgPlayerSetSubtitleStream() override = default;

  int GetStreamId() { return m_streamId; }
private:
  int m_streamId;
};

class CDVDMsgPlayerSetState : public CDVDMsg
{
public:
  explicit CDVDMsgPlayerSetState(const std::string& state) : CDVDMsg(PLAYER_SET_STATE), m_state(state) {}
  ~CDVDMsgPlayerSetState() override = default;

  std::string GetState() { return m_state; }
private:
  std::string m_state;
};

class CDVDMsgPlayerSeek : public CDVDMsg
{
public:
  struct CMode
  {
    double time = 0;
    bool relative = false;
    bool backward = false;
    bool accurate = true;
    bool sync = true;
    bool restore = true;
    bool trickplay = false;
  };

  explicit CDVDMsgPlayerSeek(CDVDMsgPlayerSeek::CMode mode) : CDVDMsg(PLAYER_SEEK),
    m_mode(mode)
  {}
  ~CDVDMsgPlayerSeek() override = default;

  double GetTime() { return m_mode.time; }
  bool GetRelative() { return m_mode.relative; }
  bool GetBackward() { return m_mode.backward; }
  bool GetAccurate() { return m_mode.accurate; }
  bool GetRestore() { return m_mode.restore; }
  bool GetTrickPlay() { return m_mode.trickplay; }
  bool GetSync() { return m_mode.sync; }

private:
  CMode m_mode;
};

class CDVDMsgPlayerSeekChapter : public CDVDMsg
{
  public:
    explicit CDVDMsgPlayerSeekChapter(int iChapter)
      : CDVDMsg(PLAYER_SEEK_CHAPTER)
      , m_iChapter(iChapter)
    {}
    ~CDVDMsgPlayerSeekChapter() override = default;

    int GetChapter() const { return m_iChapter; }

  private:

    int m_iChapter;
};

class CDVDMsgPlayerSetSpeed : public CDVDMsg
{
public:
  struct SpeedParams
  {
    int m_speed;
    bool m_isTempo;
  };

  explicit CDVDMsgPlayerSetSpeed(SpeedParams params)
  : CDVDMsg(PLAYER_SETSPEED)
  , m_params(params)
  {}
  ~CDVDMsgPlayerSetSpeed() override = default;

  int GetSpeed() const { return m_params.m_speed; }
  bool IsTempo() const { return m_params.m_isTempo; }

private:

  SpeedParams m_params;

};

class CDVDMsgOpenFile : public CDVDMsg
{
public:
  struct FileParams
  {
    CFileItem m_item;
    CPlayerOptions m_options;
  };

  explicit CDVDMsgOpenFile(const FileParams &params)
  : CDVDMsg(PLAYER_OPENFILE)
  , m_params(params)
  {}
  ~CDVDMsgOpenFile() override = default;

  CFileItem& GetItem() { return m_params.m_item; }
  CPlayerOptions& GetOptions() { return m_params.m_options; }

private:

  FileParams m_params;
};

////////////////////////////////////////////////////////////////////////////////
//////
////// DEMUXER_ Messages
//////
////////////////////////////////////////////////////////////////////////////////

class CDVDMsgDemuxerPacket : public CDVDMsg
{
public:
  CDVDMsgDemuxerPacket(DemuxPacket* packet, bool drop = false);
  ~CDVDMsgDemuxerPacket() override;
  DemuxPacket* GetPacket() { return m_packet; }
  unsigned int GetPacketSize();
  bool GetPacketDrop() { return m_drop; }
  DemuxPacket* m_packet;
  bool m_drop;
};

class CDVDMsgDemuxerReset : public CDVDMsg
{
public:
  CDVDMsgDemuxerReset() : CDVDMsg(DEMUXER_RESET)  {}
  ~CDVDMsgDemuxerReset() override = default;
};



////////////////////////////////////////////////////////////////////////////////
//////
////// VIDEO_ Messages
//////
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
//////
////// SUBTITLE_ Messages
//////
////////////////////////////////////////////////////////////////////////////////

class CDVDMsgSubtitleClutChange : public CDVDMsg
{
public:
  explicit CDVDMsgSubtitleClutChange(uint8_t* data) : CDVDMsg(SUBTITLE_CLUTCHANGE) { memcpy(m_data, data, 16*4); }
  ~CDVDMsgSubtitleClutChange() override = default;

  uint8_t m_data[16][4];
};