-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmpv.c
243 lines (225 loc) · 7.14 KB
/
mpv.c
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
//////////////////////////////////////////////////////////////////////////////
/// ///
/// This file is part of the VDR mpv plugin and licensed under AGPLv3 ///
/// ///
/// See the README file for copyright information ///
/// ///
//////////////////////////////////////////////////////////////////////////////
#include <string>
#include <vdr/plugin.h>
// set this define to create the instance of the config class
#define CREATE_CONFIG 1
#include "config.h"
#include "control.h"
#include "filebrowser.h"
#include "setup.h"
#include "player.h"
#include "menu_options.h"
#include "mpv_service.h"
static const char *VERSION = "1.8.1"
#ifdef GIT_REV
"-GIT" GIT_REV
#endif
;
using std::string;
static const char *DESCRIPTION = trNOOP("mpv player plugin");
class cMpvPlugin:public cPlugin
{
private:
void PlayFile(string Filename, bool Shuffle=false);
bool IsIsoImage(string Filename);
void PlayFileHandleType(string Filename, bool Shuffle=false);
public:
cMpvPlugin(void);
virtual ~cMpvPlugin(void);
virtual const char *Version(void) { return VERSION; }
virtual const char *Description(void) { return tr(DESCRIPTION); }
virtual const char *CommandLineHelp(void) { return MpvPluginConfig->CommandLineHelp(); }
virtual bool ProcessArgs(int argc, char *argv[]) { return MpvPluginConfig->ProcessArgs(argc, argv); }
virtual bool Initialize(void);
virtual void MainThreadHook(void) {}
virtual const char *MainMenuEntry(void) { return MpvPluginConfig->HideMainMenuEntry ? NULL : MpvPluginConfig->MainMenuEntry.c_str(); }
virtual cOsdObject *MainMenuAction(void);
virtual cMenuSetupPage *SetupMenu(void) { return new cMpvPluginSetup; }
virtual bool SetupParse(const char *Name, const char *Value) { return MpvPluginConfig->SetupParse(Name, Value); }
virtual bool Service(const char *Id, void *Data = NULL);
virtual const char **SVDRPHelpPages(void) { return NULL; }
virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplayCode);
};
bool cMpvPlugin::Initialize(void)
{
if (MpvPluginConfig->SavePos)
{
DIR *hDir;
string watch_later = PLGRESDIR;
watch_later += "/watch_later";
hDir = opendir(watch_later.c_str());
if (!hDir)
esyslog("[mpv] No directory %s, mpv can't resume play!\n", watch_later.c_str());
else
closedir(hDir);
}
return true;
}
void cMpvPlugin::PlayFile(string Filename, bool Shuffle)
{
if (!cMpvPlayer::PlayerIsRunning())
cControl::Launch(new cMpvControl(Filename.c_str(), Shuffle));
else
{
#if APIVERSNUM < 20402
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(true));
#else
cMutexLock ControlMutexLock;
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(ControlMutexLock, true));
#endif
if(control)
control->PlayNew(Filename.c_str());
}
}
cMpvPlugin::cMpvPlugin(void)
{
MpvPluginConfig = new cMpvPluginConfig();
}
cMpvPlugin::~cMpvPlugin(void)
{
delete MpvPluginConfig;
}
cOsdObject *cMpvPlugin::MainMenuAction(void)
{
if (cMpvPlayer::PlayerIsRunning())
{
if (!MpvPluginConfig->ShowOptions)
return new cMpvFilebrowser(MpvPluginConfig->BrowserRoot, MpvPluginConfig->DiscDevice);
else
if (cMpvPlayer::Player()->NetworkPlay())
return new cMpvMenuPlaylist(cMpvPlayer::Player());
else
return new cMpvMenuOptions(cMpvPlayer::Player());
}
return new cMpvFilebrowser(MpvPluginConfig->BrowserRoot, MpvPluginConfig->DiscDevice);
}
bool cMpvPlugin::Service(const char *id, void *data)
{
#if APIVERSNUM >= 20402
cMutexLock ControlMutexLock;
#endif
if (strcmp(id, "Mpv_Seek") == 0)
{
Mpv_Seek *seekInfo = (Mpv_Seek *)data;
#if APIVERSNUM < 20402
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(true));
#else
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(ControlMutexLock, true));
#endif
if(control)
{
if(seekInfo->SeekRelative != 0)
{
control->SeekRelative(seekInfo->SeekRelative);
}
else if(seekInfo->SeekAbsolute >= 0)
{
control->SeekTo(seekInfo->SeekAbsolute);
}
}
return true;
}
if (strcmp(id, "ScaleVideo") == 0)
{
Mpv_ScaleVideo *scaleVideo = (Mpv_ScaleVideo *)data;
#if APIVERSNUM < 20402
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(true));
#else
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(ControlMutexLock, true));
#endif
if(control)
{
control->ScaleVideo(scaleVideo->x, scaleVideo->y, scaleVideo->width, scaleVideo->height);
}
return true;
}
if (strcmp(id, "GrabImage") == 0)
{
Mpv_GrabImage *grabImage = (Mpv_GrabImage *)data;
#if APIVERSNUM < 20402
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(true));
#else
cMpvControl* control = dynamic_cast<cMpvControl*>(cControl::Control(ControlMutexLock, true));
#endif
if(control)
{
grabImage->image = control->GrabImage(&grabImage->size, &grabImage->width, &grabImage->height);
}
return true;
}
if (strcmp(id, "Mpv_PlayFile") == 0)
{
Mpv_PlayFile *playFile = (Mpv_PlayFile *)data;
PlayFileHandleType(playFile->Filename);
return true;
}
if (strcmp(id, "Mpv_PlaylistShuffle") == 0)
{
Mpv_PlaylistShuffle *shuffleFile = (Mpv_PlaylistShuffle *)data;
PlayFileHandleType(shuffleFile->Filename, true);
return true;
}
if (strcmp(id, "Mpv_SetTitle") == 0)
{
Mpv_SetTitle *setTitle = (Mpv_SetTitle *) data;
MpvPluginConfig->TitleOverride = setTitle->Title;
return true;
}
if (strcmp(id, MPV_START_PLAY_SERVICE) == 0)
{
Mpv_StartPlayService_v1_0_t *r = (Mpv_StartPlayService_v1_0_t *) data;
PlayFileHandleType(r->Filename);
return true;
}
if (strcmp(id, MPV_SET_TITLE_SERVICE) == 0)
{
Mpv_SetTitleService_v1_0_t *r = (Mpv_SetTitleService_v1_0_t *) data;
MpvPluginConfig->TitleOverride = r->Title;
return true;
}
return false;
}
cString cMpvPlugin::SVDRPCommand(const char *Command, const char *Option, int &ReplayCode)
{
#ifdef DEBUG
dsyslog ("Command %s Option %s\n", Command, Option);
#endif
if (strcasecmp(Command, "PLAY") == 0)
{
PlayFileHandleType(Option);
cControl::Attach();
return "starting player";
}
return NULL;
}
bool cMpvPlugin::IsIsoImage(string Filename)
{
vector<string> IsoExtensions;
IsoExtensions.push_back("bin");
IsoExtensions.push_back("dvd");
IsoExtensions.push_back("img");
IsoExtensions.push_back("iso");
IsoExtensions.push_back("mdf");
IsoExtensions.push_back("nrg");
for (unsigned int i=0;i<IsoExtensions.size();i++)
{
if (Filename.substr(Filename.find_last_of(".") + 1) == IsoExtensions[i])
return true;
}
return false;
}
void cMpvPlugin::PlayFileHandleType(string Filename, bool Shuffle)
{
if (IsIsoImage(Filename.c_str())) // handle dvd iso images
{
Filename = "dvd://menu/" + Filename;
}
PlayFile(Filename, Shuffle);
}
VDRPLUGINCREATOR(cMpvPlugin); // Don't touch this!