aboutsummaryrefslogtreecommitdiff
path: root/lib/addons/library.kodi.adsp/libKODI_adsp.cpp
blob: e7cbd2ea811bc98880e3c9408104cde08a96b667 (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
/*
 *      Copyright (C) 2013-2014 Team KODI
 *      http://kodi.tv
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with KODI; see the file COPYING.  If not, see
 *  <http://www.gnu.org/licenses/>.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string>
#include "addons/kodi-addon-dev-kit/include/kodi/libKODI_adsp.h"
#include "addons/binary/interfaces/api1/AudioDSP/AddonCallbacksAudioDSP.h"

#ifdef _WIN32
#include <windows.h>
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

using namespace std;
using namespace KodiAPI::V1::AudioDSP;

extern "C"
{

DLLEXPORT void* ADSP_register_me(void *hdl)
{
  CB_ADSPLib *cb = NULL;
  if (!hdl)
    fprintf(stderr, "libKODI_adsp-ERROR: ADSPLib_register_me is called with NULL handle !!!\n");
  else
  {
    cb = (CB_ADSPLib*)((AddonCB*)hdl)->ADSPLib_RegisterMe(((AddonCB*)hdl)->addonData);
    if (!cb)
      fprintf(stderr, "libKODI_adsp-ERROR: ADSPLib_register_me can't get callback table from KODI !!!\n");
  }
  return cb;
}

DLLEXPORT void ADSP_unregister_me(void *hdl, void* cb)
{
  if (hdl && cb)
    ((AddonCB*)hdl)->ADSPLib_UnRegisterMe(((AddonCB*)hdl)->addonData, (CB_ADSPLib*)cb);
}

DLLEXPORT void ADSP_add_menu_hook(void *hdl, void* cb, AE_DSP_MENUHOOK *hook)
{
  if (cb == NULL)
    return;

  ((CB_ADSPLib*)cb)->AddMenuHook(((AddonCB*)hdl)->addonData, hook);
}

DLLEXPORT void ADSP_remove_menu_hook(void *hdl, void* cb, AE_DSP_MENUHOOK *hook)
{
  if (cb == NULL)
    return;

  ((CB_ADSPLib*)cb)->RemoveMenuHook(((AddonCB*)hdl)->addonData, hook);
}

DLLEXPORT void ADSP_register_mode(void *hdl, void* cb, AE_DSP_MODES::AE_DSP_MODE *mode)
{
  if (cb == NULL)
    return;

  ((CB_ADSPLib*)cb)->RegisterMode(((AddonCB*)hdl)->addonData, mode);
}

DLLEXPORT void ADSP_unregister_mode(void *hdl, void* cb, AE_DSP_MODES::AE_DSP_MODE *mode)
{
  if (cb == NULL)
    return;

  ((CB_ADSPLib*)cb)->UnregisterMode(((AddonCB*)hdl)->addonData, mode);
}

///-------------------------------------
/// CAddonSoundPlay

DLLEXPORT CAddonSoundPlay* ADSP_get_sound_play(void *hdl, void *cb, const char *filename)
{
  return new CAddonSoundPlay(hdl, cb, filename);
}

DLLEXPORT void ADSP_release_sound_play(CAddonSoundPlay* p)
{
  delete p;
}

CAddonSoundPlay::CAddonSoundPlay(void *hdl, void *cb, const char *filename)
 : m_Filename(filename),
   m_Handle(hdl),
   m_cb(cb)
{
  m_PlayHandle = NULL;
  if (!hdl || !cb)
    fprintf(stderr, "libKODI_adsp-ERROR: ADSP_get_sound_play is called with NULL handle !!!\n");
  else
  {
    m_PlayHandle = ((CB_ADSPLib*)m_cb)->SoundPlay_GetHandle(((AddonCB*)m_Handle)->addonData, m_Filename.c_str());
    if (!m_PlayHandle)
      fprintf(stderr, "libKODI_adsp-ERROR: ADSP_get_sound_play can't get callback table from KODI !!!\n");
  }
}

CAddonSoundPlay::~CAddonSoundPlay()
{
  if (m_PlayHandle)
    ((CB_ADSPLib*)m_cb)->SoundPlay_ReleaseHandle(((AddonCB*)m_Handle)->addonData, m_PlayHandle);
}

void CAddonSoundPlay::Play()
{
  if (m_PlayHandle)
    ((CB_ADSPLib*)m_cb)->SoundPlay_Play(((AddonCB*)m_Handle)->addonData, m_PlayHandle);
}

void CAddonSoundPlay::Stop()
{
  if (m_PlayHandle)
    ((CB_ADSPLib*)m_cb)->SoundPlay_Stop(((AddonCB*)m_Handle)->addonData, m_PlayHandle);
}

bool CAddonSoundPlay::IsPlaying()
{
  if (!m_PlayHandle)
    return false;

  return ((CB_ADSPLib*)m_cb)->SoundPlay_IsPlaying(((AddonCB*)m_Handle)->addonData, m_PlayHandle);
}

void CAddonSoundPlay::SetChannel(AE_DSP_CHANNEL channel)
{
  if (m_PlayHandle)
    ((CB_ADSPLib*)m_cb)->SoundPlay_SetChannel(((AddonCB*)m_Handle)->addonData, m_PlayHandle, channel);
}

AE_DSP_CHANNEL CAddonSoundPlay::GetChannel()
{
  if (!m_PlayHandle)
    return AE_DSP_CH_INVALID;
  return ((CB_ADSPLib*)m_cb)->SoundPlay_GetChannel(((AddonCB*)m_Handle)->addonData, m_PlayHandle);
}

void CAddonSoundPlay::SetVolume(float volume)
{
  if (m_PlayHandle)
    ((CB_ADSPLib*)m_cb)->SoundPlay_SetVolume(((AddonCB*)m_Handle)->addonData, m_PlayHandle, volume);
}

float CAddonSoundPlay::GetVolume()
{
  if (!m_PlayHandle)
    return 0.0f;

  return ((CB_ADSPLib*)m_cb)->SoundPlay_GetVolume(((AddonCB*)m_Handle)->addonData, m_PlayHandle);
}

};