[vdr-plugin-xineliboutput] 01/01: New upstream version 1.1.0+git20170131

Tobias Grimm tiber-guest at moszumanska.debian.org
Tue Jan 31 23:25:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

tiber-guest pushed a commit to branch upstream
in repository vdr-plugin-xineliboutput.

commit e4a92633b43d1cb5530b2a79ba08ac5eee67dfd3
Author: Tobias Grimm <etobi at debian.org>
Date:   Tue Jan 31 23:05:50 2017 +0100

    New upstream version 1.1.0+git20170131
---
 .gitignore                              |  19 ++
 HISTORY                                 |  20 +-
 Makefile                                |  12 +-
 README                                  |  12 +-
 config.c                                |  15 +-
 config.h                                |   6 +-
 configure                               |  20 +-
 device.c                                |  66 ++++-
 device.h                                |   9 +-
 equalizer.c                             |   2 +-
 equalizer.h                             |   2 +-
 frontend.c                              |  18 +-
 frontend.h                              |   2 +-
 frontend_local.c                        | 122 +++++-----
 frontend_local.h                        |   2 +-
 frontend_svr.c                          |  39 ++-
 frontend_svr.h                          |   4 +-
 include/vdr-xineliboutput/service_pip.h |   2 +-
 logdefs.c                               |   2 +-
 logdefs.h                               |   2 +-
 media_player.c                          |   3 +-
 media_player.h                          |   2 +-
 menu.c                                  |   7 +-
 menu.h                                  |   2 +-
 menuitems.c                             |   2 +-
 menuitems.h                             |   2 +-
 mpg2c.c                                 |   2 +-
 osd.c                                   |   2 +-
 osd.h                                   |   2 +-
 setup_menu.c                            |   4 +-
 setup_menu.h                            |   2 +-
 tools.c                                 |   3 +-
 tools/avahi.c                           | 253 ++++++++++++++++++++
 tools/avahi.h                           |  17 ++
 tools/backgroundwriter.c                |   2 +-
 tools/backgroundwriter.h                |   2 +-
 tools/bitstream.h                       |  20 +-
 tools/cxsocket.c                        |  30 +--
 tools/cxsocket.h                        |   6 +-
 tools/debug_mutex.h                     |   2 +-
 tools/display_message.h                 |   2 +-
 tools/functor.h                         |   2 +-
 tools/functorimpl.h                     |   2 +-
 tools/future.h                          |   2 +-
 tools/general_remote.h                  |   2 +-
 tools/h264.c                            | 115 ++++-----
 tools/h264.h                            |   8 +-
 tools/h265.c                            | 137 +++++++++++
 tools/h265.h                            |  49 ++++
 tools/http.c                            |   2 +-
 tools/http.h                            |   2 +-
 tools/iso639.h                          |   2 +-
 tools/listiter.h                        |   2 +-
 tools/metainfo_menu.c                   |   2 +-
 tools/metainfo_menu.h                   |   2 +-
 tools/mpeg.c                            |  47 ++--
 tools/mpeg.h                            |   8 +-
 tools/osd_command.h                     |   2 +-
 tools/pes.c                             |   2 +-
 tools/pes.h                             |   2 +-
 tools/pip_service_impl.h                |   2 +-
 tools/playlist.c                        |  11 +-
 tools/playlist.h                        |   2 +-
 tools/rle.c                             |   2 +-
 tools/rle.h                             |   2 +-
 tools/rtcp.h                            |   2 +-
 tools/rtp.h                             |   2 +-
 tools/sap.h                             |  15 +-
 tools/sdp.h                             |   4 +-
 tools/section_lock.h                    |   2 +-
 tools/sys_cap.h                         |   2 +-
 tools/time_ms.h                         |   2 +-
 tools/time_pts.c                        |   2 +-
 tools/time_pts.h                        |   2 +-
 tools/timer.c                           |   2 +-
 tools/timer.h                           |   2 +-
 tools/ts.c                              |  53 ++--
 tools/ts.h                              |   5 +-
 tools/udp_buffer.h                      |   2 +-
 tools/udp_pes_scheduler.c               |  19 +-
 tools/udp_pes_scheduler.h               |   2 +-
 tools/vdrdiscovery.c                    |  13 +-
 tools/vdrdiscovery.h                    |   4 +-
 vdrlogo_32x32.c                         |   2 +-
 xine/adjustable_scr.c                   |   2 +-
 xine/adjustable_scr.h                   |   2 +-
 xine/demux_xvdr.c                       | 411 ++++++++++++++++++--------------
 xine/demux_xvdr_tsdata.c                |   2 +-
 xine/demux_xvdr_tsdata.h                |   2 +-
 xine/osd_manager.c                      |   4 +-
 xine/osd_manager.h                      |   2 +-
 xine/post.c                             |   3 +-
 xine/post_util.h                        |   2 +-
 xine/ts2es.c                            |  20 +-
 xine/ts2es.h                            |   2 +-
 xine/vo_frameoutput.c                   |   2 +-
 xine/vo_frameoutput.h                   |   2 +-
 xine/vo_hook.c                          |   2 +-
 xine/vo_hook.h                          |   2 +-
 xine/vo_lastpts.c                       |   2 +-
 xine/vo_lastpts.h                       |   2 +-
 xine/vo_osdreorder.c                    |   2 +-
 xine/vo_osdreorder.h                    |   2 +-
 xine/vo_osdscaler.c                     |   2 +-
 xine/vo_osdscaler.h                     |   2 +-
 xine/vo_post.h                          |   2 +-
 xine/vo_props.h                         |   2 +-
 xine/xvdr_metronom.c                    |   5 +-
 xine/xvdr_metronom.h                    |   2 +-
 xine_fbfe_frontend.c                    |   2 +-
 xine_frontend.c                         |  12 +-
 xine_frontend.h                         |   2 +-
 xine_frontend_cec.c                     |  73 ++++--
 xine_frontend_cec.h                     |   2 +-
 xine_frontend_internal.h                |   2 +-
 xine_frontend_kbd.c                     |   2 +-
 xine_frontend_kbd.h                     |   2 +-
 xine_frontend_lirc.c                    |   2 +-
 xine_frontend_lirc.h                    |   2 +-
 xine_frontend_main.c                    |   2 +-
 xine_input_vdr.c                        |  70 +++++-
 xine_input_vdr.h                        |   2 +-
 xine_input_vdr_mrl.h                    |   2 +-
 xine_input_vdr_net.h                    |   2 +-
 xine_post_audiochannel.c                |   2 +-
 xine_post_autocrop.c                    |   8 +-
 xine_post_swscale.c                     |   2 +-
 xine_sxfe_frontend.c                    |  24 +-
 xineliboutput.c                         |   8 +-
 129 files changed, 1389 insertions(+), 606 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5263aee
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,19 @@
+.dependencies
+config.mak
+configure.log
+features.h
+
+black_720x576.c
+nosignal_720x576.c
+vdrlogo_720x576.c
+
+*.o
+*.so
+libvdr-*.so.*
+libxineliboutput-*.so.*
+mpg2c
+vdr-fbfe
+vdr-sxfe
+
+po/*.mo
+po/*.pot
diff --git a/HISTORY b/HISTORY
index 7214079..9d5f8e8 100644
--- a/HISTORY
+++ b/HISTORY
@@ -3,8 +3,26 @@ VDR Plugin 'xineliboutput' Revision History
 
 ????-??-??: Version 2.0.0
 
-- Support for cDevice::ScaleVideo()
+- Moved from CVS to GIT (see README)
+- Support vdr-2.3.1
 - Dropped support for vdr < 2.0
+- Fixed ts demuxing with some video streams (Thanks to Niedermeier Guenter).
+- Fixed primary device switching.
+- Fixed segfault when playing audio-only stream with visualization.
+- Fixed toggling fullscreen mode.
+- Fixed lost post processing when stream is reconnected.
+- Fixed HUD OSD crash with UHD resolution video output.
+- Added an option to trigger vdr-suspendoutput when there are no connected clients.
+- Added HDMI-CEC input support (libcec).
+- Added support for cDevice::ScaleVideo().
+- Added an option to disable media player resume file creation.
+- Added PRIM command into SVDRP interface.
+- Added option to use True Color OSD when no client is connected.
+- Added support for HEVC.
+- Improved H.264 support.
+- Bug fixes.
+- Build system updates.
+- Translation updates.
 
 2013-08-20: Version 1.1.0
 
diff --git a/Makefile b/Makefile
index 3a82460..55c77f9 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
 # See the main source file 'xineliboutput.c' for copyright information and
 # how to reach the author.
 #
-# $Id: Makefile,v 1.120 2015/04/22 08:23:48 phintuka Exp $
+# $Id$
 #
 
 # The official name of this plugin.
@@ -64,13 +64,13 @@ endif
 
 # Use package data if installed...otherwise assume we're under the VDR source directory:
 PKGCFG = $(if $(VDRDIR),$(shell pkg-config --variable=$(1) $(VDRDIR)/vdr.pc),$(shell PKG_CONFIG_PATH="$$PKG_CONFIG_PATH:../../.." pkg-config --variable=$(1) vdr))
+BINDIR = $(call PKGCFG,bindir)
 LIBDIR = $(call PKGCFG,libdir)
 LOCDIR = $(call PKGCFG,locdir)
 PLGCFG = $(call PKGCFG,plgcfg)
 VIDEODIR = $(call PKGCFG,videodir)
 
 TMPDIR  ?= /tmp
-BINDIR  ?= /usr/bin
 
 INSTALL ?= install
 
@@ -80,6 +80,9 @@ INSTALL ?= install
 
 -include Make.config
 
+ifeq ($(strip $(BINDIR)),)
+  BINDIR = /usr/bin
+endif
 
 ###
 ### check for VDR
@@ -198,7 +201,7 @@ endif
 ifeq ($(XINELIBOUTPUT_VDRPLUGIN), yes)
 OBJS = $(PLUGIN).o device.o frontend.o osd.o config.o menu.o setup_menu.o \
        menuitems.o media_player.o equalizer.o \
-       frontend_local.o frontend_svr.o \
+       frontend_local.o frontend_svr.o tools/avahi.o \
        tools/cxsocket.o tools/udp_pes_scheduler.o \
        tools/backgroundwriter.o tools/playlist.o tools/http.o \
        tools/vdrdiscovery.o tools/time_pts.o tools.o \
@@ -229,7 +232,7 @@ endif
 OBJS_XINEINPUTVDR = xine_input_vdr.o xine/demux_xvdr.o \
                     xine/ts2es.o xine/demux_xvdr_tsdata.o \
                     xine/adjustable_scr.o xine/xvdr_metronom.o xine/osd_manager.o \
-                    tools/rle.o tools/ts.o tools/pes.o tools/mpeg.o tools/h264.o
+                    tools/rle.o tools/ts.o tools/pes.o tools/mpeg.o tools/h264.o tools/h265.o
 
 OBJS_XINE = $(OBJS_XINEINPUTVDR) xine_post_autocrop.o xine_post_swscale.o xine_post_audiochannel.o
 
@@ -343,6 +346,7 @@ endif
 install-lib: $(TARGETS_VDR)
 ifeq ($(XINELIBOUTPUT_VDRPLUGIN), yes)
 	@echo Installing $^
+	@mkdir -p $(DESTDIR)$(LIBDIR)
 	install -D $^ $(DESTDIR)$(LIBDIR)/
 endif
 
diff --git a/README b/README
index 0275213..075ae4f 100644
--- a/README
+++ b/README
@@ -61,14 +61,16 @@ WARNING
   be stopped to first router regardless of network configuration.
 
 
-Public CVS
+Git
+
+  Latest fixes are available from sourceforge.net public GIT repository.
 
-  Latest fixes are available from sourceforge.net public CVS
-  (http://sourceforge.net/cvs/?group_id=160063).
+  GIT checkout command:
+  git clone git://git.code.sf.net/p/xineliboutput/git xineliboutput-git
 
-  CVS checkout command:
-  cvs -d:pserver:anonymous at xineliboutput.cvs.sourceforge.net:/cvsroot/xineliboutput co vdr-xineliboutput
+Public CVS
 
+  CVS is not updated anymore.
 
 Buildtime options
 
diff --git a/config.c b/config.c
index f9ce147..8851646 100644
--- a/config.c
+++ b/config.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: config.c,v 1.118 2013/10/28 15:31:45 rofafor Exp $
+ * $Id$
  *
  */
 
@@ -720,6 +720,7 @@ config_t::config_t() {
   main_menu_mode = ShowMenu;
   last_hotkey = -1;//kNone;
   force_primary_device = 0;
+  use_suspendoutput = 0;
 };
 
 #if 0
@@ -732,7 +733,7 @@ uint8_t *config_t::readonly_options = &g_readonly_options[0];
 cString config_t::m_ProcessedArgs;
 bool config_t::ProcessArg(const char *Name, const char *Value)
 {
-  if(SetupParse(Name, Value)) {
+  if (Name && Value && SetupParse(Name, Value)) {
     m_ProcessedArgs = cString::sprintf("%s%s ", *m_ProcessedArgs ? *m_ProcessedArgs : " ", Name);
     return true;
   }
@@ -741,7 +742,7 @@ bool config_t::ProcessArg(const char *Name, const char *Value)
 
 bool config_t::ProcessArgs(int argc, char *argv[])
 {
-  static const char short_options[] = "fDw:h:l:mr:A:V:d:P:C:pc";
+  static const char short_options[] = "fDw:h:l:mr:A:V:d:P:C:pct";
 
   static const struct option long_options[] = {
       { "fullscreen",   no_argument,       NULL, 'f' },
@@ -763,7 +764,9 @@ bool config_t::ProcessArgs(int argc, char *argv[])
       { "post",         required_argument, NULL, 'P' },
       { "config",       required_argument, NULL, 'C' },
       { "primary",      no_argument,       NULL, 'p' },
+      { "auto-suspend", no_argument,       NULL, 's' },
       { "exit-on-close",no_argument,       NULL, 'c' },
+      { "truecolor",    no_argument,       NULL, 't' },
       { NULL,           no_argument,       NULL,  0  }
     };
 
@@ -781,6 +784,8 @@ bool config_t::ProcessArgs(int argc, char *argv[])
               break;
     case 'f': ProcessArg("Fullscreen", "1");
               break;
+    case 't': ProcessArg("truecoloreverytime", "1");
+	      break;
     case 'D': ProcessArg("X11.HUDOSD", "1");
               if (optarg && strstr(optarg, "xshape")) {
                 ProcessArg("XShapeHUDOSD", "1");
@@ -864,6 +869,8 @@ bool config_t::ProcessArgs(int argc, char *argv[])
               break;
     case 'p': ProcessArg("ForcePrimaryDevice", "1");
               break;
+    case 's': ProcessArg("AutoSuspendOutput", "1");
+              break;
     case 'c': exit_on_close = 1;
               break;
 
@@ -888,6 +895,7 @@ bool config_t::SetupParse(const char *Name, const char *Value)
   else if (!strcasecmp(Name, "Fullscreen"))         fullscreen = atoi(Value);
   else if (!strcasecmp(Name, "DisplayAspect"))      display_aspect = strstra(Value, s_aspects, 0);
   else if (!strcasecmp(Name, "ForcePrimaryDevice")) force_primary_device = atoi(Value);
+  else if (!strcasecmp(Name, "AutoSuspendOutput"))  use_suspendoutput = atoi(Value);
 
   else if (!strcasecmp(Name, "X11.WindowId"))     window_id = (!strcmp(Value, "root")) ? WINDOW_ID_ROOT : atoi(Value);
   else if (!strcasecmp(Name, "X11.WindowWidth"))  width = atoi(Value);
@@ -899,6 +907,7 @@ bool config_t::SetupParse(const char *Name, const char *Value)
   else if (!strcasecmp(Name, "X11.OpenglAlways")) opengl = atoi(Value);
   else if (!strcasecmp(Name, "X11.OpenglHUDOSD")) hud_osd |= (atoi(Value) ? HUD_OPENGL : 0);
   else if (!strcasecmp(Name, "X11.XShapeHUDOSD")) hud_osd |= (atoi(Value) ? HUD_XSHAPE : 0);
+  else if (!strcasecmp(Name, "truecoloreverytime")) truecoloreverytime = atoi(Value);
 
   else if (!strcasecmp(Name, "Audio.Driver")) STRN0CPY(audio_driver, Value);
   else if (!strcasecmp(Name, "Audio.Port"))   STRN0CPY(audio_port, Value);
diff --git a/config.h b/config.h
index 347846a..253d479 100644
--- a/config.h
+++ b/config.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: config.h,v 1.91 2013/10/28 09:14:47 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -264,6 +264,9 @@ class config_t {
     // Force xineliboutput to be the primary device
     int  force_primary_device;
 
+    // Use vdr-suspendoutput: suspend when there are no clients
+    int  use_suspendoutput;
+
     // OSD state
     eMainMenuMode  main_menu_mode;      // used internally to open right sub-menu
     cOsdObject    *pending_menu_action; // used to replace current OSD with another type of OSD object
@@ -294,6 +297,7 @@ class config_t {
     int  window_id;        // use existing X11 window
     int  hud_osd;          // head up display OSD
     int  opengl;           // use opengl acceleration for video and HUD OSD
+    int  truecoloreverytime;
 
     // Audio settings
     int  speaker_type;
diff --git a/configure b/configure
index 55c165c..20d496d 100755
--- a/configure
+++ b/configure
@@ -7,7 +7,7 @@
 # See the main source file 'xineliboutput.c' for copyright information and
 # how to reach the author.
 #
-# * $Id: configure,v 1.45 2014/01/14 08:21:33 phintuka Exp $
+# * $Id$
 #
 
 PKG_CONFIG="pkg-config"
@@ -243,11 +243,12 @@ FEATURES="
   libbluray
   libcec
   mce-dbus-names
+  avahi-client
 "
 
 # set defaults
 
-enable x11 vdr fb xine i18n
+enable x11 vdr fb xine i18n libcec
 
 # clear log file
 
@@ -282,6 +283,7 @@ show_help(){
   echo "  --disable-vdpau        disable VDPAU support (X11) [no]"
   echo "  --disable-i18n         disable i18n support [no]"
   echo "  --disable-libcap       disable libcap support [no]"
+  echo "  --disable-avahi-client disable avahi support [no]"
   echo
   echo "  --debug                debug configure script"
   echo "  --disable-pkgconfig    do not use pkg-config"
@@ -336,7 +338,7 @@ done
 check_deps(){
   disabled libxine && disable x11 fb libavutil libjpeg libcec
   disabled x11     && disable dbus-glib-1 xshm xrandr xrender xshape opengl xdpms xinerama vdpau
-  disabled vdr     && disable libextractor libcap libbluray
+  disabled vdr     && disable libextractor libcap libbluray avahi-client
   disabled dlfcn   && disable opengl
   disabled pthread && disable opengl
   disabled xrender && disable xshape xshm
@@ -357,6 +359,7 @@ test_pkgconfig
 test_library     VDR   libextractor "extractor.h"        "-lextractor" "EXTRACTOR_getKeywords(0,0)"
 test_library     VDR   libcap       "sys/capability.h"   "-lcap"       "cap_get_proc()"
 test_library     VDR   libbluray    "libbluray/bluray.h" "-lbluray"    "bd_get_disc_info(0)"
+test_library     VDR   avahi-client "avahi-client/publish.h" "-lavahi-common -lavahi-client"    "avahi_client_new"
 test_library     XINE  libxine      "xine.h"             "-lxine"      "xine_init(0)"
 test_library     DLFCN dlfcn        "dlfcn.h"            "-ldl"        "dlopen(0,0)"
 
@@ -374,7 +377,16 @@ if enabled libxine; then
   test_library   JPEG    libjpeg      "jpeglib.h"              "-ljpeg"      "jpeg_create_compress(0)"
   test_library   X11     x11          "X11/X.h"                "-lX11"       "XInitThreads()"
   test_library   PTHREAD pthread      "pthread.h"              "-lpthread"   "pthread_create(0,0,0,0)"
-  test_library   CEC     libcec       "libcec/cecc.h"          "-lcec"       "cec_initialize(0)"
+
+  if enabled libcec; then
+    test_library   CEC     libcec       "libcec/cecc.h"          "-lcec"       "libcec_initialise(0)"
+    if disabled libcec; then
+      # try libcec < 3.0.0
+      enable libcec
+      test_library   CEC     libcec       "libcec/cecc.h"          "-lcec"       "cec_initialise(0)"
+    fi
+  fi
+
   if enabled x11; then
     test_library X11  xext         "X11/extensions/Xext.h"     "-lXext"      ""
     test_library X11  xshm         "X11/extensions/XShm.h"     "-lXext"      "XShmQueryExtension(0)"
diff --git a/device.c b/device.c
index edb9357..a1b7a23 100644
--- a/device.c
+++ b/device.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: device.c,v 1.127 2013/08/21 09:40:22 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -19,6 +19,7 @@
 #include <vdr/skins.h>
 #include <vdr/status.h>
 #include <vdr/remote.h>
+#include <vdr/plugin.h>
 
 //#define XINELIBOUTPUT_DEBUG
 //#define XINELIBOUTPUT_DEBUG_STDERR
@@ -118,7 +119,7 @@ void cXinelibStatusMonitor::ChannelSwitch(const cDevice *Device,
 #ifdef DEBUG_SWITCHING_TIME
       switchtimeOn = cTimeMs::Now();
 #endif
-      m_Device.SetTvMode(Channels.GetByNumber(ChannelNumber));
+      m_Device.SetTvMode(ChannelNumber);
       TRACE("cXinelibStatusMonitor: Set to TvMode");
     }
   } else {
@@ -345,6 +346,14 @@ bool cXinelibDevice::ForcePrimaryDevice(bool On)
   m_MainThreadFunctors.Add(CreateFunctor(this, &cXinelibDevice::ForcePrimaryDeviceImpl, On));
   m_MainThreadLock.Unlock();
 
+  if (On) {
+    int timeout = 10;
+    while (this != cDevice::PrimaryDevice() && timeout-- > 0) {
+      isyslog("waiting for primary device ...");
+      cCondWait::SleepMs(100);
+    }
+  }
+
   return xc.force_primary_device ||
          (cDevice::PrimaryDevice() && this == cDevice::PrimaryDevice());
 }
@@ -385,13 +394,40 @@ void cXinelibDevice::ForcePrimaryDeviceImpl(bool On)
 	  xc.main_menu_mode = CloseOsd; /* will be executed in future by vdr main thread */
 	  cRemote::CallPlugin("xineliboutput");
 	}
+#if VDRVERSNUM >= 20301
+        LOCK_CHANNELS_READ;
+        const cChannel *channel = Channels->GetByNumber(CurrentChannel());
+#else
 	cChannel *channel = Channels.GetByNumber(CurrentChannel());
+#endif
 	cDevice::SetPrimaryDevice(m_OriginalPrimaryDevice);
 	PrimaryDevice()->SwitchChannel(channel, true);
 	m_OriginalPrimaryDevice = 0;
       }
     }
   }
+
+  if (xc.use_suspendoutput && !m_local) {
+    cPlugin *p = cPluginManager::GetPlugin("suspendoutput");
+    if (p) {
+      bool result = true;
+      if (m_ForcePrimaryDeviceCnt == 0) {
+        LOGDBG("enabling suspendoutput");
+        result = p->Service("SuspendOutputPlugin-v1.0", (void*)"Suspend");
+      }
+      if (m_ForcePrimaryDeviceCnt == 1) {
+        LOGDBG("disabling suspendoutput");
+        result = p->Service("SuspendOutputPlugin-v1.0", (void*)"Resume");
+      }
+      if (!result) {
+        LOGERR("suspendoutput service failed. "
+               "--auto-suspend option requires vdr-suspendoutput plugin version 2.1.0 or later.");
+      }
+    } else {
+      LOGERR("suspendoutputr plugin not loaded ?");
+      LOGERR("--auto-suspend option requires vdr-suspendoutput plugin.");
+    }
+  }
 }
 
 //
@@ -584,14 +620,25 @@ void cXinelibDevice::StopOutput(void)
   ForEach(m_clients, &cXinelibThread::SetNoVideo, false);
 }
 
-void cXinelibDevice::SetTvMode(cChannel *Channel)
+static bool IsRadioChannel(int ChannelNumber)
+{
+#if VDRVERSNUM >= 20301
+    LOCK_CHANNELS_READ;
+    const cChannel *Channel = Channels->GetByNumber(ChannelNumber);
+#else
+    const cChannel *Channel = Channels.GetByNumber(ChannelNumber);
+#endif
+    if (Channel && !Channel->Vpid() && (Channel->Apid(0) || Channel->Apid(1)))
+      return true;
+    return false;
+}
+
+void cXinelibDevice::SetTvMode(int ChannelNumber)
 {
   TRACEF("cXinelibDevice::SetTvMode");
   TRACK_TIME(250);
 
-  m_RadioStream = false;
-  if (Channel && !Channel->Vpid() && (Channel->Apid(0) || Channel->Apid(1)))
-    m_RadioStream = true;
+  m_RadioStream = IsRadioChannel(ChannelNumber);
   if(m_PlayMode == pmAudioOnlyBlack)
     m_RadioStream = true;
   TRACE("cXinelibDevice::SetTvMode - isRadio = "<<m_RadioStream);
@@ -904,7 +951,7 @@ bool cXinelibDevice::PlayFile(const char *FileName, int Position,
     if(!m_liveMode)
       SetReplayMode();
     else
-      SetTvMode(Channels.GetByNumber(cDevice::CurrentChannel()));
+      SetTvMode(cDevice::CurrentChannel());
     m_PlayingFile = pmNone;
   }
 
@@ -1099,8 +1146,7 @@ int cXinelibDevice::PlayTsVideo(const uchar *Data, int Length)
       if (!m_tssVideoSize)
         m_tssVideoSize = ts_state_init(4096);
 
-      if (ts_get_video_size(m_tssVideoSize, Data, m_VideoSize,
-                            (PatPmtParser()->Vtype() == ISO_14496_PART10_VIDEO))) {
+      if (ts_get_video_size(m_tssVideoSize, Data, m_VideoSize, (ts_stream_type)PatPmtParser()->Vtype())) {
 
         m_StreamStart = false;
         LOGMSG("Detected video size %dx%d", m_VideoSize->width, m_VideoSize->height);
@@ -1441,11 +1487,13 @@ void cXinelibDevice::SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayForma
 #endif
 }
 
+#if VDRVERSNUM < 20301
 eVideoSystem cXinelibDevice::GetVideoSystem(void)
 {
   TRACEF("cXinelibDevice::GetVideoSystem");
   return cDevice::GetVideoSystem();
 }
+#endif
 
 void cXinelibDevice::GetVideoSize(int &Width, int &Height, double &VideoAspect)
 {
diff --git a/device.h b/device.h
index 2c6704d..40fd554 100644
--- a/device.h
+++ b/device.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: device.h,v 1.66 2014/01/07 16:03:54 rofafor Exp $
+ * $Id$
  *
  */
 
@@ -123,7 +123,9 @@ class cXinelibDevice : public cDevice
   public:
     virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat);
     virtual void SetVideoFormat(bool VideoFormat16_9);
+#if VDRVERSNUM < 20301
     virtual eVideoSystem GetVideoSystem(void);
+#endif
 
     struct video_size_s *m_VideoSize;
     struct ts_state_s   *m_tssVideoSize;
@@ -170,8 +172,9 @@ class cXinelibDevice : public cDevice
     cXinelibStatusMonitor *m_statusMonitor;
     bool m_liveMode;
 
-  public:
-    void SetTvMode(cChannel *Channel);
+  protected:
+    friend class cXinelibStatusMonitor;
+    void SetTvMode(int ChannelNumber);
     void SetReplayMode(void);
     void StopOutput(void);
 
diff --git a/equalizer.c b/equalizer.c
index ef460db..ba4b618 100644
--- a/equalizer.c
+++ b/equalizer.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: equalizer.c,v 1.8 2012/03/18 19:17:07 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/equalizer.h b/equalizer.h
index 6492f7c..515e814 100644
--- a/equalizer.h
+++ b/equalizer.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: equalizer.h,v 1.2 2012/03/18 19:17:07 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/frontend.c b/frontend.c
index 864b4c9..96c8b30 100644
--- a/frontend.c
+++ b/frontend.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: frontend.c,v 1.101 2012/03/19 11:57:18 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -91,7 +91,7 @@ void cXinelibThread::KeypressHandler(const char *keymap, const char *key,
     if (!remote->Put(key, repeat, release)) {
       if (!strcmp(keymap, "KBD")) {
         uint64_t value = 0;
-        sscanf(key, "%"PRIX64, &value);
+        sscanf(key, "%" PRIX64, &value);
         if (value) {
           remote->cRemote::Put(KBDKEY(value));
           return;
@@ -255,6 +255,7 @@ cXinelibThread::cXinelibThread(cXinelibDevice *Dev, const char *Description) : c
   m_bEndOfStreamReached = false;
   m_bPlayingFile = false;
   m_StatusMonitor = NULL;
+  m_SpuLangAuto = true;
 }
 
 cXinelibThread::~cXinelibThread()
@@ -472,8 +473,11 @@ int cXinelibThread::Play_Mpeg1_PES(const uchar *data1, int len)
       i1 += 2;
     }
     
-    if(len<i1+5) return len;
-    
+    if (len < i1 + 5) {
+      delete[] data2;
+      return len;
+    }
+
     data2[i2++] = 0x80;
     
     if ((data1[i1] & 0xf0) == 0x20) { 
@@ -519,7 +523,7 @@ int cXinelibThread::Play_Mpeg1_PES(const uchar *data1, int len)
       r = Play(data2, newlen + 6);
     } 
   
-    delete data2;
+    delete [] data2;
     return r==newlen+6 ? ((data1[4]<<8)|data1[5])+6 : 0;
   }
   return len; // nothing useful found ...
@@ -560,7 +564,7 @@ bool cXinelibThread::Play_Mpeg2_ES(const uchar *data, int len, int streamID, boo
     Poll(p, 100);
 
     if (blocklen + hdrlen != Play(frame, blocklen + hdrlen)) {
-      delete frame;
+      delete [] frame;
       return false;
     }
   }
@@ -620,6 +624,7 @@ bool cXinelibThread::LogoDisplay(void)
   if(fd >= 0) {
     uint8_t *data = (uint8_t*)malloc(STARTUP_MAX_SIZE);
     int datalen = read(fd, data, STARTUP_MAX_SIZE);
+    close(fd);
     if(datalen == STARTUP_MAX_SIZE) {
       LOGMSG("WARNING: custom startup image %s too large", *Path);
     } else if(datalen<=0) {
@@ -633,7 +638,6 @@ bool cXinelibThread::LogoDisplay(void)
       return r;
     }
     free(data);
-    close(fd);
   }
   
   /* use default image */
diff --git a/frontend.h b/frontend.h
index a7eb09d..15d21a7 100644
--- a/frontend.h
+++ b/frontend.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: frontend.h,v 1.45 2012/03/19 11:57:18 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/frontend_local.c b/frontend_local.c
index 665772d..fd834ed 100644
--- a/frontend_local.c
+++ b/frontend_local.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: frontend_local.c,v 1.61 2013/08/18 07:58:29 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -32,16 +32,16 @@
 
 //------------------------------ cRwLockBlock ---------------------------------
 
-class cRwLockBlock 
+class cRwLockBlock
 {
   private:
     cRwLock& m_Lock;
 
   public:
-    cRwLockBlock(cRwLock& lock, bool write) : m_Lock(lock)  
-      { m_Lock.Lock(write);}
+    cRwLockBlock(cRwLock& lock, bool write) : m_Lock(lock)
+      { m_Lock.Lock(write); }
 
-    ~cRwLockBlock()  
+    ~cRwLockBlock()
       { m_Lock.Unlock(); }
 };
 
@@ -66,7 +66,7 @@ extern "C" {
     } else if (!xc.use_x_keyboard || !key) {
 
       /* Only X11 key events came this way in local mode.
-	 Keyboard is handled by vdr. */
+         Keyboard is handled by vdr. */
       LOGMSG("keypress_handler(%s): X11 Keyboard disabled in config", key);
 
     } else {
@@ -147,9 +147,9 @@ void cXinelibLocal::OsdCmd(void *cmd)
     fe->xine_osd_command(fe, (struct osd_command_s*)cmd);
 }
 
-uchar *cXinelibLocal::GrabImage(int &Size, bool Jpeg, 
-				int Quality, int SizeX, 
-				int SizeY)
+uchar *cXinelibLocal::GrabImage(int &Size, bool Jpeg,
+                                int Quality, int SizeX,
+                                int SizeY)
 {
   uchar *data;
   LOCK_FE;
@@ -181,7 +181,7 @@ int64_t cXinelibLocal::GetSTC()
 // Playback files
 //
 
-bool cXinelibLocal::EndOfStreamReached(void) 
+bool cXinelibLocal::EndOfStreamReached(void)
 {
   LOCK_THREAD;
   if(fe && fe->xine_is_finished(fe, 1))
@@ -193,9 +193,9 @@ bool cXinelibLocal::EndOfStreamReached(void)
 // Configuration
 //
 
-void cXinelibLocal::ConfigureWindow(int fullscreen, int width, int height, 
-				    int modeswitch, const char *modeline, 
-				    int aspect, int scale_video)
+void cXinelibLocal::ConfigureWindow(int fullscreen, int width, int height,
+                                    int modeswitch, const char *modeline,
+                                    int aspect, int scale_video)
 {
   LOCK_FE;
   if(fe)
@@ -211,10 +211,10 @@ void cXinelibLocal::ConfigureDecoder(int pes_buffers)
     LOCK_FE;
     xc.pes_buffers = pes_buffers;
     if(!fe)
-      return;    
+      return;
     m_bReady = false;
     m_bReconfigRequest = true;
-    fe->fe_interrupt(fe);    
+    fe->fe_interrupt(fe);
   }
 
   while (!m_bReady && Running())
@@ -290,7 +290,7 @@ frontend_t *cXinelibLocal::load_frontend(const char *fe_name)
       LOGERR("load_frontend: can't stat %s", libname);
     } else if((statbuffer.st_mode & S_IFMT) != S_IFREG) {
       LOGMSG("load_frontend: %s not regular file ! trying to load anyway ...",
-	     libname);
+             libname);
     }
 
     if ( !(lib = dlopen (libname, RTLD_LAZY | RTLD_GLOBAL))) {
@@ -301,19 +301,20 @@ frontend_t *cXinelibLocal::load_frontend(const char *fe_name)
       frontend_t *fe = (**fe_creator)();
 
       if (fe) {
-	if (h_fe_lib)
-	  dlclose(h_fe_lib);
-	h_fe_lib = lib;
+        if (h_fe_lib)
+          dlclose(h_fe_lib);
+        h_fe_lib = lib;
 
-	LOGDBG("Using frontend %s (%s) from %s",
-	       xc.s_frontends[fe_ind], xc.s_frontendNames[fe_ind],
-	       xc.s_frontend_files[fe_ind]);
+        LOGDBG("Using frontend %s (%s) from %s",
+               xc.s_frontends[fe_ind], xc.s_frontendNames[fe_ind],
+               xc.s_frontend_files[fe_ind]);
 
-	return fe;
+        return fe;
       } else {
-	LOGMSG("Frontend %s (%s) creation failed",
-	       xc.s_frontends[fe_ind], xc.s_frontendNames[fe_ind]);
+        LOGMSG("Frontend %s (%s) creation failed",
+               xc.s_frontends[fe_ind], xc.s_frontendNames[fe_ind]);
       }
+      dlclose(lib);
     } else {
       LOGERR("Frontend entry point not found");
       dlclose(lib);
@@ -331,7 +332,7 @@ frontend_t *cXinelibLocal::load_frontend(const char *fe_name)
 // Thread main loop
 //
 
-void cXinelibLocal::Action(void) 
+void cXinelibLocal::Action(void)
 {
   frontend_t *curr_fe = NULL;
 
@@ -340,31 +341,30 @@ void cXinelibLocal::Action(void)
   SetPriority(2); /* lower priority */
 
   // init frontend
+
+  curr_fe = load_frontend(xc.local_frontend);
   if(!curr_fe) {
-    curr_fe = load_frontend(xc.local_frontend);
-    if(!curr_fe) {
-      LOGMSG("cXinelibLocal: Error initializing frontend");
-      Cancel(-1);
-    } else {
-      LOGDBG("cXinelibLocal::Action - fe created");
-      curr_fe->fe_message_cb = keypress_handler;
-      curr_fe->fe_message_h  = this;
-      if(!curr_fe->fe_display_open(curr_fe,
-                                   xc.xpos, xc.ypos, xc.width, xc.height, xc.fullscreen,
-                                   xc.hud_osd,
-                                   xc.opengl,
-                                   xc.modeswitch, xc.modeline, xc.display_aspect,
-                                   0/*no_x_kbd*/, 0/*gui_hotkeys*/, 0/*touchscreen*/,
-                                   xc.video_port,
-                                   xc.scale_video,
-                                   NULL,
-                                   xc.window_id)) {
-	LOGMSG("cXinelibLocal: Error initializing display");
-        Cancel(-1);
-      } else {
-	LOGDBG("cXinelibLocal::Action - fe->fe_display_open ok");
-      }
-    }
+    LOGMSG("cXinelibLocal: Error initializing frontend");
+    Cancel(-1);
+    return;
+  }
+  LOGDBG("cXinelibLocal::Action - fe created");
+  curr_fe->fe_message_cb = keypress_handler;
+  curr_fe->fe_message_h  = this;
+  if(!curr_fe->fe_display_open(curr_fe,
+                               xc.xpos, xc.ypos, xc.width, xc.height, xc.fullscreen,
+                               xc.hud_osd,
+                               xc.opengl,
+                               xc.modeswitch, xc.modeline, xc.display_aspect,
+                               0/*no_x_kbd*/, 0/*gui_hotkeys*/, 0/*touchscreen*/,
+                               xc.video_port,
+                               xc.scale_video,
+                               NULL,
+                               xc.window_id)) {
+    LOGMSG("cXinelibLocal: Error initializing display");
+    Cancel(-1);
+  } else {
+    LOGDBG("cXinelibLocal::Action - fe->fe_display_open ok");
   }
 
   // main loop
@@ -377,13 +377,13 @@ void cXinelibLocal::Action(void)
 
       fe = curr_fe;
       if(m_bReconfigRequest) {
-	if(!fe->xine_init(fe, xc.audio_driver, xc.audio_port,
-			  xc.video_driver,
-			  xc.pes_buffers,
-			  xc.post_plugins, xc.config_file)) {
-	  LOGMSG("cXinelibLocal: Error initializing frontend");
-	  break;
-	}
+        if(!fe->xine_init(fe, xc.audio_driver, xc.audio_port,
+                          xc.video_driver,
+                          xc.pes_buffers,
+                          xc.post_plugins, xc.config_file)) {
+          LOGMSG("cXinelibLocal: Error initializing frontend");
+          break;
+        }
         LOGDBG("cXinelibLocal::Action - fe->xine_init ok");
         m_bReconfigRequest = false;
       }
@@ -404,7 +404,7 @@ void cXinelibLocal::Action(void)
       LOGDBG("cXinelibLocal::Action - fe->xine_play ok");
 
       m_StreamPos = 0;
-      Xine_Control("STREAMPOS 0"); 
+      Xine_Control("STREAMPOS 0");
       Xine_Control("VERSION " XINELIBOUTPUT_VERSION " " "\r\n");
     }
 
@@ -427,17 +427,17 @@ void cXinelibLocal::Action(void)
     }
 
     // main event loop
-    LOGDBG("cXinelibLocal:Action - Starting event loop");   
+    LOGDBG("cXinelibLocal:Action - Starting event loop");
     {
       LOCK_FE;
       while (Running() && m_bReady &&
              (/*m_bLoopPlay ||*/ !fe->xine_is_finished(fe, 0)) &&
              fe->fe_run(fe))
-	/*cCondWait::SleepMs(50)*/ ;
+        /*cCondWait::SleepMs(50)*/ ;
     }
 
     LOGDBG("cXinelibLocal::Action - event loop terminated, "
-	   "xine_is_finished=%d", fe->xine_is_finished(fe, 0));
+           "xine_is_finished=%d", fe->xine_is_finished(fe, 0));
 
     {
       LOCK_THREAD;
diff --git a/frontend_local.h b/frontend_local.h
index 04004a5..496eac6 100644
--- a/frontend_local.h
+++ b/frontend_local.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: frontend_local.h,v 1.11 2012/03/17 20:19:27 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/frontend_svr.c b/frontend_svr.c
index a79b406..ac9c8ea 100644
--- a/frontend_svr.c
+++ b/frontend_svr.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: frontend_svr.c,v 1.109 2014/06/23 12:20:28 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -45,6 +45,7 @@
 #include "tools/sdp.h"
 #include "tools/rle.h"
 #include "tools/sys_cap.h"
+#include "tools/avahi.h"
 
 #include "frontend_svr.h"
 #include "device.h"
@@ -136,6 +137,8 @@ cXinelibServer::cXinelibServer(cXinelibDevice *Dev, int listen_port) :
   m_Port = listen_port;
   m_ServerId = time(NULL) ^ getpid();
 
+  m_hAvahi = NULL;
+
   fd_listen    = -1;
   fd_discovery = -1;
 
@@ -184,6 +187,10 @@ cXinelibServer::~cXinelibServer()
   delete m_Scheduler;
 
   free(m_Header);
+
+  if (m_hAvahi) {
+    x_avahi_stop(m_hAvahi);
+  }
 }
 
 void cXinelibServer::Clear(void)
@@ -783,7 +790,7 @@ int cXinelibServer::SupportsTrueColorOSD(void)
         has_clients++;
     }
 
-  return has_clients ? 1 : -1;
+  return has_clients || xc.truecoloreverytime ? 1 : -1;
 }
 
 int cXinelibServer::PlayFileCtrl(const char *Cmd, int TimeoutMs)
@@ -822,6 +829,11 @@ bool cXinelibServer::Listen(int listen_port)
   bool result = false;
   TRACEF("cXinelibServer::Listen");
 
+  if (m_hAvahi) {
+    x_avahi_stop(m_hAvahi);
+    m_hAvahi = NULL;
+  }
+
   if(listen_port <= 0 || listen_port > 0xffff) {
     CLOSESOCKET(fd_listen);
     CLOSESOCKET(fd_discovery);
@@ -838,6 +850,7 @@ bool cXinelibServer::Listen(int listen_port)
 
     int iReuse = 1;
     struct sockaddr_in name;
+    memset(&name, 0, sizeof(name));
     name.sin_family = AF_INET;
     name.sin_addr.s_addr = htonl(INADDR_ANY);
     name.sin_port = htons(m_Port);
@@ -876,10 +889,12 @@ bool cXinelibServer::Listen(int listen_port)
   CLOSESOCKET(fd_discovery);
   if(xc.remote_usebcast) {
     fd_discovery = udp_discovery_init();
-    if(udp_discovery_broadcast(fd_discovery, m_Port, xc.remote_local_ip) < 0)
-      CLOSESOCKET(fd_discovery);
-    else
-      LOGMSG("Listening for UDP broadcasts on port %d", m_Port);
+    if (fd_discovery >= 0) {
+      if(udp_discovery_broadcast(fd_discovery, m_Port, xc.remote_local_ip) < 0)
+        CLOSESOCKET(fd_discovery);
+      else
+        LOGMSG("Listening for UDP broadcasts on port %d", m_Port);
+    }
   }
 
   // set up multicast sockets
@@ -894,6 +909,9 @@ bool cXinelibServer::Listen(int listen_port)
       m_Scheduler->AddRtp();
   }
 
+  // AVAHI announces
+  m_hAvahi = x_avahi_start(listen_port, xc.remote_use_rtsp, xc.remote_use_http);
+
   return result;
 }
 
@@ -1758,7 +1776,7 @@ void cXinelibServer::Handle_ClientConnected(int fd)
     const char *msg = "Server busy.\r\n";
     ssize_t len = strlen(msg);
     // too many clients
-    LOGMSG("Too many clients, connection refused");
+    LOGMSG("Too many clients (%d), connection refused", cli);
     if(write(fd, msg, len) != len)
       LOGERR("Write failed.");
     CLOSESOCKET(fd);
@@ -1826,8 +1844,7 @@ void cXinelibServer::Action(void)
 {
   TRACEF("cXinelibServer::Action");
 
-  int    i, fds=0;
-  pollfd pfd[MAXCLIENTS];
+  pollfd pfd[2*MAXCLIENTS + 2];
 
   /* higher priority */
   if (have_cap_sys_nice())
@@ -1855,9 +1872,9 @@ void cXinelibServer::Action(void)
   m_bReady=true;
 
   if(fd_listen>=0)
-    while (Running() && fds>=0) {
+    while (Running()) {
+      int i, fds = 0;
 
-      fds = 0;
       if(fd_listen>=0) {
         pfd[fds].fd = fd_listen;
         pfd[fds++].events = POLLIN;
diff --git a/frontend_svr.h b/frontend_svr.h
index 83d8b01..2c40403 100644
--- a/frontend_svr.h
+++ b/frontend_svr.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: frontend_svr.h,v 1.32 2012/03/17 20:19:27 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -106,6 +106,8 @@ protected:
     int  fd_listen;
     int  fd_discovery;
 
+    void *m_hAvahi;
+
     cxSocket fd_control[MAXCLIENTS];
     int      fd_data   [MAXCLIENTS];
 
diff --git a/include/vdr-xineliboutput/service_pip.h b/include/vdr-xineliboutput/service_pip.h
index ee43561..493d64c 100644
--- a/include/vdr-xineliboutput/service_pip.h
+++ b/include/vdr-xineliboutput/service_pip.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: service_pip.h,v 1.1 2010/03/12 21:15:05 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/logdefs.c b/logdefs.c
index ec434e2..797c5f4 100644
--- a/logdefs.c
+++ b/logdefs.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: logdefs.c,v 1.3 2010/07/19 13:39:24 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/logdefs.h b/logdefs.h
index a650ca7..e865b8a 100644
--- a/logdefs.h
+++ b/logdefs.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: logdefs.h,v 1.16 2011/11/01 12:26:36 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/media_player.c b/media_player.c
index 0b9b8ca..f3c7915 100644
--- a/media_player.c
+++ b/media_player.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: media_player.c,v 1.95 2013/10/28 09:14:47 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -751,6 +751,7 @@ eOSState cXinelibPlayerControl::ProcessKey(eKeys Key)
       case kUser9:
       case k3:      m_Player->Control("SEEK +20");  break;
       case k2:      xc.subtitle_vpos -= 10;
+                    /* fall thru */
       case k5:      xc.subtitle_vpos += 5;
                     m_Player->Control("SUBTITLES %d", xc.subtitle_vpos);
                     break;
diff --git a/media_player.h b/media_player.h
index 9f621f6..2ec6419 100644
--- a/media_player.h
+++ b/media_player.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: media_player.h,v 1.24 2012/03/19 11:07:52 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/menu.c b/menu.c
index 62046cd..0516a12 100644
--- a/menu.c
+++ b/menu.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: menu.c,v 1.97 2013/10/25 17:22:38 rofafor Exp $
+ * $Id$
  *
  */
 
@@ -589,6 +589,11 @@ cMenuXinelib::cMenuXinelib(cXinelibDevice *Dev)
 
   novideo = m_Dev->GetPlayMode() == pmAudioOnlyBlack ? 1 : 0;
 
+  audio_ctrl_compress = NULL;
+  ctrl_autocrop = NULL;
+  ctrl_overscan = NULL;
+  ctrl_novideo = NULL;
+
   Add(SeparatorItem(tr("Media")));
   if (xc.media_menu_items & MEDIA_MENU_FILES)
     Add(SubMenuItem(tr("Play file"),        osUser1));
diff --git a/menu.h b/menu.h
index 7a9ce0c..7fcf9b9 100644
--- a/menu.h
+++ b/menu.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: menu.h,v 1.11 2012/03/19 11:29:14 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/menuitems.c b/menuitems.c
index 3a59bbf..0bb286c 100644
--- a/menuitems.c
+++ b/menuitems.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: menuitems.c,v 1.15 2009/08/02 11:38:24 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/menuitems.h b/menuitems.h
index 7c79406..a117727 100644
--- a/menuitems.h
+++ b/menuitems.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: menuitems.h,v 1.10 2010/01/19 22:06:52 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/mpg2c.c b/mpg2c.c
index b04d869..2dd1fad 100644
--- a/mpg2c.c
+++ b/mpg2c.c
@@ -6,7 +6,7 @@
  *
  * mpg2.c: 
  *
- * $Id: mpg2c.c,v 1.3 2006/06/04 11:00:04 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/osd.c b/osd.c
index 5aa4593..1ff831a 100644
--- a/osd.c
+++ b/osd.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: osd.c,v 1.54 2015/02/20 16:04:16 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/osd.h b/osd.h
index c467294..ef80f64 100644
--- a/osd.h
+++ b/osd.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: osd.h,v 1.6 2011/03/20 23:04:47 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/setup_menu.c b/setup_menu.c
index 84c56d1..bd99766 100644
--- a/setup_menu.c
+++ b/setup_menu.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: setup_menu.c,v 1.89 2013/10/28 09:14:47 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -1888,6 +1888,7 @@ eOSState cTestGrayscale::ProcessKey(eKeys key)
 	return osEnd;
       case kRight:
 	br += 0xffff/1024*2;
+        /* fall thru */
       case kLeft:
 	br -= 0xffff/1024;
 	sprintf(s, "b %d", br);
@@ -1897,6 +1898,7 @@ eOSState cTestGrayscale::ProcessKey(eKeys key)
 	return osContinue;	
       case kUp:
 	co += 0xffff/1024*2;
+        /* fall thru */
       case kDown:
 	co -= 0xffff/1024;
 	sprintf(s, "c %d", co);
diff --git a/setup_menu.h b/setup_menu.h
index 7da7bc3..bbd02dd 100644
--- a/setup_menu.h
+++ b/setup_menu.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: setup_menu.h,v 1.2 2012/03/19 09:53:14 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools.c b/tools.c
index ff7cc68..b1af31e 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: tools.c,v 1.2 2009/01/27 09:25:22 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -21,4 +21,5 @@
 #include "tools/pes.c"
 #include "tools/mpeg.c"
 #include "tools/h264.c"
+#include "tools/h265.c"
 #include "tools/ts.c"
diff --git a/tools/avahi.c b/tools/avahi.c
new file mode 100644
index 0000000..dfb4929
--- /dev/null
+++ b/tools/avahi.c
@@ -0,0 +1,253 @@
+/*
+ * avahi.c: mDNS announce
+ *
+ * See the main source file 'xineliboutput.c' for copyright information and
+ * how to reach the author.
+ *
+ * $Id$
+ *
+ */
+
+#include "avahi.h"
+
+#include "../logdefs.h"            // logging
+#include "../features.h"
+
+#ifdef HAVE_AVAHI_CLIENT
+
+#include <errno.h>
+#include <stdio.h>  // snprintf
+#include <stdlib.h>
+#include <string.h>
+
+#include <pthread.h>
+
+#include <avahi-client/client.h>
+#include <avahi-client/publish.h>
+#include <avahi-common/alternative.h>
+#include <avahi-common/simple-watch.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/error.h>
+#include <avahi-common/timeval.h>
+
+typedef struct {
+  AvahiEntryGroup *group;
+  AvahiSimplePoll *simple_poll;
+
+  char *name;
+  int   port;
+
+  int   rtsp;
+  int   http;
+
+  pthread_t thread;
+} avahi_data;
+
+static void _create_services(AvahiClient *c, avahi_data *d);
+
+static void _entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata)
+{
+  avahi_data *d = (avahi_data *)userdata;
+  d->group = g;
+
+  switch (state) {
+  case AVAHI_ENTRY_GROUP_ESTABLISHED:
+    LOGMSG("AVAHI service '%s' successfully established.", d->name);
+    break;
+
+  case AVAHI_ENTRY_GROUP_COLLISION: {
+    char *n;
+    /* A service name collision with a remote service
+     * happened. Let's pick a new name */
+    n = avahi_alternative_service_name(d->name);
+    avahi_free(d->name);
+    d->name = n;
+    LOGERR("AVAHI service name collision, renaming service to '%s'", d->name);
+    _create_services(avahi_entry_group_get_client(g), d);
+    break;
+  }
+
+  case AVAHI_ENTRY_GROUP_FAILURE :
+    LOGERR("AVAHI entry group failure: %s", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));
+    avahi_simple_poll_quit(d->simple_poll);
+    break;
+  case AVAHI_ENTRY_GROUP_UNCOMMITED:
+  case AVAHI_ENTRY_GROUP_REGISTERING:
+    break;
+  }
+}
+
+static void _create_services(AvahiClient *c, avahi_data *d)
+{
+  char *n;
+  int ret;
+
+  if (!d->group) {
+    if (!(d->group = avahi_entry_group_new(c, _entry_group_callback, d))) {
+      LOGERR("avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(c)));
+      goto fail;
+    }
+  }
+
+  if (avahi_entry_group_is_empty(d->group)) {
+    LOGMSG("AVAHI: adding service '%s'", d->name);
+
+    if (d->rtsp) {
+      if ((ret = avahi_entry_group_add_service(d->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET/*UNSPEC*/, (AvahiPublishFlags)0,
+                                               d->name, "_rtsp._tcp", NULL, NULL, d->port, NULL)) < 0) {
+        if (ret == AVAHI_ERR_COLLISION)
+          goto collision;
+        LOGERR("AVAHI failed to add _rtsp._tcp service: %s", avahi_strerror(ret));
+        goto fail;
+      }
+    }
+
+    if (d->http) {
+      if ((ret = avahi_entry_group_add_service(d->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET/*UNSPEC*/, (AvahiPublishFlags)0,
+                                               d->name, "_http._tcp", NULL, NULL, d->port, NULL)) < 0) {
+        if (ret == AVAHI_ERR_COLLISION)
+          goto collision;
+        LOGERR("AVAHI failed to add _http._tcp service: %s", avahi_strerror(ret));
+        goto fail;
+      }
+    }
+
+    if ((ret = avahi_entry_group_add_service(d->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET/*UNSPEC*/, (AvahiPublishFlags)0,
+                                             d->name, "_xvdr._tcp", NULL, NULL, d->port, NULL)) < 0) {
+      if (ret == AVAHI_ERR_COLLISION)
+        goto collision;
+      LOGERR("AVAHI failed to add _xvdr._tcp service: %s", avahi_strerror(ret));
+      goto fail;
+    }
+
+
+    /* Tell the server to register the service */
+    if ((ret = avahi_entry_group_commit(d->group)) < 0) {
+      LOGERR("AVAHI failed to commit entry group: %s", avahi_strerror(ret));
+      goto fail;
+    }
+  }
+  return;
+
+ collision:
+  n = avahi_alternative_service_name(d->name);
+  avahi_free(d->name);
+  d->name = n;
+  LOGMSG("AVAHI service name collision, renaming service to '%s'", d->name);
+  avahi_entry_group_reset(d->group);
+  _create_services(c, d);
+  return;
+
+ fail:
+  avahi_simple_poll_quit(d->simple_poll);
+}
+
+static void _client_callback(AvahiClient *c, AvahiClientState state, void * userdata)
+{
+  avahi_data *d = (avahi_data *)userdata;
+
+  switch (state) {
+  case AVAHI_CLIENT_S_RUNNING:
+    _create_services(c, d);
+    break;
+
+  case AVAHI_CLIENT_FAILURE:
+    LOGERR("AVAHI client failure: %s", avahi_strerror(avahi_client_errno(c)));
+    avahi_simple_poll_quit(d->simple_poll);
+    break;
+
+  case AVAHI_CLIENT_S_COLLISION:
+  case AVAHI_CLIENT_S_REGISTERING:
+    if (d->group)
+      avahi_entry_group_reset(d->group);
+    break;
+
+  case AVAHI_CLIENT_CONNECTING:
+    break;
+  }
+}
+
+/*
+ *
+ */
+
+static void *_avahi_run(void *h)
+{
+  avahi_data *d = (avahi_data *)h;
+  AvahiClient *client = NULL;
+  int error;
+
+  if (!(d->simple_poll = avahi_simple_poll_new())) {
+    LOGMSG("AVAHI failed to create simple poll object");
+    return NULL;
+  }
+
+  d->name = avahi_strdup("VDR (xineliboutput)");
+
+  client = avahi_client_new(avahi_simple_poll_get(d->simple_poll), (AvahiClientFlags)0, _client_callback, d, &error);
+  if (!client) {
+    LOGERR("AVAHI failed to create client: %s", avahi_strerror(error));
+    return NULL;
+  }
+
+  /* Run the main loop */
+  avahi_simple_poll_loop(d->simple_poll);
+
+  LOGMSG("AVAHI terminating");
+
+  avahi_client_free(client);
+
+  return NULL;
+}
+
+void *x_avahi_start(int port, int rtsp, int http)
+{
+  void *h = calloc(1, sizeof(avahi_data));
+
+  if (h) {
+    avahi_data *d = (avahi_data *)h;
+    int err;
+
+    d->port = port;
+    d->rtsp = rtsp;
+    d->http = http;
+
+    if ((err = pthread_create (&d->thread, NULL, _avahi_run, h)) != 0) {
+      LOGERR("AVAHI can't create new thread (%s)", strerror(err));
+    }
+  }
+
+  return h;
+}
+
+static void _avahi_free(void *h)
+{
+  avahi_data *d = (avahi_data *)h;
+  if (d->simple_poll)
+    avahi_simple_poll_free(d->simple_poll);
+  avahi_free(d->name);
+
+  free(h);
+}
+
+void x_avahi_stop(void *h)
+{
+  avahi_data *d = (avahi_data *)h;
+  void *p;
+
+  avahi_simple_poll_quit(d->simple_poll);
+
+  pthread_cancel (d->thread);
+  pthread_join (d->thread, &p);
+
+  _avahi_free(d);
+}
+
+#else /* HAVE_AVAHI */
+
+
+void x_avahi_stop(void *h)
+{
+}
+
+#endif /* HAVE_AVAHI */
diff --git a/tools/avahi.h b/tools/avahi.h
new file mode 100644
index 0000000..5a0f61a
--- /dev/null
+++ b/tools/avahi.h
@@ -0,0 +1,17 @@
+/*
+ * avahi.h: mDNS announce
+ *
+ * See the main source file 'xineliboutput.c' for copyright information and
+ * how to reach the author.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef XINELIBOUTPUT_AVAHI_H_
+#define XINELIBOUTPUT_AVAHI_H_
+
+void x_avahi_stop(void *h);
+void *x_avahi_start(int port, int rtsp, int http);
+
+#endif /* XINELIBOUTPUT_AVAHI_H_ */
diff --git a/tools/backgroundwriter.c b/tools/backgroundwriter.c
index cfb5ba9..3f60e3e 100644
--- a/tools/backgroundwriter.c
+++ b/tools/backgroundwriter.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: backgroundwriter.c,v 1.23 2010/07/19 13:20:21 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/backgroundwriter.h b/tools/backgroundwriter.h
index 5993553..b4066b8 100644
--- a/tools/backgroundwriter.h
+++ b/tools/backgroundwriter.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: backgroundwriter.h,v 1.10 2012/01/16 12:12:49 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/bitstream.h b/tools/bitstream.h
index 8e6a37c..bc5ace4 100644
--- a/tools/bitstream.h
+++ b/tools/bitstream.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: bitstream.h,v 1.3 2009/02/14 20:44:15 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -16,15 +16,15 @@
 
 typedef struct {
   const uint8_t *data;
-  int            count; /* in bits */
-  int            index; /* in bits */
+  size_t         count; /* in bits */
+  size_t         index; /* in bits */
 } br_state;
 
 #define BR_INIT(data,bytes) { (data), 8*(bytes), 0 }
 
 #define BR_EOF(br) ((br)->index >= (br)->count)
 
-static inline void br_init(br_state *br, const uint8_t *data, int bytes)
+static inline void br_init(br_state *br, const uint8_t *data, size_t bytes)
 {
   br->data  = data;
   br->count = 8*bytes;
@@ -61,15 +61,15 @@ static inline void br_skip_bits(br_state *br, int n)
 
 
 typedef struct {
-  uint8_t *data;
-  uint8_t *data_end;
-  uint32_t cache; 
+  const uint8_t *data;
+  const uint8_t *data_end;
+  uint32_t cache;
   uint32_t cache_bits;
 } br_state;
 
 #define BR_INIT(data,bytes) { (data), (data)+(bytes), 0, 0 }
 
-static inline void br_init(br_state *br, const uint8_t *data, int bytes)
+static inline void br_init(br_state *br, const uint8_t *data, size_t bytes)
 {
   br->data       = data;
   br->data_end   = data + bytes;
@@ -124,7 +124,7 @@ static inline void br_skip_bits(br_state *br, int n)
   } else {
     /* drop cached bits */
     n -= br->cache_bits;
-  
+
     /* drop full bytes */
     br->data += (n >> 3);
     n &= 7;
@@ -138,7 +138,7 @@ static inline void br_skip_bits(br_state *br, int n)
     }
   }
 }
- 
+
 
 # endif /* NOCACHE */
 
diff --git a/tools/cxsocket.c b/tools/cxsocket.c
index 09dcd90..a4db707 100644
--- a/tools/cxsocket.c
+++ b/tools/cxsocket.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: cxsocket.c,v 1.12 2010/07/19 13:20:22 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -64,31 +64,7 @@ bool cxSocket::set_blocking(bool state)
 
 bool cxSocket::set_buffers(int Tx, int Rx)
 {
-  int max_buf = Tx;
-  /*while(max_buf) {*/
-    errno = 0;
-    if(setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(int))) {
-      LOGERR("cxSocket: setsockopt(SO_SNDBUF,%d) failed", max_buf);
-      /*max_buf >>= 1;*/
-    }
-    /*else {*/
-      int tmp = 0;
-      int len = sizeof(int);
-      errno = 0;
-      if(getsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, &tmp, (socklen_t*)&len)) {
-	LOGERR("cxSocket: getsockopt(SO_SNDBUF,%d) failed", max_buf);
-	/*break;*/
-      } else if(tmp != max_buf) {
-	LOGDBG("cxSocket: setsockopt(SO_SNDBUF): got %d bytes", tmp);
-	/*max_buf >>= 1;*/
-	/*continue;*/
-      }
-    /*}*/
-  /*}*/
-
-  max_buf = Rx;
-  setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, &max_buf, sizeof(int));
-
+  ::set_socket_buffers(m_fd, Tx, Rx);
   return true;
 }
 
@@ -300,6 +276,8 @@ ssize_t cxSocket::printf(const char *fmt, ...)
 
   va_start(argp, fmt);
   r = vsnprintf(buf, sizeof(buf), fmt, argp);
+  va_end(argp);
+
   if(r<0)
     LOGERR("cxSocket::printf: vsnprintf failed");
   else if(r >= (int)sizeof(buf))
diff --git a/tools/cxsocket.h b/tools/cxsocket.h
index 1193b32..d56bf36 100644
--- a/tools/cxsocket.h
+++ b/tools/cxsocket.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: cxsocket.h,v 1.21 2010/07/19 13:20:22 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -137,7 +137,9 @@ static inline void set_socket_buffers(int s, int txbuf, int rxbuf)
   /*}*/
 
   max_buf = rxbuf;
-  setsockopt(s, SOL_SOCKET, SO_RCVBUF, &max_buf, sizeof(int));
+  if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &max_buf, sizeof(int)) < 0) {
+    LOGERR("setsockopt(SO_RCVBUF,%d) failed", max_buf);
+  }
 }
 
 //
diff --git a/tools/debug_mutex.h b/tools/debug_mutex.h
index b759762..706658e 100644
--- a/tools/debug_mutex.h
+++ b/tools/debug_mutex.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: debug_mutex.h,v 1.3 2007/03/14 11:50:08 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/display_message.h b/tools/display_message.h
index 9b1806f..7f6df31 100644
--- a/tools/display_message.h
+++ b/tools/display_message.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: display_message.h,v 1.2 2007/01/06 04:28:08 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/functor.h b/tools/functor.h
index 466fa2c..67170e2 100644
--- a/tools/functor.h
+++ b/tools/functor.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: functor.h,v 1.1 2006/08/24 23:25:07 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/functorimpl.h b/tools/functorimpl.h
index 9ae7f4a..fe10dad 100644
--- a/tools/functorimpl.h
+++ b/tools/functorimpl.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: functorimpl.h,v 1.1 2006/08/24 23:25:07 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/future.h b/tools/future.h
index 0747fc9..e5c5414 100644
--- a/tools/future.h
+++ b/tools/future.h
@@ -5,7 +5,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: future.h,v 1.2 2006/08/19 23:44:07 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/general_remote.h b/tools/general_remote.h
index 80e33f1..c7f80d4 100644
--- a/tools/general_remote.h
+++ b/tools/general_remote.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: general_remote.h,v 1.1 2006/06/03 10:04:27 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/h264.c b/tools/h264.c
index ac41306..9bfc819 100644
--- a/tools/h264.c
+++ b/tools/h264.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: h264.c,v 1.9 2010/02/02 22:47:35 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -23,7 +23,8 @@
 #include "mpeg.h"
 #include "h264.h"
 
-int h264_parse_sps(const uint8_t *buf, int len, h264_sps_data_t *sps)
+
+int h264_parse_sps(const uint8_t *buf, size_t len, h264_sps_data_t *sps)
 {
   br_state br = BR_INIT(buf, len);
   int profile_idc, pic_order_cnt_type;
@@ -47,15 +48,15 @@ int h264_parse_sps(const uint8_t *buf, int len, h264_sps_data_t *sps)
     br_skip_ue_golomb(&br); /* bit_depth_chroma - 8           */
     br_skip_bit(&br);       /* transform_bypass               */
     if (br_get_bit(&br))    /* seq_scaling_matrix_present     */
-      for (i = 0; i < 8; i++)  
-	if (br_get_bit(&br)) { /* seq_scaling_list_present    */
-	  int last = 8, next = 8, size = (i<6) ? 16 : 64;
-	  for (j = 0; j < size; j++) {
-	    if (next)
-	      next = (last + br_get_se_golomb(&br)) & 0xff;
-	    last = next ?: last;
-	  }
-	}
+      for (i = 0; i < 8; i++)
+        if (br_get_bit(&br)) { /* seq_scaling_list_present    */
+          int last = 8, next = 8, size = (i<6) ? 16 : 64;
+          for (j = 0; j < size; j++) {
+            if (next)
+              next = (last + br_get_se_golomb(&br)) & 0xff;
+            last = next ?: last;
+          }
+        }
   }
 
   br_skip_ue_golomb(&br);      /* log2_max_frame_num - 4 */
@@ -78,10 +79,10 @@ int h264_parse_sps(const uint8_t *buf, int len, h264_sps_data_t *sps)
   LOGDBG("H.264 SPS: pic_width:  %u mbs", (unsigned) sps->width);
   LOGDBG("H.264 SPS: pic_height: %u mbs", (unsigned) sps->height);
   LOGDBG("H.264 SPS: frame only flag: %d", frame_mbs_only);
-  
+
   sps->width  *= 16;
   sps->height *= 16 * (2-frame_mbs_only);
-  
+
   if (!frame_mbs_only)
     if (br_get_bit(&br)) /* mb_adaptive_frame_field_flag */
       LOGDBG("H.264 SPS: MBAFF");
@@ -91,12 +92,12 @@ int h264_parse_sps(const uint8_t *buf, int len, h264_sps_data_t *sps)
     uint32_t crop_right  = br_get_ue_golomb(&br);
     uint32_t crop_top    = br_get_ue_golomb(&br);
     uint32_t crop_bottom = br_get_ue_golomb(&br);
-    LOGDBG("H.264 SPS: cropping %d %d %d %d", 
-	   crop_left, crop_top, crop_right, crop_bottom);
+    LOGDBG("H.264 SPS: cropping %d %d %d %d",
+           crop_left, crop_top, crop_right, crop_bottom);
 
     sps->width -= 2*(crop_left + crop_right);
     if (frame_mbs_only)
-      sps->height -= 2*(crop_top + crop_bottom); 
+      sps->height -= 2*(crop_top + crop_bottom);
     else
       sps->height -= 4*(crop_top + crop_bottom);
   }
@@ -109,31 +110,31 @@ int h264_parse_sps(const uint8_t *buf, int len, h264_sps_data_t *sps)
       LOGDBG("H.264 SPS: aspect_ratio_idc %d", aspect_ratio_idc);
 
       if (aspect_ratio_idc == 255 /* Extended_SAR */) {
-	sps->pixel_aspect.num = br_get_u16(&br); /* sar_width */
-	sps->pixel_aspect.den = br_get_u16(&br); /* sar_height */
-	LOGDBG("H.264 SPS: -> sar %dx%d", sps->pixel_aspect.num, sps->pixel_aspect.den);
+        sps->pixel_aspect.num = br_get_u16(&br); /* sar_width */
+        sps->pixel_aspect.den = br_get_u16(&br); /* sar_height */
+        LOGDBG("H.264 SPS: -> sar %dx%d", sps->pixel_aspect.num, sps->pixel_aspect.den);
       } else {
-	static const mpeg_rational_t aspect_ratios[] =
-	  { /* page 213: */
-	    /* 0: unknown */
-	    {0, 1},
-	    /* 1...16: */
-	    { 1,  1}, {12, 11}, {10, 11}, {16, 11}, { 40, 33}, {24, 11}, {20, 11}, {32, 11}, 
-	    {80, 33}, {18, 11}, {15, 11}, {64, 33}, {160, 99}, { 4,  3}, { 3,  2}, { 2,  1}
-	  };
-
-	if (aspect_ratio_idc < sizeof(aspect_ratios)/sizeof(aspect_ratios[0])) {
-	  memcpy(&sps->pixel_aspect, &aspect_ratios[aspect_ratio_idc], sizeof(mpeg_rational_t));
-	  LOGDBG("H.264 SPS: -> aspect ratio %d / %d", sps->pixel_aspect.num, sps->pixel_aspect.den);
-	} else {
-	  LOGMSG("H.264 SPS: aspect_ratio_idc out of range !");
-	}
+        static const mpeg_rational_t aspect_ratios[] =
+          { /* page 213: */
+            /* 0: unknown */
+            {0, 1},
+            /* 1...16: */
+            { 1,  1}, {12, 11}, {10, 11}, {16, 11}, { 40, 33}, {24, 11}, {20, 11}, {32, 11},
+            {80, 33}, {18, 11}, {15, 11}, {64, 33}, {160, 99}, { 4,  3}, { 3,  2}, { 2,  1}
+          };
+
+        if (aspect_ratio_idc < sizeof(aspect_ratios)/sizeof(aspect_ratios[0])) {
+          memcpy(&sps->pixel_aspect, &aspect_ratios[aspect_ratio_idc], sizeof(mpeg_rational_t));
+          LOGDBG("H.264 SPS: -> aspect ratio %d / %d", sps->pixel_aspect.num, sps->pixel_aspect.den);
+        } else {
+          LOGMSG("H.264 SPS: aspect_ratio_idc out of range !");
+        }
       }
     }
   }
 
   LOGDBG("H.264 SPS: -> video size %dx%d, aspect %d:%d",
-	 sps->width, sps->height, sps->pixel_aspect.num, sps->pixel_aspect.den);
+         sps->width, sps->height, sps->pixel_aspect.num, sps->pixel_aspect.den);
 
   if(BR_EOF(&br)) {
     LOGDBG("H.264 SPS: not enough data ?");
@@ -142,9 +143,9 @@ int h264_parse_sps(const uint8_t *buf, int len, h264_sps_data_t *sps)
   return 1;
 }
 
-static int h264_nal_unescape(uint8_t *dst, const uint8_t *src, int len)
+static int h264_nal_unescape(uint8_t *dst, const uint8_t *src, size_t len)
 {
-  int s = 0, d = 0;
+  size_t s = 0, d = 0;
   while (s < len) {
     if (!src[s] && !src[s+1]) {
       /* hit 00 00 xx */
@@ -152,13 +153,13 @@ static int h264_nal_unescape(uint8_t *dst, const uint8_t *src, int len)
       s += 2;
       d += 2;
       if (src[s] == 3) {
-	s++; /* 00 00 03 xx --> 00 00 xx */
-	/*LOGDBG("h264_nal_unescape: hit 00 00 03 %02x", src[s]);*/
-	if (s >= len)
-	  return d;
+        s++; /* 00 00 03 xx --> 00 00 xx */
+        /*LOGDBG("h264_nal_unescape: hit 00 00 03 %02x", src[s]);*/
+        if (s >= len)
+          return d;
       } /* else if (src[s] == 0 || src[s] == 1) {
-	LOGDBG("h264_nal_unescape: invalid NAL sequence 00 00 %02x %02x", src[s], src[s+1]);
-	return -1;
+        LOGDBG("h264_nal_unescape: invalid NAL sequence 00 00 %02x %02x", src[s], src[s+1]);
+        return -1;
       }*/
     }
     dst[d++] = src[s++];
@@ -166,9 +167,10 @@ static int h264_nal_unescape(uint8_t *dst, const uint8_t *src, int len)
   return d;
 }
 
-int h264_get_picture_type(const uint8_t *buf, int len)
+int h264_get_picture_type(const uint8_t *buf, size_t len)
 {
-  int i;
+  size_t i;
+  if (len > 5)
   for (i = 0; i < len-5; i++) {
     if (IS_NAL_AUD(buf + i)) {
       uint8_t type = (buf[i + 4] >> 5);
@@ -183,34 +185,35 @@ int h264_get_picture_type(const uint8_t *buf, int len)
   return NO_PICTURE;
 }
 
-int h264_get_video_size(const uint8_t *buf, int len, video_size_t *size)
+int h264_get_video_size(const uint8_t *buf, size_t len, video_size_t *size)
 {
-  int i;
+  size_t i;
 
   /* if I-frame, search for NAL SPS */
   if (h264_get_picture_type(buf, len) != I_FRAME)
     return 0;
 
   /* scan video packet for sequence parameter set */
+  if (len > 4)
   for (i = 5; i < len-4; i++) 
     if (buf[i] == 0 && buf[i + 1] == 0 && buf[i + 2] == 1 && (buf[i + 3] & 0x1f) == NAL_SPS) {
 
       uint8_t nal_data[len];
       int     nal_len;
 
-      LOGDBG("H.264: Found NAL SPS at offset %d/%d", i, len);
+      LOGDBG("H.264: Found NAL SPS at offset %zd/%zd", i, len);
 
       if (0 < (nal_len = h264_nal_unescape(nal_data, buf+i+4, len-i-4))) {
 
-	h264_sps_data_t sps = {0};
+        h264_sps_data_t sps = {0};
 
-	if (h264_parse_sps(nal_data, nal_len, &sps)) {
-	  size->width  = sps.width;
-	  size->height = sps.height;
-	  memcpy(&size->pixel_aspect, &sps.pixel_aspect, sizeof(mpeg_rational_t));
-	  return 1;
-	}
-	LOGMSG("h264_get_video_size: not enough data ?");
+        if (h264_parse_sps(nal_data, nal_len, &sps)) {
+          size->width  = sps.width;
+          size->height = sps.height;
+          memcpy(&size->pixel_aspect, &sps.pixel_aspect, sizeof(mpeg_rational_t));
+          return 1;
+        }
+        LOGMSG("h264_get_video_size: not enough data ?");
       }
     }
 
diff --git a/tools/h264.h b/tools/h264.h
index da82614..2371bcc 100644
--- a/tools/h264.h
+++ b/tools/h264.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: h264.h,v 1.10 2010/02/02 22:42:51 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -47,17 +47,17 @@ struct video_size_s;
 /*
  * input: start of NAL SPS (without 00 00 01 07)
  */
-int h264_parse_sps(const uint8_t *buf, int len, h264_sps_data_t *sps);
+int h264_parse_sps(const uint8_t *buf, size_t len, h264_sps_data_t *sps);
 
 /*
  * input: start of H.264 video data (not PES)
  */
-int  h264_get_picture_type(const uint8_t *buf, int len);
+int  h264_get_picture_type(const uint8_t *buf, size_t len);
 
 /*
  * input: start of H.264 video data (not PES)
  */
-int  h264_get_video_size(const uint8_t *buf, int len, struct video_size_s *size);
+int  h264_get_video_size(const uint8_t *buf, size_t len, struct video_size_s *size);
 
 
 #ifdef __cplusplus
diff --git a/tools/h265.c b/tools/h265.c
new file mode 100644
index 0000000..61dbfe4
--- /dev/null
+++ b/tools/h265.c
@@ -0,0 +1,137 @@
+/*
+ * h265.c: H.265 bitstream decoding
+ *
+ * See the main source file 'xineliboutput.c' for copyright information and
+ * how to reach the author.
+ *
+ * $Id$
+ *
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#ifndef LOG_MODULENAME
+#  define LOG_MODULENAME "[h265     ] "
+#  define SysLogLevel    iSysLogLevel
+#  include "../logdefs.h"
+#endif
+
+#define NOCACHE 1
+#include "bitstream.h"
+
+#include "h265.h"
+
+static int h265_parse_sps(const uint8_t *buf, size_t len, h265_sps_data_t *sps)
+{
+  br_state br = BR_INIT(buf, len);
+  unsigned i;
+
+  /* sps_video_parameter_set_id = */ br_skip_bits(&br, 4);
+  uint8_t sps_max_sub_layers_minus1 = br_get_bits(&br,3);
+
+  br_skip_bits(&br, 1 + 8 + 32 + 4 + 43 + 1 + 8);
+
+  uint8_t sub_layer_profile_present_flag[8];
+  uint8_t sub_layer_level_present_flag[8];
+  for (i = 0; i < sps_max_sub_layers_minus1; i++) {
+    sub_layer_profile_present_flag[i] = br_get_bit(&br);
+    sub_layer_level_present_flag[i] = br_get_bit(&br);
+  }
+
+  if (sps_max_sub_layers_minus1 > 0) {
+    for (i = sps_max_sub_layers_minus1; i < 8; i++) {
+      br_skip_bits(&br, 2);
+    }
+  }
+
+  for (i = 0; i < sps_max_sub_layers_minus1; i++) {
+    if (sub_layer_profile_present_flag[i]) {
+      br_skip_bits(&br, 8 + 32 + 4 + 43 + 1);
+    }
+    if (sub_layer_level_present_flag[i]) {
+      br_skip_bits(&br, 8);
+    }
+  }
+
+  /* sps_seq_parameter_set_id = */br_skip_ue_golomb(&br);
+  unsigned int chroma_format_idc = br_get_ue_golomb(&br);
+
+  if (chroma_format_idc == 3) {
+    /* separate_colour_plane_flag = */br_skip_bit(&br);
+  }
+
+  sps->width  = br_get_ue_golomb(&br);
+  sps->height = br_get_ue_golomb(&br);
+
+  if (BR_EOF(&br)) {
+    LOGMSG("h265_parse_sps: not enough data ?");
+    return 0;
+  }
+
+  return 1;
+}
+
+static int h265_nal_unescape(uint8_t *dst, const uint8_t *src, size_t len)
+{
+  size_t s = 0, d = 0;
+  while (s < len - 3) {
+
+    if (!src[s] && !src[s+1] && src[s+2]) {
+      /* hit 00 00 xx */
+      dst[d] = dst[d+1] = 0;
+      s += 2;
+      d += 2;
+
+      if (src[s] == 3) {
+        s++; /* 00 00 03 xx --> 00 00 xx */
+        /*LOGDBG("h265_nal_unescape: hit 00 00 03 %02x", src[s]);*/
+        if (s >= len)
+          return d;
+      } /* else if (src[s] == 0 || src[s] == 1) {
+        LOGDBG("h265_nal_unescape: invalid NAL sequence 00 00 %02x %02x", src[s], src[s+1]);
+        return -1;
+      }*/
+    } else {
+      dst[d++] = src[s++];
+    }
+  }
+  return d;
+}
+
+/*
+ * input: start of H.265 video data (not PES)
+ */
+int h265_get_video_size(const uint8_t *buf, size_t len, struct video_size_s *size)
+{
+  size_t i;
+
+  /* scan video packet for sequence parameter set */
+  if (len > 5)
+  for (i = 5; i < len-5; i++) {
+    if (buf[i] == 0 && buf[i + 1] == 0 && buf[i + 2] == 1 &&
+        (buf[i + 3] >> 1) == H265_NAL_SPS) {
+
+      uint8_t nal_data[len];
+      int     nal_len;
+
+      LOGDBG("H.265: Found NAL SPS at offset %zu/%zu", i, len);
+      if (0 < (nal_len = h265_nal_unescape(nal_data, buf+i+5, len-i-5))) {
+        h265_sps_data_t sps = {0};
+
+        if (h265_parse_sps(nal_data, nal_len, &sps)) {
+          size->width  = sps.width;
+          size->height = sps.height;
+
+          /* XXX */
+          size->pixel_aspect.num = 1;
+          size->pixel_aspect.den = 1;
+          return 1;
+        }
+        LOGMSG("h265_get_video_size: not enough data ?");
+      }
+    }
+  }
+
+  return 0;
+}
diff --git a/tools/h265.h b/tools/h265.h
new file mode 100644
index 0000000..fc0dbae
--- /dev/null
+++ b/tools/h265.h
@@ -0,0 +1,49 @@
+/*
+ * h265.h:
+ *
+ * See the main source file 'xineliboutput.c' for copyright information and
+ * how to reach the author.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef _XINELIBOUTPUT_H265_H_
+#define _XINELIBOUTPUT_H265_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "mpeg.h"
+
+
+#define H265_NAL_SPS      0x21  /* Sequence Parameter Set */
+#define H265_NAL_AUD      0x23  /* Access Unit Delimiter */
+#define H265_NAL_EOS_NUT  0x24  /* End of Sequence */
+#define H265_NAL_EOB_NUT  0x25  /* End of bitstream */
+
+
+#if defined(__i386__) || defined(__x86_64__)
+#  define IS_H265_NAL_AUD(buf)     (*(const uint32_t *)(buf) == 0x46010000U)
+#else
+#  define IS_H265_NAL_AUD(buf)     ((buf)[0] == 0 && (buf)[1] == 0 && (buf)[2] == 1 && (buf)[3] == (H265_NAL_AUD<<1))
+#endif
+
+typedef struct {
+  uint16_t        width;
+  uint16_t        height;
+  /* ... */
+} h265_sps_data_t;
+
+/*
+ * input: start of H.265 video data (not PES)
+ */
+int  h265_get_video_size(const uint8_t *buf, size_t len, struct video_size_s *size);
+
+
+#ifdef __cplusplus
+} /* extern "C" { */
+#endif
+
+#endif /* _XINELIBOUTPUT_H265_H_ */
diff --git a/tools/http.c b/tools/http.c
index 29b4341..bf86359 100644
--- a/tools/http.c
+++ b/tools/http.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: http.c,v 1.8 2012/01/29 19:30:55 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/http.h b/tools/http.h
index 752d444..44d965f 100644
--- a/tools/http.h
+++ b/tools/http.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: http.h,v 1.5 2007/01/07 09:45:48 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/iso639.h b/tools/iso639.h
index 653cdb4..68e94db 100644
--- a/tools/iso639.h
+++ b/tools/iso639.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: iso639.h,v 1.6 2011/03/19 17:03:56 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/listiter.h b/tools/listiter.h
index 54ccc7b..deb9f59 100644
--- a/tools/listiter.h
+++ b/tools/listiter.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: listiter.h,v 1.3 2010/03/15 14:13:43 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/metainfo_menu.c b/tools/metainfo_menu.c
index 1250a5b..b6ca6c7 100644
--- a/tools/metainfo_menu.c
+++ b/tools/metainfo_menu.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: metainfo_menu.c,v 1.10 2010/03/12 20:26:43 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/metainfo_menu.h b/tools/metainfo_menu.h
index 5a002b4..fa0a643 100644
--- a/tools/metainfo_menu.h
+++ b/tools/metainfo_menu.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: metainfo_menu.h,v 1.1 2008/05/07 13:27:15 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/mpeg.c b/tools/mpeg.c
index dce455b..c93cd34 100644
--- a/tools/mpeg.c
+++ b/tools/mpeg.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: mpeg.c,v 1.5 2012/12/31 16:42:45 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -21,9 +21,10 @@ const char * const picture_type_str[] = {
   "P-Frame"
 };
 
-int mpeg2_get_picture_type(const uint8_t *buf, int len)
+int mpeg2_get_picture_type(const uint8_t *buf, size_t len)
 {
-  int i;
+  size_t i;
+  if (len > 5)
   for (i = 0; i < len-5; i++)
     if (IS_SC_PICTURE(buf + i))
       return (buf[i + 5] >> 3) & 0x07;
@@ -31,9 +32,10 @@ int mpeg2_get_picture_type(const uint8_t *buf, int len)
   return NO_PICTURE;
 }
 
-int mpeg2_is_sequence_header(const uint8_t *buf, int len)
+int mpeg2_is_sequence_header(const uint8_t *buf, size_t len)
 {
-  int i;
+  size_t i;
+  if (len > 6)
   for (i = 0; i < len-6; i++) {
     if (IS_SC_SEQUENCE(buf + i)) {
       return 1;
@@ -42,30 +44,31 @@ int mpeg2_is_sequence_header(const uint8_t *buf, int len)
   return 0;
 }
 
-int mpeg2_get_video_size(const uint8_t *buf, int len, video_size_t *size)
+int mpeg2_get_video_size(const uint8_t *buf, size_t len, video_size_t *size)
 {
-  int i;
+  size_t i;
+  if (len > 6)
   for (i = 0; i < len-6; i++) {
     if (IS_SC_SEQUENCE(buf + i)) {
-	static const mpeg_rational_t mpeg2_aspect[16] = {
-	  {0,1}, {1,1}, {4,3}, {16,9}, {221,100},
-	  {0,1}, {0,1}, {0,1}, { 0,1}, {  0,1},
-	  {0,1}, {0,1}, {0,1}, { 0,1}, {  0,1},
-	  {0,1},
-	};
+      static const mpeg_rational_t mpeg2_aspect[16] = {
+        {0,1}, {1,1}, {4,3}, {16,9}, {221,100},
+        {0,1}, {0,1}, {0,1}, { 0,1}, {  0,1},
+        {0,1}, {0,1}, {0,1}, { 0,1}, {  0,1},
+        {0,1},
+      };
 
-	int d = (buf[i+4] << 16) | (buf[i+5] << 8) | buf[i+6];
-	int a = buf[i+7] >> 4;
+      unsigned d = (buf[i+4] << 16) | (buf[i+5] << 8) | buf[i+6];
+      unsigned a = (unsigned)buf[i+7] >> 4;
 
-	size->width  = (d >> 12);
-	size->height = (d & 0xfff);
+      size->width  = (d >> 12);
+      size->height = (d & 0xfff);
 
-	memcpy(&size->pixel_aspect, &mpeg2_aspect[a], sizeof(mpeg_rational_t));
-	size->pixel_aspect.num *= size->height;
-	size->pixel_aspect.den *= size->width;
+      memcpy(&size->pixel_aspect, &mpeg2_aspect[a & 0xf], sizeof(mpeg_rational_t));
+      size->pixel_aspect.num *= size->height;
+      size->pixel_aspect.den *= size->width;
 
-	return 1;
-      }
+      return 1;
+    }
   }
   return 0;
 }
diff --git a/tools/mpeg.h b/tools/mpeg.h
index 1b7f07b..af9b45c 100644
--- a/tools/mpeg.h
+++ b/tools/mpeg.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: mpeg.h,v 1.9 2012/12/31 16:42:45 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -51,17 +51,17 @@ extern const char * const picture_type_str[];
 /*
  * input: start of MPEG video data (not PES)
  */
-int mpeg2_get_picture_type(const uint8_t *buf, int len);
+int mpeg2_get_picture_type(const uint8_t *buf, size_t len);
 
 /*
  * input: start of MPEG video data (not PES)
  */
-int mpeg2_get_video_size(const uint8_t *buf, int len, video_size_t *size);
+int mpeg2_get_video_size(const uint8_t *buf, size_t len, video_size_t *size);
 
 /*
  * 
  */
-int mpeg2_is_sequence_header(const uint8_t *buf, int len);
+int mpeg2_is_sequence_header(const uint8_t *buf, size_t len);
 
 #ifdef __cplusplus
 } /* extern "C" { */
diff --git a/tools/osd_command.h b/tools/osd_command.h
index 5dffda6..7df24a1 100644
--- a/tools/osd_command.h
+++ b/tools/osd_command.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: osd_command.h,v 1.1 2014/06/23 12:20:28 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/pes.c b/tools/pes.c
index 26f1cab..3f04fac 100644
--- a/tools/pes.c
+++ b/tools/pes.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: pes.c,v 1.11 2012/08/30 08:36:39 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/pes.h b/tools/pes.h
index c8ef764..67dbec8 100644
--- a/tools/pes.h
+++ b/tools/pes.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: pes.h,v 1.13 2009/07/01 09:56:26 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/pip_service_impl.h b/tools/pip_service_impl.h
index 57c2fc0..5b9bc39 100644
--- a/tools/pip_service_impl.h
+++ b/tools/pip_service_impl.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: pip_service_impl.h,v 1.1 2010/03/12 21:15:04 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/playlist.c b/tools/playlist.c
index 9f4328a..80244d0 100644
--- a/tools/playlist.c
+++ b/tools/playlist.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: playlist.c,v 1.34 2012/01/30 07:47:36 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -290,7 +290,7 @@ class cPlaylistReader
   cPlaylistItem *Prev(void) { return m_Playlist.Last(); }
 
  public:
-  cPlaylistReader(cPlaylist& Playlist) : m_Playlist(Playlist) {}
+ cPlaylistReader(cPlaylist& Playlist) : m_Playlist(Playlist), m_Position(-1) {}
   virtual ~cPlaylistReader() {}
 
   virtual char *Parse(char *line) = 0;
@@ -837,9 +837,9 @@ int cPlaylist::ReadPlaylist(const char *file)
   if(f) {
     LOGDBG("cPlaylist: parsing %s", file);
     const char *ext = strrchr(file, '.');
-    if(!strcasecmp(ext, ".pls"))
+    if(ext && !strcasecmp(ext, ".pls"))
       parser = new cPlsReader(*this);
-    else if(!strcasecmp(ext, ".asx"))
+    else if(ext && !strcasecmp(ext, ".asx"))
       parser = new cAsxReader(*this);
     else /*if(!strcasecmp(ext, ".m3u"))*/
       parser = new cM3uReader(*this); /* parses plain lists (.ram, ...) too ...*/
@@ -898,6 +898,9 @@ int cPlaylist::ReadPlaylist(const char *file)
     if(n >= MAX_PLAYLIST_FILES) 
       LOGMSG("cPlaylist: Found over %d matching files, list truncated!", n);
     LOGDBG("cPlaylist: Found %d matching files", n);
+
+    delete parser;
+
     return n;
   }
 
diff --git a/tools/playlist.h b/tools/playlist.h
index 2229576..f7d0a21 100644
--- a/tools/playlist.h
+++ b/tools/playlist.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: playlist.h,v 1.14 2010/12/09 14:13:03 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/rle.c b/tools/rle.c
index 3d7094c..57caa52 100644
--- a/tools/rle.c
+++ b/tools/rle.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: rle.c,v 1.12 2014/06/23 12:20:28 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/rle.h b/tools/rle.h
index ef36d4c..d5aff4c 100644
--- a/tools/rle.h
+++ b/tools/rle.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: rle.h,v 1.8 2014/06/23 12:14:15 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/rtcp.h b/tools/rtcp.h
index 1c85629..9f51d5d 100644
--- a/tools/rtcp.h
+++ b/tools/rtcp.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: rtcp.h,v 1.4 2010/07/19 13:20:22 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/rtp.h b/tools/rtp.h
index 038c01a..638a676 100644
--- a/tools/rtp.h
+++ b/tools/rtp.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: rtp.h,v 1.4 2010/07/19 13:20:22 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/sap.h b/tools/sap.h
index 80a544a..212b8d4 100644
--- a/tools/sap.h
+++ b/tools/sap.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: sap.h,v 1.9 2010/07/19 13:20:22 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -139,12 +139,15 @@ static inline int sap_send_pdu(int *pfd, sap_pdu_t *pdu, uint32_t dst_ip)
       return -1;
     }
 
-    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &iReuse, sizeof(int));
-    setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &iTtl, sizeof(int));
-    setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &iLoop, sizeof(int));
+    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &iReuse, sizeof(int)) < 0 ||
+        setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &iTtl, sizeof(int)) < 0 ||
+        setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &iLoop, sizeof(int)) < 0) {
+      LOGERR("UDP/SAP multicast setsockopt() failed.");
+    }
 
     // Connect to multicast address
     struct sockaddr_in sin;
+    memset(&sin, 0, sizeof(sin));
     sin.sin_family = AF_INET;
     sin.sin_port = htons(SAP_UDP_PORT);
     sin.sin_addr.s_addr = dst_ip ? dst_ip : inet_addr(SAP_IP_ADDRESS_GLOBAL);
@@ -153,7 +156,9 @@ static inline int sap_send_pdu(int *pfd, sap_pdu_t *pdu, uint32_t dst_ip)
       LOGERR("UDP/SAP multicast connect() failed.");
     
     // Set to non-blocking mode
-    fcntl (fd, F_SETFL, fcntl (fd, F_GETFL) | O_NONBLOCK);
+    if (fcntl (fd, F_SETFL, fcntl (fd, F_GETFL) | O_NONBLOCK) < 0) {
+      LOGERR("UDP/SAP multicast: error setting non-blocking mode");
+    }
 
     if(pfd)
       *pfd = fd;
diff --git a/tools/sdp.h b/tools/sdp.h
index 6492a98..8e236b0 100644
--- a/tools/sdp.h
+++ b/tools/sdp.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: sdp.h,v 1.5 2009/02/10 12:42:38 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -54,7 +54,7 @@ static const char *vdr_sdp_description(const char *vdr_ip,
   s_data = cString::sprintf(
            /*** session ***/
            /* version    */        "v=0"
-           /* origin     */ "\r\n" "o=%s %u %"PRIu64" IN IP4 %s"
+           /* origin     */ "\r\n" "o=%s %u %" PRIu64 " IN IP4 %s"
            /* name       */ "\r\n" "s=%s@%s (multicast %s:%d)"
            /* opt:info   */ /*"\r\n" "i=vdr-xineliboutput primary device output"*/
            /* time       */ "\r\n" "t=0 0"
diff --git a/tools/section_lock.h b/tools/section_lock.h
index e781a2c..1f608fe 100644
--- a/tools/section_lock.h
+++ b/tools/section_lock.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: section_lock.h,v 1.1 2010/03/15 12:07:44 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/sys_cap.h b/tools/sys_cap.h
index 1d616ec..e99b769 100644
--- a/tools/sys_cap.h
+++ b/tools/sys_cap.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: sys_cap.h,v 1.3 2011/04/09 12:50:16 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/time_ms.h b/tools/time_ms.h
index f0c3e3d..7e0ab37 100644
--- a/tools/time_ms.h
+++ b/tools/time_ms.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: time_ms.h,v 1.2 2012/03/20 09:10:33 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/time_pts.c b/tools/time_pts.c
index 7b402be..da0b6cf 100644
--- a/tools/time_pts.c
+++ b/tools/time_pts.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: time_pts.c,v 1.4 2008/04/28 20:48:05 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/time_pts.h b/tools/time_pts.h
index 8c0c254..6365b50 100644
--- a/tools/time_pts.h
+++ b/tools/time_pts.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: time_pts.h,v 1.4 2008/04/28 20:48:05 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/timer.c b/tools/timer.c
index 30993d2..4c28f63 100644
--- a/tools/timer.c
+++ b/tools/timer.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: timer.c,v 1.2 2007/10/15 00:15:07 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/timer.h b/tools/timer.h
index 7424514..1560b25 100644
--- a/tools/timer.h
+++ b/tools/timer.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: timer.h,v 1.1 2006/06/03 10:04:28 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/ts.c b/tools/ts.c
index 4524b2f..5ab044b 100644
--- a/tools/ts.c
+++ b/tools/ts.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: ts.c,v 1.33 2013/01/06 21:23:43 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -423,6 +423,7 @@ int ts_parse_pmt (pmt_data_t *pmt, uint program_no, const uint8_t *pkt)
       case ISO_14496_PART2_VIDEO:
       case ISO_14496_PART10_VIDEO:
       case STREAM_VIDEO_VC1:
+      case STREAM_VIDEO_HEVC:
         LOGPMT("parse_pmt: video pid 0x%.4x type %2.2x", pid, stream[0]);
         if (pmt->video_pid == INVALID_PID) {
           pmt->video_pid  = pid;
@@ -784,9 +785,13 @@ int ts_get_picture_type(ts_state_t *ts, const uint8_t *data, int h264)
 
 #include "h264.h"
 #include "mpeg.h"
+#include "h265.h"
 
-int ts_get_video_size(ts_state_t *ts, const uint8_t *data, video_size_t *size, int h264)
+int ts_get_video_size(ts_state_t *ts, const uint8_t *data, video_size_t *size, ts_stream_type vid_type)
 {
+  int h264 = (vid_type == ISO_14496_PART10_VIDEO);
+  int h265 = (vid_type == STREAM_VIDEO_HEVC);
+
   /* Accumulate data. Skip all data until start code. */
   if (ts_get_pes(ts, data) < 9)
     return 0;
@@ -807,24 +812,38 @@ int ts_get_video_size(ts_state_t *ts, const uint8_t *data, video_size_t *size, i
   while (ts->buf_len > 9) {
     uint8_t *buf = ts->buf;
 
-    /* MPEG2 sequence start code */
-    if (h264 != 1 && IS_SC_SEQUENCE(buf)) {
-      if (mpeg2_get_video_size(ts->buf, ts->buf_len, size)) {
-        ts_state_reset(ts);
-        return 1;
+    if (h265) {
+      /* HEVC NAL AUD */
+      if (IS_H265_NAL_AUD(buf)) {
+        if (h265_get_video_size(ts->buf, ts->buf_len, size)) {
+          ts_state_reset(ts);
+          return 1;
+        }
+        if (ts->buf_len < ts->buf_size - TS_SIZE)
+          return 0;
+      }
+
+    } else if (h264) {
+      /* H.264 NAL AUD */
+      if (IS_NAL_AUD(buf)) {
+        if (h264_get_video_size(ts->buf, ts->buf_len, size)) {
+          ts_state_reset(ts);
+          return 1;
+        }
+        if (ts->buf_len < ts->buf_size - TS_SIZE)
+          return 0;
       }
-      if (ts->buf_len < ts->buf_size - TS_SIZE)
-        return 0;
-    }
 
-    /* H.264 NAL AUD */
-    if (h264 != 0 && IS_NAL_AUD(buf)) {
-      if (h264_get_video_size(ts->buf, ts->buf_len, size)) {
-        ts_state_reset(ts);
-        return 1;
+    } else {
+      /* MPEG2 sequence start code */
+      if (IS_SC_SEQUENCE(buf)) {
+        if (mpeg2_get_video_size(ts->buf, ts->buf_len, size)) {
+          ts_state_reset(ts);
+          return 1;
+        }
+        if (ts->buf_len < ts->buf_size - TS_SIZE)
+          return 0;
       }
-      if (ts->buf_len < ts->buf_size - TS_SIZE)
-        return 0;
     }
 
     /* find next start code */
diff --git a/tools/ts.h b/tools/ts.h
index 9a06860..8d90314 100644
--- a/tools/ts.h
+++ b/tools/ts.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: ts.h,v 1.19 2013/01/06 21:23:43 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -74,6 +74,7 @@ typedef enum {
   ISO_14496_PART2_VIDEO  = 0x10,  /* ISO/IEC 14496-2 Visual (MPEG-4) */
   ISO_14496_PART3_AUDIO  = 0x11,  /* ISO/IEC 14496-3 Audio with LATM transport syntax */
   ISO_14496_PART10_VIDEO = 0x1b,  /* ISO/IEC 14496-10 Video (MPEG-4 part 10/AVC, aka H.264) */
+  STREAM_VIDEO_HEVC      = 0x24,
   STREAM_VIDEO_MPEG      = 0x80,
   STREAM_AUDIO_AC3       = 0x81,
 
@@ -199,7 +200,7 @@ void        ts_state_dispose(ts_state_t *ts);
 
 int64_t ts_get_pts(ts_state_t *ts, const uint8_t *data);
 int     ts_get_picture_type(ts_state_t *ts, const uint8_t *data, int h264);
-int     ts_get_video_size(ts_state_t *ts, const uint8_t *data, struct video_size_s *size, int h264);
+int     ts_get_video_size(ts_state_t *ts, const uint8_t *data, struct video_size_s *size, ts_stream_type vid_type);
 
 
 #ifdef __cplusplus
diff --git a/tools/udp_buffer.h b/tools/udp_buffer.h
index cedd188..60815b9 100644
--- a/tools/udp_buffer.h
+++ b/tools/udp_buffer.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: udp_buffer.h,v 1.8 2010/06/04 10:40:21 rofafor Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/udp_pes_scheduler.c b/tools/udp_pes_scheduler.c
index fb2e4db..c0f7e4d 100644
--- a/tools/udp_pes_scheduler.c
+++ b/tools/udp_pes_scheduler.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: udp_pes_scheduler.c,v 1.57 2013/10/25 17:22:38 rofafor Exp $
+ * $Id$
  *
  */
 
@@ -186,6 +186,7 @@ bool cUdpScheduler::AddRtp(void)
 
   if(xc.remote_local_ip[0]) {
     struct sockaddr_in name;
+    memset(&name, 0, sizeof(name));
     name.sin_family = AF_INET;
     name.sin_addr.s_addr = inet_addr(xc.remote_local_ip);
     if(name.sin_addr.s_addr == INADDR_NONE)
@@ -227,6 +228,7 @@ bool cUdpScheduler::AddRtp(void)
 
   if(xc.remote_local_ip[0]) {
     struct sockaddr_in name;
+    memset(&name, 0, sizeof(name));
     name.sin_family = AF_INET;
     name.sin_addr.s_addr = inet_addr(xc.remote_local_ip);
     name.sin_port = htons(xc.remote_rtp_port+1);
@@ -575,13 +577,14 @@ void cUdpScheduler::Send_RTCP(void)
     msg->hdr.count  = 1;
 
     msg->sdes.ssrc   = m_ssrc;
-    msg->sdes.item[0].type   = RTCP_SDES_CNAME;
-    sprintf(msg->sdes.item[0].data, "VDR@%s:%d%c%c%c", 
+    rtcp_sdes_item_t *it = &msg->sdes.item[0];
+    it->type   = RTCP_SDES_CNAME;
+    sprintf(it->data, "VDR@%s:%d%c%c%c",
 	    hostname[0] ? hostname : xc.remote_rtp_addr,
 	    xc.remote_rtp_port, 0, 0, 0);
-    msg->sdes.item[0].length = strlen(msg->sdes.item[0].data);
-    msg->hdr.length = htons(1 + 1 + ((msg->sdes.item[0].length - 2) + 3) / 4); 
-    
+    it->length = strlen(it->data);
+    msg->hdr.length = htons(1 + 1 + ((it->length - 2) + 3) / 4);
+
     content += sizeof(rtcp_common_t) + 4*ntohs(msg->hdr.length);
     msg = (rtcp_packet_t *)content;
 
@@ -625,8 +628,8 @@ void cUdpScheduler::Send_SAP(bool Announce)
                                               2001,
                                               xc.listen_port,
                                               xc.remote_rtp_addr,
-                                              payload_type,
                                               m_ssrc,
+                                              payload_type,
                                               xc.remote_rtp_port,
                                               xc.remote_rtp_ttl);
   if(!sdp_descr)
@@ -679,7 +682,7 @@ void cUdpScheduler::Schedule(const uchar *Data, int Length)
 
   if (DATA_IS_TS(Data)) {
     if (ts_get_pcr_n(Data, Length/TS_SIZE, &pts)) {
-      LOGSCR("UDP PCR: %"PRId64, pts);
+      LOGSCR("UDP PCR: %" PRId64, pts);
       ScrSource = eScrFromPcr;
       elapsed   = CalcElapsedVtime(pts, eScrFromPcr);
     }
diff --git a/tools/udp_pes_scheduler.h b/tools/udp_pes_scheduler.h
index 91d2799..dd1f5b4 100644
--- a/tools/udp_pes_scheduler.h
+++ b/tools/udp_pes_scheduler.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: udp_pes_scheduler.h,v 1.23 2010/03/14 11:50:50 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/tools/vdrdiscovery.c b/tools/vdrdiscovery.c
index 665e871..31262ae 100644
--- a/tools/vdrdiscovery.c
+++ b/tools/vdrdiscovery.c
@@ -7,10 +7,14 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vdrdiscovery.c,v 1.11 2011/02/28 13:17:52 phintuka Exp $
+ * $Id$
  *
  */
 
+#ifndef _GNU_SOURCE 
+#  define _GNU_SOURCE  /* asprintf */
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #ifdef __FreeBSD__
@@ -228,7 +232,6 @@ int udp_discovery_find_server(int *port, char *address)
 	if(!strncmp(mystring, buf, strlen(mystring))) {
           char *iploc;
 	  LOGDBG("Valid discovery message");
-	  close(fd_discovery);
 
 	  // default: use broadcast source address
 	  sprintf(address, "%d.%d.%d.%d",
@@ -257,9 +260,11 @@ int udp_discovery_find_server(int *port, char *address)
 	  }
 
 	  *port = -1;
-	  if(1 == sscanf(buf + strlen(mystring), "%d", port) && 
-	     *port >= 1000 && *port <= 0xffff)
+          if(1 == sscanf(buf + strlen(mystring), "%d", port) &&
+             *port >= 1000 && *port <= 0xffff) {
+            close(fd_discovery);
 	    return 1;
+          }
 	  LOGMSG("Server-given port is invalid !");
 	} else {
 	  LOGDBG("NOT valid discovery message");
diff --git a/tools/vdrdiscovery.h b/tools/vdrdiscovery.h
index be5f26e..02acab1 100644
--- a/tools/vdrdiscovery.h
+++ b/tools/vdrdiscovery.h
@@ -7,7 +7,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vdrdiscovery.h,v 1.5 2009/02/10 15:26:11 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -30,7 +30,7 @@ struct sockaddr_in;
  * udp_discovery_find_server()
  *
  * Search for server. Return address and port.
- * Returns 0 on success.
+ * Returns > 0 on success.
  */
 int udp_discovery_find_server(int *port, char *address);
 
diff --git a/vdrlogo_32x32.c b/vdrlogo_32x32.c
index aafb8f8..64bca51 100644
--- a/vdrlogo_32x32.c
+++ b/vdrlogo_32x32.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vdrlogo_32x32.c,v 1.4 2009/05/27 09:39:08 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/adjustable_scr.c b/xine/adjustable_scr.c
index 94e0b66..58cb491 100644
--- a/xine/adjustable_scr.c
+++ b/xine/adjustable_scr.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: adjustable_scr.c,v 1.5 2012/03/22 12:03:37 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/adjustable_scr.h b/xine/adjustable_scr.h
index 1bd81dd..57e953c 100644
--- a/xine/adjustable_scr.h
+++ b/xine/adjustable_scr.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: adjustable_scr.h,v 1.3 2012/03/22 12:03:37 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/demux_xvdr.c b/xine/demux_xvdr.c
index fd1b790..10e4da9 100644
--- a/xine/demux_xvdr.c
+++ b/xine/demux_xvdr.c
@@ -33,6 +33,7 @@
 #include "../xine_input_vdr_mrl.h"
 #include "../tools/mpeg.h"
 #include "../tools/h264.h"
+#include "../tools/h265.h"
 #include "../tools/pes.h"
 #include "../tools/ts.h"
 
@@ -154,6 +155,9 @@ static void detect_video_decoders(demux_xvdr_t *this)
   LOGDBG("Using H.264      decoder \"%s\"%s",
          name, this->coreavc_h264_decoder ? " (dshowserver (CoreAVC))" : "");
 
+#ifdef BUF_VIDEO_HEVC
+  LOG_DECODER(BUF_VIDEO_HEVC,    "HEVC");
+#endif
   LOG_DECODER(BUF_VIDEO_VC1,     "VC-1");
 }
 
@@ -164,21 +168,14 @@ static void detect_audio_decoders(demux_xvdr_t *this)
   LOG_DECODER(BUF_AUDIO_AAC,     "AAC");
   LOG_DECODER(BUF_AUDIO_DTS,     "DTS");
   LOG_DECODER(BUF_AUDIO_LPCM_BE, "LPCM");
-#ifdef BUF_AUDIO_AAC_EAC3
-  LOG_DECODER(BUF_AUDIO_AAC_EAC3, "E-AC-3");
+#ifdef BUF_AUDIO_EAC3
+  LOG_DECODER(BUF_AUDIO_EAC3, "E-AC-3");
 #endif
 #ifdef BUF_AUDIO_AAC_LATM
   LOG_DECODER(BUF_AUDIO_AAC_LATM, "AAC LATM");
 #endif
 }
 
-static void demux_xvdr_parse_ts(demux_xvdr_t *this, buf_element_t *buf);
-static void demux_xvdr_parse_pes(demux_xvdr_t *this, buf_element_t *buf);
-
-static int32_t parse_video_stream(demux_xvdr_t *this, uint8_t *p, buf_element_t *buf);
-static int32_t parse_audio_stream(demux_xvdr_t *this, uint8_t *p, buf_element_t *buf);
-static int32_t parse_private_stream_1(demux_xvdr_t *this, uint8_t *p, buf_element_t *buf);
-
 static void pts_wrap_workaround(demux_xvdr_t *this, buf_element_t *buf, int video)
 {
   /* PTS wrap workaround */
@@ -261,16 +258,30 @@ static void put_control_buf(fifo_buffer_t *buffer, fifo_buffer_t *pool, int cmd)
   if(buf) {
     buf->type = cmd;
     buffer->put(buffer, buf);
+  } else {
+    LOGERR("put_control_buf(0x%08x): get_buf_element() failed !", (unsigned)cmd);
   }
 }
 
 /*
  * post_sequence_end()
  *
- * Add MPEG2 or H.264 sequence end code to fifo buffer
+ * Add sequence end code to fifo buffer
  */
 static void post_sequence_end(fifo_buffer_t *fifo, uint32_t video_type)
 {
+  uint8_t code;
+  switch (video_type) {
+    case BUF_VIDEO_MPEG:  code = SC_SEQUENCE_END;
+    case BUF_VIDEO_H264:  code = NAL_END_SEQ;
+    case BUF_VIDEO_VC1:   code = NAL_END_SEQ;
+#ifdef BUF_VIDEO_HEVC
+    case BUF_VIDEO_HEVC:  code = (H265_NAL_EOB_NUT << 1);
+#endif
+    default:
+      return;
+  }
+
   buf_element_t *buf = fifo->buffer_pool_try_alloc(fifo);
   if (buf) {
     buf->type = video_type;
@@ -279,97 +290,19 @@ static void post_sequence_end(fifo_buffer_t *fifo, uint32_t video_type)
     buf->content[0] = 0x00;
     buf->content[1] = 0x00;
     buf->content[2] = 0x01;
-    buf->content[3] = (video_type == BUF_VIDEO_H264) ? NAL_END_SEQ : SC_SEQUENCE_END;
-    fifo->put(fifo, buf);
-  }
-}
-
-/*
- * post_frame_end()
- *
- * Signal end of video frame to decoder.
- *
- * This function is used with:
- *  - FFmpeg mpeg2 decoder
- *  - FFmpeg and CoreAVC H.264 decoders
- *  - NOT with libmpeg2 mpeg decoder
- */
-static void post_frame_end(demux_xvdr_t *this, buf_element_t *vid_buf)
-{
-  buf_element_t *cbuf = this->video_fifo->buffer_pool_try_alloc (this->video_fifo) ?:
-                        this->audio_fifo->buffer_pool_try_alloc (this->audio_fifo);
+    buf->content[3] = code;
 
-  if (!cbuf) {
-    LOGMSG("post_frame_end(): buffer_pool_try_alloc() failed, retrying");
-    xine_usec_sleep (10*1000);
-    cbuf = this->video_fifo->buffer_pool_try_alloc (this->video_fifo);
-    if (!cbuf) {
-      LOGERR("post_frame_end(): get_buf_element() failed !");
-      return;
+#ifdef BUF_VIDEO_HEVC
+    if (video_type == BUF_VIDEO_HEVC) {
+      buf->size++;
+      buf->content[4] = 0x01; /* layer_id 0, temporal_id 1 */
     }
-  }
-
-  cbuf->type          = this->video_type;
-  cbuf->decoder_flags = BUF_FLAG_FRAME_END;
-
-  if (!this->bih_posted) {
-    video_size_t size = {0};
-    if (pes_get_video_size(vid_buf->content, vid_buf->size, &size, this->video_type == BUF_VIDEO_H264)) {
-
-      /* reset decoder buffer */
-      cbuf->decoder_flags |= BUF_FLAG_FRAME_START;
-
-      /* Fill xine_bmiheader for CoreAVC / H.264 */
-
-      if (this->video_type == BUF_VIDEO_H264 && this->coreavc_h264_decoder) {
-        xine_bmiheader *bmi = (xine_bmiheader*) cbuf->content;
-
-        cbuf->decoder_flags |= BUF_FLAG_HEADER;
-        cbuf->decoder_flags |= BUF_FLAG_STDHEADER;   /* CoreAVC: buffer contains bmiheader */
-        cbuf->size           = sizeof(xine_bmiheader);
-
-        memset (bmi, 0, sizeof(xine_bmiheader));
-
-        bmi->biSize   = sizeof(xine_bmiheader);
-        bmi->biWidth  = size.width;
-        bmi->biHeight = size.height;
-
-        bmi->biPlanes        = 1;
-        bmi->biBitCount      = 24;
-        bmi->biCompression   = 0x34363248;
-        bmi->biSizeImage     = 0;
-        bmi->biXPelsPerMeter = size.pixel_aspect.num;
-        bmi->biYPelsPerMeter = size.pixel_aspect.den;
-        bmi->biClrUsed       = 0;
-        bmi->biClrImportant  = 0;
-      }
-
-      /* Set aspect ratio for ffmpeg mpeg2 / CoreAVC H.264 decoder
-       * (not for FFmpeg H.264 or libmpeg2 mpeg2 decoders)
-       */
-
-      if (size.pixel_aspect.num &&
-          (this->video_type != BUF_VIDEO_H264 || this->coreavc_h264_decoder)) {
-        cbuf->decoder_flags |= BUF_FLAG_HEADER;
-        cbuf->decoder_flags |= BUF_FLAG_ASPECT;
-        /* pixel ratio -> frame ratio */
-        if (size.pixel_aspect.num > size.height) {
-          cbuf->decoder_info[1] = size.pixel_aspect.num / size.height;
-          cbuf->decoder_info[2] = size.pixel_aspect.den / size.width;
-        } else {
-          cbuf->decoder_info[1] = size.pixel_aspect.num * size.width;
-          cbuf->decoder_info[2] = size.pixel_aspect.den * size.height;
-        }
-      }
-
-      LOGDBG("post_frame_end: video width %d, height %d, pixel aspect %d:%d",
-             size.width, size.height, size.pixel_aspect.num, size.pixel_aspect.den);
+#endif
 
-      this->bih_posted = 1;
-    }
+    fifo->put(fifo, buf);
+  } else {
+    LOGERR("post_sequence_end(): get_buf_element() failed !");
   }
-
-  this->video_fifo->put (this->video_fifo, cbuf);
 }
 
 static void track_audio_stream_change(demux_xvdr_t *this, buf_element_t *buf)
@@ -450,92 +383,27 @@ static void demux_xvdr_fwd_buf(demux_xvdr_t *this, buf_element_t *buf)
   buf->free_buffer (buf);
 }
 
-static void demux_xvdr_parse_pack (demux_xvdr_t *this)
-{
-  buf_element_t *buf = NULL;
-  uint8_t       *p;
-
-  buf = this->input->read_block (this->input, this->video_fifo, 8128);
-
-  if (!buf) {
-    if (errno == EINTR) {
-      LOGVERBOSE("input->read_block() was interrupted");
-      ts_data_flush(this->ts_data);
-    } else if (errno != EAGAIN) {
-      LOGDBG("DEMUX_FINISHED (input returns NULL with error)");
-      this->status = DEMUX_FINISHED;
-      ts_data_dispose(&this->ts_data);
-    }
-    return;
-  }
-
-  /* If this is not a block for the demuxer, pass it
-   * straight through. */
-  if (buf->type != BUF_DEMUX_BLOCK) {
-    ts_data_flush (this->ts_data);
-    demux_xvdr_fwd_buf (this, buf);
-    return;
-  }
-
-  p = buf->content; /* len = this->blocksize; */
-  buf->decoder_flags = 0;
-
-  if (DATA_IS_TS(p)) {
-    demux_xvdr_parse_ts (this, buf);
-    return;
-  }
-  if (DATA_IS_PES(p)) {
-    demux_xvdr_parse_pes (this, buf);
-    return;
-  }
-
-  LOGMSG("Header %02x %02x %02x (should be 0x000001 or 0x47)", p[0], p[1], p[2]);
-  buf->free_buffer (buf);
-  return;
-}
-
-static void demux_xvdr_parse_pes (demux_xvdr_t *this, buf_element_t *buf)
-{
-  uint8_t       *p = buf->content;
-  int32_t        result;
-
-  if (IS_PADDING_PACKET(p)) {
-    buf->free_buffer (buf);
-    return;
-  }
-
-  this->stream_id  = p[3];
-
-  if (this->ts_data) {
-    ts_data_flush(this->ts_data);
-    ts_data_dispose(&this->ts_data);
-  }
-
-  if (IS_VIDEO_PACKET(p)) {
-    result = parse_video_stream(this, p, buf);
-  } else if (IS_MPEG_AUDIO_PACKET(p)) {
-    result = parse_audio_stream(this, p, buf);
-  } else if (IS_PS1_PACKET(p)) {
-    result = parse_private_stream_1(this, p, buf);
-  } else {
-    LOGMSG("Unrecognised PES stream 0x%02x", this->stream_id);
-    buf->free_buffer (buf);
-    return;
-  }
-
-  if (result < 0) {
-    return;
-  }
-
-  LOGMSG("error! freeing buffer.");
-  buf->free_buffer (buf);
-}
-
 /*
  * demux_xvdr_parse_ts()
  *
  * MPEG-TS demuxing
  */
+
+static unsigned int vtype_to_xine_buf_type(unsigned vtype)
+{
+  switch (vtype) {
+    case ISO_11172_VIDEO:         return BUF_VIDEO_MPEG;
+    case ISO_13818_VIDEO:         return BUF_VIDEO_MPEG;
+    case ISO_14496_PART2_VIDEO:   return BUF_VIDEO_MPEG4;
+    case ISO_14496_PART10_VIDEO:  return BUF_VIDEO_H264;
+    case STREAM_VIDEO_VC1:        return BUF_VIDEO_VC1;
+#ifdef BUF_VIDEO_HEVC
+    case STREAM_VIDEO_HEVC:       return BUF_VIDEO_HEVC;
+#endif
+  }
+  return 0;
+}
+
 static void demux_xvdr_parse_ts (demux_xvdr_t *this, buf_element_t *buf)
 {
   if (!this->ts_data)
@@ -550,7 +418,7 @@ static void demux_xvdr_parse_ts (demux_xvdr_t *this, buf_element_t *buf)
 
     /* parse PAT */
     if (ts_pid == 0) {
-      pat_data_t pat;
+      pat_data_t pat = {{ 0 }};
 
       if (ts_parse_pat(&pat, buf->content)) {
         if (ts_data->pmt_pid        != pat.pmt_pid[0] ||
@@ -577,8 +445,11 @@ static void demux_xvdr_parse_ts (demux_xvdr_t *this, buf_element_t *buf)
         LOGDBG("PMT changed, resetting demuxer");
         ts_data_ts2es_init(&ts_data, this->stream->video_fifo, this->stream->audio_fifo);
 
-        this->video_type = (ts_data->pmt.video_type == ISO_14496_PART10_VIDEO) ?
-                           BUF_VIDEO_H264 : BUF_VIDEO_MPEG;
+        this->video_type = vtype_to_xine_buf_type(ts_data->pmt.video_type);
+        if (!this->video_type) {
+          LOGMSG("unsupported video codec 0x%02x detected (no support in xine-lib ?)", ts_data->pmt.video_type);
+          ts_data->pmt.video_pid = INVALID_PID;
+        }
 
         /* Inform UI of channels changes */
         xine_event_t event;
@@ -643,6 +514,99 @@ static void demux_xvdr_parse_ts (demux_xvdr_t *this, buf_element_t *buf)
   buf->free_buffer(buf);
 }
 
+/*
+ * PES demuxing
+ */
+
+/*
+ * post_frame_end()
+ *
+ * Signal end of video frame to decoder.
+ *
+ * This function is used with:
+ *  - FFmpeg mpeg2 decoder
+ *  - FFmpeg and CoreAVC H.264 decoders
+ *  - NOT with libmpeg2 mpeg decoder
+ */
+static void post_frame_end(demux_xvdr_t *this, buf_element_t *vid_buf)
+{
+  buf_element_t *cbuf = this->video_fifo->buffer_pool_try_alloc (this->video_fifo) ?:
+                        this->audio_fifo->buffer_pool_try_alloc (this->audio_fifo);
+
+  if (!cbuf) {
+    LOGMSG("post_frame_end(): buffer_pool_try_alloc() failed, retrying");
+    xine_usec_sleep (10*1000);
+    cbuf = this->video_fifo->buffer_pool_try_alloc (this->video_fifo);
+    if (!cbuf) {
+      LOGERR("post_frame_end(): get_buf_element() failed !");
+      return;
+    }
+  }
+
+  cbuf->type          = this->video_type;
+  cbuf->decoder_flags = BUF_FLAG_FRAME_END;
+
+  if (!this->bih_posted) {
+
+    video_size_t size = {0};
+    if (pes_get_video_size(vid_buf->content, vid_buf->size, &size, this->video_type == BUF_VIDEO_H264)) {
+
+      /* reset decoder buffer */
+      cbuf->decoder_flags |= BUF_FLAG_FRAME_START;
+
+      /* Fill xine_bmiheader for CoreAVC / H.264 */
+
+      if (this->video_type == BUF_VIDEO_H264 && this->coreavc_h264_decoder) {
+        xine_bmiheader *bmi = (xine_bmiheader*) cbuf->content;
+
+        cbuf->decoder_flags |= BUF_FLAG_HEADER;
+        cbuf->decoder_flags |= BUF_FLAG_STDHEADER;   /* CoreAVC: buffer contains bmiheader */
+        cbuf->size           = sizeof(xine_bmiheader);
+
+        memset (bmi, 0, sizeof(xine_bmiheader));
+
+        bmi->biSize   = sizeof(xine_bmiheader);
+        bmi->biWidth  = size.width;
+        bmi->biHeight = size.height;
+
+        bmi->biPlanes        = 1;
+        bmi->biBitCount      = 24;
+        bmi->biCompression   = 0x34363248;
+        bmi->biSizeImage     = 0;
+        bmi->biXPelsPerMeter = size.pixel_aspect.num;
+        bmi->biYPelsPerMeter = size.pixel_aspect.den;
+        bmi->biClrUsed       = 0;
+        bmi->biClrImportant  = 0;
+      }
+
+      /* Set aspect ratio for ffmpeg mpeg2 / CoreAVC H.264 decoder
+       * (not for FFmpeg H.264 or libmpeg2 mpeg2 decoders)
+       */
+
+      if (size.pixel_aspect.num &&
+          (this->video_type != BUF_VIDEO_H264 || this->coreavc_h264_decoder)) {
+        cbuf->decoder_flags |= BUF_FLAG_HEADER;
+        cbuf->decoder_flags |= BUF_FLAG_ASPECT;
+        /* pixel ratio -> frame ratio */
+        if (size.pixel_aspect.num > size.height) {
+          cbuf->decoder_info[1] = size.pixel_aspect.num / size.height;
+          cbuf->decoder_info[2] = size.pixel_aspect.den / size.width;
+        } else {
+          cbuf->decoder_info[1] = size.pixel_aspect.num * size.width;
+          cbuf->decoder_info[2] = size.pixel_aspect.den * size.height;
+        }
+      }
+
+      LOGDBG("post_frame_end: video width %d, height %d, pixel aspect %d:%d",
+             size.width, size.height, size.pixel_aspect.num, size.pixel_aspect.den);
+
+      this->bih_posted = 1;
+    }
+  }
+
+  this->video_fifo->put (this->video_fifo, cbuf);
+}
+
 /* FIXME: Extension data is not parsed, and is also not skipped. */
 
 static int32_t parse_pes_for_pts(demux_xvdr_t *this, uint8_t *p, buf_element_t *buf)
@@ -1073,6 +1037,91 @@ static int32_t parse_audio_stream(demux_xvdr_t *this, uint8_t *p, buf_element_t
   return -1;
 }
 
+static void demux_xvdr_parse_pes (demux_xvdr_t *this, buf_element_t *buf)
+{
+  uint8_t       *p = buf->content;
+  int32_t        result;
+
+  if (IS_PADDING_PACKET(p)) {
+    buf->free_buffer (buf);
+    return;
+  }
+
+  this->stream_id  = p[3];
+
+  if (this->ts_data) {
+    ts_data_flush(this->ts_data);
+    ts_data_dispose(&this->ts_data);
+  }
+
+  if (IS_VIDEO_PACKET(p)) {
+    result = parse_video_stream(this, p, buf);
+  } else if (IS_MPEG_AUDIO_PACKET(p)) {
+    result = parse_audio_stream(this, p, buf);
+  } else if (IS_PS1_PACKET(p)) {
+    result = parse_private_stream_1(this, p, buf);
+  } else {
+    LOGMSG("Unrecognised PES stream 0x%02x", this->stream_id);
+    buf->free_buffer (buf);
+    return;
+  }
+
+  if (result < 0) {
+    return;
+  }
+
+  LOGMSG("error! freeing buffer.");
+  buf->free_buffer (buf);
+}
+
+/*
+ * demux main
+ */
+
+static void demux_xvdr_parse_pack (demux_xvdr_t *this)
+{
+  buf_element_t *buf = NULL;
+  uint8_t       *p;
+
+  buf = this->input->read_block (this->input, this->video_fifo, 8128);
+
+  if (!buf) {
+    if (errno == EINTR) {
+      LOGVERBOSE("input->read_block() was interrupted");
+      ts_data_flush(this->ts_data);
+    } else if (errno != EAGAIN) {
+      LOGDBG("DEMUX_FINISHED (input returns NULL with error)");
+      this->status = DEMUX_FINISHED;
+      ts_data_dispose(&this->ts_data);
+    }
+    return;
+  }
+
+  /* If this is not a block for the demuxer, pass it
+   * straight through. */
+  if (buf->type != BUF_DEMUX_BLOCK) {
+    ts_data_flush (this->ts_data);
+    demux_xvdr_fwd_buf (this, buf);
+    return;
+  }
+
+  p = buf->content; /* len = this->blocksize; */
+  buf->decoder_flags = 0;
+
+  if (DATA_IS_TS(p)) {
+    demux_xvdr_parse_ts (this, buf);
+    return;
+  }
+  if (DATA_IS_PES(p)) {
+    demux_xvdr_parse_pes (this, buf);
+    return;
+  }
+
+  LOGMSG("Header %02x %02x %02x (should be 0x000001 or 0x47)", p[0], p[1], p[2]);
+  buf->free_buffer (buf);
+  return;
+}
+
 /*
  * interface
  */
diff --git a/xine/demux_xvdr_tsdata.c b/xine/demux_xvdr_tsdata.c
index 853c0e3..4d54b34 100644
--- a/xine/demux_xvdr_tsdata.c
+++ b/xine/demux_xvdr_tsdata.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: demux_xvdr_tsdata.c,v 1.4 2010/03/19 21:44:27 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/demux_xvdr_tsdata.h b/xine/demux_xvdr_tsdata.h
index ad1db2c..0ca4675 100644
--- a/xine/demux_xvdr_tsdata.h
+++ b/xine/demux_xvdr_tsdata.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: demux_xvdr_tsdata.h,v 1.3 2010/03/19 21:44:27 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/osd_manager.c b/xine/osd_manager.c
index 68ed458..b3de2aa 100644
--- a/xine/osd_manager.c
+++ b/xine/osd_manager.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: osd_manager.c,v 1.30 2014/06/23 12:20:28 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -671,7 +671,7 @@ static int exec_osd_set_argb(osd_manager_impl_t *this, osd_command_t *cmd)
 
   /* allocate buffer */
   if (!osd->argb_buffer) {
-    osd->argb_buffer = calloc(sizeof(uint32_t), osd->extent_width * osd->extent_height);
+    osd->argb_buffer = calloc(sizeof(uint32_t), (size_t)osd->extent_width * (size_t)osd->extent_height);
   }
   if (!osd->argb_layer) {
     set_argb_layer(&osd->argb_layer, argb_layer_create());
diff --git a/xine/osd_manager.h b/xine/osd_manager.h
index f5bee15..1d158c0 100644
--- a/xine/osd_manager.h
+++ b/xine/osd_manager.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: osd_manager.h,v 1.2 2013/01/15 20:33:29 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/post.c b/xine/post.c
index fd6fb26..214be22 100644
--- a/xine/post.c
+++ b/xine/post.c
@@ -129,7 +129,7 @@ static void __pplugin_update_parameters(xine_post_t *post, char *args)
         while((*p != '\0') && (*p != '='))
           p++;
 
-        if(p && strlen(p)) {
+        if(*p) {
           int param_num = 0;
 
           *p++ = '\0';
@@ -344,6 +344,7 @@ void pplugin_parse_and_store_post(fe_t *fe, int plugin_type,
 
       (*_post_elements)[i] = NULL;
       (*_post_elements_num) += num;
+      free(posts);
     }
     else {
       *_post_elements     = posts;
diff --git a/xine/post_util.h b/xine/post_util.h
index 394ccae..db3cdd5 100644
--- a/xine/post_util.h
+++ b/xine/post_util.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: post_util.h,v 1.5 2008/12/14 00:52:35 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/ts2es.c b/xine/ts2es.c
index 6de24b1..73fc1f3 100644
--- a/xine/ts2es.c
+++ b/xine/ts2es.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: ts2es.c,v 1.23 2013/10/28 11:43:43 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -247,10 +247,15 @@ buf_element_t *ts2es_put(ts2es_t *this, uint8_t *data, fifo_buffer_t *src_fifo)
   /* check if PES packet is complete */
   if (this->pes_len > 0) {
     if (this->pes_len <= bytes) {
-      this->buf->decoder_flags |= BUF_FLAG_FRAME_END;
-      result = this->buf;
-      this->buf = NULL;
-      this->pes_error = 1; /* to drop rest of data */
+      /* XXX FIXME: one call to ts2es_put may result in two output packets
+       * if stream mixes known-length and unknown-length packets. */
+      if (!result) {
+        this->buf->decoder_flags |= BUF_FLAG_FRAME_END;
+        result = this->buf;
+        this->buf = NULL;
+        this->pes_error = 1; /* to drop rest of data */
+      }
+      this->pes_len = 0;
     } else {
       this->pes_len -= bytes;
     }
@@ -305,6 +310,11 @@ ts2es_t *ts2es_init(fifo_buffer_t *dst_fifo, ts_stream_type stream_type, uint st
     case STREAM_VIDEO_VC1:
       data->xine_buf_type = BUF_VIDEO_VC1;
       break;
+#ifdef BUF_VIDEO_HEVC
+    case STREAM_VIDEO_HEVC:
+      data->xine_buf_type = BUF_VIDEO_HEVC;
+      break;
+#endif
 
     /* AUDIO (PES streams 0xc0...0xdf) */
     case  ISO_11172_AUDIO:
diff --git a/xine/ts2es.h b/xine/ts2es.h
index 72e4218..11a979f 100644
--- a/xine/ts2es.h
+++ b/xine/ts2es.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: ts2es.h,v 1.2 2009/08/18 10:04:32 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_frameoutput.c b/xine/vo_frameoutput.c
index 01f2551..b49fd72 100644
--- a/xine/vo_frameoutput.c
+++ b/xine/vo_frameoutput.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_frameoutput.c,v 1.1 2012/03/07 08:27:40 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_frameoutput.h b/xine/vo_frameoutput.h
index b861079..9fa4da8 100644
--- a/xine/vo_frameoutput.h
+++ b/xine/vo_frameoutput.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_frameoutput.h,v 1.1 2012/03/07 08:27:40 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_hook.c b/xine/vo_hook.c
index a5c463a..6dbff1b 100644
--- a/xine/vo_hook.c
+++ b/xine/vo_hook.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_hook.c,v 1.6 2011/03/10 10:03:11 durchflieger Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_hook.h b/xine/vo_hook.h
index 34aa374..e2d6fc3 100644
--- a/xine/vo_hook.h
+++ b/xine/vo_hook.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_hook.h,v 1.3 2008/12/14 01:14:54 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_lastpts.c b/xine/vo_lastpts.c
index 1b2a602..ee17ec1 100644
--- a/xine/vo_lastpts.c
+++ b/xine/vo_lastpts.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_lastpts.c,v 1.7 2012/03/10 20:56:30 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_lastpts.h b/xine/vo_lastpts.h
index 7b45a5a..cb80f67 100644
--- a/xine/vo_lastpts.h
+++ b/xine/vo_lastpts.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_lastpts.h,v 1.1 2010/01/26 11:36:21 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_osdreorder.c b/xine/vo_osdreorder.c
index 6e0b2eb..ff006d2 100644
--- a/xine/vo_osdreorder.c
+++ b/xine/vo_osdreorder.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_osdreorder.c,v 1.2 2012/03/07 08:25:37 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_osdreorder.h b/xine/vo_osdreorder.h
index 7f195e8..ea67248 100644
--- a/xine/vo_osdreorder.h
+++ b/xine/vo_osdreorder.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_osdreorder.h,v 1.1 2009/03/17 12:14:41 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_osdscaler.c b/xine/vo_osdscaler.c
index 008c0da..6360ab8 100644
--- a/xine/vo_osdscaler.c
+++ b/xine/vo_osdscaler.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_osdscaler.c,v 1.16 2014/06/23 12:14:16 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_osdscaler.h b/xine/vo_osdscaler.h
index 14a3233..fb4291c 100644
--- a/xine/vo_osdscaler.h
+++ b/xine/vo_osdscaler.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_osdscaler.h,v 1.1 2008/11/20 09:24:27 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_post.h b/xine/vo_post.h
index 639f109..ac3077a 100644
--- a/xine/vo_post.h
+++ b/xine/vo_post.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_post.h,v 1.3 2008/12/14 01:19:21 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/vo_props.h b/xine/vo_props.h
index 8185e08..c291e88 100644
--- a/xine/vo_props.h
+++ b/xine/vo_props.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: vo_props.h,v 1.5 2010/05/30 20:31:18 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine/xvdr_metronom.c b/xine/xvdr_metronom.c
index 948f9ff..240a968 100644
--- a/xine/xvdr_metronom.c
+++ b/xine/xvdr_metronom.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xvdr_metronom.c,v 1.21 2012/03/26 18:49:34 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -134,7 +134,8 @@ static void got_video_frame(metronom_t *metronom, vo_frame_t *frame)
 
   pthread_mutex_unlock(&this->mutex);
 
-  this->orig_metronom->got_video_frame (this->orig_metronom, frame);
+  if (this->orig_metronom)
+    this->orig_metronom->got_video_frame (this->orig_metronom, frame);
 
   frame->pts = pts;
 }
diff --git a/xine/xvdr_metronom.h b/xine/xvdr_metronom.h
index 158c3cb..25e7aaf 100644
--- a/xine/xvdr_metronom.h
+++ b/xine/xvdr_metronom.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xvdr_metronom.h,v 1.14 2012/03/26 18:49:34 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_fbfe_frontend.c b/xine_fbfe_frontend.c
index 8cc4ea5..254087e 100644
--- a/xine_fbfe_frontend.c
+++ b/xine_fbfe_frontend.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_fbfe_frontend.c,v 1.51 2013/08/18 07:58:29 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_frontend.c b/xine_frontend.c
index d89aee5..d473492 100644
--- a/xine_frontend.c
+++ b/xine_frontend.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend.c,v 1.127 2013/10/28 07:45:50 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -959,11 +959,11 @@ static void fe_post_unload(const fe_t *this)
 
 static void fe_post_close(const fe_t *this, const char *name, int which)
 {
-  post_plugins_t *posts = this->postplugins;
-
   if(!this)
     return;
 
+  post_plugins_t *posts = this->postplugins;
+
   if(name && !strcmp(name, "AudioVisualization")) {
     name = NULL;
     which = POST_AUDIO_VIS;
@@ -1042,13 +1042,13 @@ static int get_opt_val(const char *s, const char *opt)
 
 static void fe_post_open(const fe_t *this, const char *name, const char *args)
 {
+  if(!this || !this->xine || !this->stream || !name)
+    return;
+
   post_plugins_t *posts = this->postplugins;
   char initstr[1024];
   int found = 0;
 
-  if(!this || !this->xine || !this->stream || !name)
-    return;
-
   /* pip */
   if(!strcmp(name, "Pip")) {
     posts->post_pip_enable = 1;
diff --git a/xine_frontend.h b/xine_frontend.h
index 6e40651..98bed0e 100644
--- a/xine_frontend.h
+++ b/xine_frontend.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend.h,v 1.31 2014/01/13 09:01:03 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_frontend_cec.c b/xine_frontend_cec.c
index a79877d..892e2d3 100644
--- a/xine_frontend_cec.c
+++ b/xine_frontend_cec.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_cec.c,v 1.4 2015/04/22 07:35:15 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -31,12 +31,25 @@
 
 #ifdef HAVE_LIBCEC
 
+#if defined(CEC_LIB_VERSION_MAJOR) && CEC_LIB_VERSION_MAJOR >= 3
+#define HAVE_LIBCEC_3
+#else
+typedef void * libcec_connection_t;
+#  define libcec_initialise(c) ((void*)cec_initialise(c))
+#  define libcec_init_video_standalone(c) cec_init_video_standalone()
+#  define libcec_find_adapters(a,b,c,d) cec_find_adapters(b,c,d)
+#  define libcec_ping_adapters(c) cec_ping_adapters()
+#  define libcec_open(c,d,e) cec_open(d,e)
+#  define libcec_close(c) cec_close()
+#  define libcec_destroy(c) cec_destroy()
+#endif
+
 /* static data */
 static volatile int exit_req = 0;
 static pthread_t cec_thread;
 static int cec_hdmi_port = 0;
 static int cec_dev_type = 0; /* 0 - TV, 5 - AVR */
-
+static int cec_not_found = 0;
 
 static const struct keymap_item {
   const uint8_t map;
@@ -246,7 +259,7 @@ ICECCallbacks callbacks = {
  * configuration
  */
 
-static void libcec_config_clear(libcec_configuration *p)
+static void _libcec_config_clear(libcec_configuration *p)
 {
   memset(p, 0, sizeof(*p));
 
@@ -254,8 +267,13 @@ static void libcec_config_clear(libcec_configuration *p)
   p->baseDevice = CEC_DEFAULT_BASE_DEVICE;
   p->iHDMIPort = CEC_DEFAULT_HDMI_PORT;
   p->tvVendor = CEC_VENDOR_UNKNOWN;
+#ifdef HAVE_LIBCEC_3
+  p->clientVersion = LIBCEC_VERSION_CURRENT;
+  p->serverVersion = LIBCEC_VERSION_CURRENT;
+#else
   p->clientVersion = CEC_CLIENT_VERSION_CURRENT;
   p->serverVersion = CEC_SERVER_VERSION_CURRENT;
+#endif
   p->bAutodetectAddress = CEC_DEFAULT_SETTING_AUTODETECT_ADDRESS;
   p->bGetSettingsFromROM = CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM;
   p->bUseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE;
@@ -350,13 +368,13 @@ static int detect_hdmi_address(frontend_t *fe_gen)
   return 0;
 }
 
-static int libcec_init(void *fe_gen)
+static libcec_connection_t _libcec_init(void *fe_gen)
 {
   libcec_configuration config;
+  libcec_connection_t conn;
 
-  libcec_config_clear(&config);
+  _libcec_config_clear(&config);
 
-  config.clientVersion = CEC_CLIENT_VERSION_CURRENT;
   strncpy(config.strDeviceName, "VDR", sizeof(config.strDeviceName));
 
   config.iPhysicalAddress = detect_hdmi_address(fe_gen);
@@ -372,32 +390,35 @@ static int libcec_init(void *fe_gen)
   config.deviceTypes.types[2] = CEC_DEVICE_TYPE_TUNER;
   //config.deviceTypes.types[3] = CEC_DEVICE_TYPE_AUDIO_SYSTEM;
 
-  if (!cec_initialise(&config)) {
-    LOGMSG("cec_initialize() failed");
-    return 0;
+  if (!(conn = libcec_initialise(&config))) {
+    LOGMSG("libcec_initialize() failed");
+    return NULL;
   }
 
-  cec_init_video_standalone();
+  libcec_init_video_standalone(conn);
 
-  return 1;
+  return conn;
 }
 
 /*
  *
  */
 
-static int libcec_open(void)
+static int _libcec_open(libcec_connection_t conn)
 {
   cec_adapter devices[10];
-  int count = cec_find_adapters(devices, 10, NULL);
+  int count = libcec_find_adapters(conn, devices, 10, NULL);
   if (count < 1) {
-    LOGMSG("No HDMI-CEC adapters found");
+    if (!cec_not_found) {
+      LOGMSG("No HDMI-CEC adapters found");
+      cec_not_found = 1;
+    }
     return 0;
   }
 
   LOGMSG("%d adapters found. Opening %s", count, devices[0].comm);
 
-  if (!cec_open(devices[0].comm, 3000)) {
+  if (!libcec_open(conn, devices[0].comm, 3000)) {
     LOGMSG("error opening CEC adapter");
     return 0;
   }
@@ -407,10 +428,10 @@ static int libcec_open(void)
   return 1;
 }
 
-static int libcec_check_device(void)
+static int _libcec_check_device(libcec_connection_t conn)
 {
-  if (!cec_ping_adapters()) {
-    LOGMSG("cec_ping_adapters() failed");
+  if (!libcec_ping_adapters(conn)) {
+    LOGMSG("libcec_ping_adapters() failed");
     return 0;
   }
 
@@ -419,16 +440,20 @@ static int libcec_check_device(void)
 
 static void cleanup(void *p)
 {
-  cec_close();
-  cec_destroy();
+#ifdef HAVE_LIBCEC_3
+  libcec_connection_t conn = *(libcec_connection_t *)p;
+#endif
+  libcec_close(conn);
+  libcec_destroy(conn);
 }
 
 static void *cec_receiver_thread(void *fe_gen)
 {
+  libcec_connection_t conn;
 
   LOGDBG("started");
 
-  pthread_cleanup_push(cleanup, NULL);
+  pthread_cleanup_push(cleanup, &conn);
 
   enum { INIT, WAIT_DEVICE, RUNNING } state = INIT;
 
@@ -438,19 +463,19 @@ static void *cec_receiver_thread(void *fe_gen)
 
     switch (state) {
     case INIT:
-      if (!libcec_init(fe_gen)) {
+      if (!(conn = _libcec_init(fe_gen))) {
 	return NULL;
       }
       state = WAIT_DEVICE;
       break;
     case WAIT_DEVICE:
-      if (libcec_open()) {
+      if (_libcec_open(conn)) {
 	state = RUNNING;
       }
       usleep(5000*1000);
       break;
     case RUNNING:
-      if (!libcec_check_device()) {
+      if (!_libcec_check_device(conn)) {
         state = WAIT_DEVICE;
       }
       usleep(1000*1000);
diff --git a/xine_frontend_cec.h b/xine_frontend_cec.h
index 3fcd2f7..7db6178 100644
--- a/xine_frontend_cec.h
+++ b/xine_frontend_cec.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_cec.h,v 1.1 2014/01/14 08:21:33 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_frontend_internal.h b/xine_frontend_internal.h
index 471451b..d36785e 100644
--- a/xine_frontend_internal.h
+++ b/xine_frontend_internal.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_internal.h,v 1.11 2012/03/19 11:51:21 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_frontend_kbd.c b/xine_frontend_kbd.c
index cbe2376..afbe5b1 100644
--- a/xine_frontend_kbd.c
+++ b/xine_frontend_kbd.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_kbd.c,v 1.4 2012/06/06 07:39:56 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_frontend_kbd.h b/xine_frontend_kbd.h
index c0b25ea..55e9666 100644
--- a/xine_frontend_kbd.h
+++ b/xine_frontend_kbd.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_kbd.h,v 1.2 2011/02/28 13:41:08 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_frontend_lirc.c b/xine_frontend_lirc.c
index 9cd45ee..f76725b 100644
--- a/xine_frontend_lirc.c
+++ b/xine_frontend_lirc.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_lirc.c,v 1.27 2012/02/17 09:15:41 phintuka Exp $
+ * $Id$
  *
  */
 /*
diff --git a/xine_frontend_lirc.h b/xine_frontend_lirc.h
index 3e2f7c4..3db4739 100644
--- a/xine_frontend_lirc.h
+++ b/xine_frontend_lirc.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_lirc.h,v 1.4 2011/02/28 13:42:42 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_frontend_main.c b/xine_frontend_main.c
index 9293ad8..edb21a3 100644
--- a/xine_frontend_main.c
+++ b/xine_frontend_main.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_frontend_main.c,v 1.105 2014/01/14 08:21:33 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_input_vdr.c b/xine_input_vdr.c
index 7b655d3..a6808ae 100644
--- a/xine_input_vdr.c
+++ b/xine_input_vdr.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_input_vdr.c,v 1.366 2014/06/23 12:20:28 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -52,7 +52,7 @@
 # error XINE_VERSION_CODE undefined !
 #endif
 
-#if XINE_VERSION_CODE >= 10190
+#if XINE_VERSION_CODE >= 10190 && XINE_VERSION_CODE < 10207
 # include "features.h"
 # ifdef HAVE_LIBAVUTIL
 #  include <libavutil/mem.h>
@@ -136,7 +136,7 @@ typedef struct {
 #  include <linux/unistd.h> /* syscall(__NR_gettid) */
 #endif
 
-static const char module_revision[] = "$Id: xine_input_vdr.c,v 1.366 2014/06/23 12:20:28 phintuka Exp $";
+static const char module_revision[] = "$Id$";
 static const char log_module_input_vdr[] = "[input_vdr] ";
 #define LOG_MODULENAME log_module_input_vdr
 #define SysLogLevel    iSysLogLevel
@@ -1284,6 +1284,46 @@ static void signal_buffer_not_empty(vdr_input_plugin_t *this)
 #if XINE_VERSION_CODE < 10190
 #  define fifo_buffer_new(stream, n, s) _x_fifo_buffer_new(n, s)
 #else
+static void fifo_buffer_dispose (fifo_buffer_t *this)
+{
+  buf_element_t *buf, *next;
+  int received = 0;
+
+  this->clear( this );
+  buf = this->buffer_pool_top;
+
+  while (buf != NULL) {
+
+    next = buf->next;
+
+    free (buf->extra_info);
+    free (buf);
+    received++;
+
+    buf = next;
+  }
+
+  while (received < this->buffer_pool_capacity) {
+
+    buf = this->get(this);
+
+    free(buf->extra_info);
+    free(buf);
+    received++;
+  }
+
+#if XINE_VERSION_CODE >= 10207
+  xine_free_aligned (this->buffer_pool_base);
+#else
+  av_free (this->buffer_pool_base);
+#endif
+  pthread_mutex_destroy(&this->mutex);
+  pthread_cond_destroy(&this->not_empty);
+  pthread_mutex_destroy(&this->buffer_pool_mutex);
+  pthread_cond_destroy(&this->buffer_pool_cond_not_empty);
+  free (this);
+}
+
 static fifo_buffer_t *fifo_buffer_new (xine_stream_t *stream, int num_buffers, uint32_t buf_size)
 {
   fifo_buffer_t *ref = stream->video_fifo;
@@ -1304,7 +1344,7 @@ static fifo_buffer_t *fifo_buffer_new (xine_stream_t *stream, int num_buffers, u
   this->size                = ref->size;
   this->num_free            = ref->num_free;
   this->data_size           = ref->data_size;
-  this->dispose             = ref->dispose;
+  this->dispose             = fifo_buffer_dispose;
   this->register_alloc_cb   = ref->register_alloc_cb;
   this->register_get_cb     = ref->register_get_cb;
   this->register_put_cb     = ref->register_put_cb;
@@ -1318,8 +1358,11 @@ static fifo_buffer_t *fifo_buffer_new (xine_stream_t *stream, int num_buffers, u
    * init buffer pool, allocate nNumBuffers of buf_size bytes each
    */
 
+#if XINE_VERSION_CODE >= 10207
+  multi_buffer = this->buffer_pool_base = xine_malloc_aligned (num_buffers * buf_size);
+#else
   multi_buffer = this->buffer_pool_base = av_mallocz (num_buffers * buf_size);
-
+#endif
   pthread_mutex_init (&this->buffer_pool_mutex, NULL);
   pthread_cond_init (&this->buffer_pool_cond_not_empty, NULL);
 
@@ -5102,7 +5145,7 @@ static void vdr_plugin_dispose (input_plugin_t *this_gen)
 
     if(fd >= 0 && this->tcp) {
       LOGDBG("Shutdown data");
-      setsockopt(fc, SOL_SOCKET, SO_LINGER, &l, sizeof(struct linger));
+      setsockopt(fd, SOL_SOCKET, SO_LINGER, &l, sizeof(struct linger));
       shutdown(fd, SHUT_RDWR);
     }
   }
@@ -5325,6 +5368,9 @@ static int alloc_udp_data_socket(int firstport, int trycount, int *port)
   name.sin_addr.s_addr = htonl(INADDR_ANY);
 
   fd = socket(PF_INET, SOCK_DGRAM, 0/*IPPROTO_UDP*/);
+  if (fd < 0) {
+    return -1;
+  }
 
   set_recv_buffer_size(fd, KILOBYTE(512));
 
@@ -5600,6 +5646,7 @@ retry_request:
   if(readline_control(this, cmd, sizeof(cmd)-1, 4) < 6 ||
      strncmp(cmd, "UDP OK", 6)) {
     LOGMSG("Server does not support UDP ? (%s)", cmd);
+    close(fd);
     return -1;
   }
 
@@ -5705,7 +5752,6 @@ static int connect_tcp_data_stream(vdr_input_plugin_t *this, const char *host,
 static int connect_pipe_data_stream(vdr_input_plugin_t *this)
 {
   char tmpbuf[256];
-  int fd_data = -1;
 
   /* check if IP address matches */
   if(!strstr(this->mrl, "127.0.0.1")) {
@@ -5730,6 +5776,7 @@ static int connect_pipe_data_stream(vdr_input_plugin_t *this)
   } else if(strncmp(tmpbuf, "PIPE /", 6)) {
     LOGMSG("Server does not support pipes ? (%s)", tmpbuf);
   } else {
+    int fd_data;
 
     LOGMSG("Connecting (data) to pipe://%s", tmpbuf+5);
     if((fd_data = open(tmpbuf+5, O_RDONLY|O_NONBLOCK)) < 0) {
@@ -5745,10 +5792,11 @@ static int connect_pipe_data_stream(vdr_input_plugin_t *this)
 	return fd_data;
       }
       LOGMSG("Data stream connection failed (PIPE)");
+      close(fd_data);
     } 
   }
 
-  close(fd_data);
+
   return -1;
 }
 
@@ -5854,8 +5902,10 @@ static int vdr_plugin_open_net (input_plugin_t *this_gen)
 	LOGMSG("Data stream connected (TCP)");
       } else {
 	/* failed */
-	close(this->fd_data);
-	close(this->fd_control);
+        if (this->fd_data >= 0)
+          close(this->fd_data);
+        if (this->fd_control >= 0)
+          close(this->fd_control);
 	this->fd_control = this->fd_data = -1;
 	return 0;
       }
diff --git a/xine_input_vdr.h b/xine_input_vdr.h
index fd54c5d..b3b4fad 100644
--- a/xine_input_vdr.h
+++ b/xine_input_vdr.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_input_vdr.h,v 1.12 2012/03/10 23:51:10 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_input_vdr_mrl.h b/xine_input_vdr_mrl.h
index 1ea6188..c27c36b 100644
--- a/xine_input_vdr_mrl.h
+++ b/xine_input_vdr_mrl.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_input_vdr_mrl.h,v 1.1 2008/11/11 23:46:41 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_input_vdr_net.h b/xine_input_vdr_net.h
index 501543a..e0e1901 100644
--- a/xine_input_vdr_net.h
+++ b/xine_input_vdr_net.h
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_input_vdr_net.h,v 1.16 2010/07/19 13:39:24 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_post_audiochannel.c b/xine_post_audiochannel.c
index 7b20381..5a6b10f 100644
--- a/xine_post_audiochannel.c
+++ b/xine_post_audiochannel.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_post_audiochannel.c,v 1.9 2012/01/09 07:36:52 phintuka Exp $
+ * $Id$
  *
  */
 
diff --git a/xine_post_autocrop.c b/xine_post_autocrop.c
index 7315113..683c8a2 100644
--- a/xine_post_autocrop.c
+++ b/xine_post_autocrop.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_post_autocrop.c,v 1.52 2011/10/30 16:59:02 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -223,16 +223,13 @@ typedef struct autocrop_post_plugin_s
 #endif
 
 # if defined(__SSE__)
-#  warning Compiling with SSE support
 #  include <xmmintrin.h>
 # elif defined(__MMX__)
-#  warning Compiling with MMX support
 #  include <mmintrin.h>
 # endif
 
 #if defined(__WORDSIZE)
 #  if __WORDSIZE == 64
-#    warning Compiling with 64-bit integer support
 #    define ENABLE_64BIT (sizeof(int) > 32)
 #  endif
 #endif
@@ -513,7 +510,7 @@ static int blank_line_Y_sse(uint8_t *data, int length)
   static const __m128_wrapper gmask = {{YNOISEFILTER32, YNOISEFILTER32,
 					YNOISEFILTER32, YNOISEFILTER32}};
   __m128 *data128 = (__m128*)(((long int)(data) + 32 + 15) & (~15));
-  register __m128 sum1, sum2, zero, mask;
+  register __m128 sum1, sum2, zero;
 
   length -= 64; /* skip borders (2 x 32 pixels) */
   length /= 16; /* 16 bytes / loop */
@@ -528,7 +525,6 @@ static int blank_line_Y_sse(uint8_t *data, int length)
    */
 
   zero = _mm_setzero_ps();
-  mask = gmask.m128;
   sum1 = zero;
   sum2 = zero;
 
diff --git a/xine_post_swscale.c b/xine_post_swscale.c
index 850561d..8efed5b 100644
--- a/xine_post_swscale.c
+++ b/xine_post_swscale.c
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- * $Id: xine_post_swscale.c,v 1.16 2011/10/30 16:59:02 phintuka Exp $
+ * $Id$
  *
  * Simple (faster) resize for avisynth
  *     Copyright (C) 2002 Tom Barry
diff --git a/xine_sxfe_frontend.c b/xine_sxfe_frontend.c
index dede8d0..ded1a42 100644
--- a/xine_sxfe_frontend.c
+++ b/xine_sxfe_frontend.c
@@ -4,7 +4,7 @@
  * See the main source file 'xineliboutput.c' for copyright information and
  * how to reach the author.
  *
- * $Id: xine_sxfe_frontend.c,v 1.209 2014/07/01 19:17:14 phintuka Exp $
+ * $Id$
  *
  */
 
@@ -1022,6 +1022,15 @@ static int hud_osd_command(frontend_t *this_gen, struct osd_command_s *cmd)
     if (!(cmd->flags & OSDFLAG_TOP_LAYER))
       return 1;
 
+    if (this->osd_height > HUD_MAX_HEIGHT ||
+        this->osd_width  > HUD_MAX_WIDTH) {
+      // XXX TODO crop or scale ?
+      // really dimensions should be runtime param, not constant...
+      LOGMSG("HUD ERROR: Unsupported OSD size: %dx%d is larger than %dx%d",
+             this->osd_width, this->osd_height, HUD_MAX_WIDTH, HUD_MAX_HEIGHT);
+      return 1;
+    }
+
     XLockDisplay(this->display);
     switch (cmd->cmd) {
     case OSD_Nop: /* Do nothing ; used to initialize delay_ms counter */
@@ -2797,7 +2806,18 @@ static void XConfigureEvent_handler(sxfe_t *this, XConfigureEvent *cev)
 
       /* inform VDR about new size */
       char str[128];
-      snprintf(str, sizeof(str), "INFO WINDOW %dx%d", this->x.width, this->x.height);
+      int w = this->x.width;
+      int h = this->x.height;
+#ifdef HAVE_XRENDER
+      // XXX quick fix for UHD displays. Should be fixed in overlay handling, not here.
+      if (this->hud) {
+        if (w > HUD_MAX_WIDTH)
+          w = HUD_MAX_WIDTH;
+        if (h > HUD_MAX_HEIGHT)
+          h = HUD_MAX_HEIGHT;
+      }
+#endif
+      snprintf(str, sizeof(str), "INFO WINDOW %dx%d", w, h);
       this->x.fe.send_event((frontend_t*)this, str);
     }
   }
diff --git a/xineliboutput.c b/xineliboutput.c
index a5c281f..b28f795 100644
--- a/xineliboutput.c
+++ b/xineliboutput.c
@@ -21,7 +21,7 @@
  *
  * xineliboutput.c: VDR Plugin interface
  *
- * $Id: xineliboutput.c,v 1.61 2014/01/31 08:58:30 rofafor Exp $
+ * $Id$
  *
  */
 
@@ -43,7 +43,7 @@
 
 //---------------------------------plugin-------------------------------------
 
-static const char *VERSION        = "2.0.0-cvs";
+static const char *VERSION        = "2.0.0-git";
 static const char *DESCRIPTION    = trNOOP("X11/xine-lib output plugin");
 static const char *MAINMENUENTRY  = trNOOP("Media Player");
 
@@ -109,7 +109,7 @@ const char cmdLineHelp[] =
 "                           fbfe    (framebuffer)\n"
 "                           none    (only remote frontends)\n"
 "  -r PORT   --remote=PORT  Listen PORT for remote clients\n"
-"                           (default "LISTEN_PORT_S")\n"
+"                           (default " LISTEN_PORT_S ")\n"
 "                           none or 0 disables remote mode\n"
 "                           Also local interface address can be specified:\n"
 "                           --remote=<ip>:<port>  (default is all interfaces)\n"
@@ -160,6 +160,8 @@ const char cmdLineHelp[] =
 "                           there are active frontend(s)\n"
 "  -c        --exit-on-close  Exit vdr when local frontend window is closed\n"
 "  -C        --config=file  Use xine-lib config file\n"
+"  -t        --truecolor    Support True Color OSD if no client is connected\n"
+"  -s        --auto-suspend Trigger vdr-suspendoutput when there are no clients\n"
 ;
 
 const char *cPluginXinelibOutput::CommandLineHelp(void)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-vdr-dvb/vdr-plugin-xineliboutput.git



More information about the pkg-vdr-dvb-changes mailing list