-
Notifications
You must be signed in to change notification settings - Fork 3
Plugin for controlling vdr via DBus as an alternative to SVDRP
License
flensrocker/vdr-plugin-dbus2vdr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a "plugin" for the Video Disk Recorder (VDR). Written by: Lars Hanisch <[email protected]> Project's homepage: https://github.com/flensrocker/vdr-plugin-dbus2vdr Latest version available at: git://github.com/flensrocker/vdr-plugin-dbus2vdr.git 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 of the License, or (at your option) any later version. See the file COPYING for more information. Description: This plugin will expose some methods via DBus to control the vdr. Installation ------------ dbus2vdr will use the system bus so your box has to be configured that the user in which context your vdr is running is allowed to connect to it. Copy the de.tvdr.vdr.conf file to /etc/dbus-1/system.d and adjust it to your needs. It is prepared that only the user 'vdr' can own the used destination and every user can call its methods. In the bin-directory you find a helper script for sending dbus messages to the vdr. Instead of calling: dbus-send --system --type=method_call --dest=de.tvdr.vdr \ --print-reply /Plugins/<pluginname> \ de.tvdr.vdr.plugin.SVDRPCommand string:'command' string:'parameter' you can call: vdr-dbus-send.sh /Plugins/<pluginname> plugin.SVDRPCommand string:'command' string:'parameter' Dependencies ------------ Debian/Ubuntu packages: libdbus-1-dev, libglib2.0-dev, pkg-config, libjpeg-dev, libpng++-dev Restrictions ------------ Objectpaths and interface names are restricted to some naming conventions. Only letters, numbers and the underscore are allowed. DBus doesn't provide any official escaping, so dbus2vdr won't do it. The only part of the names, which could contain other symbols are name of plugins. But "officially" there are also no other characters than letters and numbers allowed. And I only knew about streamdev-server/-client which break this rule. I think they should get fixed... Multi Instance Support ---------------------- The default destination address is "de.tvdr.vdr". In case of a vdr version above 1.7.4 and an instance id (vdr parameter -i) greater than 0, this instance id is appended to this address, e.g. "de.tvdr.vdr1". If you use this feature you have to clone the dbus-policy file and change the address. For vdr-dbus-send.sh set the environment variable VDR_ID to the instance id - e.g.: VDR_ID=1 vdr-dbus-send.sh /Status status.IsReplaying Commandline Arguments --------------------- -s, --shutdown-hooks=/path/to/shutdown-hooks uses all files in the given directory as shutdown-hooks usually it's /usr/share/vdr/shutdown-hooks -w, --shutdown-hooks-wrapper=/path/to/shutdown-hooks-wrapper path to a program that will call the shutdown-hooks with suid -o, --osd creates an OSD-provider which will save the OSD as PNG files (see comments below at section "OSD") --systemd use sd_notify to notify systemd -u, --upstart enable Upstart started/stopped events -n, --network enable network support (see comments below at section "Network") --session connect to the session D-Bus daemon --no-system don't connect to the system D-Bus daemon --no-mainloop don't start GMainLoop (don't use this option if you don't understand) --nulldevice[=force] creates an output device, which does nothing can be activated to suspend in/output of DVB streams if "force" dbus2vdr will set this device as primary device on startup Interface "channel" ------------------- - get count of channels vdr-dbus-send.sh /Channels channel.Count - get current channel vdr-dbus-send.sh /Channels channel.Current - get channels between from_index and to_index vdr-dbus-send.sh /Channels channel.GetFromTo int32:from_index int32:to_index - list channels like SVDRP command CHAN vdr-dbus-send.sh /Channels channel.List string:'[ :groups | <number> | <name> | <id> ]' The returned array contains the channel number and the string from the channels.conf. Interface "device" ------------------- - get current primary device vdr-dbus-send.sh /Devices device.GetPrimary - get index of the nulldevice (-1 if not created) vdr-dbus-send.sh /Devices device.GetNullDevice - request switch to primary device vdr-dbus-send.sh /Devices device.RequestPrimary int32:index - list devices vdr-dbus-send.sh /Devices device.List The returned array contains the device index, number, a boolean value "hasDecoder", a boolean value "isPrimary" and the name of the device. Interface "epg" --------------- - disable EIT scanner with timeout (default: 3600) vdr-dbus-send.sh /EPG epg.DisableScanner int32:3600 - enable EIT scanner vdr-dbus-send.sh /EPG epg.EnableScanner - clear EPG data with a value for inactivity timeout of eit-scanner (default: 10) vdr-dbus-send.sh /EPG epg.ClearEPG string:'channel' int32:10 - add EPG entry vdr-dbus-send.sh /EPG epg.PutEntry array:string:'C ...','E ...',... The end marker argument '.' will be added if not provided. - read EPG data from file vdr-dbus-send.sh /EPG epg.PutFile string:'/path/to/epg/data' - get current or next event of given or all channels if string is empty vdr-dbus-send.sh /EPG epg.Now string:'channel' vdr-dbus-send.sh /EPG epg.Next string:'channel' vdr-dbus-send.sh /EPG epg.At string:'channel' uint64:time The events are returned as an array of structs. Each struct contains a string as a key and a variant as its value. Possible keys and their variant type are: ChannelID string EventID uint32 Title string ShortText string Description string StartTime uint64 EndTime uint64 Duration uint64 Vps uint64 RunningStatus int32 ParentalRating int32 ContentID[i] int32 (0 <= i <= MaxEventContents) Content[i] string (0 <= i <= MaxEventContents) Interface "plugin" ------------------ If a plugin's name contains a hyphen, it will be replaced with an underscore in its object-path, e.g. streamdev-server will be found at /Plugins/streamdev_server. - send SVDRP commands to plugins vdr-dbus-send.sh /Plugins/<pluginname> plugin.SVDRPCommand string:'command' string:'parameter' If the SVDRP command doesn't take a parameter you must pass an empty string. - call Service method of plugins vdr-dbus-send.sh /Plugins/<pluginname> plugin.Service string:'id' string:'data' Interface "pluginmanager" ------------------ - list all loaded plugins vdr-dbus-send.sh /Plugins pluginmanager.List You'll get an array of structs containing two strings, the name and the version of the plugins. Interface "recording" --------------------- - trigger an update of the list of recordings vdr-dbus-send.sh /Recordings recording.Update - get info about one recording vdr-dbus-send.sh /Recordings recording.Get [ variant:int32:number | variant:string:'path' ] The following is returned: struct of int32 number of recording array of string key variant value possible keys: Path, Name, Title, Start, Deleted, Priority, Lifetime, HierarchyLevels, FramesPerSecond, NumFrames, LengthInSeconds, FileSizeMB, IsPesRecording, IsNew, IsEdited If an cRecordingInfo object exists there can also be: Info/ChannelID, Info/ChannelName, Info/Title, Info/ShortText, Info/Description, Info/Aux, Info/FramesPerSecond If the info object has components there might be: Info/Component/<nr>/stream, Info/Component/<nr>/type, Info/Component/<nr>/language, Info/Component/<nr>/description - list recordings vdr-dbus-send.sh /Recordings recording.List returned is an array of the same structs as with "Get". - play recording given by path or number vdr-dbus-send.sh /Recordings recording.Play [ variant:int32:number | variant:string:'path' ] [ variant:string:'hh:mm:ss.f' | variant:int32:framenumber ] If framenumber is -1, playing is resumed at the last saved position. If your vdr is patched with the "extra video directories" patch there are also the following methods. - add extra video directory vdr-dbus-send.sh /Recordings recording.AddExtraVideoDirectory string:directory Don't forget to manually update your recordings after adding all directories. - clear extra video directories list vdr-dbus-send.sh /Recordings recording.ClearExtraVideoDirectories - delete an extra video directory vdr-dbus-send.sh /Recordings recording.DeleteExtraVideoDirectory string:directory - list all extra video directories vdr-dbus-send.sh /Recordings recording.ListExtraVideoDirectories Besides the usual reply-code and -message you get an array of strings with the currently present video directories. Interface "remote" ------------------ - enable/disable the remote vdr-dbus-send.sh /Remote remote.Enable vdr-dbus-send.sh /Remote remote.Disable vdr-dbus-send.sh /Remote remote.Status - hit a key, you may specify more than one key vdr-dbus-send.sh /Remote remote.HitKey string:'Menu' vdr-dbus-send.sh /Remote remote.HitKeys array:string:'Menu','Down','Down','Ok',... - display list of strings on the osd and let the user select one vdr-dbus-send.sh /Remote remote.AskUser string:'title' array:string:'item 1','item 2',... The zero-based index of the selected item will be returned with the signal "AskUserSelect", the first parameter is the title-string, the second the index. An index of -1 means, no item is selected (or osd closed because of a timeout). - open the main menu entry of a plugin vdr-dbus-send.sh /Remote remote.CallPlugin string:'name-of-plugin' - switch channel like SVDRP command CHAN vdr-dbus-send.sh /Remote remote.SwitchChannel string:'[ + | - | <number> | <name> | <id> ]' - get/set volume like SVDRP command VOLU vdr-dbus-send.sh /Remote remote.GetVolume vdr-dbus-send.sh /Remote remote.SetVolume variant:string:'[ <number> | + | - | mute ]' vdr-dbus-send.sh /Remote remote.SetVolume variant:int32:<number> return type: - int32 with the current volume - bool with the current mute status additional return values at SetVolume: - int32 reply code - string reply message Interface "setup" ----------------- - list all parameters from setup.conf vdr-dbus-send.sh /Setup setup.List return type is an array of structs containing a string and a variant. The string contains the key of the line from the setup.conf. The variant can be: - struct of three integers "(iii)": value of the option and its min and max values - struct of string and integer "(si)": value of the option and its max length (-1 for unknown) - 64bit integer "x": value of the option (timestamp) - get parameters from setup.conf vdr-dbus-send.sh /Setup setup.Get string:'MinUserInactivity' - set parameters to setup.conf vdr-dbus-send.sh /Setup setup.Set string:'MinUserInactivity' variant:int32:0 Some parameters are known to be integers (look at setup.c) with a valid range. All others are handled as strings. WARNING: Be careful to set values unknown to dbus2vdr. It will trigger a reload of the whole setup.conf including calls to SetupParse of every plugin. This might have unexpected side effects! - delete parameters from setup.conf vdr-dbus-send.sh /Setup setup.Del string:'PrimaryLimit' You may also get/set/delete parameters for plugins with vdr-dbus-send.sh /Setup setup.Get string:'pluginname.parameter' vdr-dbus-send.sh /Setup setup.Set string:'pluginname.parameter' variant:string:'value' vdr-dbus-send.sh /Setup setup.Del string:'pluginname.parameter' but it is not guaranteed that it will work and that changes will affect the plugin's behaviour immediately. dbus2vdr will call the plugin's "SetupParse" function. If it returns true the value is stored in the setup.conf. You may need to restart vdr. - delete all settings of one plugin vdr-dbus-send.sh /Setup setup.Del string:'pluginname.*' Interface "shutdown" -------------------- - ask vdr if it is ready for shutdown vdr-dbus-send.sh /Shutdown shutdown.ConfirmShutdown boolean:true possible reply codes: 250: vdr is ready for shutdown 550: vdr is not ready for shutdown (unknown reason) 901: user is active 902: cutter is active 903: recording is active 904: recording is active in the near future 905: some plugin is active 906: some plugin will wakeup vdr in the near future 990: (reply message contains SHUTDOWNCMD) 991: (reply message contains TRY_AGAIN of the shutdown-hooks) 992: (reply message contains ABORT_MESSAGE of the shutdown-hooks) 999: shutdown-hook returned a non-zero exit code You may shutdown vdr on reply codes 250 and 990. If SHUTDOWNCMD is given use this command for shutdown. 'shutdown-wrapper' is a tool which calls the shutdown-hooks. If the hooks need elevated privileges set the SUID bit of the wrapper accordingly. The boolean argument "ignoreuser" will ignore user activity. This may be useful for external frontends like XBMC etc.. - ask if user is active vdr-dbus-send.sh /Shutdown shutdown.IsUserActive This is a more efficient way to check if the user is active than using ConfirmShutdown, because the shutdown hooks won't be executed if the user is inactive. - ask if vdr was started manually vdr-dbus-send.sh /Shutdown shutdown.ManualStart Actually it compares the startup time of vdr with the current set NextWakeupTime. If the startup time is around the NextWakeupTime (600 seconds) "true" will be returned. Remember that NextWakeupTime may change while vdr is running. - get timestamp of next wakeup vdr-dbus-send.sh /Shutdown shutdown.NextWakeupTime Returns the starttime of the next timer or the next plugin. Remember that NextWakeupTime may change while vdr is running. - set vdr to non-interactive mode vdr-dbus-send.sh /Shutdown shutdown.SetUserInactive Interface "skin" ---------------- - display a message at the OSD vdr-dbus-send.sh /Skin skin.QueueMessage string:'message text' - get information about available skins vdr-dbus-send.sh /Skin skin.ListSkins You will get an array of index, name and description. - get information about current skin vdr-dbus-send.sh /Skin skin.CurrentSkin You will get the index, name and description. - set the current skin vdr-dbus-send.sh /Skin skin.SetSkin string:'name' Interface "status" ------------------ Via the status interface the signals from vdr's cStatus class will be emitted. See <vdr/status.h> for more information about the parameters. - "ChannelSwitch" int32 DeviceNumber int32 ChannelNumber bool LiveView - "Recording" int32 DeviceNumber string Name string FileName bool On - "Replaying" string Name string FileName bool On - "SetAudioChannel" int32 AudioChannel - "SetAudioTrack" int32 Index array:string Tracks - "SetSubtitleTrack" int32 Index array:string Tracks - "SetVolume" int32 Volume boolean Absolute - "TimerChange" string Timer string Change (may be "tcMod", "tcAdd" or "tcDel") And there are the following methods on the status interface. - is vdr replaying a recording vdr-dbus-send.sh /Status status.IsReplaying It returns the name, filename and a boolean value like the signal "Replaying". Interface "timer" ----------------- - list all timers as an array of strings like SVDRP command LSTT vdr-dbus-send.sh /Timers timer.List - list all timers as an array of structs vdr-dbus-send.sh /Timers timer.ListDetailed The following fields are returned: int32 id string remote (with vdr >= 2.3.1) uint32 flags string channel-id string day/weekdays int32 start int32 stop int32 priority int32 lifetime string filename string aux uint32 event-id boolean recording boolean pending boolean in vps margin - get infos about the next timer vdr-dbus-send.sh /Timers timer.Next The following is returned: int32 reply code (250 for success, 550 on error) int32 timer id (-1 if there's no timer at all) int32 'rel' seconds (see SVDRP NEXT REL) uint64 starttime in seconds since epoch (time_t format) uint64 stoptime in seconds since epoch (time_t format) string title of the event - add new timer vdr-dbus-send.sh /Timers timer.New string:'timer' The following is returned: int32 reply code (250 for success, 501 on error) string reply message - delete a timer vdr-dbus-send.sh /Timers timer.Delete int32:number The following is returned: int32 reply code (250 for success, 501 on error, 550 on recording/editing) string reply message Interface "vdr" ----------------- - get status of vdr vdr-dbus-send.sh /vdr vdr.Status The following is returned: string "Start", "Ready", "Stop" or "Unknown" Through the lifetime of dbus2vdr there are three signals which are sent via this interface. The instance-id of the vdr is sent as the first argument, type is int32. "Start": is sent when cPlugin::Start is called "Ready": is sent when cPlugin::MainThreadHook is called the first time "Stop" : is sent when cPlugin::Stop is called Plugin-Service calls -------------------- Right after the start of the default GMainLoop all plugins are called with "dbus2vdr-MainLoopStarted" Just before the main loop quits, all plugins are called with "dbus2vdr-MainLoopStopped" Network ------- If started with the parameter "--network" dbus2vdr expects a file "network-address.conf" in its plugin config directory. Its contents should contain a string representing a dbus-address like printed of "dbus-daemon --print-address". There must be only one connection string with the method "tcp". A sample configuration for this special dbus-daemon can be found at etc/network.conf. There's also a sample Upstart job at etc/dbus2vdr.conf. This job should run as a user job, not as a system job, since it's reachable from the net. Interfaces must explicitly be enabled to listen on the network monitor. For now a subset of the status, timer and recording interface is implemented. (work in progress, must be documented...) OSD --- If started with the parameter "--osd" dbus2vdr will create an OSD-provider. If you have another output plugin running, this is not recommended since it may override its OSD-provider. For now it's just for fun (or a headless vdr). If the vdr opens an OSD, dbus2vdr will dump the pixmap to a PNG file and signals this. Every change at the OSD will generate another PNG and signal. If the OSD closes all files will be deleted. Every image between "Open" and "Close" has to be displayed on top of its predecessors. - create the DBus-OSD-provider on the fly vdr-dbus-send.sh /OSD osd.CreateProvider - delete the DBus-OSD-provider and reinstantiate the OSD-provider of the primary device vdr-dbus-send.sh /OSD osd.DeleteProvider interface: de.tvdr.vdr.osd path: /OSD signal: Open parameter: osd-id (string, actually the path where the PNGs will be stored) left (int32, left position of OSD) top (int32, top position of OSD) signal: Display parameter: filename (string) left (int32) top (int32) vx (int32, x-coordinate of dirty part relative to left) vy (int32, y-coordinate of dirty part relative to top) signal: Close parameter: osd-id (string) You can watch the signals with (or write your own program): dbus-monitor --system "type='signal',sender='de.tvdr.vdr',interface='de.tvdr.vdr.osd'" Since the DBus signals are not really "fast" the files may not exist anymore if you receive them. Systemd ------- When all plugins are started and dbus2vdr enters the first time the "MainThreadHook" it can notify systemd with a sd_notify call and "READY=1". systemd will then know that vdr has been fully initialised and dependant services can be started. You have to use "Type=notify" at the service definition file. Upstart ------- When all plugins are started and dbus2vdr enters the first time the "MainThreadHook" it raises SIGSTOP so Upstart knows vdr has been fully initialized. If you want to start vdr whenever a client tries to access de.tvdr.vdr on DBus you can create a DBus service file like /usr/share/dbus-1/system-services/de.tvdr.vdr-upstart.service with the following content: [D-BUS Service] Name=de.tvdr.vdr Exec=/bin/true UpstartJob=true Your vdr-upstart-job has to "start on dbus-activation de.tvdr.vdr". If you don't use Upstart "Exec" has to point to your "runvdr" or whatever you use and you can omit the "UpstartJob=true" line. Using the Python binding ------------------------ First, I don't know Python at all, I just copy code fragments from the Python Binding Tutorial [1] and replace the sample strings with dbus2vdr related ones. I hope everybody familiar with Python will know what to do... import dbus bus = dbus.SystemBus() Timers = bus.get_object('de.tvdr.vdr', '/Timers') props = Timers.Next(dbus_interface = 'de.tvdr.vdr.timer') # props is now a tuple with data like mentioned above How to implement new interfaces ------------------------------- - add the interface name to common.h - create a subclass of cDBusObject and pass the object path and introspection data to its base constructor - call AddMethod for all supported methods - add the object to the desired connections (system, session, network) Notes to myself --------------- to use dbus in a ssh-shell: look at ~/.dbus/session-bus/`dbus-uuidgen-get`-... and export DBUS_SESSION_BUS_ADDRESS Links ----- [1] http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.txt
About
Plugin for controlling vdr via DBus as an alternative to SVDRP
Topics
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published