summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h150
1 files changed, 150 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h
new file mode 100644
index 0000000..e0dc881
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_inputstream.h
@@ -0,0 +1,150 @@
1/*
2 * Copyright (C) 2005-2016 Team XBMC
3 * http://www.xbmc.org
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#pragma once
22
23#include <string>
24#include <vector>
25#include <string.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include "libXBMC_addon.h"
29
30#ifdef BUILD_KODI_ADDON
31#include "DVDDemuxPacket.h"
32#else
33#include "cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h"
34#endif
35
36#ifdef _WIN32
37#define INPUTSTREAM_HELPER_DLL "\\library.kodi.inputstream\\libKODI_inputstream" ADDON_HELPER_EXT
38#else
39#define INPUTSTREAM_HELPER_DLL_NAME "libKODI_inputstream-" ADDON_HELPER_ARCH ADDON_HELPER_EXT
40#define INPUTSTREAM_HELPER_DLL "/library.kodi.inputstream/" INPUTSTREAM_HELPER_DLL_NAME
41#endif
42
43class CHelper_libKODI_inputstream
44{
45public:
46 CHelper_libKODI_inputstream(void)
47 {
48 m_libKODI_inputstream = nullptr;
49 m_Handle = nullptr;
50 }
51
52 ~CHelper_libKODI_inputstream(void)
53 {
54 if (m_libKODI_inputstream)
55 {
56 INPUTSTREAM_unregister_me(m_Handle, m_Callbacks);
57 dlclose(m_libKODI_inputstream);
58 }
59 }
60
61 /*!
62 * @brief Resolve all callback methods
63 * @param handle Pointer to the add-on
64 * @return True when all methods were resolved, false otherwise.
65 */
66 bool RegisterMe(void* handle)
67 {
68 m_Handle = handle;
69
70 std::string libBasePath;
71 libBasePath = ((cb_array*)m_Handle)->libPath;
72 libBasePath += INPUTSTREAM_HELPER_DLL;
73
74 m_libKODI_inputstream = dlopen(libBasePath.c_str(), RTLD_LAZY);
75 if (m_libKODI_inputstream == nullptr)
76 {
77 fprintf(stderr, "Unable to load %s\n", dlerror());
78 return false;
79 }
80
81 INPUTSTREAM_register_me = (void* (*)(void *HANDLE))
82 dlsym(m_libKODI_inputstream, "INPUTSTREAM_register_me");
83 if (INPUTSTREAM_register_me == nullptr)
84 {
85 fprintf(stderr, "Unable to assign function %s\n", dlerror());
86 return false;
87 }
88
89 INPUTSTREAM_unregister_me = (void (*)(void* HANDLE, void* CB))
90 dlsym(m_libKODI_inputstream, "INPUTSTREAM_unregister_me");
91 if (INPUTSTREAM_unregister_me == nullptr)
92 {
93 fprintf(stderr, "Unable to assign function %s\n", dlerror());
94 return false;
95 }
96
97 INPUTSTREAM_free_demux_packet = (void (*)(void* HANDLE, void* CB, DemuxPacket* pPacket))
98 dlsym(m_libKODI_inputstream, "INPUTSTREAM_free_demux_packet");
99 if (INPUTSTREAM_free_demux_packet == NULL)
100 {
101 fprintf(stderr, "Unable to assign function %s\n", dlerror());
102 return false;
103 }
104
105 INPUTSTREAM_allocate_demux_packet = (DemuxPacket* (*)(void* HANDLE, void* CB, int iDataSize))
106 dlsym(m_libKODI_inputstream, "INPUTSTREAM_allocate_demux_packet");
107 if (INPUTSTREAM_allocate_demux_packet == NULL)
108 {
109 fprintf(stderr, "Unable to assign function %s\n", dlerror());
110 return false;
111 }
112
113 m_Callbacks = INPUTSTREAM_register_me(m_Handle);
114 return m_Callbacks != nullptr;
115 }
116
117 /*!
118 * @brief Allocate a demux packet. Free with FreeDemuxPacket
119 * @param iDataSize The size of the data that will go into the packet
120 * @return The allocated packet
121 */
122 DemuxPacket* AllocateDemuxPacket(int iDataSize)
123 {
124 return INPUTSTREAM_allocate_demux_packet(m_Handle, m_Callbacks, iDataSize);
125 }
126
127 /*!
128 * @brief Free a packet that was allocated with AllocateDemuxPacket
129 * @param pPacket The packet to free
130 */
131 void FreeDemuxPacket(DemuxPacket* pPacket)
132 {
133 return INPUTSTREAM_free_demux_packet(m_Handle, m_Callbacks, pPacket);
134 }
135
136protected:
137 void* (*INPUTSTREAM_register_me)(void*);
138 void (*INPUTSTREAM_unregister_me)(void*, void*);
139 void (*INPUTSTREAM_free_demux_packet)(void*, void*, DemuxPacket*);
140 DemuxPacket* (*INPUTSTREAM_allocate_demux_packet)(void*, void*, int);
141
142private:
143 void* m_libKODI_inputstream;
144 void* m_Handle;
145 void* m_Callbacks;
146 struct cb_array
147 {
148 const char* libPath;
149 };
150};