summaryrefslogtreecommitdiff
path: root/config.c
blob: 9fdc834e23269f7168778efa28b5b3f83091ff59 (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
//////////////////////////////////////////////////////////////////////////////
///                                                                        ///
/// This file is part of the VDR mpv plugin and licensed under AGPLv3      ///
///                                                                        ///
/// See the README file for copyright information                          ///
///                                                                        ///
//////////////////////////////////////////////////////////////////////////////

#include <stdlib.h>
#include <unistd.h>
#include <sstream>
#include <vdr/tools.h>

#include "config.h"

cMpvPluginConfig::cMpvPluginConfig()
{
  HideMainMenuEntry = 0;
  UsePassthrough = 1;
  UseDtsHdPassthrough = 1;
  StereoDownmix = 0;
  PlaylistOnNextKey = 0;
  PlaylistIfNoChapters = 1;
  ShowMediaTitle = 0;

  BrowserRoot = "/";
  RefreshRate = 0;
  VideoOut = "vdpau";
  HwDec = "vdpau";
  AudioOut = "alsa:device=default";
  DiscDevice = "/dev/dvd";
  Languages = "deu,de,ger,eng,en";
  PlayListExtString = "m3u,ini,pls,txt,playlist";

  X11Display = ":0.0";
}

vector<string> cMpvPluginConfig::ExplodeString(string Input)
{
  vector<string> Result;

  std::stringstream Data(Input);
  string Item;
  while(std::getline(Data, Item, ','))
  {
    if (Item != "")
      Result.push_back(Item);
  }
  return Result;
}

int cMpvPluginConfig::ProcessArgs(int argc, char *const argv[])
{
  char *s;
  if ((s = getenv("DISPLAY")))
  {
    X11Display = s;
  }
  else
    setenv("DISPLAY", X11Display.c_str(), 1);

  for (;;)
  {
    switch (getopt(argc, argv, "a:v:h:d:b:l:x:r"))
    {
      case 'a': // audio out
        AudioOut = optarg;
      continue;
      case 'v': // video out
        VideoOut = optarg;
      continue;
      case 'h': // hwdec-codecs
        HwDec = optarg;
      continue;
      case 'd': // dvd-device
        DiscDevice = optarg;
      continue;
      case 'b': // browser root
        BrowserRoot = optarg;
      continue;
      case 'l':  // languages
        Languages = optarg;
      continue;
      case 'x':  // playlist extensions
        PlayListExtString = optarg;
      continue;
      case 'r': // refresh rate
        RefreshRate = 1;
      continue;
      case EOF:
      break;
      case ':':
        esyslog("[mpv]: missing argument for option '%c'\n", optopt);
        return 0;
      default:
        esyslog("[mpv]: unkown option '%c'\n", optopt);
        return 0;
    }
    break;
  }
  while (optind < argc)
  {
    esyslog("[mpv]: unhandled argument '%s'\n", argv[optind++]);
  }

  //convert the playlist extension string to a vector
  PlaylistExtensions = ExplodeString(PlayListExtString);

  return 1;
}

const char *cMpvPluginConfig::CommandLineHelp(void)
{
  return
    "  -a audio\tmpv --ao (Default: alsa:device=default)\n"
    "  -v video\tmpv --vo (Default: vdpau)\n"
    "  -h hwdec\tmpv --hwdec-codecs (Default: vdpau)\n"
    "  -d device\tmpv optical disc device (Default: /dev/dvd)\n"
    "  -l languages\tlanguages for audio and subtitles (Default: deu,de,ger,eng,en)\n"
    "  -b /dir\tbrowser root directory\n"
    "  -x extensions\tfiles with this extensions are handled as playlists\n"
    "\t\t(Default: m3u,ini,pls,txt,playlist)\n"
#ifdef USE_XRANDR
    "  -r\t\tswitch modeline to refresh rate of played file\n"
#endif
    ;
}

bool cMpvPluginConfig::SetupParse(const char *name, const char *value)
{
  if (!strcasecmp(name, "HideMainMenuEntry"))
    HideMainMenuEntry = atoi(value);
  else if (!strcasecmp(name, "UsePassthrough"))
    UsePassthrough = atoi(value);
  else if (!strcasecmp(name, "StereoDownmix"))
    StereoDownmix = atoi(value);
  else if (!strcasecmp(name, "UseDtsHdPassthrough"))
    UseDtsHdPassthrough = atoi(value);
  else if (!strcasecmp(name, "PlaylistOnNextKey"))
    PlaylistOnNextKey = atoi(value);
  else if (!strcasecmp(name, "PlaylistIfNoChapters"))
    PlaylistIfNoChapters = atoi(value);
  else if (!strcasecmp(name, "ShowMediaTitle"))
    ShowMediaTitle = atoi(value);
  else
    return false;
  return true;
}