kodi
DVDInputStreamBluray.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 "BlurayStateSerializer.h"
12 #include "DVDInputStream.h"
13 
14 #include <list>
15 #include <memory>
16 
17 extern "C"
18 {
19 #include <libbluray/bluray.h>
20 #include <libbluray/bluray-version.h>
21 #include <libbluray/keys.h>
22 #include <libbluray/overlay.h>
23 #include <libbluray/player_settings.h>
24 #include "DVDInputStreamFile.h"
25 }
26 
27 #define MAX_PLAYLIST_ID 99999
28 #define MAX_CLIP_ID 99999
29 #define BD_EVENT_MENU_OVERLAY -1
30 #define BD_EVENT_MENU_ERROR -2
31 #define BD_EVENT_ENC_ERROR -3
32 
33 #define HDMV_PID_VIDEO 0x1011
34 #define HDMV_PID_AUDIO_FIRST 0x1100
35 #define HDMV_PID_AUDIO_LAST 0x111f
36 #define HDMV_PID_PG_FIRST 0x1200
37 #define HDMV_PID_PG_LAST 0x121f
38 #define HDMV_PID_PG_HDR_FIRST 0x12a0
39 #define HDMV_PID_PG_HDR_LAST 0x12bf
40 #define HDMV_PID_IG_FIRST 0x1400
41 #define HDMV_PID_IG_LAST 0x141f
42 
43 class CDVDOverlayImage;
44 class IVideoPlayer;
45 
47  : public CDVDInputStream
52 {
53 public:
54  CDVDInputStreamBluray() = delete;
55  CDVDInputStreamBluray(IVideoPlayer* player, const CFileItem& fileitem);
56  ~CDVDInputStreamBluray() override;
57  bool Open() override;
58  void Close() override;
59  int Read(uint8_t* buf, int buf_size) override;
60  int64_t Seek(int64_t offset, int whence) override;
61  void Abort() override;
62  bool IsEOF() override;
63  int64_t GetLength() override;
64  int GetBlockSize() override { return 6144; }
65  ENextStream NextStream() override;
66 
67 
68  /* IMenus */
69  void ActivateButton() override { UserInput(BD_VK_ENTER); }
70  void SelectButton(int iButton) override
71  {
72  if(iButton < 10)
73  UserInput((bd_vk_key_e)(BD_VK_0 + iButton));
74  }
75  int GetCurrentButton() override { return 0; }
76  int GetTotalButtons() override { return 0; }
77  void OnUp() override { UserInput(BD_VK_UP); }
78  void OnDown() override { UserInput(BD_VK_DOWN); }
79  void OnLeft() override { UserInput(BD_VK_LEFT); }
80  void OnRight() override { UserInput(BD_VK_RIGHT); }
81 
85  bool OnMenu() override;
86  void OnBack() override
87  {
88  if(IsInMenu())
89  OnMenu();
90  }
91  void OnNext() override {}
92  void OnPrevious() override {}
93 
98  MenuType GetSupportedMenuType() override;
99 
100  bool IsInMenu() override;
101  bool OnMouseMove(const CPoint &point) override { return MouseMove(point); }
102  bool OnMouseClick(const CPoint &point) override { return MouseClick(point); }
103  void SkipStill() override;
104  bool GetState(std::string& xmlstate) override;
105  bool SetState(const std::string& xmlstate) override;
106  bool CanSeek() override;
107 
108 
109  void UserInput(bd_vk_key_e vk);
110  bool MouseMove(const CPoint &point);
111  bool MouseClick(const CPoint &point);
112 
113  int GetChapter() override;
114  int GetChapterCount() override;
115  void GetChapterName(std::string& name, int ch=-1) override {};
116  int64_t GetChapterPos(int ch) override;
117  bool SeekChapter(int ch) override;
118 
119  CDVDInputStream::IDisplayTime* GetIDisplayTime() override { return this; }
120  int GetTotalTime() override;
121  int GetTime() override;
122 
123  CDVDInputStream::IPosTime* GetIPosTime() override { return this; }
124  bool PosTime(int ms) override;
125 
126  void GetStreamInfo(int pid, std::string &language);
127 
128  void OverlayCallback(const BD_OVERLAY * const);
129 #ifdef HAVE_LIBBLURAY_BDJ
130  void OverlayCallbackARGB(const struct bd_argb_overlay_s * const);
131 #endif
132 
133  BLURAY_TITLE_INFO* GetTitleLongest();
134  BLURAY_TITLE_INFO* GetTitleFile(const std::string& name);
135 
136  void ProcessEvent();
137 
138 protected:
139  struct SPlane;
140 
141  void OverlayFlush(int64_t pts);
142  void OverlayClose();
143  static void OverlayClear(SPlane& plane, int x, int y, int w, int h);
144  static void OverlayInit (SPlane& plane, int w, int h);
145 
146  IVideoPlayer* m_player = nullptr;
147  BLURAY* m_bd = nullptr;
148  const BLURAY_TITLE* m_title = nullptr;
149  BLURAY_TITLE_INFO* m_titleInfo = nullptr;
150  uint32_t m_playlist = MAX_PLAYLIST_ID + 1;
151  BLURAY_CLIP_INFO* m_clip = nullptr;
152  uint32_t m_angle = 0;
153  bool m_menu = false;
154  bool m_isInMainMenu = false;
155  bool m_hasOverlay = false;
156  bool m_navmode = false;
157  int m_dispTimeBeforeRead = 0;
158 
159  typedef std::shared_ptr<CDVDOverlayImage> SOverlay;
160  typedef std::list<SOverlay> SOverlays;
161 
162  struct SPlane
163  {
164  SOverlays o;
165  int w = 0;
166  int h = 0;
167  };
168 
169  SPlane m_planes[2];
170  enum EHoldState {
171  HOLD_NONE = 0,
172  HOLD_HELD,
173  HOLD_DATA,
174  HOLD_STILL,
175  HOLD_ERROR,
176  HOLD_EXIT
177  } m_hold = HOLD_NONE;
178  BD_EVENT m_event;
179 #ifdef HAVE_LIBBLURAY_BDJ
180  struct bd_argb_buffer_s m_argb;
181 #endif
182 
183  private:
184  bool OpenStream(CFileItem &item);
185  void SetupPlayerSettings();
186  void FreeTitleInfo();
187  std::unique_ptr<CDVDInputStreamFile> m_pstream;
188  std::string m_rootPath;
189 
191  CBlurayStateSerializer m_blurayStateSerializer;
192 };
Definition: IVideoPlayer.h:28
Definition: DVDInputStream.h:50
Definition: DVDInputStream.h:54
Definition: DVDInputStreamBluray.h:162
Definition: DVDInputStream.h:83
Auxiliar class to serialize/deserialize the Bluray state (into/from XML)
Definition: BlurayStateSerializer.h:22
Definition: DVDInputStreamBluray.h:46
Definition: DVDOverlayImage.h:18
Definition: DVDInputStream.h:94
MenuType GetSupportedMenuType() override
Get the supported menu type.
Definition: DVDInputStreamBluray.cpp:1193
bool OnMenu() override
Open the Menu.
Definition: DVDInputStreamBluray.cpp:1127
Definition: DVDInputStream.h:76
Represents a file on a share.
Definition: FileItem.h:102